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 Balakowiczifneq ($(OBJTREE),$(SRCTREE)) 27f9328639SMarian Balakowiczifeq ($(CURDIR),$(SRCTREE)) 28f9328639SMarian Balakowiczdir := 29f9328639SMarian Balakowiczelse 30f9328639SMarian Balakowiczdir := $(subst $(SRCTREE)/,,$(CURDIR)) 31f9328639SMarian Balakowiczendif 32f9328639SMarian Balakowicz 33f9328639SMarian Balakowiczobj := $(if $(dir),$(OBJTREE)/$(dir)/,$(OBJTREE)/) 34f9328639SMarian Balakowiczsrc := $(if $(dir),$(SRCTREE)/$(dir)/,$(SRCTREE)/) 35f9328639SMarian Balakowicz 36f9328639SMarian Balakowicz$(shell mkdir -p $(obj)) 37f9328639SMarian Balakowiczelse 38f9328639SMarian Balakowiczobj := 39f9328639SMarian Balakowiczsrc := 40f9328639SMarian Balakowiczendif 41f9328639SMarian Balakowicz 42592c5cabSwdenk# clean the slate ... 43592c5cabSwdenkPLATFORM_RELFLAGS = 44592c5cabSwdenkPLATFORM_CPPFLAGS = 45592c5cabSwdenkPLATFORM_LDFLAGS = 46592c5cabSwdenk 47e2211743Swdenk######################################################################### 48e2211743Swdenk 49d984fed0SScott WoodHOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer \ 50d984fed0SScott Wood $(HOSTCPPFLAGS) 51d984fed0SScott WoodHOSTSTRIP = strip 52d984fed0SScott Wood 53d984fed0SScott Wood# 54d984fed0SScott Wood# Mac OS X / Darwin's C preprocessor is Apple specific. It 55d984fed0SScott Wood# generates numerous errors and warnings. We want to bypass it 56d984fed0SScott Wood# and use GNU C's cpp. To do this we pass the -traditional-cpp 57d984fed0SScott Wood# option to the compiler. Note that the -traditional-cpp flag 58d984fed0SScott Wood# DOES NOT have the same semantics as GNU C's flag, all it does 59d984fed0SScott Wood# is invoke the GNU preprocessor in stock ANSI/ISO C fashion. 60d984fed0SScott Wood# 61d984fed0SScott Wood# Apple's linker is similar, thanks to the new 2 stage linking 62d984fed0SScott Wood# multiple symbol definitions are treated as errors, hence the 63d984fed0SScott Wood# -multiply_defined suppress option to turn off this error. 64d984fed0SScott Wood# 65d984fed0SScott Wood 664cda4378SMike Frysingerifeq ($(HOSTOS),darwin) 67c7da8c19SAndreas Biessmann# get major and minor product version (e.g. '10' and '6' for Snow Leopard) 68c7da8c19SAndreas BiessmannDARWIN_MAJOR_VERSION = $(shell sw_vers -productVersion | cut -f 1 -d '.') 69c7da8c19SAndreas BiessmannDARWIN_MINOR_VERSION = $(shell sw_vers -productVersion | cut -f 2 -d '.') 70c7da8c19SAndreas Biessmann 71f534c7cdSMike Frysingeros_x_before = $(shell if [ $(DARWIN_MAJOR_VERSION) -le $(1) -a \ 72f534c7cdSMike Frysinger $(DARWIN_MINOR_VERSION) -le $(2) ] ; then echo "$(3)"; else echo "$(4)"; fi ;) 73c7da8c19SAndreas Biessmann 74c7da8c19SAndreas Biessmann# Snow Leopards build environment has no longer restrictions as described above 75f534c7cdSMike FrysingerHOSTCC = $(call os_x_before, 10, 5, "cc", "gcc") 76f534c7cdSMike FrysingerHOSTCFLAGS += $(call os_x_before, 10, 4, "-traditional-cpp") 77f534c7cdSMike FrysingerHOSTLDFLAGS += $(call os_x_before, 10, 5, "-multiply_defined suppress") 78e2211743Swdenkelse 79e2211743SwdenkHOSTCC = gcc 80e2211743Swdenkendif 81d984fed0SScott Wood 82d984fed0SScott Woodifeq ($(HOSTOS),cygwin) 83d984fed0SScott WoodHOSTCFLAGS += -ansi 84d984fed0SScott Woodendif 85d984fed0SScott Wood 86d984fed0SScott Wood# We build some files with extra pedantic flags to try to minimize things 87d984fed0SScott Wood# that won't build on some weird host compiler -- though there are lots of 88d984fed0SScott Wood# exceptions for files that aren't complaint. 89d984fed0SScott Wood 90d984fed0SScott WoodHOSTCFLAGS_NOPED = $(filter-out -pedantic,$(HOSTCFLAGS)) 91d984fed0SScott WoodHOSTCFLAGS += -pedantic 92e2211743Swdenk 93e2211743Swdenk######################################################################### 941820d4c7SWolfgang Denk# 951820d4c7SWolfgang Denk# Option checker (courtesy linux kernel) to ensure 961820d4c7SWolfgang Denk# only supported compiler options are used 971820d4c7SWolfgang Denk# 981820d4c7SWolfgang Denkcc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \ 991820d4c7SWolfgang Denk > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;) 100e2211743Swdenk 101e2211743Swdenk# 102e2211743Swdenk# Include the make variables (CC, etc...) 103e2211743Swdenk# 104e2211743SwdenkAS = $(CROSS_COMPILE)as 105e2211743SwdenkLD = $(CROSS_COMPILE)ld 106e2211743SwdenkCC = $(CROSS_COMPILE)gcc 107e2211743SwdenkCPP = $(CC) -E 108e2211743SwdenkAR = $(CROSS_COMPILE)ar 109e2211743SwdenkNM = $(CROSS_COMPILE)nm 11094a91e24SMike FrysingerLDR = $(CROSS_COMPILE)ldr 111e2211743SwdenkSTRIP = $(CROSS_COMPILE)strip 112e2211743SwdenkOBJCOPY = $(CROSS_COMPILE)objcopy 113e2211743SwdenkOBJDUMP = $(CROSS_COMPILE)objdump 114e2211743SwdenkRANLIB = $(CROSS_COMPILE)RANLIB 115e2211743Swdenk 116c4e5f52aSWolfgang Denk######################################################################### 117c4e5f52aSWolfgang Denk 118c4e5f52aSWolfgang Denk# Load generated board configuration 119c4e5f52aSWolfgang Denksinclude $(OBJTREE)/include/autoconf.mk 120*5e987ddfSJoakim Tjernlundsinclude $(OBJTREE)/include/config.mk 121c4e5f52aSWolfgang Denk 12203b7004dSPeter Tyser# Some architecture config.mk files need to know what CPUDIR is set to, 12303b7004dSPeter Tyser# so calculate CPUDIR before including ARCH/SOC/CPU config.mk files. 1248d1f2682SPeter Tyser# Check if arch/$ARCH/cpu/$CPU exists, otherwise assume arch/$ARCH/cpu contains 1258d1f2682SPeter Tyser# CPU-specific code. 1268d1f2682SPeter TyserCPUDIR=arch/$(ARCH)/cpu/$(CPU) 1278d1f2682SPeter Tyserifneq ($(SRCTREE)/$(CPUDIR),$(wildcard $(SRCTREE)/$(CPUDIR))) 1288d1f2682SPeter TyserCPUDIR=arch/$(ARCH)/cpu 1298d1f2682SPeter Tyserendif 13003b7004dSPeter Tyser 131ea0364f1SPeter Tysersinclude $(TOPDIR)/arch/$(ARCH)/config.mk # include architecture dependend rules 13203b7004dSPeter Tysersinclude $(TOPDIR)/$(CPUDIR)/config.mk # include CPU specific rules 13303b7004dSPeter Tyser 134c4e5f52aSWolfgang Denkifdef SOC 13503b7004dSPeter Tysersinclude $(TOPDIR)/$(CPUDIR)/$(SOC)/config.mk # include SoC specific rules 136c4e5f52aSWolfgang Denkendif 137c4e5f52aSWolfgang Denkifdef VENDOR 138c4e5f52aSWolfgang DenkBOARDDIR = $(VENDOR)/$(BOARD) 139c4e5f52aSWolfgang Denkelse 140c4e5f52aSWolfgang DenkBOARDDIR = $(BOARD) 141c4e5f52aSWolfgang Denkendif 142c4e5f52aSWolfgang Denkifdef BOARD 143c4e5f52aSWolfgang Denksinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules 144c4e5f52aSWolfgang Denkendif 145c4e5f52aSWolfgang Denk 146c4e5f52aSWolfgang Denk######################################################################### 147c4e5f52aSWolfgang Denk 1481954be6eSWolfgang Denkifneq (,$(findstring s,$(MAKEFLAGS))) 1491954be6eSWolfgang DenkARFLAGS = cr 1501954be6eSWolfgang Denkelse 1512b208f53SWolfgang DenkARFLAGS = crv 1521954be6eSWolfgang Denkendif 153e2211743SwdenkRELFLAGS= $(PLATFORM_RELFLAGS) 154e2211743SwdenkDBGFLAGS= -g # -DDEBUG 155e2211743SwdenkOPTFLAGS= -Os #-fomit-frame-pointer 1566dd652faSwdenkifndef LDSCRIPT 1574aeb251fSwdenk#LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds.debug 158887e2ec9SStefan Roeseifeq ($(CONFIG_NAND_U_BOOT),y) 159887e2ec9SStefan RoeseLDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot-nand.lds 160887e2ec9SStefan Roeseelse 161e2211743SwdenkLDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds 1626dd652faSwdenkendif 163887e2ec9SStefan Roeseendif 1646dd652faSwdenkOBJCFLAGS += --gap-fill=0xff 165e2211743Swdenk 166b783edaeSwdenkgccincdir := $(shell $(CC) -print-file-name=include) 167b783edaeSwdenk 168e2211743SwdenkCPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \ 169161b2af4SMike Frysinger -D__KERNEL__ 17014d0a02aSWolfgang Denkifneq ($(CONFIG_SYS_TEXT_BASE),) 17114d0a02aSWolfgang DenkCPPFLAGS += -DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE) 172161b2af4SMike Frysingerendif 173f9328639SMarian Balakowicz 1746c97a20dSKumar Galaifneq ($(RESET_VECTOR_ADDRESS),) 1756c97a20dSKumar GalaCPPFLAGS += -DRESET_VECTOR_ADDRESS=$(RESET_VECTOR_ADDRESS) 1766c97a20dSKumar Galaendif 1776c97a20dSKumar Gala 178f9328639SMarian Balakowiczifneq ($(OBJTREE),$(SRCTREE)) 179f9328639SMarian BalakowiczCPPFLAGS += -I$(OBJTREE)/include2 -I$(OBJTREE)/include 180f9328639SMarian Balakowiczendif 181f9328639SMarian Balakowicz 182f9328639SMarian BalakowiczCPPFLAGS += -I$(TOPDIR)/include 183f9328639SMarian BalakowiczCPPFLAGS += -fno-builtin -ffreestanding -nostdinc \ 184f9328639SMarian Balakowicz -isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS) 185e2211743Swdenk 186e2211743Swdenkifdef BUILD_TAG 187e2211743SwdenkCFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes \ 188e2211743Swdenk -DBUILD_TAG='"$(BUILD_TAG)"' 189e2211743Swdenkelse 190e2211743SwdenkCFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes 191e2211743Swdenkendif 192e2211743Swdenk 19328eab0d7SHaavard SkinnemoenCFLAGS += $(call cc-option,-fno-stack-protector) 19428eab0d7SHaavard Skinnemoen 195e11887a7SHaavard Skinnemoen# $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format> 196e11887a7SHaavard Skinnemoen# option to the assembler. 197e11887a7SHaavard SkinnemoenAFLAGS_DEBUG := 198b62fa913SMarian Balakowicz 199483a0cf8SMarian Balakowicz# turn jbsr into jsr for m68k 200483a0cf8SMarian Balakowiczifeq ($(ARCH),m68k) 201483a0cf8SMarian Balakowiczifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4) 202483a0cf8SMarian BalakowiczAFLAGS_DEBUG := -Wa,-gstabs,-S 203483a0cf8SMarian Balakowiczendif 204483a0cf8SMarian Balakowiczendif 205b62fa913SMarian Balakowicz 206e2211743SwdenkAFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS) 207e2211743Swdenk 2088aba9dceSNobuhiro IwamatsuLDFLAGS += $(PLATFORM_LDFLAGS) 2098aba9dceSNobuhiro Iwamatsu 2108aba9dceSNobuhiro IwamatsuLDFLAGS_u-boot += -Bstatic -T $(obj)u-boot.lds $(PLATFORM_LDFLAGS) 21114d0a02aSWolfgang Denkifneq ($(CONFIG_SYS_TEXT_BASE),) 2128aba9dceSNobuhiro IwamatsuLDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE) 213161b2af4SMike Frysingerendif 214e2211743Swdenk 215e2211743Swdenk# Location of a usable BFD library, where we define "usable" as 216e2211743Swdenk# "built for ${HOST}, supports ${TARGET}". Sensible values are 217e2211743Swdenk# - When cross-compiling: the root of the cross-environment 218e2211743Swdenk# - Linux/ppc (native): /usr 219e2211743Swdenk# - NetBSD/ppc (native): you lose ... (must extract these from the 220e2211743Swdenk# binutils build directory, plus the native and U-Boot include 221e2211743Swdenk# files don't like each other) 222e2211743Swdenk# 223e2211743Swdenk# So far, this is used only by tools/gdb/Makefile. 224e2211743Swdenk 2254cda4378SMike Frysingerifeq ($(HOSTOS),darwin) 226e2211743SwdenkBFD_ROOT_DIR = /usr/local/tools 227e2211743Swdenkelse 228ea909b76Swdenkifeq ($(HOSTARCH),$(ARCH)) 229ea909b76Swdenk# native 230ea909b76SwdenkBFD_ROOT_DIR = /usr 231ea909b76Swdenkelse 232e2211743Swdenk#BFD_ROOT_DIR = /LinuxPPC/CDK # Linux/i386 233e2211743Swdenk#BFD_ROOT_DIR = /usr/pkg/cross # NetBSD/i386 234e2211743SwdenkBFD_ROOT_DIR = /opt/powerpc 235e2211743Swdenkendif 236ea909b76Swdenkendif 237e2211743Swdenk 238e2211743Swdenk######################################################################### 239e2211743Swdenk 240d984fed0SScott Woodexport HOSTCC HOSTCFLAGS HOSTLDFLAGS PEDCFLAGS HOSTSTRIP CROSS_COMPILE \ 241434c51a5SPeter Tyser AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP MAKE 24214d0a02aSWolfgang Denkexport CONFIG_SYS_TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS 243e2211743Swdenk 244e2211743Swdenk######################################################################### 245e2211743Swdenk 2465ec5529bSMike Frysinger# Allow boards to use custom optimize flags on a per dir/file basis 24789f39e17SPeter TyserBCURDIR = $(subst $(SRCTREE)/,,$(CURDIR:$(obj)%=%)) 248326a6945SMike FrysingerALL_AFLAGS = $(AFLAGS) $(AFLAGS_$(BCURDIR)/$(@F)) $(AFLAGS_$(BCURDIR)) 249326a6945SMike FrysingerALL_CFLAGS = $(CFLAGS) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR)) 250f9328639SMarian Balakowicz$(obj)%.s: %.S 251326a6945SMike Frysinger $(CPP) $(ALL_AFLAGS) -o $@ $< 252f9328639SMarian Balakowicz$(obj)%.o: %.S 253326a6945SMike Frysinger $(CC) $(ALL_AFLAGS) -o $@ $< -c 254f9328639SMarian Balakowicz$(obj)%.o: %.c 255326a6945SMike Frysinger $(CC) $(ALL_CFLAGS) -o $@ $< -c 25631f30c9eSMike Frysinger$(obj)%.i: %.c 257326a6945SMike Frysinger $(CPP) $(ALL_CFLAGS) -o $@ $< -c 25831f30c9eSMike Frysinger$(obj)%.s: %.c 259326a6945SMike Frysinger $(CC) $(ALL_CFLAGS) -o $@ $< -c -S 260f9328639SMarian Balakowicz 261e2211743Swdenk######################################################################### 2626d8962e8SSebastien Carlier 2636d8962e8SSebastien Carlier# If the list of objects to link is empty, just create an empty built-in.o 2646d8962e8SSebastien Carliercmd_link_o_target = $(if $(strip $1),\ 2658aba9dceSNobuhiro Iwamatsu $(LD) $(LDFLAGS) -r -o $@ $1,\ 2666d8962e8SSebastien Carlier rm -f $@; $(AR) rcs $@ ) 2676d8962e8SSebastien Carlier 2686d8962e8SSebastien Carlier######################################################################### 269