Skip to content

Commit c526436

Browse files
committed
Add reformat target for consistent code formatting.
Signed-off-by: Victor Toni <[email protected]>
1 parent f47644d commit c526436

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

.clang-format

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
Language: Cpp
2+
3+
IndentWidth: 4
4+
ContinuationIndentWidth: 8
5+
6+
ColumnLimit: 120
7+
8+
AlignAfterOpenBracket: false
9+
10+
AlignConsecutiveAssignments: true
11+
12+
# not supported in clang-format-3.7
13+
# supported in clang-format-3.8 and above
14+
AlignConsecutiveDeclarations: true
15+
16+
AlignTrailingComments: true
17+
18+
AllowAllParametersOfDeclarationOnNextLine: true
19+
20+
AllowShortBlocksOnASingleLine: false
21+
AllowShortFunctionsOnASingleLine: false
22+
AllowShortIfStatementsOnASingleLine: false
23+
AllowShortLoopsOnASingleLine: false
24+
25+
# Control of individual brace wrapping cases
26+
# not supported in clang-format-3.7
27+
# supported in clang-format-3.8 and above
28+
BraceWrapping: {
29+
AfterClass: 'true'
30+
AfterControlStatement: 'false'
31+
AfterEnum: 'true'
32+
AfterFunction: 'true'
33+
AfterNamespace: 'true'
34+
AfterStruct: 'true'
35+
AfterUnion: 'true'
36+
BeforeCatch: 'true'
37+
BeforeElse: 'false'
38+
IndentBraces: 'false'
39+
}
40+
41+
BreakBeforeBraces: Stroustrup
42+
43+
IndentCaseLabels: true
44+
45+
KeepEmptyLinesAtTheStartOfBlocks: true
46+
47+
MaxEmptyLinesToKeep: 1
48+
49+
# Pointer is aligned to right side
50+
PointerAlignment: Right
51+
52+
# High penalty to avoid line break just after return type
53+
PenaltyReturnTypeOnItsOwnLine: 10000
54+
55+
SpaceAfterCStyleCast: true
56+
57+
SpacesInParentheses: false
58+
SpaceInEmptyParentheses: false
59+
SpaceBeforeParens: ControlStatements
60+
61+
UseTab: Never

Makefile.am

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,15 @@ ChangeLog:
88
AUTHORS: ChangeLog
99
( echo "Authors and contributors, in alphabetical order: "; echo; \
1010
sed -r "s/^Author: (.*)/\1/;t;d" $< | sort -u ) > $@
11+
12+
if HAVE_CLANG_FORMAT
13+
14+
.PHONY: reformat
15+
16+
reformat:
17+
@echo "Reformatting header files..."
18+
@CLANG_FORMAT@ -style=file -i `find . -name "*.h"`
19+
@echo "Reformatting C files..."
20+
@CLANG_FORMAT@ -style=file -i `find . -name "*.c"`
21+
22+
endif

configure.ac

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ AC_CONFIG_SRCDIR([src/igmpproxy.c])
55
AC_CONFIG_HEADERS([config.h])
66
AC_PROG_CC_C99
77

8+
AC_CHECK_PROGS(
9+
[CLANG_FORMAT], [clang-format clang-format-4.0 clang-format-3.9],
10+
[AC_MSG_ERROR([clang-format was not not found during configure.])]
11+
)
12+
AM_CONDITIONAL([HAVE_CLANG_FORMAT], [test -n "$CLANG_FORMAT"])
13+
814
AC_CANONICAL_HOST
915
case $host_os in
1016
linux*|uclinux*) os=linux;;

0 commit comments

Comments
 (0)