blob: bc87bafe0272516a999883c815dd87aebd18dd3e [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -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
72ifeq ($(strip $(board)),$(filter $(board),vehicle_dc))
73PLATFORM_CPPFLAGS+= -DCONFIG_ZX297520V3E_VEHICLE_DC
74endif
75
xf.li6c8fc1e2023-08-12 00:11:09 -070076ifeq ($(strip $(board)),$(filter $(board),vehicle_dc_ref))
77PLATFORM_CPPFLAGS+= -DCONFIG_ZX297520V3E_VEHICLE_DC_REF
78endif
79
lh9ed821d2023-04-07 01:36:19 -070080ifdef ARCH
81sinclude $(TOPDIR)/$(ARCH)_config.mk # include architecture dependend rules
82endif
83ifdef CPU
84sinclude $(TOPDIR)/cpu/$(CPU)/config.mk # include CPU specific rules
85endif
86ifdef VENDOR
87BOARDDIR = $(VENDOR)/$(BOARD)
88else
89BOARDDIR = $(BOARD)
90endif
91ifdef BOARD
92sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules
93endif
94
95#########################################################################
96
97CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
98 else if [ -x /bin/bash ]; then echo /bin/bash; \
99 else echo sh; fi ; fi)
100
101ifeq ($(HOSTOS)-$(HOSTARCH),darwin-ppc)
102HOSTCC = cc
103else
104HOSTCC = gcc
105endif
106HOSTCFLAGS = -Wall -Wstrict-prototypes -O0 -fomit-frame-pointer #zhouqi
107HOSTSTRIP = strip
108
109#########################################################################
110#
111# Option checker (courtesy linux kernel) to ensure
112# only supported compiler options are used
113#
114cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
115 > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
116
117#
118# Include the make variables (CC, etc...)
119#
120AS = $(CROSS_COMPILE)as
121LD = $(CROSS_COMPILE)ld
122CC = $(CROSS_COMPILE)gcc
123CPP = $(CC) -E
124AR = $(CROSS_COMPILE)ar
125NM = $(CROSS_COMPILE)nm
126STRIP = $(CROSS_COMPILE)strip
127OBJCOPY = $(CROSS_COMPILE)objcopy
128OBJDUMP = $(CROSS_COMPILE)objdump
129RANLIB = $(CROSS_COMPILE)RANLIB
130
131RELFLAGS= $(PLATFORM_RELFLAGS)
132DBGFLAGS= -g # -DDEBUG
133OPTFLAGS= -Os #-fomit-frame-pointer
134ifndef LDSCRIPT
135#LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/z-load.lds.debug
136LDSCRIPT := $(TOPDIR)/cpu/$(CPU)/z-load.lds
137endif
138OBJCFLAGS += --gap-fill=0xff
139
140gccincdir := $(shell $(CC) -print-file-name=include)
141
142CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \
143 -D__KERNEL__ -DTEXT_BASE=$(TEXT_BASE) \
144 -D _CHIP_ZX297520V3 \
145 -I$(TOPDIR)/include \
146 -I$(TOPDIR)/../../../../pub/project/zx297520v3/include/drv \
147 -I$(TOPDIR)/../../../../pub/project/zx297520v3/include/infra \
148 -I$(TOPDIR)/../../../../pub/project/zx297520v3/include/psm \
149 -I$(TOPDIR)/../../../../pub/include/infra \
150 -fno-builtin -ffreestanding -nostdinc -isystem \
151 $(gccincdir) -pipe $(PLATFORM_CPPFLAGS)
152
153ifdef BUILD_TAG
154CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes \
155 -DBUILD_TAG='"$(BUILD_TAG)"'
156else
157CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes
158endif
159
160AFLAGS_DEBUG := -Wa,-gstabs
161AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS)
162
163LDFLAGS += -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS) -nostdlib
164
165# Location of a usable BFD library, where we define "usable" as
166# "built for ${HOST}, supports ${TARGET}". Sensible values are
167# - When cross-compiling: the root of the cross-environment
168# - Linux/ppc (native): /usr
169# - NetBSD/ppc (native): you lose ... (must extract these from the
170# binutils build directory, plus the native and U-Boot include
171# files don't like each other)
172#
173# So far, this is used only by tools/gdb/Makefile.
174
175ifeq ($(HOSTOS)-$(HOSTARCH),darwin-ppc)
176BFD_ROOT_DIR = /usr/local/tools
177else
178ifeq ($(HOSTARCH),$(ARCH))
179# native
180BFD_ROOT_DIR = /usr
181else
182#BFD_ROOT_DIR = /LinuxPPC/CDK # Linux/i386
183#BFD_ROOT_DIR = /usr/pkg/cross # NetBSD/i386
184BFD_ROOT_DIR = /opt/powerpc
185endif
186endif
187
188#########################################################################
189
190export CONFIG_SHELL HPATH HOSTCC HOSTCFLAGS CROSS_COMPILE \
191 AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP \
192 MAKE
193export TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS
194
195#########################################################################
196
197%.s: %.S
198 $(CPP) $(AFLAGS) -o $@ $(CURDIR)/$<
199%.o: %.S
200 $(CC) $(AFLAGS) -c -o $@ $(CURDIR)/$<
201%.o: %.c
202 $(CC) $(CFLAGS) -c -o $@ $<
203
204.depend: Makefile $(SOBJS:.o=.S) $(OBJS:.o=.c) $(AOBJS:.o=.S) $(START:.o=.S) $(COBJS:.o=.c)
205 $(CC) -M $(CPPFLAGS) $(SOBJS:.o=.S) $(OBJS:.o=.c) | \
206 sed -e "s/\:/\\\:/g"|sed -e "s/\\\: /\: /g"> $@
207
208#########################################################################