@@ -28,6 +28,11 @@ TEST_ARGS = gtest/gtest-all.cc gtest/gtest_main.cc $(OPENSSL_SUPPORT) $(ZLIB_SUP
28
28
# OSS-Fuzz will define its own value for LIB_FUZZING_ENGINE.
29
29
LIB_FUZZING_ENGINE ?= standalone_fuzz_target_runner.o
30
30
31
+ CLANG_FORMAT = clang-format
32
+ REALPATH = $(shell which grealpath 2>/dev/null || which realpath 2>/dev/null)
33
+ STYLE_CHECK_FILES = $(filter-out httplib.h httplib.cc, \
34
+ $(wildcard example/* .h example/* .cc fuzzing/* .h fuzzing/* .cc * .h * .cc ../httplib.h) )
35
+
31
36
all : test test_split
32
37
./test
33
38
@@ -45,6 +50,28 @@ test_split : test.cc ../httplib.h httplib.cc Makefile cert.pem
45
50
check_abi :
46
51
@./check-shared-library-abi-compatibility.sh
47
52
53
+ .PHONY : style_check
54
+ style_check : $(STYLE_CHECK_FILES )
55
+ @for file in $(STYLE_CHECK_FILES ) ; do \
56
+ $(CLANG_FORMAT ) $$ file > $$ file.formatted; \
57
+ if ! diff -u $$ file $$ file.formatted; then \
58
+ file2=$$($(REALPATH ) --relative-to=.. $$file) ; \
59
+ printf " \n%*s\n" 80 | tr ' ' ' #' ; \
60
+ printf " ##%*s##\n" 76; \
61
+ printf " ## %-70s ##\n" " $$ file2 not properly formatted. Please run clang-format." ; \
62
+ printf " ##%*s##\n" 76; \
63
+ printf " %*s\n\n" 80 | tr ' ' ' #' ; \
64
+ failed=1; \
65
+ fi ; \
66
+ rm -f $$ file.formatted; \
67
+ done ; \
68
+ if [ -n " $$ failed" ]; then \
69
+ echo " Style check failed for one or more files. See above for details." ; \
70
+ false ; \
71
+ else \
72
+ echo " All files are properly formatted." ; \
73
+ fi
74
+
48
75
test_proxy : test_proxy.cc ../httplib.h Makefile cert.pem
49
76
$(CXX ) -o $@ -I.. $(CXXFLAGS ) test_proxy.cc $(TEST_ARGS )
50
77
0 commit comments