linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] Makefile: adding debug version of sparse
@ 2017-08-13 19:08 Christopher Li
  2017-08-13 19:31 ` Luc Van Oostenryck
  0 siblings, 1 reply; 10+ messages in thread
From: Christopher Li @ 2017-08-13 19:08 UTC (permalink / raw)
  To: Linux-Sparse; +Cc: Luc Van Oostenryck

The debug version has the -DSPARSE_DEBUG enabled.
It is intended to include more verification in the
debug version. For now the debug version remain
the same as the release version.

Because the debug version has different compile flags,
all *.o file need to be recompile under the debug flag.
These debug version object file is stored in  debug/
directory.

<name>-dbg is the finial debug version of the
program <name>.

Full compile time is doubled because every thing
needs to compile twice. One for release version.
One for debug version.

Signed-off-by: Christopher Li <sparse@chrisli.org>
---
 Makefile | 38 +++++++++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index 48e1f50..6660220 100644
--- a/Makefile
+++ b/Makefile
@@ -14,6 +14,7 @@ OS = linux
 CC = gcc
 CFLAGS = -O2 -finline-functions -fno-strict-aliasing -g
 CFLAGS += -Wall -Wwrite-strings
+DBG_CFLAGS = $(ALL_CFLAGS) -DSPARSE_DEBUG
 LDFLAGS += -g
 LD = gcc
 AR = ar
@@ -83,7 +84,9 @@ PROGRAMS += test-inspect
 INST_PROGRAMS += test-inspect
 test-inspect_EXTRA_DEPS := ast-model.o ast-view.o ast-inspect.o
 test-inspect_OBJS := test-inspect.o $(test-inspect_EXTRA_DEPS)
-$(test-inspect_OBJS) $(test-inspect_OBJS:.o=.sc): CFLAGS += $(GTK_CFLAGS)
+
+$(test-inspect_OBJS) $(test-inspect_OBJS:.o=.sc) \
+$(addprefix debug/, $(test-inspect_OBJS) $(test-inspect_OBJS:.o=.sc))
: CFLAGS += $(GTK_CFLAGS)
 test-inspect_EXTRA_OBJS := $(GTK_LIBS)
 else
 $(warning Your system does not have gtk3/gtk2, disabling test-inspect)
@@ -165,8 +168,13 @@ SED_PC_CMD = 's|@version@|$(VERSION)|g; \
 # Allow users to override build settings without dirtying their trees
 -include local.mk

+DBG_PROGRAMS := $(addprefix debug/, $(addsuffix -dbg, $(PROGRAMS)))
+DBG_LIB_FILE := $(addprefix debug/, $(LIB_FILE))
+DBG_LIB_OBJS := $(addprefix debug/, $(LIB_OBJS))
+DBG_SLIB_FILE := $(addprefix debug/, $(SLIB_FILE))
+DBG_LIBS := $(addprefix debug/, $(LIBS))

-all: $(PROGRAMS) sparse.pc
+all: $(PROGRAMS) $(DBG_PROGRAMS) sparse.pc

 all-installable: $(INST_PROGRAMS) $(LIBS) $(LIB_H) sparse.pc

@@ -189,14 +197,24 @@ sparse.pc: sparse.pc.in
 compile_EXTRA_DEPS = compile-i386.o

 $(foreach p,$(PROGRAMS),$(eval $(p): $($(p)_EXTRA_DEPS) $(LIBS)))
+$(foreach p,$(PROGRAMS),$(eval debug/$(p)-dbg: $(addprefix debug/,
$($(p)_EXTRA_DEPS)) $(DBG_LIBS)))
+
+
 $(PROGRAMS): % : %.o
  $(QUIET_LINK)$(LD) $(LDFLAGS) -o $@ $^ $($@_EXTRA_OBJS)
+$(DBG_PROGRAMS): debug/%-dbg : debug/%.o
+ $(eval EXTRA := $($(@F:-dbg=)_EXTRA_OBJS))
+ $(QUIET_LINK)$(LD) $(LDFLAGS) -o $@ $^ $(EXTRA)

 $(LIB_FILE): $(LIB_OBJS)
  $(QUIET_AR)$(AR) rcs $@ $(LIB_OBJS)
+$(DBG_LIB_FILE): $(DBG_LIB_OBJS)
+ $(QUIET_AR)$(AR) rcs $@ $(DBG_LIB_OBJS)

 $(SLIB_FILE): $(LIB_OBJS)
  $(QUIET_LINK)$(CC) $(LDFLAGS) -Wl,-soname,$@ -shared -o $@ $(LIB_OBJS)
+$(DBG_SLIB_FILE): $(DBG_LIB_OBJS)
+ $(QUIET_LINK)$(CC) $(LDFLAGS) -Wl,-soname,$@ -shared -o $@ $(DBG_LIB_OBJS)

 DEP_FILES := $(wildcard .*.o.d)

@@ -204,21 +222,31 @@ ifneq ($(DEP_FILES),)
 include $(DEP_FILES)
 endif

-c2xml.o c2xml.sc: CFLAGS += $(LIBXML_CFLAGS)
+c2xml.o c2xml.sc debug/c2xml.o debug/c2xml.sc: CFLAGS += $(LIBXML_CFLAGS)

-pre-process.sc: CHECKER_FLAGS += -Wno-vla
+pre-process.sc debug/pre-process.sc: CHECKER_FLAGS += -Wno-vla

+debug:
+ @mkdir debug
+
+debug/%.o: %.c $(LIB_H) | debug
+ $(QUIET_CC)$(CC) -o $@ -c $(DBG_CFLAGS) $<
 %.o: %.c $(LIB_H)
  $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<

+debug/%.sc: %.c sparse
+ $(QUIET_CHECK) $(CHECKER) $(CHECKER_FLAGS) -c $(DBG_CFLAGS) $<
 %.sc: %.c sparse
  $(QUIET_CHECK) $(CHECKER) $(CHECKER_FLAGS) -c $(ALL_CFLAGS) $<

-ALL_OBJS :=  $(LIB_OBJS) $(foreach p,$(PROGRAMS),$(p).o $($(p)_EXTRA_DEPS))
+ALL_OBJS :=  $(LIB_OBJS) $(DBG_LIB_OBJS) \
+ $(foreach p,$(PROGRAMS),$(p).o debug/$(p).o $($(p)_EXTRA_DEPS)
debug/$($(p)_EXTRA_DEPS))
+
 selfcheck: $(ALL_OBJS:.o=.sc)


 clean: clean-check
+ rm -rf debug
  rm -f *.[oa] .*.d *.so $(PROGRAMS) $(SLIB_FILE) pre-process.h sparse.pc

 dist:
-- 
2.13.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-08-14  0:24 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-13 19:08 [PATCH 1/4] Makefile: adding debug version of sparse Christopher Li
2017-08-13 19:31 ` Luc Van Oostenryck
2017-08-13 20:14   ` Christopher Li
2017-08-13 20:19     ` Luc Van Oostenryck
2017-08-13 20:22       ` Christopher Li
2017-08-13 21:25         ` Christopher Li
2017-08-13 21:10       ` Randy Dunlap
2017-08-13 21:38     ` Ramsay Jones
2017-08-13 21:47       ` Luc Van Oostenryck
2017-08-14  0:24       ` Christopher Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).