Partly undo 54e00c1: put include back to root.make and use SECONDEXPANSION.
[maemo-rb.git] / tools / root.make
blob032daf5a1c6f762d65977eeab9fcb608d9e4e100
1 # __________ __ ___.
2 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
3 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6 # \/ \/ \/ \/ \/
7 # $Id$
10 include $(TOOLSDIR)/functions.make
12 DEFINES = -DROCKBOX -DMEMORYSIZE=$(MEMORYSIZE) $(TARGET) \
13 -DTARGET_ID=$(TARGET_ID) -DTARGET_NAME=\"$(MODELNAME)\" $(BUILDDATE) \
14 $(EXTRA_DEFINES) # <-- -DSIMULATOR or not
15 INCLUDES = -I$(BUILDDIR) -I$(BUILDDIR)/lang $(TARGET_INC)
17 CFLAGS = $(INCLUDES) $(DEFINES) $(GCCOPTS)
18 PPCFLAGS = $(filter-out -g -Dmain=SDL_main,$(CFLAGS)) # cygwin sdl-config fix
19 ASMFLAGS = -D__ASSEMBLER__ # work around gcc 3.4.x bug with -std=gnu99, only meant for .S files
21 TOOLS = $(TOOLSDIR)/rdf2binary $(TOOLSDIR)/convbdf \
22 $(TOOLSDIR)/codepages $(TOOLSDIR)/scramble $(TOOLSDIR)/bmp2rb \
23 $(TOOLSDIR)/uclpack $(TOOLSDIR)/mkboot $(TOOLSDIR)/iaudio_bl_flash.c \
24 $(TOOLSDIR)/iaudio_bl_flash.h
27 ifeq (,$(PREFIX))
28 ifdef APP_TYPE
29 # for sims, set simdisk/ as default
30 ifeq ($(APP_TYPE),sdl-sim)
31 RBPREFIX = simdisk
32 else ifeq ($(APP_TYPE),sdl-app)
33 RBPREFIX = /usr/local
34 endif
36 INSTALL = --install="$(RBPREFIX)"
37 else
38 # /dev/null as magic to tell it wasn't set, error out later in buildzip.pl
39 INSTALL = --install=/dev/null
40 endif
41 else
42 RBPREFIX = $(PREFIX)
43 INSTALL = --install="$(RBPREFIX)"
44 endif
46 RBINFO = $(BUILDDIR)/rockbox-info.txt
48 # list suffixes to be understood by $*
49 .SUFFIXES: .rock .codec .map .elf .c .S .o .bmp .a
51 .PHONY: all clean tags zip tools manual bin build info langs
53 ifeq (,$(filter clean veryclean reconf tags voice voicetools manual manual-pdf manual-html manual-zhtml manual-txt manual-ztxt manual-zip help fontzip ,$(MAKECMDGOALS)))
54 # none of the above
55 DEPFILE = $(BUILDDIR)/make.dep
57 endif
59 all: $(DEPFILE) build
61 # Subdir makefiles. their primary purpose is to populate SRC, OTHER_SRC,
62 # ASMDEFS_SRC, CORE_LIBS and EXTRA_LIBS. But they also define special
63 # dependencies and compile rules
64 include $(TOOLSDIR)/tools.make
66 ifeq (,$(findstring checkwps,$(APPSDIR)))
67 ifeq (,$(findstring database,$(APPSDIR)))
68 include $(FIRMDIR)/firmware.make
69 include $(ROOTDIR)/apps/bitmaps/bitmaps.make
70 ifeq (,$(findstring bootloader,$(APPSDIR)))
71 include $(ROOTDIR)/lib/skin_parser/skin_parser.make
72 endif
73 endif
74 endif
76 #included before codecs.make and plugins.make so they see them)
77 ifndef APP_TYPE
78 include $(ROOTDIR)/lib/libsetjmp/libsetjmp.make
79 ifeq (arm,$(ARCH))
80 include $(ROOTDIR)/lib/arm_support/arm_support.make
81 endif
82 endif
84 ifeq (arm,$(ARCH))
85 include $(ROOTDIR)/lib/unwarminder/unwarminder.make
86 endif
88 ifneq (,$(findstring bootloader,$(APPSDIR)))
89 include $(APPSDIR)/bootloader.make
90 else ifneq (,$(findstring bootbox,$(APPSDIR)))
91 BOOTBOXLDOPTS = -Wl,--gc-sections
92 include $(APPSDIR)/bootbox.make
93 else ifneq (,$(findstring checkwps,$(APP_TYPE)))
94 include $(APPSDIR)/checkwps.make
95 include $(ROOTDIR)/lib/skin_parser/skin_parser.make
96 else ifneq (,$(findstring database,$(APP_TYPE)))
97 include $(APPSDIR)/database.make
98 else ifneq (,$(findstring warble,$(APP_TYPE)))
99 include $(ROOTDIR)/lib/rbcodec/test/warble.make
100 else
101 include $(APPSDIR)/apps.make
102 include $(ROOTDIR)/lib/rbcodec/rbcodec.make
103 include $(APPSDIR)/lang/lang.make
105 ifdef SOFTWARECODECS
106 include $(APPSDIR)/codecs/codecs.make
107 endif
109 ifdef ENABLEDPLUGINS
110 include $(APPSDIR)/plugins/bitmaps/pluginbitmaps.make
111 include $(APPSDIR)/plugins/plugins.make
112 endif
114 ifneq (,$(findstring sdl,$(APP_TYPE)))
115 include $(ROOTDIR)/uisimulator/uisimulator.make
116 endif
118 ifneq (,$(findstring ypr0,$(APP_TYPE)))
119 include $(ROOTDIR)/firmware/target/hosted/ypr0/ypr0.make
120 endif
122 ifneq (,$(findstring android, $(APP_TYPE)))
123 include $(ROOTDIR)/android/android.make
124 endif
126 ifneq (,$(findstring pandora, $(MODELNAME)))
127 include $(ROOTDIR)/packaging/pandora/pandora.make
128 endif
130 endif # bootloader
132 OBJ := $(SRC:.c=.o)
133 OBJ := $(OBJ:.S=.o)
134 OBJ += $(BMP:.bmp=.o)
135 OBJ := $(subst $(ROOTDIR),$(BUILDDIR),$(OBJ))
137 build: $(TOOLS) $(BUILDDIR)/$(BINARY) $(CODECS) $(ROCKS) $(ARCHOSROM) $(RBINFO)
139 $(RBINFO): $(BUILDDIR)/$(BINARY)
140 $(SILENT)echo Creating $(@F)
141 $(SILENT)$(TOOLSDIR)/mkinfo.pl $@
143 $(DEPFILE) dep:
144 $(call PRINTS,Generating dependencies)
145 $(call mkdepfile,$(DEPFILE)_,$(SRC))
146 $(call mkdepfile,$(DEPFILE)_,$(OTHER_SRC:%.lua=))
147 $(call mkdepfile,$(DEPFILE)_,$(ASMDEFS_SRC))
148 $(call bmpdepfile,$(DEPFILE)_,$(BMP) $(PBMP))
149 @mv $(DEPFILE)_ $(DEPFILE)
151 bin: $(DEPFILE) $(TOOLS) $(BUILDDIR)/$(BINARY) $(RBINFO)
152 rocks: $(DEPFILE) $(TOOLS) $(ROCKS)
153 codecs: $(DEPFILE) $(TOOLS) $(CODECS)
154 tools: $(TOOLS)
156 -include $(DEPFILE)
158 veryclean: clean
159 $(SILENT)rm -rf $(TOOLS)
161 clean::
162 $(SILENT)echo Cleaning build directory
163 $(SILENT)rm -rf rockbox.zip rockbox.7z rockbox.tar rockbox.tar.gz \
164 rockbox.tar.bz2 TAGS apps firmware tools comsim sim lang lib \
165 manual *.pdf *.a credits.raw rockbox.ipod bitmaps \
166 pluginbitmaps UI256.bmp rockbox-full.zip html txt \
167 rockbox-manual*.zip sysfont.h rockbox-info.txt voicefontids \
168 *.wav *.mp3 *.voice $(CLEANOBJS) \
169 $(LINKRAM) $(LINKROM) rockbox.elf rockbox.map rockbox.bin \
170 make.dep rombox.elf rombox.map rombox.bin rombox.ucl romstart.txt \
171 $(BINARY) $(FLASHFILE) uisimulator bootloader flash $(BOOTLINK) \
172 rockbox.apk
174 #### linking the binaries: ####
176 .SECONDEXPANSION:
178 ifeq (,$(findstring bootloader,$(APPSDIR)))
179 # not bootloader
181 OBJ += $(LANG_O)
183 ifndef APP_TYPE
185 ## target build
186 CONFIGFILE := $(FIRMDIR)/export/config/$(MODELNAME).h
187 RAMLDS := $(FIRMDIR)/target/$(CPU)/$(MANUFACTURER)/app.lds
188 LINKRAM := $(BUILDDIR)/ram.link
189 ROMLDS := $(FIRMDIR)/rom.lds
190 LINKROM := $(BUILDDIR)/rom.link
192 $(LINKRAM): $(RAMLDS) $(CONFIGFILE)
193 $(call PRINTS,PP $(@F))
194 $(call preprocess2file,$<,$@,-DLOADADDRESS=$(LOADADDRESS))
196 $(LINKROM): $(ROMLDS)
197 $(call PRINTS,PP $(@F))
198 $(call preprocess2file,$<,$@,-DLOADADDRESS=$(LOADADDRESS))
200 $(BUILDDIR)/rockbox.elf : $$(OBJ) $(FIRMLIB) $(VOICESPEEXLIB) $(CORE_LIBS) $$(LINKRAM)
201 $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -Os -nostdlib -o $@ $(OBJ) \
202 -L$(BUILDDIR)/firmware -lfirmware \
203 -L$(BUILDDIR)/apps/codecs $(call a2lnk, $(VOICESPEEXLIB)) \
204 -L$(BUILDDIR)/lib $(call a2lnk, $(CORE_LIBS)) \
205 -lgcc $(BOOTBOXLDOPTS) $(GLOBAL_LDOPTS) \
206 -T$(LINKRAM) -Wl,-Map,$(BUILDDIR)/rockbox.map
208 $(BUILDDIR)/rombox.elf : $$(OBJ) $(FIRMLIB) $(VOICESPEEXLIB) $(CORE_LIBS) $$(LINKROM)
209 $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -Os -nostdlib -o $@ $(OBJ) \
210 -L$(BUILDDIR)/firmware -lfirmware \
211 -L$(BUILDDIR)/apps/codecs $(call a2lnk, $(VOICESPEEXLIB)) \
212 -L$(BUILDDIR)/lib $(call a2lnk, $(CORE_LIBS)) \
213 -lgcc $(BOOTBOXLDOPTS) $(GLOBAL_LDOPTS) \
214 -T$(LINKROM) -Wl,-Map,$(BUILDDIR)/rombox.map
216 $(BUILDDIR)/rockbox.bin : $(BUILDDIR)/rockbox.elf
217 $(call PRINTS,OC $(@F))$(OC) $(if $(filter yes, $(USE_ELF)), -S -x, -O binary) $< $@
219 $(BUILDDIR)/rombox.bin : $(BUILDDIR)/rombox.elf
220 $(call PRINTS,OC $(@F))$(OC) -O binary $< $@
223 # If there's a flashfile defined for this target (rockbox.ucl for Archos
224 # models) Then check if the mkfirmware script fails, as then it is (likely)
225 # because the image is too big and we need to create a compressed image
226 # instead.
228 $(BUILDDIR)/$(BINARY) : $(BUILDDIR)/rockbox.bin $(FLASHFILE)
229 $(call PRINTS,SCRAMBLE $(notdir $@))($(MKFIRMWARE) $< $@; \
230 stat=$$?; \
231 if test -n "$(FLASHFILE)"; then \
232 if test "$$stat" -ne 0; then \
233 echo "Image too big, making a compressed version!"; \
234 $(MAKE) -C $(FIRMDIR)/decompressor OBJDIR=$(BUILDDIR)/firmware/decompressor; \
235 $(MKFIRMWARE) $(BUILDDIR)/firmware/decompressor/compressed.bin $@; \
236 fi \
237 fi )
239 # archos
240 $(BUILDDIR)/rockbox.ucl: $(BUILDDIR)/rockbox.bin
241 $(call PRINTS,UCLPACK $(@F))$(TOOLSDIR)/uclpack --best --2e -b1048576 $< $@ >/dev/null
243 MAXINFILE = $(BUILDDIR)/temp.txt
244 MAXOUTFILE = $(BUILDDIR)/romstart.txt
246 $(BUILDDIR)/rombox.ucl: $(BUILDDIR)/rombox.bin $(MAXOUTFILE)
247 $(call PRINTS,UCLPACK $(@F))$(TOOLSDIR)/uclpack --none $< $@ >/dev/null; \
248 perl $(TOOLSDIR)/romsizetest.pl `cat $(MAXOUTFILE)` $<; \
249 if test $$? -ne 0; then \
250 echo "removing UCL file again, making it a fake one"; \
251 echo "fake" > $@; \
254 $(MAXOUTFILE):
255 $(call PRINTS,Creating $(@F))
256 $(SILENT)echo '#include "config.h"' > $(MAXINFILE)
257 $(SILENT)echo "ROM_START" >> $(MAXINFILE)
258 $(call preprocess2file,$(MAXINFILE),$(MAXOUTFILE))
259 $(SILENT)rm $(MAXINFILE)
261 # iriver
262 $(BUILDDIR)/rombox.iriver: $(BUILDDIR)/rombox.bin
263 $(call PRINTS,Build ROM file)$(MKFIRMWARE) $< $@
265 endif # !APP_TYPE
266 endif # !bootloader
269 voicetools:
270 $(SILENT)$(MAKE) -C $(TOOLSDIR) CC=$(HOSTCC) AR=$(HOSTAR) rbspeexenc voicefont wavtrim
272 tags:
273 $(SILENT)rm -f TAGS
274 $(SILENT)etags -o $(BUILDDIR)/TAGS $(filter-out %.o,$(SRC) $(OTHER_SRC))
276 fontzip:
277 $(SILENT)$(TOOLSDIR)/buildzip.pl $(VERBOSEOPT) --app=$(APPLICATION) -m \"$(MODELNAME)\" -r "$(ROOTDIR)" --rbdir="$(RBDIR)" -f 1 -o rockbox-fonts.zip $(TARGET) $(BINARY)
279 zip: $(BUILDDIR)/rockbox.zip
281 ifdef NODEPS
282 $(BUILDDIR)/rockbox.zip:
283 else
284 $(BUILDDIR)/rockbox.zip: build
285 endif
286 $(SILENT)$(TOOLSDIR)/buildzip.pl $(VERBOSEOPT) --app=$(APPLICATION) -m \"$(MODELNAME)\" -i \"$(TARGET_ID)\" -r "$(ROOTDIR)" --rbdir="$(RBDIR)" $(TARGET) $(BINARY)
288 mapzip:
289 $(SILENT)find . -name "*.map" | xargs zip rockbox-maps.zip
291 elfzip:
292 $(SILENT)find . -name "*.elf" | xargs zip rockbox-elfs.zip
294 fullzip:
295 $(SILENT)$(TOOLSDIR)/buildzip.pl $(VERBOSEOPT) --app=$(APPLICATION) -m \"$(MODELNAME)\" -i \"$(TARGET_ID)\" -r "$(ROOTDIR)" --rbdir="$(RBDIR)" -f 2 -o rockbox-full.zip $(TARGET) $(BINARY)
297 7zip:
298 $(SILENT)$(TOOLSDIR)/buildzip.pl $(VERBOSEOPT) --app=$(APPLICATION) -m \"$(MODELNAME)\" -i \"$(TARGET_ID)\" -o "rockbox.7z" -z "7za a -mx=9" -r "$(ROOTDIR)" --rbdir="$(RBDIR)" $(TARGET) $(BINARY)
300 tar:
301 $(SILENT)rm -f rockbox.tar
302 $(SILENT)$(TOOLSDIR)/buildzip.pl $(VERBOSEOPT) --app=$(APPLICATION) -m \"$(MODELNAME)\" -i \"$(TARGET_ID)\" -o "rockbox.tar" -z "tar -cf" -r "$(ROOTDIR)" --rbdir="$(RBDIR)" $(TARGET) $(BINARY)
304 bzip2: tar
305 $(SILENT)bzip2 -f9 rockbox.tar
307 gzip: tar
308 $(SILENT)gzip -f9 rockbox.tar
310 manual manual-pdf:
311 $(SILENT)$(MAKE) -C $(MANUALDIR) OBJDIR=$(BUILDDIR)/manual manual-pdf
312 manual-html:
313 $(SILENT)$(MAKE) -C $(MANUALDIR) OBJDIR=$(BUILDDIR)/manual manual-html
314 manual-zhtml: manual-zip
315 manual-txt:
316 $(SILENT)$(MAKE) -C $(MANUALDIR) OBJDIR=$(BUILDDIR)/manual manual-txt
317 manual-ztxt:
318 $(SILENT)$(MAKE) -C $(MANUALDIR) OBJDIR=$(BUILDDIR)/manual manual-txt-zip
319 manual-zip:
320 $(SILENT)$(MAKE) -C $(MANUALDIR) OBJDIR=$(BUILDDIR)/manual manual-zip
322 ifdef TTS_ENGINE
324 voice: voicetools $(BUILDDIR)/apps/features
325 $(SILENT)for f in `cat $(BUILDDIR)/apps/features`; do feat="$$feat:$$f" ; done ; \
326 for lang in `echo $(VOICELANGUAGE) |sed "s/,/ /g"`; do $(TOOLSDIR)/voice.pl -V -l=$$lang -t=$(MODELNAME)$$feat -i=$(TARGET_ID) -e="$(ENCODER)" -E="$(ENC_OPTS)" -s=$(TTS_ENGINE) -S="$(TTS_OPTS)"; done \
328 endif
330 ifeq (,$(findstring android, $(APP_TYPE)))
331 bininstall: $(BUILDDIR)/$(BINARY)
332 @echo "Installing your rockbox binary in your '$(RBPREFIX)' dir"
333 $(SILENT)cp $(BINARY) "$(RBPREFIX)/.rockbox/"
335 install:
336 @echo "Installing your build in your '$(RBPREFIX)' dir"
337 $(SILENT)$(TOOLSDIR)/buildzip.pl $(VERBOSEOPT) --app=$(APPLICATION) -m "$(MODELNAME)" -i "$(TARGET_ID)" $(INSTALL) -z "zip -r0" -r "$(ROOTDIR)" --rbdir="$(RBDIR)" -f 0 $(TARGET) $(BINARY)
339 fullinstall:
340 @echo "Installing a full setup in your '$(RBPREFIX)' dir"
341 $(SILENT)$(TOOLSDIR)/buildzip.pl $(VERBOSEOPT) --app=$(APPLICATION) -m "$(MODELNAME)" -i "$(TARGET_ID)" $(INSTALL) -z "zip -r0" -r "$(ROOTDIR)" --rbdir="$(RBDIR)" -f 2 $(TARGET) $(BINARY)
343 symlinkinstall:
344 @echo "Installing a full setup with links in your '$(RBPREFIX)' dir"
345 $(SILENT)$(TOOLSDIR)/buildzip.pl $(VERBOSEOPT) --app=$(APPLICATION) -m "$(MODELNAME)" -i "$(TARGET_ID)" $(INSTALL) -z "zip -r0" -r "$(ROOTDIR)" --rbdir="$(RBDIR)" -f 2 $(TARGET) $(BINARY) -l
346 endif
348 help:
349 @echo "A few helpful make targets"
350 @echo ""
351 @echo "all - builds a full Rockbox (default), including tools"
352 @echo "bin - builds only the Rockbox.<target name> file"
353 @echo "rocks - builds only plugins"
354 @echo "codecs - builds only codecs"
355 @echo "dep - regenerates make dependency database"
356 @echo "clean - cleans a build directory (not tools)"
357 @echo "veryclean - cleans the build and tools directories"
358 @echo "manual - builds a manual (pdf)"
359 @echo "manual-html - HTML manual"
360 @echo "manual-zip - HTML manual (zipped)"
361 @echo "manual-txt - txt manual"
362 @echo "fullzip - creates a rockbox.zip of your build with fonts"
363 @echo "zip - creates a rockbox.zip of your build (no fonts)"
364 @echo "gzip - creates a rockbox.tar.gz of your build (no fonts)"
365 @echo "bzip2 - creates a rockbox.tar.bz2 of your build (no fonts)"
366 @echo "7zip - creates a rockbox.7z of your build (no fonts)"
367 @echo "fontzip - creates rockbox-fonts.zip"
368 @echo "mapzip - creates rockbox-maps.zip with all .map files"
369 @echo "elfzip - creates rockbox-elfs.zip with all .elf files"
370 @echo "pnd - creates rockbox.pnd archive (Pandora builds only)"
371 @echo "tools - builds the tools only"
372 @echo "voice - creates the voice clips (voice builds only)"
373 @echo "voicetools - builds the voice tools only"
374 @echo "install - installs your build (at PREFIX, defaults to simdisk/ for simulators (no fonts))"
375 @echo "fullinstall - installs your build (like install, but with fonts)"
376 @echo "symlinkinstall - like fullinstall, but with links instead of copying files. (Good for developing on simulator)"
377 @echo "reconf - rerun configure with the same selection"
379 ### general compile rules:
381 # when source and object are in different locations (normal):
382 $(BUILDDIR)/%.o: $(ROOTDIR)/%.c
383 $(SILENT)mkdir -p $(dir $@)
384 $(call PRINTS,CC $(subst $(ROOTDIR)/,,$<))$(CC) $(CFLAGS) -c $< -o $@
386 $(BUILDDIR)/%.o: $(ROOTDIR)/%.S
387 $(SILENT)mkdir -p $(dir $@)
388 $(call PRINTS,CC $(subst $(ROOTDIR)/,,$<))$(CC) $(CFLAGS) $(ASMFLAGS) -c $< -o $@
390 # generated definitions for use in .S files
391 $(BUILDDIR)/%_asmdefs.h: $(ROOTDIR)/%_asmdefs.c
392 $(call PRINTS,ASMDEFS $(@F))
393 $(SILENT)mkdir -p $(dir $@)
394 $(call asmdefs2file,$<,$@)
396 # when source and object are both in BUILDDIR (generated code):
397 %.o: %.c
398 $(SILENT)mkdir -p $(dir $@)
399 $(call PRINTS,CC $(subst $(ROOTDIR)/,,$<))$(CC) $(CFLAGS) -c $< -o $@
401 %.o: %.S
402 $(SILENT)mkdir -p $(dir $@)
403 $(call PRINTS,CC $(subst $(ROOTDIR)/,,$<))$(CC) $(CFLAGS) $(ASMFLAGS) -c $< -o $@
405 Makefile: $(TOOLSDIR)/configure
406 ifneq (reconf,$(MAKECMDGOALS))
407 $(SILENT)echo "*** tools/configure is newer than Makefile. You should run 'make reconf'."
408 endif
410 reconf:
411 $(SILENT$)$(TOOLSDIR)/configure $(CONFIGURE_OPTIONS)