config.mk 12 KB

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