From patchwork Thu Oct 17 08:34:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 284123 X-Patchwork-Delegate: trini@ti.com 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 0FC2F2C00BC for ; Thu, 17 Oct 2013 19:35:44 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C0BD24A0EE; Thu, 17 Oct 2013 10:35:42 +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 fzlAklkCFbuA; Thu, 17 Oct 2013 10:35:42 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1A2FF4A0BB; Thu, 17 Oct 2013 10:35:27 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8ED3A4A0B9 for ; Thu, 17 Oct 2013 10:35:24 +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 dQBLB+mX73de for ; Thu, 17 Oct 2013 10:35: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.mei.co.jp (smtp.mei.co.jp [133.183.100.20]) by theia.denx.de (Postfix) with ESMTP id 4AF3D4A0A6 for ; Thu, 17 Oct 2013 10:35:16 +0200 (CEST) Received: from mail-gw.jp.panasonic.com ([157.8.1.157]) by smtp.mei.co.jp (8.12.11.20060614/3.7W/kc-maile12) with ESMTP id r9H8Z80u005436; Thu, 17 Oct 2013 17:35:08 +0900 (JST) Received: from epochmail.jp.panasonic.com ([157.8.1.130]) by mail.jp.panasonic.com (8.11.6p2/3.7W/kc-maili17) with ESMTP id r9H8Z9303003; Thu, 17 Oct 2013 17:35:09 +0900 Received: by epochmail.jp.panasonic.com (8.12.11.20060308/3.7W/lomi15) id r9H8Z99H015974; Thu, 17 Oct 2013 17:35:09 +0900 Received: from poodle by lomi15.jp.panasonic.com (8.12.11.20060308/3.7W) with ESMTP id r9H8Z9Lv015907; Thu, 17 Oct 2013 17:35:09 +0900 Received: from beagle.diag.org (beagle.diag.org [10.184.179.16]) by poodle (Postfix) with ESMTP id EB9992743A5D; Thu, 17 Oct 2013 17:35:08 +0900 (JST) From: Masahiro Yamada To: u-boot@lists.denx.de Date: Thu, 17 Oct 2013 17:34:47 +0900 Message-Id: <1381998905-28338-2-git-send-email-yamada.m@jp.panasonic.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1381998905-28338-1-git-send-email-yamada.m@jp.panasonic.com> References: <1381998905-28338-1-git-send-email-yamada.m@jp.panasonic.com> Cc: Tom Rini Subject: [U-Boot] [PATCH v3 01/19] Makefile: prepare for using Kbuild-style Makefile X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 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 Every makefile in sub directories has common lines at the top and the bottom. This commit pushes the common parts into script/Makefile.build. Going forward sub-makefiles only need to describe this part: COBJS := ... COBJS += ... SOBJS := ... But using obj-y is preferable to prepare for switching to Kbuild. The conventional (non-Kbuild) Makefile style is still supported. This is achieved by greping the Makefile before entering into it. U-Boot conventional sub makefiles always include some other makefiles. So the build system searches a line beginning with "include" keyword in the makefile in order to distinguish which style it is. If the Makefile include a "include" line, we assume it is a conventional U-Boot style. Otherwise, it is treated as a Kbuild-style makefile. With this tweak, we can switch sub-makefiles from U-Boot style to Kbuild style little by little. obj-y := foo/ syntax (descending into the sub directory) is not supportd yet. It will be implemented in the upcomming commit. Signed-off-by: Masahiro Yamada Cc: Simon Glass Cc: Tom Rini --- Changes for v3: - Re-write complicated parts with $(call select_makefile, ...) - Add indents - Shorten commit log and move verbose explanation below '---' Changes for v2: - fix commit log (purely cosmetic) Note1: (At first, I tried to grep "rules.mk" keyword instead of "^include", but I found it does not work. Almost all sub makefiles include "rules.mk", but there exist three exception: - board/avnet/fx12mm/Makefile - board/avnet/v5fx30teval/Makefile - board/xilinx/ml507/Makefile These three makefiles include "rules.mk" indirectly. Anyway, they look weird, so they should be fixed lator.) Note2: Note that this refactoring breaks nothing because it just moves the common parts into scripts/Makefile.build. Note3: Of course, scripts/Makefile.build added by this commit is temporary. It shall be replaced with the one of Linux Kernel in future. Note4: For v3, I pushed dirty stuff into select_makefile function. But this has a side effect. When invoking $(call select_makefile,...) , GNU make reports the warning make[1]: warning: jobserver unavailable: using -j1. Add `+' to parent make rule. To suppress this, I added '+' lile: +$(call select_makefile, $(dir $(subst $(obj),,$@))) Makefile | 36 +++++++++++++++++++++++++++++++----- scripts/Makefile.build | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ spl/Makefile | 22 ++++++++++++++++++++-- 3 files changed, 99 insertions(+), 7 deletions(-) create mode 100644 scripts/Makefile.build diff --git a/Makefile b/Makefile index dc04179..ca3d9ea 100644 --- a/Makefile +++ b/Makefile @@ -594,14 +594,32 @@ ifeq ($(CONFIG_KALLSYMS),y) $(GEN_UBOOT) $(obj)common/system_map.o endif +# Tentative step for Kbuild-style makefiles coexist with conventional U-Boot style makefiles +# U-Boot conventional sub makefiles always include some other makefiles. +# So, the build system searches a line beginning with "include" before entering into the sub makefile +# in order to distinguish which style it is. +# If the Makefile include a "include" line, we assume it is an U-Boot style makefile. +# Otherwise, it is treated as a Kbuild-style makefile. +select_makefile = \ + +if grep -q "^include" $1/Makefile; then \ + $(MAKE) -C $1; \ + else \ + $(MAKE) -C $1 -f $(TOPDIR)/scripts/Makefile.build; \ + mv $(dir $@)built-in.o $@; \ + fi + +# We do not need to build $(OBJS) explicitly. +# It is built while we are at $(CPUDIR)/lib$(CPU).o build. $(OBJS): depend - $(MAKE) -C $(CPUDIR) $(if $(REMOTE_BUILD),$@,$(notdir $@)) + if grep -q "^include" $(CPUDIR)/Makefile; then \ + $(MAKE) -C $(CPUDIR) $(if $(REMOTE_BUILD),$@,$(notdir $@)); \ + fi $(LIBS): depend $(SUBDIR_TOOLS) - $(MAKE) -C $(dir $(subst $(obj),,$@)) + +$(call select_makefile, $(dir $(subst $(obj),,$@))) $(LIBBOARD): depend $(LIBS) - $(MAKE) -C $(dir $(subst $(obj),,$@)) + +$(call select_makefile, $(dir $(subst $(obj),,$@))) $(SUBDIRS): depend $(MAKE) -C $@ all @@ -629,6 +647,13 @@ $(obj)tpl/u-boot-tpl.bin: $(SUBDIR_TOOLS) depend updater: $(MAKE) -C tools/updater all +select_makefile2 = \ + if grep -q "^include" $1/Makefile; then \ + $(MAKE) -C $1 _depend; \ + else \ + $(MAKE) -C $1 -f $(TOPDIR)/scripts/Makefile.build _depend; \ + fi + # Explicitly make _depend in subdirs containing multiple targets to prevent # parallel sub-makes creating .depend files simultaneously. depend dep: $(TIMESTAMP_FILE) $(VERSION_FILE) \ @@ -637,8 +662,9 @@ depend dep: $(TIMESTAMP_FILE) $(VERSION_FILE) \ $(obj)include/autoconf.mk \ $(obj)include/generated/generic-asm-offsets.h \ $(obj)include/generated/asm-offsets.h - for dir in $(SUBDIRS) $(CPUDIR) $(LDSCRIPT_MAKEFILE_DIR) ; do \ - $(MAKE) -C $$dir _depend ; done + +for dir in $(SUBDIRS) $(CPUDIR) $(LDSCRIPT_MAKEFILE_DIR) ; do \ + $(call select_makefile2, $$dir); \ + done TAG_SUBDIRS = $(SUBDIRS) TAG_SUBDIRS += $(dir $(__LIBS)) diff --git a/scripts/Makefile.build b/scripts/Makefile.build new file mode 100644 index 0000000..f969ec5 --- /dev/null +++ b/scripts/Makefile.build @@ -0,0 +1,48 @@ +# our default target +.PHONY: all +all: + +include $(TOPDIR)/config.mk + +LIB := $(obj)built-in.o +LIBGCC = $(obj)libgcc.o +SRCS := + +include Makefile + +# Backward compatible: obj-y is preferable +COBJS := $(sort $(COBJS) $(COBJS-y)) +SOBJS := $(sort $(SOBJS) $(SOBJS-y)) + +# Going forward use the following +obj-y := $(sort $(obj-y)) +extra-y := $(sort $(extra-y)) +lib-y := $(sort $(lib-y)) + +SRCS += $(COBJS:.o=.c) $(SOBJS:.o=.S) \ + $(wildcard $(obj-y:.o=.c) $(obj-y:.o=.S) $(lib-y:.o=.c) $(lib-y:.o=.S) $(extra-y:.o=.c) $(extra-y:.o=.S)) +OBJS := $(addprefix $(obj),$(COBJS) $(SOBJS) $(obj-y)) + +LGOBJS := $(addprefix $(obj),$(sort $(GLSOBJS) $(GLCOBJS)) $(lib-y)) + +all: $(LIB) $(addprefix $(obj),$(extra-y)) + +$(LIB): $(obj).depend $(OBJS) + $(call cmd_link_o_target, $(OBJS)) + +ifneq ($(strip $(lib-y)),) +all: $(LIBGCC) + +$(LIBGCC): $(obj).depend $(LGOBJS) + $(call cmd_link_o_target, $(LGOBJS)) +endif + +######################################################################### + +# defines $(obj).depend target + +include $(TOPDIR)/rules.mk + +sinclude $(obj).depend + +######################################################################### diff --git a/spl/Makefile b/spl/Makefile index b366ac2..64ebfb7 100644 --- a/spl/Makefile +++ b/spl/Makefile @@ -200,11 +200,29 @@ GEN_UBOOT = \ $(obj)$(SPL_BIN): depend $(START) $(LIBS) $(obj)u-boot-spl.lds $(GEN_UBOOT) +# Tentative step for Kbuild-style makefiles coexist with conventional U-Boot style makefiles +# U-Boot conventional sub makefiles always include some other makefiles. +# So, the build system searches a line beginning with "include" before entering into the sub makefile +# in order to distinguish which style it is. +# If the Makefile include a "include" line, we assume it is an U-Boot style makefile. +# Otherwise, it is treated as a Kbuild-style makefile. +select_makefile = \ + if grep -q "^include" $1/Makefile; then \ + $(MAKE) -C $1; \ + else \ + $(MAKE) -C $1 -f $(TOPDIR)/scripts/Makefile.build; \ + mv $(dir $@)built-in.o $@; \ + fi + +# We do not need to build $(START) explicitly. +# It is built while we are at $(CPUDIR)/lib$(CPU).o build. $(START): depend - $(MAKE) -C $(SRCTREE)/$(START_PATH) $@ + if grep -q "^include" $(SRCTREE)$(dir $(subst $(SPLTREE),,$@))Makefile; then \ + $(MAKE) -C $(SRCTREE)/$(START_PATH) $@; \ + fi $(LIBS): depend - $(MAKE) -C $(SRCTREE)$(dir $(subst $(SPLTREE),,$@)) + +$(call select_makefile, $(SRCTREE)$(dir $(subst $(SPLTREE),,$@))) $(obj)u-boot-spl.lds: $(LDSCRIPT) depend $(CPP) $(CPPFLAGS) $(LDPPFLAGS) -I$(obj). -ansi -D__ASSEMBLY__ -P - < $< > $@