config.mk 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. ifneq ($(CONFIG_SYS_TEXT_BASE),)
  177. CPPFLAGS += -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE)
  178. endif
  179. ifneq ($(CONFIG_SPL_TEXT_BASE),)
  180. CPPFLAGS += -DCONFIG_SPL_TEXT_BASE=$(CONFIG_SPL_TEXT_BASE)
  181. endif
  182. ifneq ($(CONFIG_SPL_PAD_TO),)
  183. CPPFLAGS += -DCONFIG_SPL_PAD_TO=$(CONFIG_SPL_PAD_TO)
  184. endif
  185. ifneq ($(CONFIG_UBOOT_PAD_TO),)
  186. CPPFLAGS += -DCONFIG_UBOOT_PAD_TO=$(CONFIG_UBOOT_PAD_TO)
  187. endif
  188. ifeq ($(CONFIG_SPL_BUILD),y)
  189. CPPFLAGS += -DCONFIG_SPL_BUILD
  190. endif
  191. # Does this architecture support generic board init?
  192. ifeq ($(__HAVE_ARCH_GENERIC_BOARD),)
  193. ifneq ($(CONFIG_SYS_GENERIC_BOARD),)
  194. CHECK_GENERIC_BOARD = $(error Your architecture does not support generic board. \
  195. Please undefined CONFIG_SYS_GENERIC_BOARD in your board config file)
  196. endif
  197. endif
  198. ifneq ($(RESET_VECTOR_ADDRESS),)
  199. CPPFLAGS += -DRESET_VECTOR_ADDRESS=$(RESET_VECTOR_ADDRESS)
  200. endif
  201. ifneq ($(OBJTREE),$(SRCTREE))
  202. CPPFLAGS += -I$(OBJTREE)/include2 -I$(OBJTREE)/include
  203. endif
  204. CPPFLAGS += -I$(TOPDIR)/include
  205. CPPFLAGS += -fno-builtin -ffreestanding -nostdinc \
  206. -isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS)
  207. CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes
  208. ifdef BUILD_TAG
  209. CFLAGS += -DBUILD_TAG='"$(BUILD_TAG)"'
  210. endif
  211. CFLAGS_SSP := $(call cc-option,-fno-stack-protector)
  212. CFLAGS += $(CFLAGS_SSP)
  213. # Some toolchains enable security related warning flags by default,
  214. # but they don't make much sense in the u-boot world, so disable them.
  215. CFLAGS_WARN := $(call cc-option,-Wno-format-nonliteral) \
  216. $(call cc-option,-Wno-format-security)
  217. CFLAGS += $(CFLAGS_WARN)
  218. # Report stack usage if supported
  219. CFLAGS_STACK := $(call cc-option,-fstack-usage)
  220. CFLAGS += $(CFLAGS_STACK)
  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. BCURDIR = $(subst $(SRCTREE)/,,$(CURDIR:$(obj)%=%))
  272. ALL_AFLAGS = $(AFLAGS) $(AFLAGS_$(BCURDIR)/$(@F)) $(AFLAGS_$(BCURDIR))
  273. ALL_CFLAGS = $(CFLAGS) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR))
  274. EXTRA_CPPFLAGS = $(CPPFLAGS_$(BCURDIR)/$(@F)) $(CPPFLAGS_$(BCURDIR))
  275. ALL_CFLAGS += $(EXTRA_CPPFLAGS)
  276. # The _DEP version uses the $< file target (for dependency generation)
  277. # See rules.mk
  278. EXTRA_CPPFLAGS_DEP = $(CPPFLAGS_$(BCURDIR)/$(addsuffix .o,$(basename $<))) \
  279. $(CPPFLAGS_$(BCURDIR))
  280. $(obj)%.s: %.S
  281. $(CPP) $(ALL_AFLAGS) -o $@ $<
  282. $(obj)%.o: %.S
  283. $(CC) $(ALL_AFLAGS) -o $@ $< -c
  284. $(obj)%.o: %.c
  285. ifneq ($(CHECKSRC),0)
  286. $(CHECK) $(CHECKFLAGS) $(ALL_CFLAGS) $<
  287. endif
  288. $(CC) $(ALL_CFLAGS) -o $@ $< -c
  289. $(obj)%.i: %.c
  290. $(CPP) $(ALL_CFLAGS) -o $@ $< -c
  291. $(obj)%.s: %.c
  292. $(CC) $(ALL_CFLAGS) -o $@ $< -c -S
  293. #########################################################################
  294. # If the list of objects to link is empty, just create an empty built-in.o
  295. cmd_link_o_target = $(if $(strip $1),\
  296. $(LD) $(LDFLAGS) -r -o $@ $1,\
  297. rm -f $@; $(AR) rcs $@ )
  298. #########################################################################