config.mk 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. #
  102. # Include the make variables (CC, etc...)
  103. #
  104. AS = $(CROSS_COMPILE)as
  105. # Always use GNU ld
  106. LD = $(shell if $(CROSS_COMPILE)ld.bfd -v > /dev/null 2>&1; \
  107. then echo "$(CROSS_COMPILE)ld.bfd"; else echo "$(CROSS_COMPILE)ld"; fi;)
  108. CC = $(CROSS_COMPILE)gcc
  109. CPP = $(CC) -E
  110. AR = $(CROSS_COMPILE)ar
  111. NM = $(CROSS_COMPILE)nm
  112. LDR = $(CROSS_COMPILE)ldr
  113. STRIP = $(CROSS_COMPILE)strip
  114. OBJCOPY = $(CROSS_COMPILE)objcopy
  115. OBJDUMP = $(CROSS_COMPILE)objdump
  116. RANLIB = $(CROSS_COMPILE)RANLIB
  117. DTC = dtc
  118. CHECK = sparse
  119. #########################################################################
  120. # Load generated board configuration
  121. sinclude $(OBJTREE)/include/autoconf.mk
  122. sinclude $(OBJTREE)/include/config.mk
  123. # Some architecture config.mk files need to know what CPUDIR is set to,
  124. # so calculate CPUDIR before including ARCH/SOC/CPU config.mk files.
  125. # Check if arch/$ARCH/cpu/$CPU exists, otherwise assume arch/$ARCH/cpu contains
  126. # CPU-specific code.
  127. CPUDIR=arch/$(ARCH)/cpu/$(CPU)
  128. ifneq ($(SRCTREE)/$(CPUDIR),$(wildcard $(SRCTREE)/$(CPUDIR)))
  129. CPUDIR=arch/$(ARCH)/cpu
  130. endif
  131. sinclude $(TOPDIR)/arch/$(ARCH)/config.mk # include architecture dependend rules
  132. sinclude $(TOPDIR)/$(CPUDIR)/config.mk # include CPU specific rules
  133. ifdef SOC
  134. sinclude $(TOPDIR)/$(CPUDIR)/$(SOC)/config.mk # include SoC specific rules
  135. endif
  136. ifdef VENDOR
  137. BOARDDIR = $(VENDOR)/$(BOARD)
  138. else
  139. BOARDDIR = $(BOARD)
  140. endif
  141. ifdef BOARD
  142. sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules
  143. endif
  144. #########################################################################
  145. # We don't actually use $(ARFLAGS) anywhere anymore, so catch people
  146. # who are porting old code to latest mainline but not updating $(AR).
  147. ARFLAGS = $(error update your Makefile to use cmd_link_o_target and not AR)
  148. RELFLAGS= $(PLATFORM_RELFLAGS)
  149. DBGFLAGS= -g # -DDEBUG
  150. OPTFLAGS= -Os #-fomit-frame-pointer
  151. OBJCFLAGS += --gap-fill=0xff
  152. gccincdir := $(shell $(CC) -print-file-name=include)
  153. CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \
  154. -D__KERNEL__
  155. # Enable garbage collection of un-used sections for SPL
  156. ifeq ($(CONFIG_SPL_BUILD),y)
  157. CPPFLAGS += -ffunction-sections -fdata-sections
  158. LDFLAGS_FINAL += --gc-sections
  159. endif
  160. # TODO(sjg@chromium.org): Is this correct on Mac OS?
  161. ifdef CONFIG_FIT_SIGNATURE
  162. HOSTLIBS += -lssl -lcrypto
  163. # This affects include/image.h, but including the board config file
  164. # is tricky, so manually define this options here.
  165. HOSTCFLAGS += -DCONFIG_FIT_SIGNATURE
  166. endif
  167. ifneq ($(CONFIG_SYS_TEXT_BASE),)
  168. CPPFLAGS += -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE)
  169. endif
  170. ifneq ($(CONFIG_SPL_TEXT_BASE),)
  171. CPPFLAGS += -DCONFIG_SPL_TEXT_BASE=$(CONFIG_SPL_TEXT_BASE)
  172. endif
  173. ifneq ($(CONFIG_SPL_PAD_TO),)
  174. CPPFLAGS += -DCONFIG_SPL_PAD_TO=$(CONFIG_SPL_PAD_TO)
  175. endif
  176. ifneq ($(CONFIG_UBOOT_PAD_TO),)
  177. CPPFLAGS += -DCONFIG_UBOOT_PAD_TO=$(CONFIG_UBOOT_PAD_TO)
  178. endif
  179. ifeq ($(CONFIG_SPL_BUILD),y)
  180. CPPFLAGS += -DCONFIG_SPL_BUILD
  181. endif
  182. # Does this architecture support generic board init?
  183. ifeq ($(__HAVE_ARCH_GENERIC_BOARD),)
  184. ifneq ($(CONFIG_SYS_GENERIC_BOARD),)
  185. CHECK_GENERIC_BOARD = $(error Your architecture does not support generic board. \
  186. Please undefined CONFIG_SYS_GENERIC_BOARD in your board config file)
  187. endif
  188. endif
  189. ifneq ($(RESET_VECTOR_ADDRESS),)
  190. CPPFLAGS += -DRESET_VECTOR_ADDRESS=$(RESET_VECTOR_ADDRESS)
  191. endif
  192. ifneq ($(OBJTREE),$(SRCTREE))
  193. CPPFLAGS += -I$(OBJTREE)/include2 -I$(OBJTREE)/include
  194. endif
  195. CPPFLAGS += -I$(TOPDIR)/include
  196. CPPFLAGS += -fno-builtin -ffreestanding -nostdinc \
  197. -isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS)
  198. CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes
  199. ifdef BUILD_TAG
  200. CFLAGS += -DBUILD_TAG='"$(BUILD_TAG)"'
  201. endif
  202. CFLAGS_SSP := $(call cc-option,-fno-stack-protector)
  203. CFLAGS += $(CFLAGS_SSP)
  204. # Some toolchains enable security related warning flags by default,
  205. # but they don't make much sense in the u-boot world, so disable them.
  206. CFLAGS_WARN := $(call cc-option,-Wno-format-nonliteral) \
  207. $(call cc-option,-Wno-format-security)
  208. CFLAGS += $(CFLAGS_WARN)
  209. # Report stack usage if supported
  210. CFLAGS_STACK := $(call cc-option,-fstack-usage)
  211. CFLAGS += $(CFLAGS_STACK)
  212. BCURDIR = $(subst $(SRCTREE)/,,$(CURDIR:$(obj)%=%))
  213. ifeq ($(findstring examples/,$(BCURDIR)),)
  214. ifeq ($(CONFIG_SPL_BUILD),)
  215. ifdef FTRACE
  216. CFLAGS += -finstrument-functions -DFTRACE
  217. endif
  218. endif
  219. endif
  220. # $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
  221. # option to the assembler.
  222. AFLAGS_DEBUG :=
  223. # turn jbsr into jsr for m68k
  224. ifeq ($(ARCH),m68k)
  225. ifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4)
  226. AFLAGS_DEBUG := -Wa,-gstabs,-S
  227. endif
  228. endif
  229. AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS)
  230. LDFLAGS += $(PLATFORM_LDFLAGS)
  231. LDFLAGS_FINAL += -Bstatic
  232. LDFLAGS_u-boot += -T $(obj)u-boot.lds $(LDFLAGS_FINAL)
  233. ifneq ($(CONFIG_SYS_TEXT_BASE),)
  234. LDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE)
  235. endif
  236. LDFLAGS_u-boot-spl += -T $(obj)u-boot-spl.lds $(LDFLAGS_FINAL)
  237. ifneq ($(CONFIG_SPL_TEXT_BASE),)
  238. LDFLAGS_u-boot-spl += -Ttext $(CONFIG_SPL_TEXT_BASE)
  239. endif
  240. # Linus' kernel sanity checking tool
  241. CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
  242. -Wbitwise -Wno-return-void -D__CHECK_ENDIAN__ $(CF)
  243. # Location of a usable BFD library, where we define "usable" as
  244. # "built for ${HOST}, supports ${TARGET}". Sensible values are
  245. # - When cross-compiling: the root of the cross-environment
  246. # - Linux/ppc (native): /usr
  247. # - NetBSD/ppc (native): you lose ... (must extract these from the
  248. # binutils build directory, plus the native and U-Boot include
  249. # files don't like each other)
  250. #
  251. # So far, this is used only by tools/gdb/Makefile.
  252. ifeq ($(HOSTOS),darwin)
  253. BFD_ROOT_DIR = /usr/local/tools
  254. else
  255. ifeq ($(HOSTARCH),$(ARCH))
  256. # native
  257. BFD_ROOT_DIR = /usr
  258. else
  259. #BFD_ROOT_DIR = /LinuxPPC/CDK # Linux/i386
  260. #BFD_ROOT_DIR = /usr/pkg/cross # NetBSD/i386
  261. BFD_ROOT_DIR = /opt/powerpc
  262. endif
  263. endif
  264. #########################################################################
  265. export HOSTCC HOSTCFLAGS HOSTLDFLAGS PEDCFLAGS HOSTSTRIP CROSS_COMPILE \
  266. AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP MAKE
  267. export CONFIG_SYS_TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS
  268. #########################################################################
  269. # Allow boards to use custom optimize flags on a per dir/file basis
  270. ALL_AFLAGS = $(AFLAGS) $(AFLAGS_$(BCURDIR)/$(@F)) $(AFLAGS_$(BCURDIR))
  271. ALL_CFLAGS = $(CFLAGS) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR))
  272. EXTRA_CPPFLAGS = $(CPPFLAGS_$(BCURDIR)/$(@F)) $(CPPFLAGS_$(BCURDIR))
  273. ALL_CFLAGS += $(EXTRA_CPPFLAGS)
  274. # The _DEP version uses the $< file target (for dependency generation)
  275. # See rules.mk
  276. EXTRA_CPPFLAGS_DEP = $(CPPFLAGS_$(BCURDIR)/$(addsuffix .o,$(basename $<))) \
  277. $(CPPFLAGS_$(BCURDIR))
  278. $(obj)%.s: %.S
  279. $(CPP) $(ALL_AFLAGS) -o $@ $<
  280. $(obj)%.o: %.S
  281. $(CC) $(ALL_AFLAGS) -o $@ $< -c
  282. $(obj)%.o: %.c
  283. ifneq ($(CHECKSRC),0)
  284. $(CHECK) $(CHECKFLAGS) $(ALL_CFLAGS) $<
  285. endif
  286. $(CC) $(ALL_CFLAGS) -o $@ $< -c
  287. $(obj)%.i: %.c
  288. $(CPP) $(ALL_CFLAGS) -o $@ $< -c
  289. $(obj)%.s: %.c
  290. $(CC) $(ALL_CFLAGS) -o $@ $< -c -S
  291. #########################################################################
  292. # If the list of objects to link is empty, just create an empty built-in.o
  293. cmd_link_o_target = $(if $(strip $1),\
  294. $(LD) $(LDFLAGS) -r -o $@ $1,\
  295. rm -f $@; $(AR) rcs $@ )
  296. #########################################################################