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