blob: a824ad13812c521f02a02b360ae54edc6d46b563 [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
9CLANG_FORMAT="$(which clang-format-5.0)"
10
11# phosphor-mboxd is a fork of mboxbridge, the reference mbox daemon
12# implementation. mboxbridge is C written with the style of the Linux kernel.
13#
14# phosphor-mboxd extended the reference in C++, and used the OpenBMC C++ style.
15#
16# To remain compliant with the C++ style guide *and* preserve source
17# compatibility with the upstream reference implementation, use two separate
18# styles.
19#
20# Further, clang-format supports describing styles for multiple languages in
21# the one .clang-format file, but *doesn't* make a distinction between C and
22# C++. So we need two files. It gets worse: the -style parameter doesn't take
23# the path to a configuration file as an argument, you instead specify the
24# literal 'file' and it goes looking for a .clang-format or _clang-format file.
25# So now we need to symlink different files in place before calling
26# ${CLANG_FORMAT}. Everything is terrible.
27#
28# ln -sf .clang-format-c .clang-format
29# git ls-files | grep '\.[ch]$' | xargs "${CLANG_FORMAT}" -i -style=file
30
31ln -sf .clang-format-c++ .clang-format
32git ls-files | grep '\.[ch]pp$' | xargs "${CLANG_FORMAT}" -i -style=file
33
34rm .clang-format