wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 1 | # |
Marian Balakowicz | d62379d | 2006-09-01 19:49:50 +0200 | [diff] [blame] | 2 | # (C) Copyright 2000-2006 |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 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 | ######################################################################### |
| 25 | |
Marian Balakowicz | d62379d | 2006-09-01 19:49:50 +0200 | [diff] [blame] | 26 | ifneq ($(OBJTREE),$(SRCTREE)) |
| 27 | ifeq ($(CURDIR),$(SRCTREE)) |
Wolfgang Denk | 4df0da5 | 2006-10-09 00:42:01 +0200 | [diff] [blame] | 28 | dir := |
Marian Balakowicz | d62379d | 2006-09-01 19:49:50 +0200 | [diff] [blame] | 29 | else |
| 30 | dir := $(subst $(SRCTREE)/,,$(CURDIR)) |
| 31 | endif |
| 32 | |
| 33 | obj := $(if $(dir),$(OBJTREE)/$(dir)/,$(OBJTREE)/) |
| 34 | src := $(if $(dir),$(SRCTREE)/$(dir)/,$(SRCTREE)/) |
| 35 | |
| 36 | $(shell mkdir -p $(obj)) |
| 37 | else |
| 38 | obj := |
| 39 | src := |
| 40 | endif |
| 41 | |
wdenk | dbae504 | 2003-06-21 00:17:24 +0000 | [diff] [blame] | 42 | # clean the slate ... |
| 43 | PLATFORM_RELFLAGS = |
| 44 | PLATFORM_CPPFLAGS = |
| 45 | PLATFORM_LDFLAGS = |
| 46 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 47 | ifeq ($(ARCH),arm) |
| 48 | ifeq ($(CROSS_COMPILE),powerpc-netbsd-) |
| 49 | PLATFORM_CPPFLAGS+= -D__ARM__ |
| 50 | endif |
| 51 | ifeq ($(CROSS_COMPILE),powerpc-openbsd-) |
| 52 | PLATFORM_CPPFLAGS+= -D__ARM__ |
| 53 | endif |
| 54 | endif |
| 55 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 56 | ######################################################################### |
| 57 | |
| 58 | CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \ |
| 59 | else if [ -x /bin/bash ]; then echo /bin/bash; \ |
| 60 | else echo sh; fi ; fi) |
| 61 | |
| 62 | ifeq ($(HOSTOS)-$(HOSTARCH),darwin-ppc) |
| 63 | HOSTCC = cc |
| 64 | else |
| 65 | HOSTCC = gcc |
| 66 | endif |
| 67 | HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer |
| 68 | HOSTSTRIP = strip |
| 69 | |
| 70 | ######################################################################### |
Wolfgang Denk | aba5809 | 2005-10-04 22:38:24 +0200 | [diff] [blame] | 71 | # |
| 72 | # Option checker (courtesy linux kernel) to ensure |
| 73 | # only supported compiler options are used |
| 74 | # |
| 75 | cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \ |
Wolfgang Denk | 03f9ba3 | 2005-10-04 23:10:28 +0200 | [diff] [blame] | 76 | > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 77 | |
| 78 | # |
| 79 | # Include the make variables (CC, etc...) |
| 80 | # |
| 81 | AS = $(CROSS_COMPILE)as |
| 82 | LD = $(CROSS_COMPILE)ld |
| 83 | CC = $(CROSS_COMPILE)gcc |
| 84 | CPP = $(CC) -E |
| 85 | AR = $(CROSS_COMPILE)ar |
| 86 | NM = $(CROSS_COMPILE)nm |
Mike Frysinger | 908e776 | 2008-02-04 19:26:57 -0500 | [diff] [blame] | 87 | LDR = $(CROSS_COMPILE)ldr |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 88 | STRIP = $(CROSS_COMPILE)strip |
| 89 | OBJCOPY = $(CROSS_COMPILE)objcopy |
| 90 | OBJDUMP = $(CROSS_COMPILE)objdump |
| 91 | RANLIB = $(CROSS_COMPILE)RANLIB |
| 92 | |
Wolfgang Denk | 979b4bd | 2008-05-03 22:25:00 +0200 | [diff] [blame] | 93 | ######################################################################### |
| 94 | |
| 95 | # Load generated board configuration |
| 96 | sinclude $(OBJTREE)/include/autoconf.mk |
| 97 | |
| 98 | ifdef ARCH |
| 99 | sinclude $(TOPDIR)/$(ARCH)_config.mk # include architecture dependend rules |
| 100 | endif |
| 101 | ifdef CPU |
| 102 | sinclude $(TOPDIR)/cpu/$(CPU)/config.mk # include CPU specific rules |
| 103 | endif |
| 104 | ifdef SOC |
| 105 | sinclude $(TOPDIR)/cpu/$(CPU)/$(SOC)/config.mk # include SoC specific rules |
| 106 | endif |
| 107 | ifdef VENDOR |
| 108 | BOARDDIR = $(VENDOR)/$(BOARD) |
| 109 | else |
| 110 | BOARDDIR = $(BOARD) |
| 111 | endif |
| 112 | ifdef BOARD |
| 113 | sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules |
| 114 | endif |
| 115 | |
| 116 | ######################################################################### |
| 117 | |
Wolfgang Denk | 71c20d6 | 2006-10-29 01:03:51 +0200 | [diff] [blame] | 118 | ifneq (,$(findstring s,$(MAKEFLAGS))) |
| 119 | ARFLAGS = cr |
| 120 | else |
Wolfgang Denk | 6a65e42 | 2006-10-09 01:02:05 +0200 | [diff] [blame] | 121 | ARFLAGS = crv |
Wolfgang Denk | 71c20d6 | 2006-10-29 01:03:51 +0200 | [diff] [blame] | 122 | endif |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 123 | RELFLAGS= $(PLATFORM_RELFLAGS) |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 124 | DBGFLAGS= -g # -DDEBUG |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 125 | OPTFLAGS= -Os #-fomit-frame-pointer |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 126 | ifndef LDSCRIPT |
wdenk | f5547d3 | 2003-09-16 17:06:05 +0000 | [diff] [blame] | 127 | #LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds.debug |
Stefan Roese | 42fbddd | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 128 | ifeq ($(CONFIG_NAND_U_BOOT),y) |
| 129 | LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot-nand.lds |
| 130 | else |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 131 | LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 132 | endif |
Stefan Roese | 42fbddd | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 133 | endif |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 134 | OBJCFLAGS += --gap-fill=0xff |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 135 | |
wdenk | bb2d927 | 2003-06-25 22:26:29 +0000 | [diff] [blame] | 136 | gccincdir := $(shell $(CC) -print-file-name=include) |
| 137 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 138 | CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \ |
Mike Frysinger | 1280555 | 2008-01-28 05:28:50 -0500 | [diff] [blame] | 139 | -D__KERNEL__ |
| 140 | ifneq ($(TEXT_BASE),) |
| 141 | CPPFLAGS += -DTEXT_BASE=$(TEXT_BASE) |
| 142 | endif |
Marian Balakowicz | d62379d | 2006-09-01 19:49:50 +0200 | [diff] [blame] | 143 | |
| 144 | ifneq ($(OBJTREE),$(SRCTREE)) |
| 145 | CPPFLAGS += -I$(OBJTREE)/include2 -I$(OBJTREE)/include |
| 146 | endif |
| 147 | |
| 148 | CPPFLAGS += -I$(TOPDIR)/include |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 149 | CPPFLAGS += -fno-builtin -ffreestanding -nostdinc \ |
Marian Balakowicz | d62379d | 2006-09-01 19:49:50 +0200 | [diff] [blame] | 150 | -isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 151 | |
| 152 | ifdef BUILD_TAG |
| 153 | CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes \ |
| 154 | -DBUILD_TAG='"$(BUILD_TAG)"' |
| 155 | else |
| 156 | CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes |
| 157 | endif |
| 158 | |
Haavard Skinnemoen | e7af207 | 2008-05-19 12:26:38 +0200 | [diff] [blame] | 159 | CFLAGS += $(call cc-option,-fno-stack-protector) |
| 160 | |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 161 | # avoid trigraph warnings while parsing pci.h (produced by NIOS gcc-2.9) |
| 162 | # this option have to be placed behind -Wall -- that's why it is here |
| 163 | ifeq ($(ARCH),nios) |
| 164 | ifeq ($(findstring 2.9,$(shell $(CC) --version)),2.9) |
wdenk | e4adb35 | 2004-05-19 21:33:14 +0000 | [diff] [blame] | 165 | CFLAGS := $(CPPFLAGS) -Wall -Wno-trigraphs |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 166 | endif |
| 167 | endif |
| 168 | |
Haavard Skinnemoen | 1cd6bf0 | 2006-10-26 17:55:31 +0200 | [diff] [blame] | 169 | # $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format> |
| 170 | # option to the assembler. |
| 171 | AFLAGS_DEBUG := |
Marian Balakowicz | 9a460d2 | 2006-05-17 12:18:48 +0200 | [diff] [blame] | 172 | |
Marian Balakowicz | 3e8b1dc | 2006-05-09 11:28:36 +0200 | [diff] [blame] | 173 | # turn jbsr into jsr for m68k |
| 174 | ifeq ($(ARCH),m68k) |
| 175 | ifeq ($(findstring 3.4,$(shell $(CC) --version)),3.4) |
| 176 | AFLAGS_DEBUG := -Wa,-gstabs,-S |
| 177 | endif |
Marian Balakowicz | 3e8b1dc | 2006-05-09 11:28:36 +0200 | [diff] [blame] | 178 | endif |
Marian Balakowicz | 9a460d2 | 2006-05-17 12:18:48 +0200 | [diff] [blame] | 179 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 180 | AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS) |
| 181 | |
Mike Frysinger | 1280555 | 2008-01-28 05:28:50 -0500 | [diff] [blame] | 182 | LDFLAGS += -Bstatic -T $(LDSCRIPT) $(PLATFORM_LDFLAGS) |
| 183 | ifneq ($(TEXT_BASE),) |
| 184 | LDFLAGS += -Ttext $(TEXT_BASE) |
| 185 | endif |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 186 | |
| 187 | # Location of a usable BFD library, where we define "usable" as |
| 188 | # "built for ${HOST}, supports ${TARGET}". Sensible values are |
| 189 | # - When cross-compiling: the root of the cross-environment |
| 190 | # - Linux/ppc (native): /usr |
| 191 | # - NetBSD/ppc (native): you lose ... (must extract these from the |
| 192 | # binutils build directory, plus the native and U-Boot include |
| 193 | # files don't like each other) |
| 194 | # |
| 195 | # So far, this is used only by tools/gdb/Makefile. |
| 196 | |
| 197 | ifeq ($(HOSTOS)-$(HOSTARCH),darwin-ppc) |
| 198 | BFD_ROOT_DIR = /usr/local/tools |
| 199 | else |
wdenk | 2029f4d | 2002-11-21 23:11:29 +0000 | [diff] [blame] | 200 | ifeq ($(HOSTARCH),$(ARCH)) |
| 201 | # native |
| 202 | BFD_ROOT_DIR = /usr |
| 203 | else |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 204 | #BFD_ROOT_DIR = /LinuxPPC/CDK # Linux/i386 |
| 205 | #BFD_ROOT_DIR = /usr/pkg/cross # NetBSD/i386 |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 206 | BFD_ROOT_DIR = /opt/powerpc |
| 207 | endif |
wdenk | 2029f4d | 2002-11-21 23:11:29 +0000 | [diff] [blame] | 208 | endif |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 209 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 210 | ifeq ($(PCI_CLOCK),PCI_66M) |
| 211 | CFLAGS := $(CFLAGS) -DPCI_66M |
| 212 | endif |
| 213 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 214 | ######################################################################### |
| 215 | |
| 216 | export CONFIG_SHELL HPATH HOSTCC HOSTCFLAGS CROSS_COMPILE \ |
| 217 | AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP \ |
| 218 | MAKE |
| 219 | export TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS |
| 220 | |
| 221 | ######################################################################### |
| 222 | |
Marian Balakowicz | d62379d | 2006-09-01 19:49:50 +0200 | [diff] [blame] | 223 | ifndef REMOTE_BUILD |
| 224 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 225 | %.s: %.S |
Marian Balakowicz | d62379d | 2006-09-01 19:49:50 +0200 | [diff] [blame] | 226 | $(CPP) $(AFLAGS) -o $@ $< |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 227 | %.o: %.S |
Marian Balakowicz | d62379d | 2006-09-01 19:49:50 +0200 | [diff] [blame] | 228 | $(CC) $(AFLAGS) -c -o $@ $< |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 229 | %.o: %.c |
| 230 | $(CC) $(CFLAGS) -c -o $@ $< |
Marian Balakowicz | d62379d | 2006-09-01 19:49:50 +0200 | [diff] [blame] | 231 | |
| 232 | else |
| 233 | |
| 234 | $(obj)%.s: %.S |
| 235 | $(CPP) $(AFLAGS) -o $@ $< |
| 236 | $(obj)%.o: %.S |
| 237 | $(CC) $(AFLAGS) -c -o $@ $< |
| 238 | $(obj)%.o: %.c |
| 239 | $(CC) $(CFLAGS) -c -o $@ $< |
| 240 | endif |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 241 | |
| 242 | ######################################################################### |