b7c21114a1cf23aaef2c851664c95a29e50367b3
[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.ift $(obj)System.map
152
153 all ift:        $(ALL)
154
155 $(obj)x-load.bin.ift: $(obj)signGP $(obj)System.map $(obj)x-load.bin
156         $(obj)./signGP $(obj)x-load.bin $(TEXT_BASE) $(CONFIG_HEADER)
157         cp $(obj)x-load.bin.ift $(obj)MLO
158  
159 $(obj)x-load.bin:       $(obj)x-load
160                 $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
161  
162 $(obj)x-load:   $(OBJS) $(LIBS) $(LDSCRIPT)
163                 UNDEF_SYM=`$(OBJDUMP) -x $(LIBS) |sed  -n -e 's/.*\(__u_boot_cmd_.*\)/-u\1/p'|sort|uniq`;\
164                 cd $(LNDIR) && $(LD) $(LDFLAGS) $$UNDEF_SYM $(__OBJS) \
165                         --start-group $(__LIBS) --end-group $(PLATFORM_LIBS) \
166                         -Map x-load.map -o x-load
167
168 $(OBJS):
169                 $(MAKE) -C cpu/$(CPU) $(if $(REMOTE_BUILD),$@,$(notdir $@))
170
171 $(LIBS):
172                 $(MAKE) -C $(dir $(subst $(obj),,$@))
173   
174 $(obj)System.map:       $(obj)x-load
175                 @$(NM) $< | \
176                 grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \
177                 sort > $(obj)System.map
178
179 oneboot:        $(obj)x-load.bin
180                 scripts/mkoneboot.sh
181
182 $(obj)signGP:   scripts/signGP.c
183                 $(HOSTCC) $(HOSTCFLAGS) -o $(obj)signGP  $<
184
185 #########################################################################
186 else
187 all $(obj)x-load $(obj)x-load.bin oneboot depend dep $(obj)System.map:
188         @echo "System not configured - see README" >&2
189         @ exit 1
190 endif
191
192 #########################################################################
193
194 unconfig:
195         rm -f $(obj)include/config.h $(obj)include/config.mk
196
197 #========================================================================
198 # ARM
199 #========================================================================
200 #########################################################################
201 ## OMAP2 (ARM1136) Systems
202 #########################################################################
203
204 #########################################################################
205 ## OMAP3 (ARM-CortexA8) Systems
206 #########################################################################
207 omap3430sdp_config :    unconfig
208         @$(MKCONFIG) $(@:_config=) arm omap3 omap3430sdp
209
210 omap3430labrador_config :    unconfig
211         @$(MKCONFIG) $(@:_config=) arm omap3 omap3430labrador
212
213 omap3evm_config :       unconfig
214         @$(MKCONFIG) $(@:_config=) arm omap3 omap3evm
215
216 overo_config :  unconfig
217         @$(MKCONFIG) $(@:_config=) arm omap3 overo
218
219 omap3530beagle_config :    unconfig
220         @$(MKCONFIG) $(@:_config=) arm omap3 omap3530beagle
221
222 igep00x0_config :    unconfig
223         @$(MKCONFIG) $(@:_config=) arm omap3 igep00x0
224
225 tam3517_config :        unconfig
226         @$(MKCONFIG) $(@:_config=) arm omap3 tam3517
227
228 tao3530_config :        unconfig
229         @$(MKCONFIG) $(@:_config=) arm omap3 tao3530
230         
231 #########################################################################
232 ## OMAP4 (ARM-CortexA9) Systems
233 #########################################################################
234 omap4430panda_config :    unconfig
235         @$(MKCONFIG) $(@:_config=) arm omap4 omap4430panda 1
236
237 #########################################################################
238
239 clean:
240         find $(OBJTREE) -type f \
241                 \( -name 'core' -o -name '*.bak' -o -name '*~' \
242                 -o -name '*.o'  -o -name '*.a'  \) -print \
243                 | xargs rm -f
244  
245 clobber:        clean
246         find $(OBJTREE) -type f \
247                 \( -name .depend -o -name '*.srec' -o -name '*.bin' \) \
248                 -print \
249                 | xargs rm -f
250         rm -f $(OBJS) $(obj)*.bak $(obj)tags $(obj)TAGS
251         rm -fr $(obj)*.*~
252         rm -f $(obj)x-load $(obj)x-load.map $(ALL) $(obj)x-load.bin.ift $(obj)signGP $(obj)MLO
253         rm -f $(obj)include/asm/proc $(obj)include/asm/arch
254
255 ifeq ($(OBJTREE),$(SRCTREE))
256 mrproper \
257 distclean:      clobber unconfig
258 else
259 mrproper \
260 distclean:      clobber unconfig
261         rm -rf $(obj)*
262 endif
263
264 backup:
265         F=`basename $(TOPDIR)` ; cd .. ; \
266         gtar --force-local -zcvf `date "+$$F-%Y-%m-%d-%T.tar.gz"` $$F
267
268 #########################################################################