From patchwork Sun Sep 8 01:42:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 273395 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 D4C9B2C010E for ; Sun, 8 Sep 2013 11:43:31 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E3B484A08E; Sun, 8 Sep 2013 03:43: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 QCDn6Xg1bFLj; Sun, 8 Sep 2013 03:43:19 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 740684A08F; Sun, 8 Sep 2013 03:42:48 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 95F6F4A064 for ; Sun, 8 Sep 2013 03:42:41 +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 EfvgAm4eGT1C for ; Sun, 8 Sep 2013 03:42:30 +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 325F24A063 for ; Sun, 8 Sep 2013 03:42:23 +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-maile13) with ESMTP id r881gLsA004927; Sun, 8 Sep 2013 10:42:21 +0900 (JST) Received: from epochmail.jp.panasonic.com ([157.8.1.130]) by mail.jp.panasonic.com (8.11.6p2/3.7W/kc-maili13) with ESMTP id r881gKJ04918; Sun, 8 Sep 2013 10:42:20 +0900 Received: by epochmail.jp.panasonic.com (8.12.11.20060308/3.7W/lomi13) id r881gKh2018173; Sun, 8 Sep 2013 10:42:20 +0900 Received: from poodle by lomi13.jp.panasonic.com (8.12.11.20060308/3.7W) with ESMTP id r881gKpo018162; Sun, 8 Sep 2013 10:42:20 +0900 Received: from beagle.diag.org (beagle.diag.org [10.184.179.16]) by poodle (Postfix) with ESMTP id 90F5E2743A5D; Sun, 8 Sep 2013 10:42:20 +0900 (JST) From: Masahiro Yamada To: u-boot@lists.denx.de Date: Sun, 8 Sep 2013 10:42:02 +0900 Message-Id: <1378604540-30445-2-git-send-email-yamada.m@jp.panasonic.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1378604540-30445-1-git-send-email-yamada.m@jp.panasonic.com> References: <1378604540-30445-1-git-send-email-yamada.m@jp.panasonic.com> Subject: [U-Boot] [PATCH 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 In every sub directory, Makefile is like follows: include $(TOPDIR)/config.mk LIB = $(obj)libfoo.o COBJS := ... COBJS += ... SOBJS := ... SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) OBJS := $(addprefix $(obj),$(COBJS) $(SOBJS)) all: $(obj).depend $(LIB) $(LIB): $(OBJS) $(call cmd_link_o_target, $(OBJS)) ######################################################################### include $(SRCTREE)/rules.mk sinclude $(obj).depend ######################################################################### Top and bottom parts are common in almost all sub-makefiles. This is a big waste. This commit pushes common parts of makefiles into script/Makefile.build. Going forward sub-makefiles only need to describe this part: COBJS := ... COBJS += ... SOBJS := ... But, script/Makefile.build includes the glue code to support obj-y, the following style (the same as Kbuild) is preferable: obj-y := ... obj-$(CONFIG_FOO) += ... obj-$(CONFIG_BAR) += ... The conventional U-Boot 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 with 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. (At first, I tried to grep "rules.mk" keyword instead, 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.) With this tweak, we can switch sub-makefiles from U-Boot style to Kbuild style little by little. This refactoring of sub makefiles is the first step towards Kbuild, and makes it easy to import a "real" Kbuild from Linux Kernel. Note that this refactoring breaks nothing because it just moves the common parts into scripts/Makefile.build. Note one more thing: obj-y := foo/ # descending into foo sub directory syntax is not supported yet. (This feature will be implemented in the upcoming commit series.) Of course, scripts/Makefile.build added by this commit is temporary. It shall be replaced with the one of Linux Kernel in future. Signed-off-by: Masahiro Yamada Cc: Simon Glass --- Makefile | 34 ++++++++++++++++++++++++++++++---- scripts/Makefile.build | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ spl/Makefile | 20 ++++++++++++++++++-- 3 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 scripts/Makefile.build diff --git a/Makefile b/Makefile index ed48279..852f80b 100644 --- a/Makefile +++ b/Makefile @@ -592,14 +592,35 @@ 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. + +# 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),,$@)) + if grep -q "^include" $(dir $(subst $(obj),,$@))Makefile; then \ + $(MAKE) -C $(dir $(subst $(obj),,$@)); \ + else \ + $(MAKE) -C $(dir $(subst $(obj),,$@)) -f $(TOPDIR)/scripts/Makefile.build; \ + mv $(dir $@)built-in.o $@; \ + fi $(LIBBOARD): depend $(LIBS) - $(MAKE) -C $(dir $(subst $(obj),,$@)) + if grep -q "^include" $(dir $(subst $(obj),,$@))/Makefile; then \ + $(MAKE) -C $(dir $(subst $(obj),,$@)); \ + else \ + $(MAKE) -C $(dir $(subst $(obj),,$@)) -f $(TOPDIR)/scripts/Makefile.build; \ + mv $(dir $@)built-in.o $@; \ + fi $(SUBDIRS): depend $(MAKE) -C $@ all @@ -636,7 +657,12 @@ depend dep: $(TIMESTAMP_FILE) $(VERSION_FILE) \ $(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 + if grep -q "^include" $$dir/Makefile; then \ + $(MAKE) -C $$dir _depend ; \ + else \ + $(MAKE) -C $$dir -f $(TOPDIR)/scripts/Makefile.build _depend; \ + fi; \ + 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 339e5e8..7497b5f 100644 --- a/spl/Makefile +++ b/spl/Makefile @@ -198,11 +198,27 @@ 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. + +# 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),,$@)) + if grep -q "^include" $(SRCTREE)$(dir $(subst $(SPLTREE),,$@))Makefile; then \ + $(MAKE) -C $(SRCTREE)$(dir $(subst $(SPLTREE),,$@)); \ + else \ + $(MAKE) -C $(SRCTREE)$(dir $(subst $(SPLTREE),,$@)) -f $(TOPDIR)/scripts/Makefile.build; \ + mv $(dir $@)built-in.o $@; \ + fi $(obj)u-boot-spl.lds: $(LDSCRIPT) depend $(CPP) $(CPPFLAGS) $(LDPPFLAGS) -I$(obj). -ansi -D__ASSEMBLY__ -P - < $< > $@