Makefile: remove TEXT_BASE
[pandora-x-loader.git] / Makefile
1 #
2 # (C) Copyright 2004-2006, Texas Instruments, <www.ti.com>
3 # Jian Zhang <jzhang@ti.com>
4 #
5 # (C) Copyright 2000-2004
6 # Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 #
8 # See file CREDITS for list of people who contributed to this
9 # project.
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation; either version 2 of
14 # the License, or (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 # MA 02111-1307 USA
25 #
26
27 HOSTARCH := $(shell uname -m | \
28         sed -e s/i.86/i386/ \
29             -e s/sun4u/sparc64/ \
30             -e s/arm.*/arm/ \
31             -e s/sa110/arm/ \
32             -e s/powerpc/ppc/ \
33             -e s/macppc/ppc/)
34
35 HOSTOS := $(shell uname -s | tr A-Z a-z | \
36             sed -e 's/\(cygwin\).*/cygwin/')
37
38 export  HOSTARCH
39
40 # Deal with colliding definitions from tcsh etc.
41 VENDOR=
42
43 #########################################################################
44 #
45 # X-loader build supports producing a object files to the separate external
46 # directory. Two use cases are supported:
47 #
48 # 1) Add O= to the make command line
49 # 'make O=/tmp/build all'
50 #
51 # 2) Set environement variable BUILD_DIR to point to the desired location
52 # 'export BUILD_DIR=/tmp/build'
53 # 'make'
54 #
55 # Command line 'O=' setting overrides BUILD_DIR environent variable.
56 #
57 # When none of the above methods is used the local build is performed and
58 # the object files are placed in the source directory.
59 #
60
61 ifdef O
62 ifeq ("$(origin O)", "command line")
63 BUILD_DIR := $(O)
64 endif
65 endif
66
67 ifneq ($(BUILD_DIR),)
68 saved-output := $(BUILD_DIR)
69
70 # Attempt to create a output directory.
71 $(shell [ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR})
72
73 # Verify if it was successful.
74 BUILD_DIR := $(shell cd $(BUILD_DIR) && /bin/pwd)
75 $(if $(BUILD_DIR),,$(error output directory "$(saved-output)" does not exist))
76 endif # ifneq ($(BUILD_DIR),)
77
78 OBJTREE         := $(if $(BUILD_DIR),$(BUILD_DIR),$(CURDIR))
79 SRCTREE         := $(CURDIR)
80 TOPDIR          := $(SRCTREE)
81 LNDIR           := $(OBJTREE)
82 export TOPDIR SRCTREE OBJTREE
83
84 MKCONFIG        := $(SRCTREE)/mkconfig
85 export MKCONFIG
86
87 ifneq ($(OBJTREE),$(SRCTREE))
88 REMOTE_BUILD    := 1
89 export REMOTE_BUILD
90 endif
91
92 # $(obj) and (src) are defined in config.mk but here in main Makefile
93 # we also need them before config.mk is included which is the case for
94 # some targets like unconfig, clean, clobber, distclean, etc.
95 ifneq ($(OBJTREE),$(SRCTREE))
96 obj := $(OBJTREE)/
97 src := $(SRCTREE)/
98 else
99 obj :=
100 src :=
101 endif
102 export obj src
103
104 # Make sure CDPATH settings don't interfere
105 unexport CDPATH
106
107 #########################################################################
108
109 ifeq ($(obj)include/config.mk,$(wildcard $(obj)include/config.mk))
110 # load ARCH, BOARD, and CPU configuration
111 include $(obj)include/config.mk
112 export  ARCH CPU BOARD VENDOR
113 # load other configuration
114 include $(TOPDIR)/config.mk
115
116 ifndef CROSS_COMPILE
117 CROSS_COMPILE = arm-none-linux-gnueabi-
118 #CROSS_COMPILE = arm-linux-
119 export  CROSS_COMPILE
120 endif
121
122 #########################################################################
123 # X-LOAD objects....order is important (i.e. start must be first)
124
125 OBJS  = cpu/$(CPU)/start.o
126  
127 OBJS := $(addprefix $(obj),$(OBJS))
128
129 LIBS += board/$(BOARDDIR)/lib$(BOARD).a
130 LIBS += cpu/$(CPU)/lib$(CPU).a
131 LIBS += lib/lib$(ARCH).a
132 LIBS += fs/fat/libfat.a
133 LIBS += disk/libdisk.a
134 LIBS += drivers/libdrivers.a
135 LIBS += common/libcommon.a
136
137 LIBS := $(addprefix $(obj),$(sort $(LIBS)))
138 .PHONY : $(LIBS)
139
140 # Add GCC lib
141 PLATFORM_LIBS += -L $(shell dirname `$(CC) $(CFLAGS) -print-libgcc-file-name`) -lgcc
142
143 SUBDIRS =  
144
145 __OBJS := $(subst $(obj),,$(OBJS))
146 __LIBS := $(subst $(obj),,$(LIBS))
147
148 #########################################################################
149 #########################################################################
150
151 ALL = $(obj)x-load.bin $(obj)System.map
152
153 all:            $(ALL)
154
155 ift:    $(ALL) $(obj)x-load.bin.ift
156
157 $(obj)x-load.bin.ift: $(obj)signGP $(obj)System.map $(obj)x-load.bin
158         $(obj)./signGP $(obj)x-load.bin $(TEXT_BASE)
159         cp $(obj)x-load.bin.ift $(obj)MLO
160  
161 $(obj)x-load.bin:       $(obj)x-load
162                 $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
163  
164 $(obj)x-load:   $(OBJS) $(LIBS) $(LDSCRIPT)
165                 UNDEF_SYM=`$(OBJDUMP) -x $(LIBS) |sed  -n -e 's/.*\(__u_boot_cmd_.*\)/-u\1/p'|sort|uniq`;\
166                 cd $(LNDIR) && $(LD) $(LDFLAGS) $$UNDEF_SYM $(__OBJS) \
167                         --start-group $(__LIBS) --end-group $(PLATFORM_LIBS) \
168                         -Map x-load.map -o x-load
169
170 $(OBJS):
171                 $(MAKE) -C cpu/$(CPU) $(if $(REMOTE_BUILD),$@,$(notdir $@))
172
173 $(LIBS):
174                 $(MAKE) -C $(dir $(subst $(obj),,$@))
175   
176 $(obj)System.map:       $(obj)x-load
177                 @$(NM) $< | \
178                 grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \
179                 sort > $(obj)System.map
180
181 oneboot:        $(obj)x-load.bin
182                 scripts/mkoneboot.sh
183
184 $(obj)signGP:   scripts/signGP.c
185                 gcc -Wall -g -O3 -o $(obj)signGP  $<
186
187 #########################################################################
188 else
189 all $(obj)x-load $(obj)x-load.bin oneboot depend dep $(obj)System.map:
190         @echo "System not configured - see README" >&2
191         @ exit 1
192 endif
193
194 #########################################################################
195
196 unconfig:
197         rm -f $(obj)include/config.h $(obj)include/config.mk
198
199 #========================================================================
200 # ARM
201 #========================================================================
202 #########################################################################
203 ## OMAP2 (ARM1136) Systems
204 #########################################################################
205
206 omap2420h4_config :    unconfig
207         @$(MKCONFIG) $(@:_config=) arm arm1136 omap2420h4
208
209 omap2430sdp_config :    unconfig
210         @$(MKCONFIG) $(@:_config=) arm arm1136 omap2430sdp
211
212 #########################################################################
213 ## OMAP3 (ARM-CortexA8) Systems
214 #########################################################################
215 omap3430sdp_config :    unconfig
216         @$(MKCONFIG) $(@:_config=) arm omap3 omap3430sdp
217
218 omap3430labrador_config :    unconfig
219         @$(MKCONFIG) $(@:_config=) arm omap3 omap3430labrador
220
221 omap3evm_config :       unconfig
222         @$(MKCONFIG) $(@:_config=) arm omap3 omap3evm
223
224 overo_config :  unconfig
225         @$(MKCONFIG) $(@:_config=) arm omap3 overo
226
227 omap3530beagle_config :    unconfig
228         @$(MKCONFIG) $(@:_config=) arm omap3 omap3530beagle
229
230 igep0020_config :    unconfig
231         @$(MKCONFIG) $(@:_config=) arm omap3 igep0020
232         
233 #########################################################################
234 ## OMAP4 (ARM-CortexA9) Systems
235 #########################################################################
236 omap4430panda_config :    unconfig
237         @./mkconfig $(@:_config=) arm omap4 omap4430panda
238
239 #########################################################################
240
241 clean:
242         find $(OBJTREE) -type f \
243                 \( -name 'core' -o -name '*.bak' -o -name '*~' \
244                 -o -name '*.o'  -o -name '*.a'  \) -print \
245                 | xargs rm -f
246  
247 clobber:        clean
248         find $(OBJTREE) -type f \
249                 \( -name .depend -o -name '*.srec' -o -name '*.bin' \) \
250                 -print \
251                 | xargs rm -f
252         rm -f $(OBJS) $(obj)*.bak $(obj)tags $(obj)TAGS
253         rm -fr $(obj)*.*~
254         rm -f $(obj)x-load $(obj)x-load.map $(ALL) $(obj)x-load.bin.ift $(obj)signGP $(obj)MLO
255         rm -f $(obj)include/asm/proc $(obj)include/asm/arch
256
257 ifeq ($(OBJTREE),$(SRCTREE))
258 mrproper \
259 distclean:      clobber unconfig
260 else
261 mrproper \
262 distclean:      clobber unconfig
263         rm -rf $(obj)*
264 endif
265
266 backup:
267         F=`basename $(TOPDIR)` ; cd .. ; \
268         gtar --force-local -zcvf `date "+$$F-%Y-%m-%d-%T.tar.gz"` $$F
269
270 #########################################################################