config.mk 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. # When cross-compiling on NetBSD, we have to define __PPC__ or else we
  43. # will pick up a va_list declaration that is incompatible with the
  44. # actual argument lists emitted by the compiler.
  45. #
  46. # [Tested on NetBSD/i386 1.5 + cross-powerpc-netbsd-1.3]
  47. ifeq ($(ARCH),ppc)
  48. ifeq ($(CROSS_COMPILE),powerpc-netbsd-)
  49. PLATFORM_CPPFLAGS+= -D__PPC__
  50. endif
  51. ifeq ($(CROSS_COMPILE),powerpc-openbsd-)
  52. PLATFORM_CPPFLAGS+= -D__PPC__
  53. endif
  54. endif
  55. ifeq ($(ARCH),arm)
  56. ifeq ($(CROSS_COMPILE),powerpc-netbsd-)
  57. PLATFORM_CPPFLAGS+= -D__ARM__
  58. endif
  59. ifeq ($(CROSS_COMPILE),powerpc-openbsd-)
  60. PLATFORM_CPPFLAGS+= -D__ARM__
  61. endif
  62. endif
  63. ifeq ($(ARCH),blackfin)
  64. PLATFORM_CPPFLAGS+= -D__BLACKFIN__ -mno-underscore
  65. endif
  66. ifdef ARCH
  67. sinclude $(TOPDIR)/$(ARCH)_config.mk # include architecture dependend rules
  68. endif
  69. ifdef CPU
  70. sinclude $(TOPDIR)/cpu/$(CPU)/config.mk # include CPU specific rules
  71. endif
  72. ifdef SOC
  73. sinclude $(TOPDIR)/cpu/$(CPU)/$(SOC)/config.mk # include SoC specific rules
  74. endif
  75. ifdef VENDOR
  76. BOARDDIR = $(VENDOR)/$(BOARD)
  77. else
  78. BOARDDIR = $(BOARD)
  79. endif
  80. ifdef BOARD
  81. sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules
  82. endif
  83. #########################################################################
  84. CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
  85. else if [ -x /bin/bash ]; then echo /bin/bash; \
  86. else echo sh; fi ; fi)
  87. ifeq ($(HOSTOS)-$(HOSTARCH),darwin-ppc)
  88. HOSTCC = cc
  89. else
  90. HOSTCC = gcc
  91. endif
  92. HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
  93. HOSTSTRIP = strip
  94. #########################################################################
  95. #
  96. # Option checker (courtesy linux kernel) to ensure
  97. # only supported compiler options are used
  98. #
  99. cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
  100. > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
  101. #
  102. # Include the make variables (CC, etc...)
  103. #
  104. AS = $(CROSS_COMPILE)as
  105. LD = $(CROSS_COMPILE)ld
  106. CC = $(CROSS_COMPILE)gcc
  107. CPP = $(CC) -E
  108. AR = $(CROSS_COMPILE)ar
  109. NM = $(CROSS_COMPILE)nm
  110. STRIP = $(CROSS_COMPILE)strip
  111. OBJCOPY = $(CROSS_COMPILE)objcopy
  112. OBJDUMP = $(CROSS_COMPILE)objdump
  113. RANLIB = $(CROSS_COMPILE)RANLIB
  114. ARFLAGS = crv
  115. RELFLAGS= $(PLATFORM_RELFLAGS)
  116. DBGFLAGS= -g # -DDEBUG
  117. OPTFLAGS= -Os #-fomit-frame-pointer
  118. ifndef LDSCRIPT
  119. #LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds.debug
  120. ifeq ($(CONFIG_NAND_U_BOOT),y)
  121. LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot-nand.lds
  122. else
  123. LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds
  124. endif
  125. endif
  126. OBJCFLAGS += --gap-fill=0xff
  127. gccincdir := $(shell $(CC) -print-file-name=include)
  128. CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \
  129. -D__KERNEL__ -DTEXT_BASE=$(TEXT_BASE) \
  130. ifneq ($(OBJTREE),$(SRCTREE))
  131. CPPFLAGS += -I$(OBJTREE)/include2 -I$(OBJTREE)/include
  132. endif
  133. CPPFLAGS += -I$(TOPDIR)/include
  134. CPPFLAGS += -fno-builtin -ffreestanding -nostdinc \
  135. -isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS)
  136. ifdef BUILD_TAG
  137. CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes \
  138. -DBUILD_TAG='"$(BUILD_TAG)"'
  139. else
  140. CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes
  141. endif
  142. # avoid trigraph warnings while parsing pci.h (produced by NIOS gcc-2.9)
  143. # this option have to be placed behind -Wall -- that's why it is here
  144. ifeq ($(ARCH),nios)
  145. ifeq ($(findstring 2.9,$(shell $(CC) --version)),2.9)
  146. CFLAGS := $(CPPFLAGS) -Wall -Wno-trigraphs
  147. endif
  148. endif
  149. AFLAGS_DEBUG := -Wa,-g
  150. # turn jbsr into jsr for m68k
  151. ifeq ($(ARCH),m68k)
  152. ifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4)
  153. AFLAGS_DEBUG := -Wa,-gstabs,-S
  154. endif
  155. endif
  156. AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS)
  157. LDFLAGS += -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
  158. # Location of a usable BFD library, where we define "usable" as
  159. # "built for ${HOST}, supports ${TARGET}". Sensible values are
  160. # - When cross-compiling: the root of the cross-environment
  161. # - Linux/ppc (native): /usr
  162. # - NetBSD/ppc (native): you lose ... (must extract these from the
  163. # binutils build directory, plus the native and U-Boot include
  164. # files don't like each other)
  165. #
  166. # So far, this is used only by tools/gdb/Makefile.
  167. ifeq ($(HOSTOS)-$(HOSTARCH),darwin-ppc)
  168. BFD_ROOT_DIR = /usr/local/tools
  169. else
  170. ifeq ($(HOSTARCH),$(ARCH))
  171. # native
  172. BFD_ROOT_DIR = /usr
  173. else
  174. #BFD_ROOT_DIR = /LinuxPPC/CDK # Linux/i386
  175. #BFD_ROOT_DIR = /usr/pkg/cross # NetBSD/i386
  176. BFD_ROOT_DIR = /opt/powerpc
  177. endif
  178. endif
  179. ifeq ($(PCI_CLOCK),PCI_66M)
  180. CFLAGS := $(CFLAGS) -DPCI_66M
  181. endif
  182. #########################################################################
  183. export CONFIG_SHELL HPATH HOSTCC HOSTCFLAGS CROSS_COMPILE \
  184. AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP \
  185. MAKE
  186. export TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS
  187. #########################################################################
  188. ifndef REMOTE_BUILD
  189. %.s: %.S
  190. $(CPP) $(AFLAGS) -o $@ $<
  191. %.o: %.S
  192. $(CC) $(AFLAGS) -c -o $@ $<
  193. %.o: %.c
  194. $(CC) $(CFLAGS) -c -o $@ $<
  195. else
  196. $(obj)%.s: %.S
  197. $(CPP) $(AFLAGS) -o $@ $<
  198. $(obj)%.o: %.S
  199. $(CC) $(AFLAGS) -c -o $@ $<
  200. $(obj)%.o: %.c
  201. $(CC) $(CFLAGS) -c -o $@ $<
  202. endif
  203. #########################################################################