From ea471349bfe6f6a95877947db18f72c4cf693630 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 15 Aug 2014 10:23:32 +0200 Subject: build: Add build flag to enable sparse checking of C source files Similar to the 'make C=1' for the Linux kernel, wire up the sparse command for our build system in a similar fashion. Use 'make C=1 [tool]' to check the source files using sparse. Of course, the sparse tool needs to be installed and available in your $PATH for this to work. Signed-off-by: Tobias Klauser --- Cmds | 7 +++++++ INSTALL | 1 + Makefile | 3 +++ Misc | 1 + Template | 1 + 5 files changed, 13 insertions(+) diff --git a/Cmds b/Cmds index 9d2675f..247a972 100644 --- a/Cmds +++ b/Cmds @@ -14,6 +14,13 @@ else STRIP = $(Q)echo -e " STRIP\t$@" && $(CROSS_COMPILE)strip endif +# sparse related +ifeq ($(C), 1) + CHECK = $(Q)echo -e " CHECK\t$<" && sparse +else + CHECK = $(Q)true +endif + # Flex/bison related LEX = $(Q)echo -e " LEX\t$<" && flex YAAC = $(Q)echo -e " YAAC\t$<" && bison diff --git a/INSTALL b/INSTALL index 830f6a1..ee0a562 100644 --- a/INSTALL +++ b/INSTALL @@ -13,6 +13,7 @@ What additional tools next to your build-chain are required? - ccache (optional) - gpg (optional) + - sparse (optional) - pkg-config: all - flex, bison: bpfc, trafgen diff --git a/Makefile b/Makefile index 03eaa61..c2735fa 100644 --- a/Makefile +++ b/Makefile @@ -107,6 +107,9 @@ ifeq ("$(origin CROSS_LD_LIBRARY_PATH)", "command line") LDFLAGS += -L$(CROSS_LD_LIBRARY_PATH) endif +CHECKFLAGS = -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix \ + -Wbitwise -Wnoreturn-void + VERSION_SHORT = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) VERSION_STRING = "$(VERSION_SHORT)$(CONFIG_RC)" VERSION_LONG = "$(VERSION_SHORT)$(CONFIG_RC) ($(NAME))" diff --git a/Misc b/Misc index 8c826ed..a56a0b1 100644 --- a/Misc +++ b/Misc @@ -114,4 +114,5 @@ help: $(Q)echo " CPPFLAGS=\"-I ...\" - Additional CFLAGS for compilation" $(Q)echo " LDFLAGS=\"-L ...\" - Additional LDFLAGS for compilation" $(Q)echo " CCACHE= - Do not use ccache for compilation" + $(Q)echo " C=1 - Check all C source files with sparse" $(Q)echo " Q= - Show verbose garbage" diff --git a/Template b/Template index e3093ea..4978eed 100644 --- a/Template +++ b/Template @@ -21,5 +21,6 @@ define TOOL_templ $(1)/%.tab.o: $(1)/%.tab.c $$(CC) $$(CFLAGS) -o $$@ -c $$< $(1)/%.o: %.c + $$(CHECK) $$(CFLAGS) $$(CHECKFLAGS) $$< $$(CC) $$(CFLAGS) -o $(1)/$$(shell basename $$@) -c $$< endef -- cgit v1.2.3-54-g00ecf