add coccicheck make target

Provide a simple way to run Coccinelle against all source files, in the form of a Makefile target. Running "make coccicheck" applies each .cocci file in contrib/coccinelle/ on all source files. It generates a .patch file for each .cocci file, containing the actual changes for effecting the transformations described by the semantic patches. Non-empty .patch files are reported. They can be applied to the work tree using "patch -p0", but should be checked to e.g. make sure they don't screw up formatting or create circular references. Coccinelle's diagnostic output (stderr) is piped into .log files. Linux has a much more elaborate make target of the same name; let's start nice and easy. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Sep 15, 2016 at 20:30 UTC 63f0a758a06f9af81717683185016275cb201190
1 file changed +14
Makefile
+14
@@ -456,6 +456,7 @@ CURL_CONFIG = curl-config
456 PTHREAD_LIBS = -lpthread
457 PTHREAD_CFLAGS =
458 GCOV = gcov
459 +SPATCH = spatch
460
461 export TCL_PATH TCLTK_PATH
462
@@ -2296,6 +2297,18 @@ check: common-cmds.h
2297 exit 1; \
2298 fi
2299
2300 +C_SOURCES = $(patsubst %.o,%.c,$(C_OBJ))
2301 +%.cocci.patch: %.cocci $(C_SOURCES)
2302 + @echo ' ' SPATCH $<; \
2303 + for f in $(C_SOURCES); do \
2304 + $(SPATCH) --sp-file $< $$f; \
2305 + done >$@ 2>$@.log; \
2306 + if test -s $@; \
2307 + then \
2308 + echo ' ' SPATCH result: $@; \
2309 + fi
2310 +coccicheck: $(patsubst %.cocci,%.cocci.patch,$(wildcard contrib/coccinelle/*.cocci))
2311 +
2312 ### Installation rules
2313
2314 ifneq ($(filter /%,$(firstword $(template_dir))),)
@@ -2487,6 +2500,7 @@ clean: profile-clean coverage-clean
2500 $(RM) -r $(GIT_TARNAME) .doc-tmp-dir
2501 $(RM) $(GIT_TARNAME).tar.gz git-core_$(GIT_VERSION)-*.tar.gz
2502 $(RM) $(htmldocs).tar.gz $(manpages).tar.gz
2503 + $(RM) contrib/coccinelle/*.cocci.patch*
2504 $(MAKE) -C Documentation/ clean
2505 ifndef NO_PERL
2506 $(MAKE) -C gitweb clean