config.mk 11 KB

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