From patchwork Sun Aug 13 19:09:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Li X-Patchwork-Id: 9898007 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9EF6F60351 for ; Sun, 13 Aug 2017 19:09:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DBFF2623D for ; Sun, 13 Aug 2017 19:09:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E7AB28599; Sun, 13 Aug 2017 19:09:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91C892623D for ; Sun, 13 Aug 2017 19:09:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751025AbdHMTJw (ORCPT ); Sun, 13 Aug 2017 15:09:52 -0400 Received: from mail-yw0-f193.google.com ([209.85.161.193]:38013 "EHLO mail-yw0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750955AbdHMTJv (ORCPT ); Sun, 13 Aug 2017 15:09:51 -0400 Received: by mail-yw0-f193.google.com with SMTP id p68so5075066ywg.5 for ; Sun, 13 Aug 2017 12:09:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:from:date:message-id:subject:to:cc; bh=iicXFTwkmMn2trduzp3f53+bYcFQImL38xS5uxTeAI4=; b=TwrW0/fOF67aISAADtivIDwiFPAPrPxa3FZKthxC56j0mm5XTPnxnHZP4l2Ie1s3q5 oSXnXChkpjUkMx6APNc71mE4lGUekfke8JLxMWFoN8YGimDWmL1SATMZNk9Q6HNlvKUf mnYHooAOmaQR5qm91EC5/FeRZ9pV1p2gaSZVPgXz6qoY4Fbp49XR5u4eJVl7lu1hWTNq Ayt18LzgE0SDVTYCzE5Oj8n8CudJGEDW5F7CCsvOP6He2TXZQqg1X1fBOGQwlA4LKjgg ftSjPfSGVVL5n2eSkAUtGlBQD/oAaiuelIQadEPnGsAqR13Z6rUg8iO36K9KpOB8ztC/ FWvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:from:date:message-id:subject :to:cc; bh=iicXFTwkmMn2trduzp3f53+bYcFQImL38xS5uxTeAI4=; b=YAI6z7V9ShYhu+V0jziMz7OUhj6+ZwINPpnY+Xf2kmfRz/iMD2gMiOlDq9858tzyk/ lUOd7mcU2dLRR6gyixFQJtCtDDR6x2fQ8/h5YwZ0HwRMGs8cMGQB4gKuhgcOcRzcH0Go y9GrJTOgJpVymThSQnIy4Hi+q7NtPFun9bSDwk6Cvh+y6DC7xu3Kgm7v6QhJMm7uQa2Y X28Oyk3lUgQpXtrZFsVyY9yWfUawQrtSsz9zQKHH66V2qNuaGYQsCeqdM5o72UQzGaTj 7Vauasaye1zfIOvuLYnvYNtoRzk2df2PICcWvied2CzMl5/j3jV9I4Ua+BX067cQcyRN K3zw== X-Gm-Message-State: AHYfb5i2k4TAuBX/xbCcc13YxKwH6O7VnNj3eKUOIZ5z/an86+AlzK+8 GQ862GegkxJWiHzfCR8l8e5IvgtIPoNd X-Received: by 10.129.141.81 with SMTP id w17mr17552573ywj.307.1502651390622; Sun, 13 Aug 2017 12:09:50 -0700 (PDT) MIME-Version: 1.0 Received: by 10.129.68.39 with HTTP; Sun, 13 Aug 2017 12:09:50 -0700 (PDT) From: Christopher Li Date: Sun, 13 Aug 2017 15:09:50 -0400 X-Google-Sender-Auth: tOtbbkX-WLzd2SQF00hBnd8WnsQ Message-ID: Subject: [PATCH 2/4] Makefile: make debug version program as debug/ To: Linux-Sparse Cc: Luc Van Oostenryck Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Compile the release version of program as and the debug version as debug/, under the debug/ directory. For the programs that are only used by developer, there is no need to generate the release version by default. Sparse is the only program that has both release version and debug version by default. Signed-off-by: Christopher Li --- Makefile | 105 +++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 55 insertions(+), 50 deletions(-) endif @@ -102,9 +122,9 @@ LLVM_CFLAGS := $(shell $(LLVM_CONFIG) --cflags | sed -e "s/-DNDEBUG//g" | sed -e LLVM_LIBS := $(shell $(LLVM_CONFIG) --libs) LLVM_LIBS += $(shell $(LLVM_CONFIG) --system-libs 2>/dev/null) PROGRAMS += $(LLVM_PROGS) -INST_PROGRAMS += sparse-llvm sparsec +INST_PROGRAMS += sparsec sparse-llvm.o: BASIC_CFLAGS += $(LLVM_CFLAGS) -sparse-llvm_EXTRA_OBJS := $(LLVM_LIBS) $(LLVM_LDFLAGS) +sparse-llvm_EXTRA_LIBS := $(LLVM_LIBS) $(LLVM_LDFLAGS) else $(warning LLVM 3.0 or later required. Your system has version $(LLVM_VERSION) installed.) endif @@ -112,20 +132,6 @@ else $(warning Your system does not have llvm, disabling sparse-llvm) endif -LIB_H= token.h parse.h lib.h symbol.h scope.h expression.h target.h \ - linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \ - storage.h ptrlist.h dissect.h - -LIB_OBJS= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \ - expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \ - char.o sort.o allocate.o compat-$(OS).o ptrlist.o \ - builtin.o \ - stats.o \ - flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.o - -LIB_FILE= libsparse.a -SLIB_FILE= libsparse.so - # If you add $(SLIB_FILE) to this, you also need to add -fpic to BASIC_CFLAGS above. # Doing so incurs a noticeable performance hit, and Sparse does not have a # stable shared library interface, so this does not occur by default. If you @@ -168,13 +174,16 @@ 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_PROGRAMS := $(addprefix debug/, $(PROGRAMS)) DBG_LIB_OBJS := $(addprefix debug/, $(LIB_OBJS)) -DBG_SLIB_FILE := $(addprefix debug/, $(SLIB_FILE)) -DBG_LIBS := $(addprefix debug/, $(LIBS)) +DBG_LIBS := $(DBG_LIB_FILE) +REL_OBJS := $(LIB_OBJS) $(foreach @F,$(PROGRAMS),$(@F).o $(EXTRA_OBJS)) +DBG_OBJS := $(DBG_LIB_OBJS) $(foreach @F,$(PROGRAMS),debug/$(@F).o $(EXTRA_OBJS)) +ALL_OBJS := $(REL_OBJS) $(DBG_OBJS) +INST_PROGRAMS += $(PROGRAMS) $(DBG_PROGRAMS) -all: $(PROGRAMS) $(DBG_PROGRAMS) sparse.pc + +all: $(REL_PROGRAMS) $(DBG_PROGRAMS) sparse.pc all-installable: $(INST_PROGRAMS) $(LIBS) $(LIB_H) sparse.pc @@ -194,17 +203,16 @@ sparse.pc: sparse.pc.in $(QUIET_GEN)sed $(SED_PC_CMD) sparse.pc.in > sparse.pc -compile_EXTRA_DEPS = compile-i386.o +compile_EXTRA_OBJS = 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))) +$(foreach @F,$(PROGRAMS),$(eval $(@F): $(EXTRA_OBJS) $(LIBS))) +$(foreach @F,$(PROGRAMS),$(eval debug/$(@F): $(addprefix debug/, $(EXTRA_OBJS)) $(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) +$(PROGRAMS): % : %.o + $(QUIET_LINK)$(LD) $(LDFLAGS) -o $@ $^ $(EXTRA_LIBS) +$(DBG_PROGRAMS): debug/% : debug/%.o + $(QUIET_LINK)$(LD) $(LDFLAGS) -o $@ $^ $(EXTRA_LIBS) $(LIB_FILE): $(LIB_OBJS) $(QUIET_AR)$(AR) rcs $@ $(LIB_OBJS) @@ -216,14 +224,12 @@ $(SLIB_FILE): $(LIB_OBJS) $(DBG_SLIB_FILE): $(DBG_LIB_OBJS) $(QUIET_LINK)$(CC) $(LDFLAGS) -Wl,-soname,$@ -shared -o $@ $(DBG_LIB_OBJS) -DEP_FILES := $(wildcard .*.o.d) +DEP_FILES := $(wildcard $(addprefix ., $(ALL_OBJ:.o=.o.d))) ifneq ($(DEP_FILES),) include $(DEP_FILES) endif -c2xml.o c2xml.sc debug/c2xml.o debug/c2xml.sc: CFLAGS += $(LIBXML_CFLAGS) - pre-process.sc debug/pre-process.sc: CHECKER_FLAGS += -Wno-vla debug: @@ -232,17 +238,16 @@ 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) $< + $(QUIET_CC)$(CC) -o $@ -c $(REL_CFLAGS) $< -debug/%.sc: %.c sparse +debug/%.sc: %.c debug/sparse $(QUIET_CHECK) $(CHECKER) $(CHECKER_FLAGS) -c $(DBG_CFLAGS) $< %.sc: %.c sparse - $(QUIET_CHECK) $(CHECKER) $(CHECKER_FLAGS) -c $(ALL_CFLAGS) $< - -ALL_OBJS := $(LIB_OBJS) $(DBG_LIB_OBJS) \ - $(foreach p,$(PROGRAMS),$(p).o debug/$(p).o $($(p)_EXTRA_DEPS) debug/$($(p)_EXTRA_DEPS)) + $(QUIET_CHECK) $(CHECKER) $(CHECKER_FLAGS) -c $(REL_CFLAGS) $< -selfcheck: $(ALL_OBJS:.o=.sc) +dbg-sc: $(DBG_OBJS:.o=.sc) +rel-sc: $(REL_OBJS:.o=.sc) +selfcheck: dbg-sc clean: clean-check diff --git a/Makefile b/Makefile index 6660220..4c89e4c 100644 --- a/Makefile +++ b/Makefile @@ -14,15 +14,18 @@ OS = linux CC = gcc CFLAGS = -O2 -finline-functions -fno-strict-aliasing -g CFLAGS += -Wall -Wwrite-strings +ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) DBG_CFLAGS = $(ALL_CFLAGS) -DSPARSE_DEBUG +REL_CFLAGS = $(ALL_CFLAGS) LDFLAGS += -g LD = gcc AR = ar PKG_CONFIG = pkg-config CHECKER = ./cgcc -no-compile CHECKER_FLAGS = +EXTRA_LIBS = $($(@F)_EXTRA_LIBS) +EXTRA_OBJS = $($(@F)_EXTRA_OBJS) -ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) # # For debugging, put this in local.mk: # @@ -63,16 +66,34 @@ MAN1DIR=$(MANDIR)/man1 INCLUDEDIR=$(PREFIX)/include PKGCONFIGDIR=$(LIBDIR)/pkgconfig -PROGRAMS=test-lexing test-parsing obfuscate compile graph sparse \ - test-linearize example test-unssa test-dissect ctags -INST_PROGRAMS=sparse cgcc +REL_PROGRAMS := sparse +PROGRAMS = $(REL_PROGRAMS) test-lexing test-parsing obfuscate compile graph \ + test-linearize example test-unssa test-dissect ctags + +LIB_H= token.h parse.h lib.h symbol.h scope.h expression.h target.h \ + linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \ + storage.h ptrlist.h dissect.h + +LIB_OBJS= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \ + expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \ + char.o sort.o allocate.o compat-$(OS).o ptrlist.o \ + builtin.o \ + stats.o \ + flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.o + +LIB_FILE= libsparse.a +SLIB_FILE= libsparse.so +DBG_LIB_FILE := $(LIB_FILE:.a=-dbg.a) +DBG_SLIB_FILE := $(SLIB_FILE:.so=-dbg.so) + +INST_PROGRAMS := cgcc INST_MAN1=sparse.1 cgcc.1 ifeq ($(HAVE_LIBXML),yes) -PROGRAMS+=c2xml -INST_PROGRAMS+=c2xml -c2xml_EXTRA_OBJS = `$(PKG_CONFIG) --libs libxml-2.0` +PROGRAMS += c2xml +c2xml_EXTRA_LIBS = `$(PKG_CONFIG) --libs libxml-2.0` LIBXML_CFLAGS := $(shell $(PKG_CONFIG) --cflags libxml-2.0) +c2xml.o c2xml.sc debug/c2xml.o debug/c2xml.sc: CFLAGS += $(LIBXML_CFLAGS) else $(warning Your system does not have libxml, disabling c2xml) endif @@ -81,13 +102,12 @@ ifeq ($(HAVE_GTK),yes) GTK_CFLAGS := $(shell $(PKG_CONFIG) --cflags gtk+-$(GTK_VERSION)) GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-$(GTK_VERSION)) 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_EXTRA_OBJS := ast-model.o ast-view.o ast-inspect.o +test-inspect_OBJS := test-inspect.o $(test-inspect_EXTRA_OBJS) $(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) +test-inspect_EXTRA_LIBS := $(GTK_LIBS) else $(warning Your system does not have gtk3/gtk2, disabling test-inspect)