config.mk 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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. HOSTSTRIP = strip
  53. #
  54. # Mac OS X / Darwin's C preprocessor is Apple specific. It
  55. # generates numerous errors and warnings. We want to bypass it
  56. # and use GNU C's cpp. To do this we pass the -traditional-cpp
  57. # option to the compiler. Note that the -traditional-cpp flag
  58. # DOES NOT have the same semantics as GNU C's flag, all it does
  59. # is invoke the GNU preprocessor in stock ANSI/ISO C fashion.
  60. #
  61. # Apple's linker is similar, thanks to the new 2 stage linking
  62. # multiple symbol definitions are treated as errors, hence the
  63. # -multiply_defined suppress option to turn off this error.
  64. #
  65. ifeq ($(HOSTOS),darwin)
  66. # get major and minor product version (e.g. '10' and '6' for Snow Leopard)
  67. DARWIN_MAJOR_VERSION = $(shell sw_vers -productVersion | cut -f 1 -d '.')
  68. DARWIN_MINOR_VERSION = $(shell sw_vers -productVersion | cut -f 2 -d '.')
  69. os_x_before = $(shell if [ $(DARWIN_MAJOR_VERSION) -le $(1) -a \
  70. $(DARWIN_MINOR_VERSION) -le $(2) ] ; then echo "$(3)"; else echo "$(4)"; fi ;)
  71. # Snow Leopards build environment has no longer restrictions as described above
  72. HOSTCC = $(call os_x_before, 10, 5, "cc", "gcc")
  73. HOSTCFLAGS += $(call os_x_before, 10, 4, "-traditional-cpp")
  74. HOSTLDFLAGS += $(call os_x_before, 10, 5, "-multiply_defined suppress")
  75. else
  76. HOSTCC = gcc
  77. endif
  78. ifeq ($(HOSTOS),cygwin)
  79. HOSTCFLAGS += -ansi
  80. endif
  81. # We build some files with extra pedantic flags to try to minimize things
  82. # that won't build on some weird host compiler -- though there are lots of
  83. # exceptions for files that aren't complaint.
  84. HOSTCFLAGS_NOPED = $(filter-out -pedantic,$(HOSTCFLAGS))
  85. HOSTCFLAGS += -pedantic
  86. #########################################################################
  87. #
  88. # Option checker, gcc version (courtesy linux kernel) to ensure
  89. # only supported compiler options are used
  90. #
  91. CC_OPTIONS_CACHE_FILE := $(OBJTREE)/include/generated/cc_options.mk
  92. CC_TEST_OFILE := $(OBJTREE)/include/generated/cc_test_file.o
  93. -include $(CC_OPTIONS_CACHE_FILE)
  94. cc-option-sys = $(shell mkdir -p $(dir $(CC_TEST_OFILE)); \
  95. if $(CC) $(CFLAGS) $(1) -S -xc /dev/null -o $(CC_TEST_OFILE) \
  96. > /dev/null 2>&1; then \
  97. echo 'CC_OPTIONS += $(strip $1)' >> $(CC_OPTIONS_CACHE_FILE); \
  98. echo "$(1)"; fi)
  99. ifeq ($(CONFIG_CC_OPT_CACHE_DISABLE),y)
  100. cc-option = $(strip $(if $(call cc-option-sys,$1),$1,$2))
  101. else
  102. cc-option = $(strip $(if $(findstring $1,$(CC_OPTIONS)),$1,\
  103. $(if $(call cc-option-sys,$1),$1,$2)))
  104. endif
  105. # cc-version
  106. # Usage gcc-ver := $(call cc-version)
  107. cc-version = $(shell $(SHELL) $(SRCTREE)/scripts/gcc-version.sh $(CC))
  108. binutils-version = $(shell $(SHELL) $(SRCTREE)/scripts/binutils-version.sh $(AS))
  109. dtc-version = $(shell $(SHELL) $(SRCTREE)/scripts/dtc-version.sh $(DTC))
  110. #
  111. # Include the make variables (CC, etc...)
  112. #
  113. AS = $(CROSS_COMPILE)as
  114. # Always use GNU ld
  115. LD = $(shell if $(CROSS_COMPILE)ld.bfd -v > /dev/null 2>&1; \
  116. then echo "$(CROSS_COMPILE)ld.bfd"; else echo "$(CROSS_COMPILE)ld"; fi;)
  117. CC = $(CROSS_COMPILE)gcc
  118. CPP = $(CC) -E
  119. AR = $(CROSS_COMPILE)ar
  120. NM = $(CROSS_COMPILE)nm
  121. LDR = $(CROSS_COMPILE)ldr
  122. STRIP = $(CROSS_COMPILE)strip
  123. OBJCOPY = $(CROSS_COMPILE)objcopy
  124. OBJDUMP = $(CROSS_COMPILE)objdump
  125. RANLIB = $(CROSS_COMPILE)RANLIB
  126. DTC = dtc
  127. CHECK = sparse
  128. #########################################################################
  129. # Load generated board configuration
  130. ifeq ($(CONFIG_TPL_BUILD),y)
  131. # Include TPL autoconf
  132. sinclude $(OBJTREE)/include/tpl-autoconf.mk
  133. else
  134. ifeq ($(CONFIG_SPL_BUILD),y)
  135. # Include SPL autoconf
  136. sinclude $(OBJTREE)/include/spl-autoconf.mk
  137. else
  138. # Include normal autoconf
  139. sinclude $(OBJTREE)/include/autoconf.mk
  140. endif
  141. endif
  142. sinclude $(OBJTREE)/include/config.mk
  143. # Some architecture config.mk files need to know what CPUDIR is set to,
  144. # so calculate CPUDIR before including ARCH/SOC/CPU config.mk files.
  145. # Check if arch/$ARCH/cpu/$CPU exists, otherwise assume arch/$ARCH/cpu contains
  146. # CPU-specific code.
  147. CPUDIR=arch/$(ARCH)/cpu/$(CPU)
  148. ifneq ($(SRCTREE)/$(CPUDIR),$(wildcard $(SRCTREE)/$(CPUDIR)))
  149. CPUDIR=arch/$(ARCH)/cpu
  150. endif
  151. sinclude $(TOPDIR)/arch/$(ARCH)/config.mk # include architecture dependend rules
  152. sinclude $(TOPDIR)/$(CPUDIR)/config.mk # include CPU specific rules
  153. ifdef SOC
  154. sinclude $(TOPDIR)/$(CPUDIR)/$(SOC)/config.mk # include SoC specific rules
  155. endif
  156. ifdef VENDOR
  157. BOARDDIR = $(VENDOR)/$(BOARD)
  158. else
  159. BOARDDIR = $(BOARD)
  160. endif
  161. ifdef BOARD
  162. sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules
  163. endif
  164. #########################################################################
  165. # We don't actually use $(ARFLAGS) anywhere anymore, so catch people
  166. # who are porting old code to latest mainline but not updating $(AR).
  167. ARFLAGS = $(error update your Makefile to use cmd_link_o_target and not AR)
  168. RELFLAGS= $(PLATFORM_RELFLAGS)
  169. DBGFLAGS= -g # -DDEBUG
  170. OPTFLAGS= -Os #-fomit-frame-pointer
  171. OBJCFLAGS += --gap-fill=0xff
  172. gccincdir := $(shell $(CC) -print-file-name=include)
  173. CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \
  174. -D__KERNEL__
  175. # Enable garbage collection of un-used sections for SPL
  176. ifeq ($(CONFIG_SPL_BUILD),y)
  177. CPPFLAGS += -ffunction-sections -fdata-sections
  178. LDFLAGS_FINAL += --gc-sections
  179. endif
  180. # TODO(sjg@chromium.org): Is this correct on Mac OS?
  181. # MXSImage needs LibSSL
  182. ifneq ($(CONFIG_MX23)$(CONFIG_MX28),)
  183. HOSTLIBS += -lssl -lcrypto
  184. # Add CONFIG_MXS into host CFLAGS, so we can check whether or not register
  185. # the mxsimage support within tools/mxsimage.c .
  186. HOSTCFLAGS += -DCONFIG_MXS
  187. endif
  188. ifdef CONFIG_FIT_SIGNATURE
  189. HOSTLIBS += -lssl -lcrypto
  190. # This affects include/image.h, but including the board config file
  191. # is tricky, so manually define this options here.
  192. HOSTCFLAGS += -DCONFIG_FIT_SIGNATURE
  193. endif
  194. ifneq ($(CONFIG_SYS_TEXT_BASE),)
  195. CPPFLAGS += -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE)
  196. endif
  197. ifeq ($(CONFIG_SPL_BUILD),y)
  198. CPPFLAGS += -DCONFIG_SPL_BUILD
  199. ifeq ($(CONFIG_TPL_BUILD),y)
  200. CPPFLAGS += -DCONFIG_TPL_BUILD
  201. endif
  202. endif
  203. # Does this architecture support generic board init?
  204. ifeq ($(__HAVE_ARCH_GENERIC_BOARD),)
  205. ifneq ($(CONFIG_SYS_GENERIC_BOARD),)
  206. CHECK_GENERIC_BOARD = $(error Your architecture does not support generic board. \
  207. Please undefined CONFIG_SYS_GENERIC_BOARD in your board config file)
  208. endif
  209. endif
  210. # Sandbox needs the base flags and includes, so keep them around
  211. BASE_CPPFLAGS := $(CPPFLAGS)
  212. ifneq ($(OBJTREE),$(SRCTREE))
  213. BASE_INCLUDE_DIRS := $(OBJTREE)/include
  214. endif
  215. BASE_INCLUDE_DIRS += $(TOPDIR)/include $(SRCTREE)/arch/$(ARCH)/include
  216. CPPFLAGS += $(patsubst %, -I%, $(BASE_INCLUDE_DIRS))
  217. CPPFLAGS += -fno-builtin -ffreestanding -nostdinc \
  218. -isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS)
  219. CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes
  220. ifdef BUILD_TAG
  221. CFLAGS += -DBUILD_TAG='"$(BUILD_TAG)"'
  222. endif
  223. CFLAGS_SSP := $(call cc-option,-fno-stack-protector)
  224. CFLAGS += $(CFLAGS_SSP)
  225. # Some toolchains enable security related warning flags by default,
  226. # but they don't make much sense in the u-boot world, so disable them.
  227. CFLAGS_WARN := $(call cc-option,-Wno-format-nonliteral) \
  228. $(call cc-option,-Wno-format-security)
  229. CFLAGS += $(CFLAGS_WARN)
  230. # Report stack usage if supported
  231. CFLAGS_STACK := $(call cc-option,-fstack-usage)
  232. CFLAGS += $(CFLAGS_STACK)
  233. BCURDIR = $(subst $(SRCTREE)/,,$(CURDIR:$(obj)%=%))
  234. ifeq ($(findstring examples/,$(BCURDIR)),)
  235. ifeq ($(CONFIG_SPL_BUILD),)
  236. ifdef FTRACE
  237. CFLAGS += -finstrument-functions -DFTRACE
  238. endif
  239. endif
  240. endif
  241. # $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
  242. # option to the assembler.
  243. AFLAGS_DEBUG :=
  244. # turn jbsr into jsr for m68k
  245. ifeq ($(ARCH),m68k)
  246. ifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4)
  247. AFLAGS_DEBUG := -Wa,-gstabs,-S
  248. endif
  249. endif
  250. AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS)
  251. LDFLAGS += $(PLATFORM_LDFLAGS)
  252. LDFLAGS_FINAL += -Bstatic
  253. LDFLAGS_u-boot += -T $(obj)u-boot.lds $(LDFLAGS_FINAL)
  254. ifneq ($(CONFIG_SYS_TEXT_BASE),)
  255. LDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE)
  256. endif
  257. LDFLAGS_$(SPL_BIN) += -T $(obj)u-boot-spl.lds $(LDFLAGS_FINAL)
  258. ifneq ($(CONFIG_SPL_TEXT_BASE),)
  259. LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_SPL_TEXT_BASE)
  260. endif
  261. # Linus' kernel sanity checking tool
  262. CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
  263. -Wbitwise -Wno-return-void -D__CHECK_ENDIAN__ $(CF)
  264. # Location of a usable BFD library, where we define "usable" as
  265. # "built for ${HOST}, supports ${TARGET}". Sensible values are
  266. # - When cross-compiling: the root of the cross-environment
  267. # - Linux/ppc (native): /usr
  268. # - NetBSD/ppc (native): you lose ... (must extract these from the
  269. # binutils build directory, plus the native and U-Boot include
  270. # files don't like each other)
  271. #
  272. # So far, this is used only by tools/gdb/Makefile.
  273. ifeq ($(HOSTOS),darwin)
  274. BFD_ROOT_DIR = /usr/local/tools
  275. else
  276. ifeq ($(HOSTARCH),$(ARCH))
  277. # native
  278. BFD_ROOT_DIR = /usr
  279. else
  280. #BFD_ROOT_DIR = /LinuxPPC/CDK # Linux/i386
  281. #BFD_ROOT_DIR = /usr/pkg/cross # NetBSD/i386
  282. BFD_ROOT_DIR = /opt/powerpc
  283. endif
  284. endif
  285. #########################################################################
  286. export HOSTCC HOSTCFLAGS HOSTLDFLAGS PEDCFLAGS HOSTSTRIP CROSS_COMPILE \
  287. AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP MAKE
  288. export CONFIG_SYS_TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS
  289. #########################################################################
  290. # Allow boards to use custom optimize flags on a per dir/file basis
  291. ALL_AFLAGS = $(AFLAGS) $(AFLAGS_$(BCURDIR)/$(@F)) $(AFLAGS_$(BCURDIR))
  292. ALL_CFLAGS = $(CFLAGS) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR))
  293. EXTRA_CPPFLAGS = $(CPPFLAGS_$(BCURDIR)/$(@F)) $(CPPFLAGS_$(BCURDIR))
  294. ALL_CFLAGS += $(EXTRA_CPPFLAGS)
  295. # The _DEP version uses the $< file target (for dependency generation)
  296. # See rules.mk
  297. EXTRA_CPPFLAGS_DEP = $(CPPFLAGS_$(BCURDIR)/$(addsuffix .o,$(basename $<))) \
  298. $(CPPFLAGS_$(BCURDIR))
  299. $(obj)%.s: %.S
  300. $(CPP) $(ALL_AFLAGS) -o $@ $<
  301. $(obj)%.o: %.S
  302. $(CC) $(ALL_AFLAGS) -o $@ $< -c
  303. $(obj)%.o: %.c
  304. ifneq ($(CHECKSRC),0)
  305. $(CHECK) $(CHECKFLAGS) $(ALL_CFLAGS) $<
  306. endif
  307. $(CC) $(ALL_CFLAGS) -o $@ $< -c
  308. $(obj)%.i: %.c
  309. $(CPP) $(ALL_CFLAGS) -o $@ $< -c
  310. $(obj)%.s: %.c
  311. $(CC) $(ALL_CFLAGS) -o $@ $< -c -S
  312. #########################################################################
  313. # If the list of objects to link is empty, just create an empty built-in.o
  314. cmd_link_o_target = $(if $(strip $1),\
  315. $(LD) $(LDFLAGS) -r -o $@ $1,\
  316. rm -f $@; $(AR) rcs $@ )
  317. #########################################################################