config.mk 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. #
  2. # (C) Copyright 2000-2013
  3. # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. #
  5. # SPDX-License-Identifier: GPL-2.0+
  6. #
  7. #########################################################################
  8. # Set shell to bash if possible, otherwise fall back to sh
  9. SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
  10. else if [ -x /bin/bash ]; then echo /bin/bash; \
  11. else echo sh; fi; fi)
  12. export SHELL
  13. ifeq ($(CURDIR),$(SRCTREE))
  14. dir :=
  15. else
  16. dir := $(subst $(SRCTREE)/,,$(CURDIR))
  17. endif
  18. ifneq ($(OBJTREE),$(SRCTREE))
  19. # Create object files for SPL in a separate directory
  20. ifeq ($(CONFIG_SPL_BUILD),y)
  21. ifeq ($(CONFIG_TPL_BUILD),y)
  22. obj := $(if $(dir),$(TPLTREE)/$(dir)/,$(TPLTREE)/)
  23. else
  24. obj := $(if $(dir),$(SPLTREE)/$(dir)/,$(SPLTREE)/)
  25. endif
  26. else
  27. obj := $(if $(dir),$(OBJTREE)/$(dir)/,$(OBJTREE)/)
  28. endif
  29. src := $(if $(dir),$(SRCTREE)/$(dir)/,$(SRCTREE)/)
  30. $(shell mkdir -p $(obj))
  31. else
  32. # Create object files for SPL in a separate directory
  33. ifeq ($(CONFIG_SPL_BUILD),y)
  34. ifeq ($(CONFIG_TPL_BUILD),y)
  35. obj := $(if $(dir),$(TPLTREE)/$(dir)/,$(TPLTREE)/)
  36. else
  37. obj := $(if $(dir),$(SPLTREE)/$(dir)/,$(SPLTREE)/)
  38. endif
  39. $(shell mkdir -p $(obj))
  40. else
  41. obj :=
  42. endif
  43. src :=
  44. endif
  45. # clean the slate ...
  46. PLATFORM_RELFLAGS =
  47. PLATFORM_CPPFLAGS =
  48. PLATFORM_LDFLAGS =
  49. #########################################################################
  50. HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer \
  51. $(HOSTCPPFLAGS)
  52. #
  53. # Mac OS X / Darwin's C preprocessor is Apple specific. It
  54. # generates numerous errors and warnings. We want to bypass it
  55. # and use GNU C's cpp. To do this we pass the -traditional-cpp
  56. # option to the compiler. Note that the -traditional-cpp flag
  57. # DOES NOT have the same semantics as GNU C's flag, all it does
  58. # is invoke the GNU preprocessor in stock ANSI/ISO C fashion.
  59. #
  60. # Apple's linker is similar, thanks to the new 2 stage linking
  61. # multiple symbol definitions are treated as errors, hence the
  62. # -multiply_defined suppress option to turn off this error.
  63. #
  64. ifeq ($(HOSTOS),darwin)
  65. # get major and minor product version (e.g. '10' and '6' for Snow Leopard)
  66. DARWIN_MAJOR_VERSION = $(shell sw_vers -productVersion | cut -f 1 -d '.')
  67. DARWIN_MINOR_VERSION = $(shell sw_vers -productVersion | cut -f 2 -d '.')
  68. os_x_before = $(shell if [ $(DARWIN_MAJOR_VERSION) -le $(1) -a \
  69. $(DARWIN_MINOR_VERSION) -le $(2) ] ; then echo "$(3)"; else echo "$(4)"; fi ;)
  70. # Snow Leopards build environment has no longer restrictions as described above
  71. HOSTCC = $(call os_x_before, 10, 5, "cc", "gcc")
  72. HOSTCFLAGS += $(call os_x_before, 10, 4, "-traditional-cpp")
  73. HOSTLDFLAGS += $(call os_x_before, 10, 5, "-multiply_defined suppress")
  74. else
  75. HOSTCC = gcc
  76. endif
  77. ifeq ($(HOSTOS),cygwin)
  78. HOSTCFLAGS += -ansi
  79. endif
  80. #########################################################################
  81. #
  82. # Option checker, gcc version (courtesy linux kernel) to ensure
  83. # only supported compiler options are used
  84. #
  85. CC_OPTIONS_CACHE_FILE := $(OBJTREE)/include/generated/cc_options.mk
  86. CC_TEST_OFILE := $(OBJTREE)/include/generated/cc_test_file.o
  87. -include $(CC_OPTIONS_CACHE_FILE)
  88. cc-option-sys = $(shell mkdir -p $(dir $(CC_TEST_OFILE)); \
  89. if $(CC) $(CFLAGS) $(1) -S -xc /dev/null -o $(CC_TEST_OFILE) \
  90. > /dev/null 2>&1; then \
  91. echo 'CC_OPTIONS += $(strip $1)' >> $(CC_OPTIONS_CACHE_FILE); \
  92. echo "$(1)"; fi)
  93. ifeq ($(CONFIG_CC_OPT_CACHE_DISABLE),y)
  94. cc-option = $(strip $(if $(call cc-option-sys,$1),$1,$2))
  95. else
  96. cc-option = $(strip $(if $(findstring $1,$(CC_OPTIONS)),$1,\
  97. $(if $(call cc-option-sys,$1),$1,$2)))
  98. endif
  99. # cc-version
  100. # Usage gcc-ver := $(call cc-version)
  101. cc-version = $(shell $(SHELL) $(SRCTREE)/scripts/gcc-version.sh $(CC))
  102. binutils-version = $(shell $(SHELL) $(SRCTREE)/scripts/binutils-version.sh $(AS))
  103. dtc-version = $(shell $(SHELL) $(SRCTREE)/scripts/dtc-version.sh $(DTC))
  104. #
  105. # Include the make variables (CC, etc...)
  106. #
  107. AS = $(CROSS_COMPILE)as
  108. # Always use GNU ld
  109. LD = $(shell if $(CROSS_COMPILE)ld.bfd -v > /dev/null 2>&1; \
  110. then echo "$(CROSS_COMPILE)ld.bfd"; else echo "$(CROSS_COMPILE)ld"; fi;)
  111. CC = $(CROSS_COMPILE)gcc
  112. CPP = $(CC) -E
  113. AR = $(CROSS_COMPILE)ar
  114. NM = $(CROSS_COMPILE)nm
  115. LDR = $(CROSS_COMPILE)ldr
  116. STRIP = $(CROSS_COMPILE)strip
  117. OBJCOPY = $(CROSS_COMPILE)objcopy
  118. OBJDUMP = $(CROSS_COMPILE)objdump
  119. RANLIB = $(CROSS_COMPILE)RANLIB
  120. DTC = dtc
  121. CHECK = sparse
  122. #########################################################################
  123. # Load generated board configuration
  124. ifeq ($(CONFIG_TPL_BUILD),y)
  125. # Include TPL autoconf
  126. sinclude $(OBJTREE)/include/tpl-autoconf.mk
  127. else
  128. ifeq ($(CONFIG_SPL_BUILD),y)
  129. # Include SPL autoconf
  130. sinclude $(OBJTREE)/include/spl-autoconf.mk
  131. else
  132. # Include normal autoconf
  133. sinclude $(OBJTREE)/include/autoconf.mk
  134. endif
  135. endif
  136. sinclude $(OBJTREE)/include/config.mk
  137. # Some architecture config.mk files need to know what CPUDIR is set to,
  138. # so calculate CPUDIR before including ARCH/SOC/CPU config.mk files.
  139. # Check if arch/$ARCH/cpu/$CPU exists, otherwise assume arch/$ARCH/cpu contains
  140. # CPU-specific code.
  141. CPUDIR=arch/$(ARCH)/cpu/$(CPU)
  142. ifneq ($(SRCTREE)/$(CPUDIR),$(wildcard $(SRCTREE)/$(CPUDIR)))
  143. CPUDIR=arch/$(ARCH)/cpu
  144. endif
  145. sinclude $(TOPDIR)/arch/$(ARCH)/config.mk # include architecture dependend rules
  146. sinclude $(TOPDIR)/$(CPUDIR)/config.mk # include CPU specific rules
  147. ifdef SOC
  148. sinclude $(TOPDIR)/$(CPUDIR)/$(SOC)/config.mk # include SoC specific rules
  149. endif
  150. ifdef VENDOR
  151. BOARDDIR = $(VENDOR)/$(BOARD)
  152. else
  153. BOARDDIR = $(BOARD)
  154. endif
  155. ifdef BOARD
  156. sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules
  157. endif
  158. #########################################################################
  159. # We don't actually use $(ARFLAGS) anywhere anymore, so catch people
  160. # who are porting old code to latest mainline but not updating $(AR).
  161. ARFLAGS = $(error update your Makefile to use cmd_link_o_target and not AR)
  162. RELFLAGS= $(PLATFORM_RELFLAGS)
  163. DBGFLAGS= -g # -DDEBUG
  164. OPTFLAGS= -Os #-fomit-frame-pointer
  165. OBJCFLAGS += --gap-fill=0xff
  166. gccincdir := $(shell $(CC) -print-file-name=include)
  167. CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \
  168. -D__KERNEL__
  169. # Enable garbage collection of un-used sections for SPL
  170. ifeq ($(CONFIG_SPL_BUILD),y)
  171. CPPFLAGS += -ffunction-sections -fdata-sections
  172. LDFLAGS_FINAL += --gc-sections
  173. endif
  174. ifneq ($(CONFIG_SYS_TEXT_BASE),)
  175. CPPFLAGS += -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE)
  176. endif
  177. ifeq ($(CONFIG_SPL_BUILD),y)
  178. CPPFLAGS += -DCONFIG_SPL_BUILD
  179. ifeq ($(CONFIG_TPL_BUILD),y)
  180. CPPFLAGS += -DCONFIG_TPL_BUILD
  181. endif
  182. endif
  183. # Does this architecture support generic board init?
  184. ifeq ($(__HAVE_ARCH_GENERIC_BOARD),)
  185. ifneq ($(CONFIG_SYS_GENERIC_BOARD),)
  186. CHECK_GENERIC_BOARD = $(error Your architecture does not support generic board. \
  187. Please undefined CONFIG_SYS_GENERIC_BOARD in your board config file)
  188. endif
  189. endif
  190. ifneq ($(OBJTREE),$(SRCTREE))
  191. CPPFLAGS += -I$(OBJTREE)/include
  192. endif
  193. CPPFLAGS += -I$(TOPDIR)/include -I$(SRCTREE)/arch/$(ARCH)/include
  194. CPPFLAGS += -fno-builtin -ffreestanding -nostdinc \
  195. -isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS)
  196. CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes
  197. ifdef BUILD_TAG
  198. CFLAGS += -DBUILD_TAG='"$(BUILD_TAG)"'
  199. endif
  200. CFLAGS_SSP := $(call cc-option,-fno-stack-protector)
  201. CFLAGS += $(CFLAGS_SSP)
  202. # Some toolchains enable security related warning flags by default,
  203. # but they don't make much sense in the u-boot world, so disable them.
  204. CFLAGS_WARN := $(call cc-option,-Wno-format-nonliteral) \
  205. $(call cc-option,-Wno-format-security)
  206. CFLAGS += $(CFLAGS_WARN)
  207. # Report stack usage if supported
  208. CFLAGS_STACK := $(call cc-option,-fstack-usage)
  209. CFLAGS += $(CFLAGS_STACK)
  210. BCURDIR = $(subst $(SRCTREE)/,,$(CURDIR:$(obj)%=%))
  211. ifeq ($(findstring examples/,$(BCURDIR)),)
  212. ifeq ($(CONFIG_SPL_BUILD),)
  213. ifdef FTRACE
  214. CFLAGS += -finstrument-functions -DFTRACE
  215. endif
  216. endif
  217. endif
  218. # $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
  219. # option to the assembler.
  220. AFLAGS_DEBUG :=
  221. # turn jbsr into jsr for m68k
  222. ifeq ($(ARCH),m68k)
  223. ifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4)
  224. AFLAGS_DEBUG := -Wa,-gstabs,-S
  225. endif
  226. endif
  227. AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS)
  228. LDFLAGS += $(PLATFORM_LDFLAGS)
  229. LDFLAGS_FINAL += -Bstatic
  230. LDFLAGS_u-boot += -T $(obj)u-boot.lds $(LDFLAGS_FINAL)
  231. ifneq ($(CONFIG_SYS_TEXT_BASE),)
  232. LDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE)
  233. endif
  234. LDFLAGS_$(SPL_BIN) += -T $(obj)u-boot-spl.lds $(LDFLAGS_FINAL)
  235. ifneq ($(CONFIG_SPL_TEXT_BASE),)
  236. LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_SPL_TEXT_BASE)
  237. endif
  238. # Linus' kernel sanity checking tool
  239. CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
  240. -Wbitwise -Wno-return-void -D__CHECK_ENDIAN__ $(CF)
  241. # Location of a usable BFD library, where we define "usable" as
  242. # "built for ${HOST}, supports ${TARGET}". Sensible values are
  243. # - When cross-compiling: the root of the cross-environment
  244. # - Linux/ppc (native): /usr
  245. # - NetBSD/ppc (native): you lose ... (must extract these from the
  246. # binutils build directory, plus the native and U-Boot include
  247. # files don't like each other)
  248. #
  249. # So far, this is used only by tools/gdb/Makefile.
  250. ifeq ($(HOSTOS),darwin)
  251. BFD_ROOT_DIR = /usr/local/tools
  252. else
  253. ifeq ($(HOSTARCH),$(ARCH))
  254. # native
  255. BFD_ROOT_DIR = /usr
  256. else
  257. #BFD_ROOT_DIR = /LinuxPPC/CDK # Linux/i386
  258. #BFD_ROOT_DIR = /usr/pkg/cross # NetBSD/i386
  259. BFD_ROOT_DIR = /opt/powerpc
  260. endif
  261. endif
  262. #########################################################################
  263. export HOSTCC HOSTCFLAGS HOSTLDFLAGS CROSS_COMPILE \
  264. AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP MAKE
  265. export CONFIG_SYS_TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS