diff mbox

[2/3] Makefile: add selfcheck target

Message ID CANeU7Q=DzoQqdBebjFh6H3WLQOA2R0mKnd9iR4aeEGYCOCxyDg@mail.gmail.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Christopher Li July 17, 2017, 3:59 a.m. UTC
"make selfcheck" will invoke sparse to check its own source code.
It is different than the "make C=1" in linux kernel because
sparse executable need to be compiled first.

"make <filename>.sc" will invoke the sparse to check specific C source
file <filename>.c

For example: "make parse.sc"

Signed-of-By: Christopher Li <sparse@chrisli.org>
---
 Makefile | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/Makefile b/Makefile
index 0706d8d..ae81586 100644
--- a/Makefile
+++ b/Makefile
@@ -72,7 +72,8 @@  GTK2_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0)
 PROGRAMS += test-inspect
 INST_PROGRAMS += test-inspect
 test-inspect_EXTRA_DEPS := ast-model.o ast-view.o ast-inspect.o
-test-inspect.o $(test-inspect_EXTRA_DEPS): BASIC_CFLAGS += $(GTK2_CFLAGS)
+test-inspect_OBJS := test-inspect.o $(test-inspect_EXTRA_DEPS)
+$(test-inspect_OBJS) $(test-inspect_OBJS:.o=.sc): CFLAGS += $(GTK2_CFLAGS)
 test-inspect_EXTRA_OBJS := $(GTK2_LIBS)
 else
 $(warning Your system does not have libgtk2, disabling test-inspect)
@@ -126,6 +127,7 @@  LIBS=$(LIB_FILE)
 V      = @
 Q      = $(V:1=)
 QUIET_CC      = $(Q:@=@echo    '     CC       '$@;)
+QUIET_CHECK   = $(Q:@=@echo    '     CHECK    '$<;)
 QUIET_AR      = $(Q:@=@echo    '     AR       '$@;)
 QUIET_GEN     = $(Q:@=@echo    '     GEN      '$@;)
 QUIET_LINK    = $(Q:@=@echo    '     LINK     '$@;)
@@ -193,11 +195,17 @@  include $(DEP_FILES)
 endif

 LIBXML_CFLAGS := $(shell $(PKG_CONFIG) --cflags libxml-2.0)
-c2xml.o: CFLAGS += $(LIBXML_CFLAGS)
+c2xml.o c2xml.sc: CFLAGS += $(LIBXML_CFLAGS)

 %.o: %.c $(LIB_H)
  $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<

+%.sc: %.c sparse
+ $(QUIET_CHECK) ./sparse -c $(ALL_CFLAGS) $<
+
+selfcheck: $(LIB_OBJS:.o=.sc) $(addsuffix .sc, $(PROGRAMS))
+
+
 clean: clean-check
  rm -f *.[oa] .*.d *.so $(PROGRAMS) $(SLIB_FILE) pre-process.h sparse.pc