From patchwork Wed Jan 29 12:26:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 314996 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 4314D2C007C for ; Wed, 29 Jan 2014 23:32:06 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 629BD4B581; Wed, 29 Jan 2014 13:32:03 +0100 (CET) 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 SWvSSyoDM5NC; Wed, 29 Jan 2014 13:32:03 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 443F94B582; Wed, 29 Jan 2014 13:28:19 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4C6E84B524 for ; Wed, 29 Jan 2014 13:27:35 +0100 (CET) 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 9Upwmug6AWo6 for ; Wed, 29 Jan 2014 13:27:33 +0100 (CET) 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 0EE984B484 for ; Wed, 29 Jan 2014 13:26:53 +0100 (CET) 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 s0TCQgop002315; Wed, 29 Jan 2014 21:26:42 +0900 (JST) Received: from epochmail.jp.panasonic.com ([157.8.1.130]) by mail.jp.panasonic.com (8.11.6p2/3.7W/kc-maili15) with ESMTP id s0TCQfB25425; Wed, 29 Jan 2014 21:26:41 +0900 Received: by epochmail.jp.panasonic.com (8.12.11.20060308/3.7W/lomi11) id s0TCQfKK021932; Wed, 29 Jan 2014 21:26:41 +0900 Received: from poodle by lomi11.jp.panasonic.com (8.12.11.20060308/3.7W) with ESMTP id s0TCQfBK021894; Wed, 29 Jan 2014 21:26:41 +0900 Received: from beagle.diag.org (beagle.diag.org [10.184.179.16]) by poodle (Postfix) with ESMTP id 7F7012740043; Wed, 29 Jan 2014 21:26:41 +0900 (JST) From: Masahiro Yamada To: u-boot@lists.denx.de Date: Wed, 29 Jan 2014 21:26:25 +0900 Message-Id: <1390998395-18567-29-git-send-email-yamada.m@jp.panasonic.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1390998395-18567-1-git-send-email-yamada.m@jp.panasonic.com> References: <1390998395-18567-1-git-send-email-yamada.m@jp.panasonic.com> Cc: Tom Rini Subject: [U-Boot] [PATCH v8 28/38] kbuild: change the top Makefile to more Kbuild-ish structure 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 This commit changes the top Makefile to handle various targets nicely. Make targets are divided into four categories: - mixed-targets We can call a configuration target and build targets at one command line like follows: $ make _config u-boot They are handled one by one. - config targets _config - no-dot-config-targets Targets we can run without board configuration such as clean, mrproper, distclean, TAGS, %docs, etc. - build targets The other target which need board configuration. Signed-off-by: Masahiro Yamada --- Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: - Rebase on the current u-boot/master - Fix a bug: make ; make tools failed at version 4. Changes in v4: None Changes in v3: None Changes in v2: - Rebase on v2014.01-rc2 tag Makefile | 287 ++++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 166 insertions(+), 121 deletions(-) diff --git a/Makefile b/Makefile index ac7dccd..2f273b9 100644 --- a/Makefile +++ b/Makefile @@ -203,34 +203,6 @@ VENDOR= ######################################################################### -# The "tools" are needed early, so put this first -# Don't include stuff already done in $(LIBS) -# The "examples" conditionally depend on U-Boot (say, when USE_PRIVATE_LIBGCC -# is "yes"), so compile examples after U-Boot is compiled. -SUBDIR_TOOLS = tools -SUBDIRS = $(SUBDIR_TOOLS) - -.PHONY : $(SUBDIRS) $(VERSION_FILE) $(TIMESTAMP_FILE) - -ifeq (include/config.mk,$(wildcard include/config.mk)) - -# Include autoconf.mk before config.mk so that the config options are available -# to all top level build files. We need the dummy all: target to prevent the -# dependency target in autoconf.mk.dep from being the default. -all: -sinclude include/autoconf.mk.dep -sinclude include/autoconf.mk - -SUBDIR_EXAMPLES-y := examples/standalone -SUBDIR_EXAMPLES-$(CONFIG_API) += examples/api -ifndef CONFIG_SANDBOX -SUBDIRS += $(SUBDIR_EXAMPLES-y) -endif - -# load ARCH, BOARD, and CPU configuration -include include/config.mk -export ARCH CPU BOARD VENDOR SOC - # set default to nothing for native builds ifeq ($(HOSTARCH),$(ARCH)) CROSS_COMPILE ?= @@ -377,15 +349,6 @@ CHECK = sparse CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ -Wbitwise -Wno-return-void -D__CHECK_ENDIAN__ $(CF) -# Use UBOOTINCLUDE when you must reference the include/ directory. -# Needed to be compatible with the O= option -UBOOTINCLUDE := -ifneq ($(OBJTREE),$(SRCTREE)) -UBOOTINCLUDE += -I$(OBJTREE)/include -endif -UBOOTINCLUDE += -I$(srctree)/include \ - -I$(srctree)/arch/$(ARCH)/include - KBUILD_CPPFLAGS := -D__KERNEL__ KBUILD_CFLAGS := -Wall -Wstrict-prototypes \ @@ -396,6 +359,7 @@ KBUILD_AFLAGS := -D__ASSEMBLY__ U_BOOT_VERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION) export VERSION PATCHLEVEL SUBLEVEL U_BOOT_VERSION +export ARCH CPU BOARD VENDOR SOC export CONFIG_SHELL HOSTCC HOSTCFLAGS HOSTLDFLAGS CROSS_COMPILE AS LD CC export CPP AR NM LDR STRIP OBJCOPY OBJDUMP export MAKE AWK @@ -428,65 +392,107 @@ scripts_basic: # To avoid any implicit rule to kick in, define an empty command. scripts/basic/%: scripts_basic ; +# To make sure we do not include .config for any of the *config targets +# catch them early, and hand them over to scripts/kconfig/Makefile +# It is allowed to specify more targets when calling make, including +# mixing *config targets and build targets. +# For example 'make oldconfig all'. +# Detect when mixed targets is specified, and make a second invocation +# of make so .config is not included in this case either (for *config). + +no-dot-config-targets := clean clobber mrproper distclean \ + cscope TAGS %tags help %docs check% coccicheck \ + backup + +config-targets := 0 +mixed-targets := 0 +dot-config := 1 + +ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),) + ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),) + dot-config := 0 + endif +endif -KBUILD_CFLAGS += -Os #-fomit-frame-pointer - -ifdef BUILD_TAG -KBUILD_CFLAGS += -DBUILD_TAG='"$(BUILD_TAG)"' +ifeq ($(KBUILD_EXTMOD),) + ifneq ($(filter config %config,$(MAKECMDGOALS)),) + config-targets := 1 + ifneq ($(filter-out config %config,$(MAKECMDGOALS)),) + mixed-targets := 1 + endif + endif endif -KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector) +ifeq ($(mixed-targets),1) +# =========================================================================== +# We're called with mixed targets (*config and build targets). +# Handle them one by one. -KBUILD_CFLAGS += -g -# $(KBUILD_AFLAGS) sets -g, which causes gcc to pass a suitable -g -# option to the assembler. -KBUILD_AFLAGS += -g +%:: FORCE + $(Q)$(MAKE) -C $(srctree) KBUILD_SRC= $@ -NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) -CHECKFLAGS += $(NOSTDINC_FLAGS) +else +ifeq ($(config-targets),1) +# =========================================================================== +# *config targets only - make sure prerequisites are updated, and descend +# in scripts/kconfig to make the *config target -# Report stack usage if supported -KBUILD_CFLAGS += $(call cc-option,-fstack-usage) +# Read arch specific Makefile to set KBUILD_DEFCONFIG as needed. +# KBUILD_DEFCONFIG may point out an alternative default configuration +# used for 'make defconfig' -KBUILD_CFLAGS += $(call cc-option,-Wno-format-nonliteral) +%_config:: + @$(MKCONFIG) -A $(@:_config=) -# turn jbsr into jsr for m68k -ifeq ($(ARCH),m68k) -ifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4) -KBUILD_AFLAGS += -Wa,-gstabs,-S -endif -endif +else +# =========================================================================== +# Build targets only - this includes vmlinux, arch specific targets, clean +# targets and others. In general all targets except *config targets. + +# load ARCH, BOARD, and CPU configuration +-include include/config.mk + +ifeq ($(dot-config),1) +# Read in config +-include include/autoconf.mk +-include include/autoconf.mk.dep # load other configuration -include $(TOPDIR)/config.mk +include $(srctree)/config.mk -ifneq ($(CONFIG_SYS_TEXT_BASE),) -KBUILD_CPPFLAGS += -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE) -endif +# +# Auto-generate the autoconf.mk file (which is included by all makefiles) +# +# This target actually generates 2 files; autoconf.mk and autoconf.mk.dep. +# the dep file is only include in this top level makefile to determine when +# to regenerate the autoconf.mk file. -export CONFIG_SYS_TEXT_BASE +quiet_cmd_autoconf_dep = GEN $@ + cmd_autoconf_dep = $(CC) -x c -DDO_DEPS_ONLY -M $(c_flags) \ + -MQ include/autoconf.mk $(srctree)/include/common.h > $@ || rm $@ -LDFLAGS_u-boot += -T u-boot.lds $(LDFLAGS_FINAL) -ifneq ($(CONFIG_SYS_TEXT_BASE),) -LDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE) -endif +include/autoconf.mk.dep: include/config.h include/common.h + $(call cmd,autoconf_dep) -# Targets which don't build the source code -NON_BUILD_TARGETS = backup clean clobber distclean mrproper unconfig %_config +quiet_cmd_autoconf = GEN $@ + cmd_autoconf = \ + $(CPP) $(c_flags) -DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && \ + sed -n -f $(srctree)/tools/scripts/define2mk.sed $@.tmp > $@; \ + rm $@.tmp + +include/autoconf.mk: include/config.h + $(call cmd,autoconf) + +ifeq ($(wildcard include/config.mk),) +$(error "System not configured - see README") +endif -# Only do the generic board check when actually building, not configuring -ifeq ($(filter $(NON_BUILD_TARGETS),$(MAKECMDGOALS)),) ifeq ($(__HAVE_ARCH_GENERIC_BOARD),) ifneq ($(CONFIG_SYS_GENERIC_BOARD),) -CHECK_GENERIC_BOARD = $(error Your architecture does not support generic board. \ +$(error Your architecture does not support generic board. \ Please undefined CONFIG_SYS_GENERIC_BOARD in your board config file) endif endif -endif - -# FIX ME -cpp_flags := $(KBUILD_CPPFLAGS) $(CPPFLAGS) $(UBOOTINCLUDE) $(NOSTDINC_FLAGS) -c_flags := $(KBUILD_CFLAGS) $(cpp_flags) # If board code explicitly specified LDSCRIPT or CONFIG_SYS_LDSCRIPT, use # that (or fail if absent). Otherwise, search for a linker script in a @@ -526,6 +532,73 @@ $(error could not find linker script) endif endif +else + + +endif # $(dot-config) + +KBUILD_CFLAGS += -Os #-fomit-frame-pointer + +ifdef BUILD_TAG +KBUILD_CFLAGS += -DBUILD_TAG='"$(BUILD_TAG)"' +endif + +KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector) + +KBUILD_CFLAGS += -g +# $(KBUILD_AFLAGS) sets -g, which causes gcc to pass a suitable -g +# option to the assembler. +KBUILD_AFLAGS += -g + +# Report stack usage if supported +KBUILD_CFLAGS += $(call cc-option,-fstack-usage) + +KBUILD_CFLAGS += $(call cc-option,-Wno-format-nonliteral) + +# turn jbsr into jsr for m68k +ifeq ($(ARCH),m68k) +ifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4) +KBUILD_AFLAGS += -Wa,-gstabs,-S +endif +endif + +ifneq ($(CONFIG_SYS_TEXT_BASE),) +KBUILD_CPPFLAGS += -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE) +endif + +export CONFIG_SYS_TEXT_BASE + +# Use UBOOTINCLUDE when you must reference the include/ directory. +# Needed to be compatible with the O= option +UBOOTINCLUDE := +ifneq ($(OBJTREE),$(SRCTREE)) +UBOOTINCLUDE += -I$(OBJTREE)/include +endif +UBOOTINCLUDE += -I$(srctree)/include \ + -I$(srctree)/arch/$(ARCH)/include + +NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) +CHECKFLAGS += $(NOSTDINC_FLAGS) + +# FIX ME +cpp_flags := $(KBUILD_CPPFLAGS) $(CPPFLAGS) $(UBOOTINCLUDE) $(NOSTDINC_FLAGS) +c_flags := $(KBUILD_CFLAGS) $(cpp_flags) + +# The "tools" are needed early, so put this first +# Don't include stuff already done in $(LIBS) +# The "examples" conditionally depend on U-Boot (say, when USE_PRIVATE_LIBGCC +# is "yes"), so compile examples after U-Boot is compiled. +SUBDIR_TOOLS = tools +SUBDIRS = $(SUBDIR_TOOLS) + +.PHONY : $(SUBDIRS) $(VERSION_FILE) $(TIMESTAMP_FILE) + +SUBDIR_EXAMPLES-y := examples/standalone +SUBDIR_EXAMPLES-$(CONFIG_API) += examples/api +ifndef CONFIG_SANDBOX +SUBDIRS += $(SUBDIR_EXAMPLES-y) +endif + ######################################################################### # U-Boot objects....order is important (i.e. start must be first) @@ -675,6 +748,11 @@ endif endif endif +LDFLAGS_u-boot += -T u-boot.lds $(LDFLAGS_FINAL) +ifneq ($(CONFIG_SYS_TEXT_BASE),) +LDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE) +endif + all: $(ALL-y) $(SUBDIR_EXAMPLES-y) u-boot.dtb: checkdtc u-boot @@ -867,7 +945,7 @@ $(OBJS): $(LIBS): depend $(SUBDIR_TOOLS) scripts_basic $(Q)$(MAKE) $(build)=$(patsubst %/,%,$(dir $@)) -$(SUBDIRS): depend scripts_basic +$(SUBDIRS): scripts_basic $(TIMESTAMP_FILE) $(VERSION_FILE) $(Q)$(MAKE) $(build)=$@ $(SUBDIR_EXAMPLES-y): u-boot @@ -948,28 +1026,6 @@ checkdtc: false; \ fi -# -# Auto-generate the autoconf.mk file (which is included by all makefiles) -# -# This target actually generates 2 files; autoconf.mk and autoconf.mk.dep. -# the dep file is only include in this top level makefile to determine when -# to regenerate the autoconf.mk file. - -quiet_cmd_autoconf_dep = GEN $@ - cmd_autoconf_dep = $(CC) -x c -DDO_DEPS_ONLY -M $(c_flags) \ - -MQ include/autoconf.mk $(srctree)/include/common.h > $@ || rm $@ - -include/autoconf.mk.dep: include/config.h include/common.h - $(call cmd,autoconf_dep) - -quiet_cmd_autoconf = GEN $@ - cmd_autoconf = \ - $(CPP) $(c_flags) -DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && \ - sed -n -f $(srctree)/tools/scripts/define2mk.sed $@.tmp > $@; \ - rm $@.tmp - -include/autoconf.mk: include/config.h - $(call cmd,autoconf) quiet_cmd_offsets = GEN $@ cmd_offsets = $(srctree)/tools/scripts/make-asm-offsets $< $@ @@ -1003,17 +1059,6 @@ $(CPUDIR)/$(SOC)/asm-offsets.s: include/config.h $(call cmd,soc_asm-offsets.s) ######################################################################### -else # !config.mk -all u-boot.hex u-boot.srec u-boot.bin \ -u-boot.img u-boot.dis u-boot \ -$(filter-out tools,$(SUBDIRS)) \ -depend dep tags ctags etags cscope System.map: - @echo "System not configured - see README" >&2 - @ exit 1 - -tools: $(VERSION_FILE) $(TIMESTAMP_FILE) - $(MAKE) $(build)=$@ all -endif # config.mk # ARM relocations should all be R_ARM_RELATIVE (32-bit) or # R_AARCH64_RELATIVE (64-bit). @@ -1066,15 +1111,6 @@ include/license.h: tools/bin2header COPYING cat COPYING | gzip -9 -c | ./tools/bin2header license_gzip > include/license.h ######################################################################### -unconfig: - @rm -f include/config.h include/config.mk \ - board/*/config.tmp board/*/*/config.tmp \ - include/autoconf.mk include/autoconf.mk.dep \ - include/spl-autoconf.mk \ - include/tpl-autoconf.mk - -%_config:: unconfig - @$(MKCONFIG) -A $(@:_config=) ######################################################################### @@ -1151,8 +1187,14 @@ clobber: clean @rm -f dts/*.tmp @rm -f $(addprefix spl/, u-boot-spl.ais, u-boot-spl-pad.ais) -mrproper \ -distclean: clobber unconfig +mrproper: clobber + @rm -f include/config.h include/config.mk \ + board/*/config.tmp board/*/*/config.tmp \ + include/autoconf.mk include/autoconf.mk.dep \ + include/spl-autoconf.mk \ + include/tpl-autoconf.mk + +distclean: mrproper ifneq ($(OBJTREE),$(SRCTREE)) rm -rf * endif @@ -1163,6 +1205,9 @@ backup: ######################################################################### +endif #ifeq ($(config-targets),1) +endif #ifeq ($(mixed-targets),1) + endif # skip-makefile PHONY += FORCE