config.mk 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. HOSTCC = cc
  59. HOSTCFLAGS += -traditional-cpp
  60. HOSTLDFLAGS += -multiply_defined suppress
  61. else
  62. HOSTCC = gcc
  63. endif
  64. ifeq ($(HOSTOS),cygwin)
  65. HOSTCFLAGS += -ansi
  66. endif
  67. # We build some files with extra pedantic flags to try to minimize things
  68. # that won't build on some weird host compiler -- though there are lots of
  69. # exceptions for files that aren't complaint.
  70. HOSTCFLAGS_NOPED = $(filter-out -pedantic,$(HOSTCFLAGS))
  71. HOSTCFLAGS += -pedantic
  72. #########################################################################
  73. #
  74. # Option checker (courtesy linux kernel) to ensure
  75. # only supported compiler options are used
  76. #
  77. cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
  78. > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
  79. #
  80. # Include the make variables (CC, etc...)
  81. #
  82. AS = $(CROSS_COMPILE)as
  83. LD = $(CROSS_COMPILE)ld
  84. CC = $(CROSS_COMPILE)gcc
  85. CPP = $(CC) -E
  86. AR = $(CROSS_COMPILE)ar
  87. NM = $(CROSS_COMPILE)nm
  88. LDR = $(CROSS_COMPILE)ldr
  89. STRIP = $(CROSS_COMPILE)strip
  90. OBJCOPY = $(CROSS_COMPILE)objcopy
  91. OBJDUMP = $(CROSS_COMPILE)objdump
  92. RANLIB = $(CROSS_COMPILE)RANLIB
  93. #########################################################################
  94. # Load generated board configuration
  95. sinclude $(OBJTREE)/include/autoconf.mk
  96. # Some architecture config.mk files need to know what CPUDIR is set to,
  97. # so calculate CPUDIR before including ARCH/SOC/CPU config.mk files.
  98. CPUDIR=cpu/$(CPU)
  99. sinclude $(TOPDIR)/lib_$(ARCH)/config.mk # include architecture dependend rules
  100. sinclude $(TOPDIR)/$(CPUDIR)/config.mk # include CPU specific rules
  101. ifdef SOC
  102. sinclude $(TOPDIR)/$(CPUDIR)/$(SOC)/config.mk # include SoC specific rules
  103. endif
  104. ifdef VENDOR
  105. BOARDDIR = $(VENDOR)/$(BOARD)
  106. else
  107. BOARDDIR = $(BOARD)
  108. endif
  109. ifdef BOARD
  110. sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules
  111. endif
  112. #########################################################################
  113. ifneq (,$(findstring s,$(MAKEFLAGS)))
  114. ARFLAGS = cr
  115. else
  116. ARFLAGS = crv
  117. endif
  118. RELFLAGS= $(PLATFORM_RELFLAGS)
  119. DBGFLAGS= -g # -DDEBUG
  120. OPTFLAGS= -Os #-fomit-frame-pointer
  121. ifndef LDSCRIPT
  122. #LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds.debug
  123. ifeq ($(CONFIG_NAND_U_BOOT),y)
  124. LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot-nand.lds
  125. else
  126. LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds
  127. endif
  128. endif
  129. OBJCFLAGS += --gap-fill=0xff
  130. gccincdir := $(shell $(CC) -print-file-name=include)
  131. CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \
  132. -D__KERNEL__
  133. ifneq ($(TEXT_BASE),)
  134. CPPFLAGS += -DTEXT_BASE=$(TEXT_BASE)
  135. endif
  136. ifneq ($(RESET_VECTOR_ADDRESS),)
  137. CPPFLAGS += -DRESET_VECTOR_ADDRESS=$(RESET_VECTOR_ADDRESS)
  138. endif
  139. ifneq ($(OBJTREE),$(SRCTREE))
  140. CPPFLAGS += -I$(OBJTREE)/include2 -I$(OBJTREE)/include
  141. endif
  142. CPPFLAGS += -I$(TOPDIR)/include
  143. CPPFLAGS += -fno-builtin -ffreestanding -nostdinc \
  144. -isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS)
  145. ifdef BUILD_TAG
  146. CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes \
  147. -DBUILD_TAG='"$(BUILD_TAG)"'
  148. else
  149. CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes
  150. endif
  151. CFLAGS += $(call cc-option,-fno-stack-protector)
  152. # avoid trigraph warnings while parsing pci.h (produced by NIOS gcc-2.9)
  153. # this option have to be placed behind -Wall -- that's why it is here
  154. ifeq ($(ARCH),nios)
  155. ifeq ($(findstring 2.9,$(shell $(CC) --version)),2.9)
  156. CFLAGS := $(CPPFLAGS) -Wall -Wno-trigraphs
  157. endif
  158. endif
  159. # $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
  160. # option to the assembler.
  161. AFLAGS_DEBUG :=
  162. # turn jbsr into jsr for m68k
  163. ifeq ($(ARCH),m68k)
  164. ifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4)
  165. AFLAGS_DEBUG := -Wa,-gstabs,-S
  166. endif
  167. endif
  168. AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS)
  169. LDFLAGS += -Bstatic -T $(obj)u-boot.lds $(PLATFORM_LDFLAGS)
  170. ifneq ($(TEXT_BASE),)
  171. LDFLAGS += -Ttext $(TEXT_BASE)
  172. endif
  173. # Location of a usable BFD library, where we define "usable" as
  174. # "built for ${HOST}, supports ${TARGET}". Sensible values are
  175. # - When cross-compiling: the root of the cross-environment
  176. # - Linux/ppc (native): /usr
  177. # - NetBSD/ppc (native): you lose ... (must extract these from the
  178. # binutils build directory, plus the native and U-Boot include
  179. # files don't like each other)
  180. #
  181. # So far, this is used only by tools/gdb/Makefile.
  182. ifeq ($(HOSTOS),darwin)
  183. BFD_ROOT_DIR = /usr/local/tools
  184. else
  185. ifeq ($(HOSTARCH),$(ARCH))
  186. # native
  187. BFD_ROOT_DIR = /usr
  188. else
  189. #BFD_ROOT_DIR = /LinuxPPC/CDK # Linux/i386
  190. #BFD_ROOT_DIR = /usr/pkg/cross # NetBSD/i386
  191. BFD_ROOT_DIR = /opt/powerpc
  192. endif
  193. endif
  194. #########################################################################
  195. export HOSTCC HOSTCFLAGS HOSTLDFLAGS PEDCFLAGS HOSTSTRIP CROSS_COMPILE \
  196. AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP MAKE
  197. export TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS
  198. #########################################################################
  199. # Allow boards to use custom optimize flags on a per dir/file basis
  200. BCURDIR := $(notdir $(CURDIR))
  201. $(obj)%.s: %.S
  202. $(CPP) $(AFLAGS) $(AFLAGS_$(@F)) $(AFLAGS_$(BCURDIR)) -o $@ $<
  203. $(obj)%.o: %.S
  204. $(CC) $(AFLAGS) $(AFLAGS_$(@F)) $(AFLAGS_$(BCURDIR)) -o $@ $< -c
  205. $(obj)%.o: %.c
  206. $(CC) $(CFLAGS) $(CFLAGS_$(@F)) $(CFLAGS_$(BCURDIR)) -o $@ $< -c
  207. $(obj)%.i: %.c
  208. $(CPP) $(CFLAGS) $(CFLAGS_$(@F)) $(CFLAGS_$(BCURDIR)) -o $@ $< -c
  209. $(obj)%.s: %.c
  210. $(CC) $(CFLAGS) $(CFLAGS_$(@F)) $(CFLAGS_$(BCURDIR)) -o $@ $< -c -S
  211. #########################################################################