config.mk 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. ifneq ($(OBJTREE),$(SRCTREE))
  25. ifeq ($(CURDIR),$(SRCTREE))
  26. dir :=
  27. else
  28. dir := $(subst $(SRCTREE)/,,$(CURDIR))
  29. endif
  30. obj := $(if $(dir),$(OBJTREE)/$(dir)/,$(OBJTREE)/)
  31. src := $(if $(dir),$(SRCTREE)/$(dir)/,$(SRCTREE)/)
  32. $(shell mkdir -p $(obj))
  33. else
  34. obj :=
  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 (courtesy linux kernel) to ensure
  81. # only supported compiler options are used
  82. #
  83. cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
  84. > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
  85. #
  86. # Include the make variables (CC, etc...)
  87. #
  88. AS = $(CROSS_COMPILE)as
  89. LD = $(CROSS_COMPILE)ld
  90. CC = $(CROSS_COMPILE)gcc
  91. CPP = $(CC) -E
  92. AR = $(CROSS_COMPILE)ar
  93. NM = $(CROSS_COMPILE)nm
  94. LDR = $(CROSS_COMPILE)ldr
  95. STRIP = $(CROSS_COMPILE)strip
  96. OBJCOPY = $(CROSS_COMPILE)objcopy
  97. OBJDUMP = $(CROSS_COMPILE)objdump
  98. RANLIB = $(CROSS_COMPILE)RANLIB
  99. #########################################################################
  100. # Load generated board configuration
  101. sinclude $(OBJTREE)/include/autoconf.mk
  102. sinclude $(OBJTREE)/include/config.mk
  103. # Some architecture config.mk files need to know what CPUDIR is set to,
  104. # so calculate CPUDIR before including ARCH/SOC/CPU config.mk files.
  105. # Check if arch/$ARCH/cpu/$CPU exists, otherwise assume arch/$ARCH/cpu contains
  106. # CPU-specific code.
  107. CPUDIR=arch/$(ARCH)/cpu/$(CPU)
  108. ifneq ($(SRCTREE)/$(CPUDIR),$(wildcard $(SRCTREE)/$(CPUDIR)))
  109. CPUDIR=arch/$(ARCH)/cpu
  110. endif
  111. sinclude $(TOPDIR)/arch/$(ARCH)/config.mk # include architecture dependend rules
  112. sinclude $(TOPDIR)/$(CPUDIR)/config.mk # include CPU specific rules
  113. ifdef SOC
  114. sinclude $(TOPDIR)/$(CPUDIR)/$(SOC)/config.mk # include SoC specific rules
  115. endif
  116. ifdef VENDOR
  117. BOARDDIR = $(VENDOR)/$(BOARD)
  118. else
  119. BOARDDIR = $(BOARD)
  120. endif
  121. ifdef BOARD
  122. sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules
  123. endif
  124. #########################################################################
  125. ifneq (,$(findstring s,$(MAKEFLAGS)))
  126. ARFLAGS = cr
  127. else
  128. ARFLAGS = crv
  129. endif
  130. RELFLAGS= $(PLATFORM_RELFLAGS)
  131. DBGFLAGS= -g # -DDEBUG
  132. OPTFLAGS= -Os #-fomit-frame-pointer
  133. # If board code explicitly specified LDSCRIPT or CONFIG_SYS_LDSCRIPT, use
  134. # that (or fail if absent). Otherwise, search for a linker script in a
  135. # standard location.
  136. ifndef LDSCRIPT
  137. #LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds.debug
  138. ifdef CONFIG_SYS_LDSCRIPT
  139. # need to strip off double quotes
  140. LDSCRIPT := $(subst ",,$(CONFIG_SYS_LDSCRIPT))
  141. endif
  142. endif
  143. ifndef LDSCRIPT
  144. ifeq ($(CONFIG_NAND_U_BOOT),y)
  145. LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot-nand.lds
  146. ifeq ($(wildcard $(LDSCRIPT)),)
  147. LDSCRIPT := $(TOPDIR)/$(CPUDIR)/u-boot-nand.lds
  148. endif
  149. endif
  150. ifeq ($(wildcard $(LDSCRIPT)),)
  151. LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds
  152. endif
  153. ifeq ($(wildcard $(LDSCRIPT)),)
  154. LDSCRIPT := $(TOPDIR)/$(CPUDIR)/u-boot.lds
  155. endif
  156. ifeq ($(wildcard $(LDSCRIPT)),)
  157. $(error could not find linker script)
  158. endif
  159. endif
  160. OBJCFLAGS += --gap-fill=0xff
  161. gccincdir := $(shell $(CC) -print-file-name=include)
  162. CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \
  163. -D__KERNEL__
  164. ifneq ($(CONFIG_SYS_TEXT_BASE),)
  165. CPPFLAGS += -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE)
  166. endif
  167. ifneq ($(RESET_VECTOR_ADDRESS),)
  168. CPPFLAGS += -DRESET_VECTOR_ADDRESS=$(RESET_VECTOR_ADDRESS)
  169. endif
  170. ifneq ($(OBJTREE),$(SRCTREE))
  171. CPPFLAGS += -I$(OBJTREE)/include2 -I$(OBJTREE)/include
  172. endif
  173. CPPFLAGS += -I$(TOPDIR)/include
  174. CPPFLAGS += -fno-builtin -ffreestanding -nostdinc \
  175. -isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS)
  176. ifdef BUILD_TAG
  177. CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes \
  178. -DBUILD_TAG='"$(BUILD_TAG)"'
  179. else
  180. CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes
  181. endif
  182. CFLAGS += $(call cc-option,-fno-stack-protector)
  183. # $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
  184. # option to the assembler.
  185. AFLAGS_DEBUG :=
  186. # turn jbsr into jsr for m68k
  187. ifeq ($(ARCH),m68k)
  188. ifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4)
  189. AFLAGS_DEBUG := -Wa,-gstabs,-S
  190. endif
  191. endif
  192. AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS)
  193. LDFLAGS += $(PLATFORM_LDFLAGS)
  194. LDFLAGS_FINAL += -Bstatic
  195. LDFLAGS_u-boot += -T $(obj)u-boot.lds $(LDFLAGS_FINAL)
  196. ifneq ($(CONFIG_SYS_TEXT_BASE),)
  197. LDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE)
  198. endif
  199. # Location of a usable BFD library, where we define "usable" as
  200. # "built for ${HOST}, supports ${TARGET}". Sensible values are
  201. # - When cross-compiling: the root of the cross-environment
  202. # - Linux/ppc (native): /usr
  203. # - NetBSD/ppc (native): you lose ... (must extract these from the
  204. # binutils build directory, plus the native and U-Boot include
  205. # files don't like each other)
  206. #
  207. # So far, this is used only by tools/gdb/Makefile.
  208. ifeq ($(HOSTOS),darwin)
  209. BFD_ROOT_DIR = /usr/local/tools
  210. else
  211. ifeq ($(HOSTARCH),$(ARCH))
  212. # native
  213. BFD_ROOT_DIR = /usr
  214. else
  215. #BFD_ROOT_DIR = /LinuxPPC/CDK # Linux/i386
  216. #BFD_ROOT_DIR = /usr/pkg/cross # NetBSD/i386
  217. BFD_ROOT_DIR = /opt/powerpc
  218. endif
  219. endif
  220. #########################################################################
  221. export HOSTCC HOSTCFLAGS HOSTLDFLAGS PEDCFLAGS HOSTSTRIP CROSS_COMPILE \
  222. AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP MAKE
  223. export CONFIG_SYS_TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS
  224. #########################################################################
  225. # Allow boards to use custom optimize flags on a per dir/file basis
  226. BCURDIR = $(subst $(SRCTREE)/,,$(CURDIR:$(obj)%=%))
  227. ALL_AFLAGS = $(AFLAGS) $(AFLAGS_$(BCURDIR)/$(@F)) $(AFLAGS_$(BCURDIR))
  228. ALL_CFLAGS = $(CFLAGS) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR))
  229. $(obj)%.s: %.S
  230. $(CPP) $(ALL_AFLAGS) -o $@ $<
  231. $(obj)%.o: %.S
  232. $(CC) $(ALL_AFLAGS) -o $@ $< -c
  233. $(obj)%.o: %.c
  234. $(CC) $(ALL_CFLAGS) -o $@ $< -c
  235. $(obj)%.i: %.c
  236. $(CPP) $(ALL_CFLAGS) -o $@ $< -c
  237. $(obj)%.s: %.c
  238. $(CC) $(ALL_CFLAGS) -o $@ $< -c -S
  239. #########################################################################
  240. # If the list of objects to link is empty, just create an empty built-in.o
  241. cmd_link_o_target = $(if $(strip $1),\
  242. $(LD) $(LDFLAGS) -r -o $@ $1,\
  243. rm -f $@; $(AR) rcs $@ )
  244. #########################################################################