1e2211743Swdenk# 2f9328639SMarian Balakowicz# (C) Copyright 2000-2006 3e2211743Swdenk# Wolfgang Denk, DENX Software Engineering, wd@denx.de. 4e2211743Swdenk# 5e2211743Swdenk# See file CREDITS for list of people who contributed to this 6e2211743Swdenk# project. 7e2211743Swdenk# 8e2211743Swdenk# This program is free software; you can redistribute it and/or 9e2211743Swdenk# modify it under the terms of the GNU General Public License as 10e2211743Swdenk# published by the Free Software Foundation; either version 2 of 11e2211743Swdenk# the License, or (at your option) any later version. 12e2211743Swdenk# 13e2211743Swdenk# This program is distributed in the hope that it will be useful, 14e2211743Swdenk# but WITHOUT ANY WARRANTY; without even the implied warranty of 15e2211743Swdenk# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16e2211743Swdenk# GNU General Public License for more details. 17e2211743Swdenk# 18e2211743Swdenk# You should have received a copy of the GNU General Public License 19e2211743Swdenk# along with this program; if not, write to the Free Software 20e2211743Swdenk# Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21e2211743Swdenk# MA 02111-1307 USA 22e2211743Swdenk# 23e2211743Swdenk 24e2211743Swdenk######################################################################### 25e2211743Swdenk 26f9328639SMarian Balakowiczifeq ($(CURDIR),$(SRCTREE)) 27f9328639SMarian Balakowiczdir := 28f9328639SMarian Balakowiczelse 29f9328639SMarian Balakowiczdir := $(subst $(SRCTREE)/,,$(CURDIR)) 30f9328639SMarian Balakowiczendif 31f9328639SMarian Balakowicz 32c8f9c302SDaniel Schwierzeckifneq ($(OBJTREE),$(SRCTREE)) 33c8f9c302SDaniel Schwierzeck# Create object files for SPL in a separate directory 34c8f9c302SDaniel Schwierzeckifeq ($(CONFIG_SPL_BUILD),y) 35c8f9c302SDaniel Schwierzeckobj := $(if $(dir),$(SPLTREE)/$(dir)/,$(SPLTREE)/) 36c8f9c302SDaniel Schwierzeckelse 37f9328639SMarian Balakowiczobj := $(if $(dir),$(OBJTREE)/$(dir)/,$(OBJTREE)/) 38c8f9c302SDaniel Schwierzeckendif 39f9328639SMarian Balakowiczsrc := $(if $(dir),$(SRCTREE)/$(dir)/,$(SRCTREE)/) 40f9328639SMarian Balakowicz 41f9328639SMarian Balakowicz$(shell mkdir -p $(obj)) 42f9328639SMarian Balakowiczelse 43c8f9c302SDaniel Schwierzeck# Create object files for SPL in a separate directory 44c8f9c302SDaniel Schwierzeckifeq ($(CONFIG_SPL_BUILD),y) 45c8f9c302SDaniel Schwierzeckobj := $(if $(dir),$(SPLTREE)/$(dir)/,$(SPLTREE)/) 46c8f9c302SDaniel Schwierzeck 47c8f9c302SDaniel Schwierzeck$(shell mkdir -p $(obj)) 48c8f9c302SDaniel Schwierzeckelse 49f9328639SMarian Balakowiczobj := 50c8f9c302SDaniel Schwierzeckendif 51f9328639SMarian Balakowiczsrc := 52f9328639SMarian Balakowiczendif 53f9328639SMarian Balakowicz 54592c5cabSwdenk# clean the slate ... 55592c5cabSwdenkPLATFORM_RELFLAGS = 56592c5cabSwdenkPLATFORM_CPPFLAGS = 57592c5cabSwdenkPLATFORM_LDFLAGS = 58592c5cabSwdenk 59e2211743Swdenk######################################################################### 60e2211743Swdenk 61d984fed0SScott WoodHOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer \ 62d984fed0SScott Wood $(HOSTCPPFLAGS) 63d984fed0SScott WoodHOSTSTRIP = strip 64d984fed0SScott Wood 65d984fed0SScott Wood# 66d984fed0SScott Wood# Mac OS X / Darwin's C preprocessor is Apple specific. It 67d984fed0SScott Wood# generates numerous errors and warnings. We want to bypass it 68d984fed0SScott Wood# and use GNU C's cpp. To do this we pass the -traditional-cpp 69d984fed0SScott Wood# option to the compiler. Note that the -traditional-cpp flag 70d984fed0SScott Wood# DOES NOT have the same semantics as GNU C's flag, all it does 71d984fed0SScott Wood# is invoke the GNU preprocessor in stock ANSI/ISO C fashion. 72d984fed0SScott Wood# 73d984fed0SScott Wood# Apple's linker is similar, thanks to the new 2 stage linking 74d984fed0SScott Wood# multiple symbol definitions are treated as errors, hence the 75d984fed0SScott Wood# -multiply_defined suppress option to turn off this error. 76d984fed0SScott Wood# 77d984fed0SScott Wood 784cda4378SMike Frysingerifeq ($(HOSTOS),darwin) 79c7da8c19SAndreas Biessmann# get major and minor product version (e.g. '10' and '6' for Snow Leopard) 80c7da8c19SAndreas BiessmannDARWIN_MAJOR_VERSION = $(shell sw_vers -productVersion | cut -f 1 -d '.') 81c7da8c19SAndreas BiessmannDARWIN_MINOR_VERSION = $(shell sw_vers -productVersion | cut -f 2 -d '.') 82c7da8c19SAndreas Biessmann 83f534c7cdSMike Frysingeros_x_before = $(shell if [ $(DARWIN_MAJOR_VERSION) -le $(1) -a \ 84f534c7cdSMike Frysinger $(DARWIN_MINOR_VERSION) -le $(2) ] ; then echo "$(3)"; else echo "$(4)"; fi ;) 85c7da8c19SAndreas Biessmann 86c7da8c19SAndreas Biessmann# Snow Leopards build environment has no longer restrictions as described above 87f534c7cdSMike FrysingerHOSTCC = $(call os_x_before, 10, 5, "cc", "gcc") 88f534c7cdSMike FrysingerHOSTCFLAGS += $(call os_x_before, 10, 4, "-traditional-cpp") 89f534c7cdSMike FrysingerHOSTLDFLAGS += $(call os_x_before, 10, 5, "-multiply_defined suppress") 90e2211743Swdenkelse 91e2211743SwdenkHOSTCC = gcc 92e2211743Swdenkendif 93d984fed0SScott Wood 94d984fed0SScott Woodifeq ($(HOSTOS),cygwin) 95d984fed0SScott WoodHOSTCFLAGS += -ansi 96d984fed0SScott Woodendif 97d984fed0SScott Wood 98d984fed0SScott Wood# We build some files with extra pedantic flags to try to minimize things 99d984fed0SScott Wood# that won't build on some weird host compiler -- though there are lots of 100d984fed0SScott Wood# exceptions for files that aren't complaint. 101d984fed0SScott Wood 102d984fed0SScott WoodHOSTCFLAGS_NOPED = $(filter-out -pedantic,$(HOSTCFLAGS)) 103d984fed0SScott WoodHOSTCFLAGS += -pedantic 104e2211743Swdenk 105e2211743Swdenk######################################################################### 1061820d4c7SWolfgang Denk# 1071820d4c7SWolfgang Denk# Option checker (courtesy linux kernel) to ensure 1081820d4c7SWolfgang Denk# only supported compiler options are used 1091820d4c7SWolfgang Denk# 1101820d4c7SWolfgang Denkcc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \ 1111820d4c7SWolfgang Denk > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;) 112e2211743Swdenk 113e2211743Swdenk# 114e2211743Swdenk# Include the make variables (CC, etc...) 115e2211743Swdenk# 116e2211743SwdenkAS = $(CROSS_COMPILE)as 117e2211743SwdenkLD = $(CROSS_COMPILE)ld 118e2211743SwdenkCC = $(CROSS_COMPILE)gcc 119e2211743SwdenkCPP = $(CC) -E 120e2211743SwdenkAR = $(CROSS_COMPILE)ar 121e2211743SwdenkNM = $(CROSS_COMPILE)nm 12294a91e24SMike FrysingerLDR = $(CROSS_COMPILE)ldr 123e2211743SwdenkSTRIP = $(CROSS_COMPILE)strip 124e2211743SwdenkOBJCOPY = $(CROSS_COMPILE)objcopy 125e2211743SwdenkOBJDUMP = $(CROSS_COMPILE)objdump 126e2211743SwdenkRANLIB = $(CROSS_COMPILE)RANLIB 127bbb0b128SSimon GlassDTC = dtc 128e2211743Swdenk 129c4e5f52aSWolfgang Denk######################################################################### 130c4e5f52aSWolfgang Denk 131c4e5f52aSWolfgang Denk# Load generated board configuration 132c4e5f52aSWolfgang Denksinclude $(OBJTREE)/include/autoconf.mk 1335e987ddfSJoakim Tjernlundsinclude $(OBJTREE)/include/config.mk 134c4e5f52aSWolfgang Denk 13503b7004dSPeter Tyser# Some architecture config.mk files need to know what CPUDIR is set to, 13603b7004dSPeter Tyser# so calculate CPUDIR before including ARCH/SOC/CPU config.mk files. 1378d1f2682SPeter Tyser# Check if arch/$ARCH/cpu/$CPU exists, otherwise assume arch/$ARCH/cpu contains 1388d1f2682SPeter Tyser# CPU-specific code. 1398d1f2682SPeter TyserCPUDIR=arch/$(ARCH)/cpu/$(CPU) 1408d1f2682SPeter Tyserifneq ($(SRCTREE)/$(CPUDIR),$(wildcard $(SRCTREE)/$(CPUDIR))) 1418d1f2682SPeter TyserCPUDIR=arch/$(ARCH)/cpu 1428d1f2682SPeter Tyserendif 14303b7004dSPeter Tyser 144ea0364f1SPeter Tysersinclude $(TOPDIR)/arch/$(ARCH)/config.mk # include architecture dependend rules 14503b7004dSPeter Tysersinclude $(TOPDIR)/$(CPUDIR)/config.mk # include CPU specific rules 14603b7004dSPeter Tyser 147c4e5f52aSWolfgang Denkifdef SOC 14803b7004dSPeter Tysersinclude $(TOPDIR)/$(CPUDIR)/$(SOC)/config.mk # include SoC specific rules 149c4e5f52aSWolfgang Denkendif 150c4e5f52aSWolfgang Denkifdef VENDOR 151c4e5f52aSWolfgang DenkBOARDDIR = $(VENDOR)/$(BOARD) 152c4e5f52aSWolfgang Denkelse 153c4e5f52aSWolfgang DenkBOARDDIR = $(BOARD) 154c4e5f52aSWolfgang Denkendif 155c4e5f52aSWolfgang Denkifdef BOARD 156c4e5f52aSWolfgang Denksinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules 157c4e5f52aSWolfgang Denkendif 158c4e5f52aSWolfgang Denk 159c4e5f52aSWolfgang Denk######################################################################### 160c4e5f52aSWolfgang Denk 1615968adc4SMike Frysinger# We don't actually use $(ARFLAGS) anywhere anymore, so catch people 1625968adc4SMike Frysinger# who are porting old code to latest mainline but not updating $(AR). 1635968adc4SMike FrysingerARFLAGS = $(error update your Makefile to use cmd_link_o_target and not AR) 164e2211743SwdenkRELFLAGS= $(PLATFORM_RELFLAGS) 165e2211743SwdenkDBGFLAGS= -g # -DDEBUG 166e2211743SwdenkOPTFLAGS= -Os #-fomit-frame-pointer 16783b7e2a7SScott Wood 1686dd652faSwdenkOBJCFLAGS += --gap-fill=0xff 169e2211743Swdenk 170b783edaeSwdenkgccincdir := $(shell $(CC) -print-file-name=include) 171b783edaeSwdenk 172e2211743SwdenkCPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \ 173161b2af4SMike Frysinger -D__KERNEL__ 174c8f9c302SDaniel Schwierzeck 175c8f9c302SDaniel Schwierzeck# Enable garbage collection of un-used sections for SPL 176c8f9c302SDaniel Schwierzeckifeq ($(CONFIG_SPL_BUILD),y) 177c8f9c302SDaniel SchwierzeckCPPFLAGS += -ffunction-sections -fdata-sections 178c8f9c302SDaniel SchwierzeckLDFLAGS_FINAL += --gc-sections 179c8f9c302SDaniel Schwierzeckendif 180c8f9c302SDaniel Schwierzeck 18114d0a02aSWolfgang Denkifneq ($(CONFIG_SYS_TEXT_BASE),) 18214d0a02aSWolfgang DenkCPPFLAGS += -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE) 183161b2af4SMike Frysingerendif 184f9328639SMarian Balakowicz 185c8f9c302SDaniel Schwierzeckifneq ($(CONFIG_SPL_TEXT_BASE),) 186c8f9c302SDaniel SchwierzeckCPPFLAGS += -DCONFIG_SPL_TEXT_BASE=$(CONFIG_SPL_TEXT_BASE) 187c8f9c302SDaniel Schwierzeckendif 188c8f9c302SDaniel Schwierzeck 189c8f9c302SDaniel Schwierzeckifeq ($(CONFIG_SPL_BUILD),y) 190c8f9c302SDaniel SchwierzeckCPPFLAGS += -DCONFIG_SPL_BUILD 191c8f9c302SDaniel Schwierzeckendif 192c8f9c302SDaniel Schwierzeck 1936c97a20dSKumar Galaifneq ($(RESET_VECTOR_ADDRESS),) 1946c97a20dSKumar GalaCPPFLAGS += -DRESET_VECTOR_ADDRESS=$(RESET_VECTOR_ADDRESS) 1956c97a20dSKumar Galaendif 1966c97a20dSKumar Gala 197f9328639SMarian Balakowiczifneq ($(OBJTREE),$(SRCTREE)) 198f9328639SMarian BalakowiczCPPFLAGS += -I$(OBJTREE)/include2 -I$(OBJTREE)/include 199f9328639SMarian Balakowiczendif 200f9328639SMarian Balakowicz 201f9328639SMarian BalakowiczCPPFLAGS += -I$(TOPDIR)/include 202f9328639SMarian BalakowiczCPPFLAGS += -fno-builtin -ffreestanding -nostdinc \ 203f9328639SMarian Balakowicz -isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS) 204e2211743Swdenk 205e2211743Swdenkifdef BUILD_TAG 206e2211743SwdenkCFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes \ 207e2211743Swdenk -DBUILD_TAG='"$(BUILD_TAG)"' 208e2211743Swdenkelse 209e2211743SwdenkCFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes 210e2211743Swdenkendif 211e2211743Swdenk 212*cca4e4aeSWolfgang DenkCFLAGS_SSP := $(call cc-option,-fno-stack-protector) 213*cca4e4aeSWolfgang DenkCFLAGS += $(CFLAGS_SSP) 2146262e4e7SMike Frysinger# Some toolchains enable security related warning flags by default, 2156262e4e7SMike Frysinger# but they don't make much sense in the u-boot world, so disable them. 216*cca4e4aeSWolfgang DenkCFLAGS_WARN := $(call cc-option,-Wno-format-nonliteral) \ 217*cca4e4aeSWolfgang Denk $(call cc-option,-Wno-format-security) 218*cca4e4aeSWolfgang DenkCFLAGS += $(CFLAGS_WARN) 21928eab0d7SHaavard Skinnemoen 220e11887a7SHaavard Skinnemoen# $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format> 221e11887a7SHaavard Skinnemoen# option to the assembler. 222e11887a7SHaavard SkinnemoenAFLAGS_DEBUG := 223b62fa913SMarian Balakowicz 224483a0cf8SMarian Balakowicz# turn jbsr into jsr for m68k 225483a0cf8SMarian Balakowiczifeq ($(ARCH),m68k) 226483a0cf8SMarian Balakowiczifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4) 227483a0cf8SMarian BalakowiczAFLAGS_DEBUG := -Wa,-gstabs,-S 228483a0cf8SMarian Balakowiczendif 229483a0cf8SMarian Balakowiczendif 230b62fa913SMarian Balakowicz 231e2211743SwdenkAFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS) 232e2211743Swdenk 2338aba9dceSNobuhiro IwamatsuLDFLAGS += $(PLATFORM_LDFLAGS) 2346dc1ecebSHaiying WangLDFLAGS_FINAL += -Bstatic 2358aba9dceSNobuhiro Iwamatsu 2366dc1ecebSHaiying WangLDFLAGS_u-boot += -T $(obj)u-boot.lds $(LDFLAGS_FINAL) 23714d0a02aSWolfgang Denkifneq ($(CONFIG_SYS_TEXT_BASE),) 2388aba9dceSNobuhiro IwamatsuLDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE) 239161b2af4SMike Frysingerendif 240e2211743Swdenk 241c8f9c302SDaniel SchwierzeckLDFLAGS_u-boot-spl += -T $(obj)u-boot-spl.lds $(LDFLAGS_FINAL) 242c8f9c302SDaniel Schwierzeckifneq ($(CONFIG_SPL_TEXT_BASE),) 243c8f9c302SDaniel SchwierzeckLDFLAGS_u-boot-spl += -Ttext $(CONFIG_SPL_TEXT_BASE) 244c8f9c302SDaniel Schwierzeckendif 245c8f9c302SDaniel Schwierzeck 246e2211743Swdenk# Location of a usable BFD library, where we define "usable" as 247e2211743Swdenk# "built for ${HOST}, supports ${TARGET}". Sensible values are 248e2211743Swdenk# - When cross-compiling: the root of the cross-environment 249e2211743Swdenk# - Linux/ppc (native): /usr 250e2211743Swdenk# - NetBSD/ppc (native): you lose ... (must extract these from the 251e2211743Swdenk# binutils build directory, plus the native and U-Boot include 252e2211743Swdenk# files don't like each other) 253e2211743Swdenk# 254e2211743Swdenk# So far, this is used only by tools/gdb/Makefile. 255e2211743Swdenk 2564cda4378SMike Frysingerifeq ($(HOSTOS),darwin) 257e2211743SwdenkBFD_ROOT_DIR = /usr/local/tools 258e2211743Swdenkelse 259ea909b76Swdenkifeq ($(HOSTARCH),$(ARCH)) 260ea909b76Swdenk# native 261ea909b76SwdenkBFD_ROOT_DIR = /usr 262ea909b76Swdenkelse 263e2211743Swdenk#BFD_ROOT_DIR = /LinuxPPC/CDK # Linux/i386 264e2211743Swdenk#BFD_ROOT_DIR = /usr/pkg/cross # NetBSD/i386 265e2211743SwdenkBFD_ROOT_DIR = /opt/powerpc 266e2211743Swdenkendif 267ea909b76Swdenkendif 268e2211743Swdenk 269e2211743Swdenk######################################################################### 270e2211743Swdenk 271d984fed0SScott Woodexport HOSTCC HOSTCFLAGS HOSTLDFLAGS PEDCFLAGS HOSTSTRIP CROSS_COMPILE \ 272434c51a5SPeter Tyser AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP MAKE 27314d0a02aSWolfgang Denkexport CONFIG_SYS_TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS 274e2211743Swdenk 275e2211743Swdenk######################################################################### 276e2211743Swdenk 2775ec5529bSMike Frysinger# Allow boards to use custom optimize flags on a per dir/file basis 27889f39e17SPeter TyserBCURDIR = $(subst $(SRCTREE)/,,$(CURDIR:$(obj)%=%)) 279326a6945SMike FrysingerALL_AFLAGS = $(AFLAGS) $(AFLAGS_$(BCURDIR)/$(@F)) $(AFLAGS_$(BCURDIR)) 280326a6945SMike FrysingerALL_CFLAGS = $(CFLAGS) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR)) 28147508843SSimon GlassEXTRA_CPPFLAGS = $(CPPFLAGS_$(BCURDIR)/$(@F)) $(CPPFLAGS_$(BCURDIR)) 28247508843SSimon GlassALL_CFLAGS += $(EXTRA_CPPFLAGS) 28347508843SSimon Glass 28447508843SSimon Glass# The _DEP version uses the $< file target (for dependency generation) 28547508843SSimon Glass# See rules.mk 28647508843SSimon GlassEXTRA_CPPFLAGS_DEP = $(CPPFLAGS_$(BCURDIR)/$(addsuffix .o,$(basename $<))) \ 28747508843SSimon Glass $(CPPFLAGS_$(BCURDIR)) 288f9328639SMarian Balakowicz$(obj)%.s: %.S 289326a6945SMike Frysinger $(CPP) $(ALL_AFLAGS) -o $@ $< 290f9328639SMarian Balakowicz$(obj)%.o: %.S 291326a6945SMike Frysinger $(CC) $(ALL_AFLAGS) -o $@ $< -c 292f9328639SMarian Balakowicz$(obj)%.o: %.c 293326a6945SMike Frysinger $(CC) $(ALL_CFLAGS) -o $@ $< -c 29431f30c9eSMike Frysinger$(obj)%.i: %.c 295326a6945SMike Frysinger $(CPP) $(ALL_CFLAGS) -o $@ $< -c 29631f30c9eSMike Frysinger$(obj)%.s: %.c 297326a6945SMike Frysinger $(CC) $(ALL_CFLAGS) -o $@ $< -c -S 298f9328639SMarian Balakowicz 299e2211743Swdenk######################################################################### 3006d8962e8SSebastien Carlier 3016d8962e8SSebastien Carlier# If the list of objects to link is empty, just create an empty built-in.o 3026d8962e8SSebastien Carliercmd_link_o_target = $(if $(strip $1),\ 3038aba9dceSNobuhiro Iwamatsu $(LD) $(LDFLAGS) -r -o $@ $1,\ 3046d8962e8SSebastien Carlier rm -f $@; $(AR) rcs $@ ) 3056d8962e8SSebastien Carlier 3066d8962e8SSebastien Carlier######################################################################### 307