All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masahiro Yamada <yamada.m@jp.panasonic.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v8 08/38] Makefile: move some variable definitions to the top Makefile
Date: Wed, 29 Jan 2014 21:26:05 +0900	[thread overview]
Message-ID: <1390998395-18567-9-git-send-email-yamada.m@jp.panasonic.com> (raw)
In-Reply-To: <1390998395-18567-1-git-send-email-yamada.m@jp.panasonic.com>

This commit moves some variable definitions from config.mk
to the top Makefile:

  - HOSTCC, HOSTCFLAGS, HOSTLDFLAGS
  - AS, LD, CC, CPP, etc.
  - SHELL (renamed to CONFIG_SHELL)

I'd like to slim down config.mk file
because it is included from all recursive make.
It is redundant to re-define the variables
every time descending into sub directories.
We should rather define them at the top Makefile
and export them.

U-Boot makefiles has been used "SHELL" variable to store shell
chosen for the user, whereas Linux Kernel uses "CONFIG_SHELL".

We should never use "SHELL" variable because it is
a special variable for GNU Make.
Changing SHELL may cause unpredictable side effects
whose root cause is usually difficult to find.
We should use a generic variable name "CONFIG_SHELL".

We should not use the syntax as follows either:

    rm -f $(obj)tools/env/{fw_printenv,fw_setenv}

This depends on "bash" although GNU Make generally
invokes "sh" to run the each rule.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
---

O'REILLY GNU Make says like follows about SHELL variable:

By default, /bin/sh is used for the shell.
This shell is controlled by the make variable SHELL
but it is not inherited from the environment.
When make starts, it imports all the variables
from the user?s environment as make variables, except SHELL.
This is because the user?s choice of shell should not cause a
makefile (possibly included in some downloaded software package) to fail.
If a user really wants to change the default shell used by make,
he can set the SHELL variable explicitly in the makefile.

Please refer to the first page of the following PDF file:
http://oreilly.com/catalog/make3/book/ch05.pdf


Changes in v8: None
Changes in v7: None
Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2:
  - Do not use bash-dependent clean rules:
     For example,
         rm -f $(obj)tools/env/{fw_printenv,fw_setenv}
       should be converted to
         rm -f $(addprefix $(obj)tools/env/, fw_printenv fw_setenv)
  - Add more comments in commit log
  - Rebase on v2014.01-rc2 tag

 Makefile  | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
 config.mk | 78 ++--------------------------------------------------
 2 files changed, 84 insertions(+), 88 deletions(-)

diff --git a/Makefile b/Makefile
index 5204ab4..0c1eef3 100644
--- a/Makefile
+++ b/Makefile
@@ -161,6 +161,73 @@ ifeq ($(HOSTARCH),$(ARCH))
 CROSS_COMPILE ?=
 endif
 
+# SHELL used by kbuild
+CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
+	  else if [ -x /bin/bash ]; then echo /bin/bash; \
+	  else echo sh; fi ; fi)
+
+HOSTCC       = gcc
+HOSTCFLAGS   = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
+
+ifeq ($(HOSTOS),cygwin)
+HOSTCFLAGS	+= -ansi
+endif
+
+# Mac OS X / Darwin's C preprocessor is Apple specific.  It
+# generates numerous errors and warnings.  We want to bypass it
+# and use GNU C's cpp.	To do this we pass the -traditional-cpp
+# option to the compiler.  Note that the -traditional-cpp flag
+# DOES NOT have the same semantics as GNU C's flag, all it does
+# is invoke the GNU preprocessor in stock ANSI/ISO C fashion.
+#
+# Apple's linker is similar, thanks to the new 2 stage linking
+# multiple symbol definitions are treated as errors, hence the
+# -multiply_defined suppress option to turn off this error.
+#
+ifeq ($(HOSTOS),darwin)
+# get major and minor product version (e.g. '10' and '6' for Snow Leopard)
+DARWIN_MAJOR_VERSION	= $(shell sw_vers -productVersion | cut -f 1 -d '.')
+DARWIN_MINOR_VERSION	= $(shell sw_vers -productVersion | cut -f 2 -d '.')
+
+os_x_before	= $(shell if [ $(DARWIN_MAJOR_VERSION) -le $(1) -a \
+	$(DARWIN_MINOR_VERSION) -le $(2) ] ; then echo "$(3)"; else echo "$(4)"; fi ;)
+
+# Snow Leopards build environment has no longer restrictions as described above
+HOSTCC       = $(call os_x_before, 10, 5, "cc", "gcc")
+HOSTCFLAGS  += $(call os_x_before, 10, 4, "-traditional-cpp")
+HOSTLDFLAGS += $(call os_x_before, 10, 5, "-multiply_defined suppress")
+endif
+
+# Make variables (CC, etc...)
+
+AS		= $(CROSS_COMPILE)as
+# Always use GNU ld
+ifneq ($(shell $(CROSS_COMPILE)ld.bfd -v 2> /dev/null),)
+LD		= $(CROSS_COMPILE)ld.bfd
+else
+LD		= $(CROSS_COMPILE)ld
+endif
+CC		= $(CROSS_COMPILE)gcc
+CPP		= $(CC) -E
+AR		= $(CROSS_COMPILE)ar
+NM		= $(CROSS_COMPILE)nm
+LDR		= $(CROSS_COMPILE)ldr
+STRIP		= $(CROSS_COMPILE)strip
+OBJCOPY		= $(CROSS_COMPILE)objcopy
+OBJDUMP		= $(CROSS_COMPILE)objdump
+AWK		= awk
+RANLIB		= $(CROSS_COMPILE)RANLIB
+DTC		= dtc
+CHECK		= sparse
+
+CHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
+		  -Wbitwise -Wno-return-void -D__CHECK_ENDIAN__ $(CF)
+
+export CONFIG_SHELL HOSTCC HOSTCFLAGS HOSTLDFLAGS CROSS_COMPILE AS LD CC
+export CPP AR NM LDR STRIP OBJCOPY OBJDUMP
+export MAKE AWK
+export DTC CHECK CHECKFLAGS
+
 # load other configuration
 include $(TOPDIR)/config.mk
 
@@ -788,27 +855,28 @@ clean:
 	       $(obj)examples/standalone/interrupt			  \
 	       $(obj)examples/standalone/mem_to_mem_idma2intr		  \
 	       $(obj)examples/standalone/sched				  \
-	       $(obj)examples/standalone/smc911{11,x}_eeprom		  \
+	       $(addprefix $(obj)examples/standalone/, smc91111_eeprom smc911x_eeprom) \
 	       $(obj)examples/standalone/test_burst			  \
 	       $(obj)examples/standalone/timer
-	@rm -f $(obj)examples/api/demo{,.bin}
+	@rm -f $(addprefix $(obj)examples/api/, demo demo.bin)
 	@rm -f $(obj)tools/bmp_logo	   $(obj)tools/easylogo/easylogo  \
 	       $(obj)tools/env/fw_printenv				  \
 	       $(obj)tools/envcrc					  \
-	       $(obj)tools/gdb/{gdbcont,gdbsend}			  \
+	       $(addprefix $(obj)tools/gdb/, gdbcont gdbsend)		  \
 	       $(obj)tools/gen_eth_addr    $(obj)tools/img2srec		  \
-	       $(obj)tools/dump{env,}image		  \
-	       $(obj)tools/mk{env,}image   $(obj)tools/mpc86x_clk	  \
-	       $(obj)tools/mk{$(BOARD),exynos}spl			  \
+	       $(obj)tools/dumpimage					  \
+	       $(addprefix $(obj)tools/, mkenvimage mkimage)		  \
+	       $(obj)tools/mpc86x_clk					  \
+	       $(addprefix $(obj)tools/, mk$(BOARD)spl mkexynosspl)	  \
 	       $(obj)tools/mxsboot					  \
 	       $(obj)tools/ncb		   $(obj)tools/ubsha1		  \
 	       $(obj)tools/kernel-doc/docproc				  \
 	       $(obj)tools/proftool
-	@rm -f $(obj)board/cray/L1/{bootscript.c,bootscript.image}	  \
+	@rm -f $(addprefix $(obj)board/cray/L1/, bootscript.c bootscript.image) \
 	       $(obj)board/matrix_vision/*/bootscript.img		  \
 	       $(obj)spl/board/samsung/$(BOARD)/tools/mk$(BOARD)spl	  \
 	       $(obj)u-boot.lds						  \
-	       $(obj)arch/blackfin/cpu/init.{lds,elf}
+	       $(addprefix $(obj)arch/blackfin/cpu/, init.lds init.elf)
 	@rm -f $(obj)include/bmp_logo.h
 	@rm -f $(obj)include/bmp_logo_data.h
 	@rm -f $(obj)lib/asm-offsets.s
@@ -843,11 +911,11 @@ clobber:	tidy
 	@rm -f $(obj)u-boot.dtb
 	@rm -f $(obj)u-boot.sb
 	@rm -f $(obj)u-boot.spr
-	@rm -f $(obj)nand_spl/{u-boot.{lds,lst},System.map}
-	@rm -f $(obj)nand_spl/{u-boot-nand_spl.lds,u-boot-spl,u-boot-spl.map}
-	@rm -f $(obj)spl/{u-boot-spl,u-boot-spl.bin,u-boot-spl.map}
+	@rm -f $(addprefix $(obj)nand_spl/, u-boot.lds u-boot.lst System.map)
+	@rm -f $(addprefix $(obj)nand_spl/, u-boot-nand_spl.lds u-boot-spl u-boot-spl.map)
+	@rm -f $(addprefix $(obj)spl/, u-boot-spl u-boot-spl.bin u-boot-spl.map)
 	@rm -f $(obj)spl/u-boot-spl.lds
-	@rm -f $(obj)tpl/{u-boot-tpl,u-boot-tpl.bin,u-boot-tpl.map}
+	@rm -f $(addprefix $(obj)tpl/, u-boot-tpl u-boot-tpl.bin u-boot-tpl.map)
 	@rm -f $(obj)tpl/u-boot-spl.lds
 	@rm -f $(obj)MLO MLO.byteswap
 	@rm -f $(obj)SPL
@@ -856,7 +924,7 @@ clobber:	tidy
 	@rm -fr $(obj)include/generated
 	@[ ! -d $(obj)nand_spl ] || find $(obj)nand_spl -name "*" -type l -print | xargs rm -f
 	@rm -f $(obj)dts/*.tmp
-	@rm -f $(obj)spl/u-boot-spl{,-pad}.ais
+	@rm -f $(addprefix $(obj)spl/, u-boot-spl.ais, u-boot-spl-pad.ais)
 
 mrproper \
 distclean:	clobber unconfig
diff --git a/config.mk b/config.mk
index b08be7a..74617d3 100644
--- a/config.mk
+++ b/config.mk
@@ -6,13 +6,6 @@
 #
 #########################################################################
 
-# Set shell to bash if possible, otherwise fall back to sh
-SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
-	else if [ -x /bin/bash ]; then echo /bin/bash; \
-	else echo sh; fi; fi)
-
-export	SHELL
-
 ifeq ($(CURDIR),$(SRCTREE))
 dir :=
 else
@@ -55,44 +48,6 @@ PLATFORM_CPPFLAGS =
 PLATFORM_LDFLAGS =
 
 #########################################################################
-
-HOSTCFLAGS	= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer \
-		  $(HOSTCPPFLAGS)
-
-#
-# Mac OS X / Darwin's C preprocessor is Apple specific.  It
-# generates numerous errors and warnings.  We want to bypass it
-# and use GNU C's cpp.	To do this we pass the -traditional-cpp
-# option to the compiler.  Note that the -traditional-cpp flag
-# DOES NOT have the same semantics as GNU C's flag, all it does
-# is invoke the GNU preprocessor in stock ANSI/ISO C fashion.
-#
-# Apple's linker is similar, thanks to the new 2 stage linking
-# multiple symbol definitions are treated as errors, hence the
-# -multiply_defined suppress option to turn off this error.
-#
-
-ifeq ($(HOSTOS),darwin)
-# get major and minor product version (e.g. '10' and '6' for Snow Leopard)
-DARWIN_MAJOR_VERSION	= $(shell sw_vers -productVersion | cut -f 1 -d '.')
-DARWIN_MINOR_VERSION	= $(shell sw_vers -productVersion | cut -f 2 -d '.')
-
-os_x_before	= $(shell if [ $(DARWIN_MAJOR_VERSION) -le $(1) -a \
-	$(DARWIN_MINOR_VERSION) -le $(2) ] ; then echo "$(3)"; else echo "$(4)"; fi ;)
-
-# Snow Leopards build environment has no longer restrictions as described above
-HOSTCC		 = $(call os_x_before, 10, 5, "cc", "gcc")
-HOSTCFLAGS	+= $(call os_x_before, 10, 4, "-traditional-cpp")
-HOSTLDFLAGS	+= $(call os_x_before, 10, 5, "-multiply_defined suppress")
-else
-HOSTCC		= gcc
-endif
-
-ifeq ($(HOSTOS),cygwin)
-HOSTCFLAGS	+= -ansi
-endif
-
-#########################################################################
 #
 # Option checker, gcc version (courtesy linux kernel) to ensure
 # only supported compiler options are used
@@ -117,30 +72,9 @@ endif
 
 # cc-version
 # Usage gcc-ver := $(call cc-version)
-cc-version = $(shell $(SHELL) $(SRCTREE)/scripts/gcc-version.sh $(CC))
-binutils-version = $(shell $(SHELL) $(SRCTREE)/scripts/binutils-version.sh $(AS))
-dtc-version = $(shell $(SHELL) $(SRCTREE)/scripts/dtc-version.sh $(DTC))
-
-#
-# Include the make variables (CC, etc...)
-#
-AS	= $(CROSS_COMPILE)as
-
-# Always use GNU ld
-LD	= $(shell if $(CROSS_COMPILE)ld.bfd -v > /dev/null 2>&1; \
-		then echo "$(CROSS_COMPILE)ld.bfd"; else echo "$(CROSS_COMPILE)ld"; fi;)
-
-CC	= $(CROSS_COMPILE)gcc
-CPP	= $(CC) -E
-AR	= $(CROSS_COMPILE)ar
-NM	= $(CROSS_COMPILE)nm
-LDR	= $(CROSS_COMPILE)ldr
-STRIP	= $(CROSS_COMPILE)strip
-OBJCOPY = $(CROSS_COMPILE)objcopy
-OBJDUMP = $(CROSS_COMPILE)objdump
-RANLIB	= $(CROSS_COMPILE)RANLIB
-DTC	= dtc
-CHECK	= sparse
+cc-version = $(shell $(CONFIG_SHELL) $(SRCTREE)/scripts/gcc-version.sh $(CC))
+binutils-version = $(shell $(CONFIG_SHELL) $(SRCTREE)/scripts/binutils-version.sh $(AS))
+dtc-version = $(shell $(CONFIG_SHELL) $(SRCTREE)/scripts/dtc-version.sh $(DTC))
 
 #########################################################################
 
@@ -286,10 +220,6 @@ ifneq ($(CONFIG_SPL_TEXT_BASE),)
 LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_SPL_TEXT_BASE)
 endif
 
-# Linus' kernel sanity checking tool
-CHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
-		  -Wbitwise -Wno-return-void -D__CHECK_ENDIAN__ $(CF)
-
 # Location of a usable BFD library, where we define "usable" as
 # "built for ${HOST}, supports ${TARGET}".  Sensible values are
 # - When cross-compiling: the root of the cross-environment
@@ -315,6 +245,4 @@ endif
 
 #########################################################################
 
-export	HOSTCC HOSTCFLAGS HOSTLDFLAGS CROSS_COMPILE \
-	AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP MAKE
 export	CONFIG_SYS_TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS
-- 
1.8.3.2

  parent reply	other threads:[~2014-01-29 12:26 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-29 12:25 [U-Boot] [PATCH v8 0/38] Switch over to real Kbuild Masahiro Yamada
2014-01-29 12:25 ` [U-Boot] [PATCH v8 01/38] .gitignore: ingore files generated by Kbuild Masahiro Yamada
2014-01-29 12:25 ` [U-Boot] [PATCH v8 02/38] Makefile.host.tmp: add a new script to refactor tools Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 03/38] tools: convert makefiles to kbuild style Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 04/38] board: samsung: refactor host programs Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 05/38] examples: Use scripts/Makefile.build Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 06/38] nand-spl: " Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 07/38] Makfile: move suffix rules to Makefile.build Masahiro Yamada
2014-01-29 12:26 ` Masahiro Yamada [this message]
2014-01-29 12:26 ` [U-Boot] [PATCH v8 09/38] Makefile: move BFD_ROOT_DIR to tools/gdb/Makefile Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 10/38] kbuild: import Kbuild.include from linux v3.13 tag Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 11/38] kbuild: Use Kbuild.include Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 12/38] Makefile: move more flags to the top Makefile Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 13/38] Makefile: refactor include path settings Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 14/38] Makefile: move more stuff to top Makefile Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 15/38] Makefile: move some flags to spl/Makefile Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 16/38] Makefile: move some flags to examples makefiles Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 17/38] kbuild: change out-of-tree build Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 18/38] kbuild: add dummy obj-y to create built-in.o Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 19/38] Makefile: rename scripts/Makefile.build to scripts/Makefile.build.tmp Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 20/38] kbuild: import more build scripts from Linux v3.13 tag Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 21/38] kbuild: use Linux Kernel build scripts Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 22/38] kbuild: delete temporary " Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 23/38] kbuild: move some lines to more suitable place Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 24/38] kbuild: convert some make rules to Kbuild style Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 25/38] kbuild: move include directives of board configuration files Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 26/38] kbuild: generate {spl, tpl}-autoconf.mk only when it is necessary Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 27/38] Makefile: remove a cleaning target "tidy" Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 28/38] kbuild: change the top Makefile to more Kbuild-ish structure Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 29/38] examples: move api/ and standalone/ entry to examples/Makefile Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 30/38] kbuild: refactor Makefile and spl/Makefile more Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 31/38] Makefile: Do not pass MTD_VERSION from the top Makefile Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 32/38] Makefile: refactor tools-all targets Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 33/38] kbuild: use scripts/Makefile.clean Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 34/38] kbuild: support simultaneous board configuration and "make all" Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 35/38] kbuild: check clean source and generate Makefile for out-of-tree build Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 36/38] board: sandburst: delete FORCEBUILD Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 37/38] kbuild: Do not generate .*.su files at the top directory Masahiro Yamada
2014-01-29 12:26 ` [U-Boot] [PATCH v8 38/38] tools/env: cross-compile fw_printenv without setting HOSTCC Masahiro Yamada
2014-01-30 21:35 ` [U-Boot] [PATCH v8 0/38] Switch over to real Kbuild Andreas Bießmann
2014-01-31  1:48   ` Masahiro Yamada
2014-01-31  9:12 ` Masahiro Yamada
2014-02-01 12:09   ` Tom Rini
2014-01-31 20:35 ` Simon Glass
2014-02-03  3:46   ` Masahiro Yamada
2014-02-06 21:10     ` Tom Rini
2014-02-16  1:30       ` Simon Glass
2014-02-16  2:51         ` Simon Glass
2014-02-18  9:02           ` Masahiro Yamada
2014-02-19  6:09             ` Simon Glass
2014-02-19  9:51               ` Masahiro Yamada
2014-02-19 17:28             ` Tom Rini
2014-02-20  8:25               ` Masahiro Yamada
2014-02-20 13:29                 ` Tom Rini
2014-02-18 14:44         ` Tom Rini
2014-02-19  1:57           ` Masahiro Yamada
2014-02-19 12:54             ` Tom Rini
2014-02-19 13:28               ` Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1390998395-18567-9-git-send-email-yamada.m@jp.panasonic.com \
    --to=yamada.m@jp.panasonic.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.