config.mk 10 KB

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