blob: b3ddcf671b46d31ea56760b3cd717bf3fa53763b [file] [log] [blame]
Andrew Jefferyf34db312018-03-09 15:27:03 +10301#!/bin/sh
2
3set -euo
4
5set -x
6
7[ -f .clang-format ] && rm .clang-format
8
William A. Kennington IIIb7c49b22018-10-11 13:54:58 -07009# Use the provided clang-format, only define a version
10# if we don't have one provided already
11export CLANG_FORMAT="${CLANG_FORMAT:-clang-format-6.0}"
Andrew Jefferyf34db312018-03-09 15:27:03 +103012
13# phosphor-mboxd is a fork of mboxbridge, the reference mbox daemon
14# implementation. mboxbridge is C written with the style of the Linux kernel.
15#
16# phosphor-mboxd extended the reference in C++, and used the OpenBMC C++ style.
17#
18# To remain compliant with the C++ style guide *and* preserve source
19# compatibility with the upstream reference implementation, use two separate
20# styles.
21#
22# Further, clang-format supports describing styles for multiple languages in
23# the one .clang-format file, but *doesn't* make a distinction between C and
24# C++. So we need two files. It gets worse: the -style parameter doesn't take
25# the path to a configuration file as an argument, you instead specify the
26# literal 'file' and it goes looking for a .clang-format or _clang-format file.
27# So now we need to symlink different files in place before calling
28# ${CLANG_FORMAT}. Everything is terrible.
29#
30# ln -sf .clang-format-c .clang-format
31# git ls-files | grep '\.[ch]$' | xargs "${CLANG_FORMAT}" -i -style=file
32
33ln -sf .clang-format-c++ .clang-format
34git ls-files | grep '\.[ch]pp$' | xargs "${CLANG_FORMAT}" -i -style=file
35
36rm .clang-format