blob: a0633c1601c2a3d56ab3f8e34a4a772c582eb98e [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001#
2# (C) Copyright 2000
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
26# clean the slate ...
27PLATFORM_RELFLAGS =
28PLATFORM_CPPFLAGS =
29PLATFORM_LDFLAGS =
30
31#
32# When cross-compiling on NetBSD, we have to define __PPC__ or else we
33# will pick up a va_list declaration that is incompatible with the
34# actual argument lists emitted by the compiler.
35#
36# [Tested on NetBSD/i386 1.5 + cross-powerpc-netbsd-1.3]
37
38ifeq ($(ARCH),ppc)
39ifeq ($(CROSS_COMPILE),powerpc-netbsd-)
40PLATFORM_CPPFLAGS+= -D__PPC__
41endif
42ifeq ($(CROSS_COMPILE),powerpc-openbsd-)
43PLATFORM_CPPFLAGS+= -D__PPC__
44endif
45endif
46
47ifeq ($(ARCH),arm)
48ifeq ($(CROSS_COMPILE),powerpc-netbsd-)
49PLATFORM_CPPFLAGS+= -D__ARM__
50endif
51ifeq ($(CROSS_COMPILE),powerpc-openbsd-)
52PLATFORM_CPPFLAGS+= -D__ARM__
53endif
54endif
55
56ifeq ($(strip $(board)),$(filter $(board),mdl_mini mifi_mini))
57PLATFORM_CPPFLAGS+= -DV3E_NOR_FLASH
58endif
59
60ifeq ($(strip $(board)),$(filter $(board),cpe))
61PLATFORM_CPPFLAGS+= -DCONFIG_ZX297520V3E_CPE
62endif
63
64ifeq ($(strip $(board)),$(filter $(board),ufi_mini))
65PLATFORM_CPPFLAGS+= -DCONFIG_ZX297520V3_UFI_MINI_32K_NOR
66endif
67
68ifeq ($(strip $(board)),$(filter $(board),mdl_ab))
69PLATFORM_CPPFLAGS+= -DCONFIG_ZX297520V3E_MDL_AB
70endif
71
72ifdef ARCH
73sinclude $(TOPDIR)/$(ARCH)_config.mk # include architecture dependend rules
74endif
75ifdef CPU
76sinclude $(TOPDIR)/cpu/$(CPU)/config.mk # include CPU specific rules
77endif
78ifdef VENDOR
79BOARDDIR = $(VENDOR)/$(BOARD)
80else
81BOARDDIR = $(BOARD)
82endif
83ifdef BOARD
84sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules
85endif
86
87#########################################################################
88
89CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
90 else if [ -x /bin/bash ]; then echo /bin/bash; \
91 else echo sh; fi ; fi)
92
93ifeq ($(HOSTOS)-$(HOSTARCH),darwin-ppc)
94HOSTCC = cc
95else
96HOSTCC = gcc
97endif
98HOSTCFLAGS = -Wall -Wstrict-prototypes -O0 -fomit-frame-pointer #zhouqi
99HOSTSTRIP = strip
100
101#########################################################################
102#
103# Option checker (courtesy linux kernel) to ensure
104# only supported compiler options are used
105#
106cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
107 > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
108
109#
110# Include the make variables (CC, etc...)
111#
112AS = $(CROSS_COMPILE)as
113LD = $(CROSS_COMPILE)ld
114CC = $(CROSS_COMPILE)gcc
115CPP = $(CC) -E
116AR = $(CROSS_COMPILE)ar
117NM = $(CROSS_COMPILE)nm
118STRIP = $(CROSS_COMPILE)strip
119OBJCOPY = $(CROSS_COMPILE)objcopy
120OBJDUMP = $(CROSS_COMPILE)objdump
121RANLIB = $(CROSS_COMPILE)RANLIB
122
123RELFLAGS= $(PLATFORM_RELFLAGS)
124DBGFLAGS= -g # -DDEBUG
125OPTFLAGS= -Os #-fomit-frame-pointer
126ifndef LDSCRIPT
127#LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/z-load.lds.debug
128LDSCRIPT := $(TOPDIR)/cpu/$(CPU)/z-load.lds
129endif
130OBJCFLAGS += --gap-fill=0xff
131
132gccincdir := $(shell $(CC) -print-file-name=include)
133
134CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \
135 -D__KERNEL__ -DTEXT_BASE=$(TEXT_BASE) \
136 -D _CHIP_ZX297520V3 \
137 -I$(TOPDIR)/include \
138 -I$(TOPDIR)/../../../../pub/project/zx297520v3/include/drv \
139 -I$(TOPDIR)/../../../../pub/project/zx297520v3/include/infra \
140 -I$(TOPDIR)/../../../../pub/project/zx297520v3/include/psm \
141 -I$(TOPDIR)/../../../../pub/include/infra \
142 -fno-builtin -ffreestanding -nostdinc -isystem \
143 $(gccincdir) -pipe $(PLATFORM_CPPFLAGS)
144
145ifdef BUILD_TAG
146CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes \
147 -DBUILD_TAG='"$(BUILD_TAG)"'
148else
149CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes
150endif
151
152AFLAGS_DEBUG := -Wa,-gstabs
153AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS)
154
155LDFLAGS += -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS) -nostdlib
156
157# Location of a usable BFD library, where we define "usable" as
158# "built for ${HOST}, supports ${TARGET}". Sensible values are
159# - When cross-compiling: the root of the cross-environment
160# - Linux/ppc (native): /usr
161# - NetBSD/ppc (native): you lose ... (must extract these from the
162# binutils build directory, plus the native and U-Boot include
163# files don't like each other)
164#
165# So far, this is used only by tools/gdb/Makefile.
166
167ifeq ($(HOSTOS)-$(HOSTARCH),darwin-ppc)
168BFD_ROOT_DIR = /usr/local/tools
169else
170ifeq ($(HOSTARCH),$(ARCH))
171# native
172BFD_ROOT_DIR = /usr
173else
174#BFD_ROOT_DIR = /LinuxPPC/CDK # Linux/i386
175#BFD_ROOT_DIR = /usr/pkg/cross # NetBSD/i386
176BFD_ROOT_DIR = /opt/powerpc
177endif
178endif
179
180#########################################################################
181
182export CONFIG_SHELL HPATH HOSTCC HOSTCFLAGS CROSS_COMPILE \
183 AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP \
184 MAKE
185export TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS
186
187#########################################################################
188
189%.s: %.S
190 $(CPP) $(AFLAGS) -o $@ $(CURDIR)/$<
191%.o: %.S
192 $(CC) $(AFLAGS) -c -o $@ $(CURDIR)/$<
193%.o: %.c
194 $(CC) $(CFLAGS) -c -o $@ $<
195
196.depend: Makefile $(SOBJS:.o=.S) $(OBJS:.o=.c) $(AOBJS:.o=.S) $(START:.o=.S) $(COBJS:.o=.c)
197 $(CC) -M $(CPPFLAGS) $(SOBJS:.o=.S) $(OBJS:.o=.c) | \
198 sed -e "s/\:/\\\:/g"|sed -e "s/\\\: /\: /g"> $@
199
200#########################################################################