From patchwork Tue Oct 4 05:26:49 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 117561 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id CBE57B6F67 for ; Tue, 4 Oct 2011 16:31:06 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1A9812850C; Tue, 4 Oct 2011 07:30:02 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id c13YUbWRa2iw; Tue, 4 Oct 2011 07:30:01 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1AF63283B1; Tue, 4 Oct 2011 07:28:28 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 863D5283D2 for ; Tue, 4 Oct 2011 07:28:19 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yRTIZTywx2vM for ; Tue, 4 Oct 2011 07:28:18 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from smtp-out.google.com (smtp-out.google.com [74.125.121.67]) by theia.denx.de (Postfix) with ESMTPS id 6E2D828378 for ; Tue, 4 Oct 2011 07:27:55 +0200 (CEST) Received: from wpaz24.hot.corp.google.com (wpaz24.hot.corp.google.com [172.24.198.88]) by smtp-out.google.com with ESMTP id p945Rr1W008581; Mon, 3 Oct 2011 22:27:53 -0700 Received: from sglass.mtv.corp.google.com (sglass.mtv.corp.google.com [172.22.72.144]) by wpaz24.hot.corp.google.com with ESMTP id p945Rn8X022115; Mon, 3 Oct 2011 22:27:51 -0700 Received: by sglass.mtv.corp.google.com (Postfix, from userid 121222) id 495CC1413A4; Mon, 3 Oct 2011 22:27:49 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 3 Oct 2011 22:26:49 -0700 Message-Id: <1317706010-17151-19-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.3.1 In-Reply-To: <1317706010-17151-1-git-send-email-sjg@chromium.org> References: <1317706010-17151-1-git-send-email-sjg@chromium.org> X-System-Of-Record: true Subject: [U-Boot] [PATCH v4 18/19] Adjust dependency rules to permit per-file flags X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de The dependency rules are currently done in a shell 'for' loop. This does not permit Makefile variables to adjust preprocessor flags as is done with normal compile flags, using the CFLAGS_path/file.o syntax. This change moves the dependency generation into the Makefile itself, and permits a CPPFLAGS_path/file.o to adjust preprocessor flags on a file or directory basis. The CPPFLAGS_... variable is also folded into CFLAGS during the build. Signed-off-by: Simon Glass --- Changes in v3: - Change U-Boot's dependency generation to permit per-file flags Changes in v4: - 'Improve' dependency generation to deal with source files containing paths - Make sure that clobber target removes all dependency files .gitignore | 2 +- Makefile | 2 +- config.mk | 7 +++++++ rules.mk | 44 +++++++++++++++++++++++++++++++++----------- 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 289ffab..1bea75f 100644 --- a/.gitignore +++ b/.gitignore @@ -40,7 +40,7 @@ # Generated files # -*.depend +*.depend* /LOG /errlog /reloc_off diff --git a/Makefile b/Makefile index ccd221e..1bfeebe 100644 --- a/Makefile +++ b/Makefile @@ -973,7 +973,7 @@ clean: | xargs rm -f clobber: clean - @find $(OBJTREE) -type f \( -name '*.depend' \ + @find $(OBJTREE) -type f \( -name '*.depend*' \ -o -name '*.srec' -o -name '*.bin' -o -name u-boot.img \) \ -print0 \ | xargs -0 rm -f diff --git a/config.mk b/config.mk index e2b440d..3fa9eef 100644 --- a/config.mk +++ b/config.mk @@ -277,6 +277,13 @@ export CONFIG_SYS_TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS BCURDIR = $(subst $(SRCTREE)/,,$(CURDIR:$(obj)%=%)) ALL_AFLAGS = $(AFLAGS) $(AFLAGS_$(BCURDIR)/$(@F)) $(AFLAGS_$(BCURDIR)) ALL_CFLAGS = $(CFLAGS) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR)) +EXTRA_CPPFLAGS = $(CPPFLAGS_$(BCURDIR)/$(@F)) $(CPPFLAGS_$(BCURDIR)) +ALL_CFLAGS += $(EXTRA_CPPFLAGS) + +# The _DEP version uses the $< file target (for dependency generation) +# See rules.mk +EXTRA_CPPFLAGS_DEP = $(CPPFLAGS_$(BCURDIR)/$(addsuffix .o,$(basename $<))) \ + $(CPPFLAGS_$(BCURDIR)) $(obj)%.s: %.S $(CPP) $(ALL_AFLAGS) -o $@ $< $(obj)%.o: %.S diff --git a/rules.mk b/rules.mk index d79fcd3..377be86 100644 --- a/rules.mk +++ b/rules.mk @@ -25,17 +25,39 @@ _depend: $(obj).depend -$(obj).depend: $(src)Makefile $(TOPDIR)/config.mk $(SRCS) $(HOSTSRCS) - @rm -f $@ - @touch $@ - @for f in $(SRCS); do \ - g=`basename $$f | sed -e 's/\(.*\)\.[[:alnum:]_]/\1.o/'`; \ - $(CC) -M $(CPPFLAGS) -MQ $(obj)$$g $$f >> $@ ; \ - done - @for f in $(HOSTSRCS); do \ - g=`basename $$f | sed -e 's/\(.*\)\.[[:alnum:]_]/\1.o/'`; \ - $(HOSTCC) -M $(HOSTCPPFLAGS) -MQ $(obj)$$g $$f >> $@ ; \ - done +# Split the source files into two camps: those in the current directory, and +# those somewhere else. For the first camp we want to support CPPFLAGS_ +# and for the second we don't / can't. +PWD_SRCS := $(filter $(notdir $(SRCS)),$(SRCS)) +OTHER_SRCS := $(filter-out $(notdir $(SRCS)),$(SRCS)) + +# This is a list of dependency files to generate +DEPS := $(basename $(patsubst %,$(obj).depend.%,$(PWD_SRCS))) + +# Join all the dependencies into a single file, in three parts +# 1 .Concatenate all the generated depend files together +# 2. Add in the deps from OTHER_SRCS which we couldn't process +# 3. Add in the HOSTSRCS +$(obj).depend: $(src)Makefile $(TOPDIR)/config.mk $(DEPS) $(HOSTSRCS) + cat /dev/null $(DEPS) >$@ + @for f in $(OTHER_SRCS); do \ + g=`basename $$f | sed -e 's/\(.*\)\.[[:alnum:]_]/\1.o/'`; \ + $(CC) -M $(CPPFLAGS) -MQ $(obj)$$g $$f >> $@ ; \ + done + @for f in $(HOSTSRCS); do \ + g=`basename $$f | sed -e 's/\(.*\)\.[[:alnum:]_]/\1.o/'`; \ + $(HOSTCC) -M $(HOSTCPPFLAGS) -MQ $(obj)$$g $$f >> $@ ; \ + done + +MAKE_DEPEND = $(CC) -M $(CPPFLAGS) $(EXTRA_CPPFLAGS_DEP) \ + -MQ $(addsuffix .o,$(basename $<)) $< >$@ + + +$(obj).depend.%: %.c + $(MAKE_DEPEND) + +$(obj).depend.%: %.S + $(MAKE_DEPEND) $(HOSTOBJS): $(obj)%.o: %.c $(HOSTCC) $(HOSTCFLAGS) $(HOSTCFLAGS_$(@F)) $(HOSTCFLAGS_$(BCURDIR)) -o $@ $< -c