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