config.mk 11 KB

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