ucl: make it possible to specify additional CFLAGS
[maemo-rb.git] / tools / root.make
blobdd827d6d3f4c6bf3e0d91e62c15b22f269d0510f
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 but they also define special dependencies and compile rules
63 include $(TOOLSDIR)/tools.make
65 ifeq (,$(findstring checkwps,$(APPSDIR)))
66 ifeq (,$(findstring database,$(APPSDIR)))
67 include $(FIRMDIR)/firmware.make
68 include $(ROOTDIR)/lib/skin_parser/skin_parser.make
69 include $(ROOTDIR)/apps/bitmaps/bitmaps.make
70 endif
71 endif
73 #included before codecs.make and plugins.make so they see $(LIBSETJMP)
74 ifndef APP_TYPE
75 include $(ROOTDIR)/lib/libsetjmp/libsetjmp.make
76 endif
78 ifneq (,$(findstring bootloader,$(APPSDIR)))
79 include $(APPSDIR)/bootloader.make
80 else ifneq (,$(findstring bootbox,$(APPSDIR)))
81 BOOTBOXLDOPTS = -Wl,--gc-sections
82 include $(APPSDIR)/bootbox.make
83 else ifneq (,$(findstring checkwps,$(APPSDIR)))
84 include $(APPSDIR)/checkwps.make
85 include $(ROOTDIR)/lib/skin_parser/skin_parser.make
86 else ifneq (,$(findstring database,$(APPSDIR)))
87 include $(APPSDIR)/database.make
88 else
89 include $(APPSDIR)/apps.make
90 include $(APPSDIR)/lang/lang.make
92 ifdef SOFTWARECODECS
93 include $(APPSDIR)/codecs/codecs.make
94 endif
96 ifdef ENABLEDPLUGINS
97 include $(APPSDIR)/plugins/bitmaps/pluginbitmaps.make
98 include $(APPSDIR)/plugins/plugins.make
99 endif
101 ifneq (,$(findstring sdl,$(APP_TYPE)))
102 include $(ROOTDIR)/uisimulator/uisimulator.make
103 endif
105 ifneq (,$(findstring ypr0,$(APP_TYPE)))
106 include $(ROOTDIR)/firmware/target/hosted/ypr0/ypr0.make
107 endif
109 ifneq (,$(findstring android, $(APP_TYPE)))
110 include $(ROOTDIR)/android/android.make
111 endif
113 ifneq (,$(findstring pandora, $(MODELNAME)))
114 include $(ROOTDIR)/packaging/pandora/pandora.make
115 endif
117 endif # bootloader
119 OBJ := $(SRC:.c=.o)
120 OBJ := $(OBJ:.S=.o)
121 OBJ += $(BMP:.bmp=.o)
122 OBJ := $(subst $(ROOTDIR),$(BUILDDIR),$(OBJ))
124 build: $(TOOLS) $(BUILDDIR)/$(BINARY) $(CODECS) $(ROCKS) $(ARCHOSROM) $(RBINFO)
126 $(RBINFO): $(BUILDDIR)/$(BINARY)
127 $(SILENT)echo Creating $(@F)
128 $(SILENT)$(TOOLSDIR)/mkinfo.pl $@
130 $(DEPFILE) dep:
131 $(call PRINTS,Generating dependencies)
132 $(call mkdepfile,$(DEPFILE)_,$(SRC))
133 $(call mkdepfile,$(DEPFILE)_,$(OTHER_SRC:%.lua=))
134 $(call mkdepfile,$(DEPFILE)_,$(ASMDEFS_SRC))
135 $(call bmpdepfile,$(DEPFILE)_,$(BMP) $(PBMP))
136 @mv $(DEPFILE)_ $(DEPFILE)
138 bin: $(DEPFILE) $(TOOLS) $(BUILDDIR)/$(BINARY) $(RBINFO)
139 rocks: $(DEPFILE) $(TOOLS) $(ROCKS)
140 codecs: $(DEPFILE) $(TOOLS) $(CODECS)
141 tools: $(TOOLS)
143 -include $(DEPFILE)
145 veryclean: clean
146 $(SILENT)rm -rf $(TOOLS)
148 clean::
149 $(SILENT)echo Cleaning build directory
150 $(SILENT)rm -rf rockbox.zip rockbox.7z rockbox.tar rockbox.tar.gz \
151 rockbox.tar.bz2 TAGS apps firmware tools comsim sim lang lib \
152 manual *.pdf *.a credits.raw rockbox.ipod bitmaps \
153 pluginbitmaps UI256.bmp rockbox-full.zip html txt \
154 rockbox-manual*.zip sysfont.h rockbox-info.txt voicefontids \
155 *.wav *.mp3 *.voice $(CLEANOBJS) \
156 $(LINKRAM) $(LINKROM) rockbox.elf rockbox.map rockbox.bin \
157 make.dep rombox.elf rombox.map rombox.bin rombox.ucl romstart.txt \
158 $(BINARY) $(FLASHFILE) uisimulator bootloader flash $(BOOTLINK) \
159 rockbox.apk
161 #### linking the binaries: ####
163 .SECONDEXPANSION:
165 ifeq (,$(findstring bootloader,$(APPSDIR)))
166 # not bootloader
168 OBJ += $(LANG_O)
170 ifndef APP_TYPE
172 ## target build
173 CONFIGFILE := $(FIRMDIR)/export/config/$(MODELNAME).h
174 RAMLDS := $(FIRMDIR)/target/$(CPU)/$(MANUFACTURER)/app.lds
175 LINKRAM := $(BUILDDIR)/ram.link
176 ROMLDS := $(FIRMDIR)/rom.lds
177 LINKROM := $(BUILDDIR)/rom.link
180 $(LINKRAM): $(RAMLDS) $(CONFIGFILE)
181 $(call PRINTS,PP $(@F))
182 $(call preprocess2file,$<,$@,-DLOADADDRESS=$(LOADADDRESS))
184 $(LINKROM): $(ROMLDS)
185 $(call PRINTS,PP $(@F))
186 $(call preprocess2file,$<,$@,-DLOADADDRESS=$(LOADADDRESS))
188 $(BUILDDIR)/rockbox.elf : $$(OBJ) $$(FIRMLIB) $$(VOICESPEEXLIB) $$(SKINLIB) $$(LINKRAM)
189 $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -Os -nostdlib -o $@ $(OBJ) \
190 -L$(BUILDDIR)/firmware -lfirmware \
191 -L$(BUILDDIR)/lib -lskin_parser \
192 -L$(BUILDDIR)/apps/codecs $(VOICESPEEXLIB:lib%.a=-l%) \
193 -lgcc $(BOOTBOXLDOPTS) $(GLOBAL_LDOPTS) \
194 -T$(LINKRAM) -Wl,-Map,$(BUILDDIR)/rockbox.map
196 $(BUILDDIR)/rombox.elf : $$(OBJ) $$(FIRMLIB) $$(VOICESPEEXLIB) $$(SKINLIB) $$(LINKROM)
197 $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -Os -nostdlib -o $@ $(OBJ) \
198 $(VOICESPEEXLIB) $(FIRMLIB) -lgcc $(GLOBAL_LDOPTS) \
199 -L$(BUILDDIR)/lib -lskin_parser \
200 -L$(BUILDDIR)/firmware -T$(LINKROM) -Wl,-Map,$(BUILDDIR)/rombox.map
202 $(BUILDDIR)/rockbox.bin : $(BUILDDIR)/rockbox.elf
203 $(call PRINTS,OC $(@F))$(OC) $(if $(filter yes, $(USE_ELF)), -S -x, -O binary) $< $@
205 $(BUILDDIR)/rombox.bin : $(BUILDDIR)/rombox.elf
206 $(call PRINTS,OC $(@F))$(OC) -O binary $< $@
209 # If there's a flashfile defined for this target (rockbox.ucl for Archos
210 # models) Then check if the mkfirmware script fails, as then it is (likely)
211 # because the image is too big and we need to create a compressed image
212 # instead.
214 $(BUILDDIR)/$(BINARY) : $(BUILDDIR)/rockbox.bin $(FLASHFILE)
215 $(call PRINTS,SCRAMBLE $(notdir $@))($(MKFIRMWARE) $< $@; \
216 stat=$$?; \
217 if test -n "$(FLASHFILE)"; then \
218 if test "$$stat" -ne 0; then \
219 echo "Image too big, making a compressed version!"; \
220 $(MAKE) -C $(FIRMDIR)/decompressor OBJDIR=$(BUILDDIR)/firmware/decompressor; \
221 $(MKFIRMWARE) $(BUILDDIR)/firmware/decompressor/compressed.bin $@; \
222 fi \
223 fi )
225 # archos
226 $(BUILDDIR)/rockbox.ucl: $(BUILDDIR)/rockbox.bin
227 $(call PRINTS,UCLPACK $(@F))$(TOOLSDIR)/uclpack --best --2e -b1048576 $< $@ >/dev/null
229 MAXINFILE = $(BUILDDIR)/temp.txt
230 MAXOUTFILE = $(BUILDDIR)/romstart.txt
232 $(BUILDDIR)/rombox.ucl: $(BUILDDIR)/rombox.bin $(MAXOUTFILE)
233 $(call PRINTS,UCLPACK $(@F))$(TOOLSDIR)/uclpack --none $< $@ >/dev/null; \
234 perl $(TOOLSDIR)/romsizetest.pl `cat $(MAXOUTFILE)` $<; \
235 if test $$? -ne 0; then \
236 echo "removing UCL file again, making it a fake one"; \
237 echo "fake" > $@; \
240 $(MAXOUTFILE):
241 $(call PRINTS,Creating $(@F))
242 $(SILENT)echo '#include "config.h"' > $(MAXINFILE)
243 $(SILENT)echo "ROM_START" >> $(MAXINFILE)
244 $(call preprocess2file,$(MAXINFILE),$(MAXOUTFILE))
245 $(SILENT)rm $(MAXINFILE)
247 # iriver
248 $(BUILDDIR)/rombox.iriver: $(BUILDDIR)/rombox.bin
249 $(call PRINTS,Build ROM file)$(MKFIRMWARE) $< $@
251 endif # !APP_TYPE
252 endif # !bootloader
255 voicetools:
256 $(SILENT)$(MAKE) -C $(TOOLSDIR) CC=$(HOSTCC) AR=$(HOSTAR) rbspeexenc voicefont wavtrim
258 tags:
259 $(SILENT)rm -f TAGS
260 $(SILENT)etags -o $(BUILDDIR)/TAGS $(filter-out %.o,$(SRC) $(OTHER_SRC))
262 fontzip:
263 $(SILENT)$(TOOLSDIR)/buildzip.pl $(VERBOSEOPT) --app=$(APPLICATION) -m \"$(MODELNAME)\" -r "$(ROOTDIR)" --rbdir="$(RBDIR)" -f 1 -o rockbox-fonts.zip $(TARGET) $(BINARY)
265 zip: $(BUILDDIR)/rockbox.zip
267 ifdef NODEPS
268 $(BUILDDIR)/rockbox.zip:
269 else
270 $(BUILDDIR)/rockbox.zip: build
271 endif
272 $(SILENT)$(TOOLSDIR)/buildzip.pl $(VERBOSEOPT) --app=$(APPLICATION) -m \"$(MODELNAME)\" -i \"$(TARGET_ID)\" -r "$(ROOTDIR)" --rbdir="$(RBDIR)" $(TARGET) $(BINARY)
274 mapzip:
275 $(SILENT)find . -name "*.map" | xargs zip rockbox-maps.zip
277 elfzip:
278 $(SILENT)find . -name "*.elf" | xargs zip rockbox-elfs.zip
280 fullzip:
281 $(SILENT)$(TOOLSDIR)/buildzip.pl $(VERBOSEOPT) --app=$(APPLICATION) -m \"$(MODELNAME)\" -i \"$(TARGET_ID)\" -r "$(ROOTDIR)" --rbdir="$(RBDIR)" -f 2 -o rockbox-full.zip $(TARGET) $(BINARY)
283 7zip:
284 $(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)
286 tar:
287 $(SILENT)rm -f rockbox.tar
288 $(SILENT)$(TOOLSDIR)/buildzip.pl $(VERBOSEOPT) --app=$(APPLICATION) -m \"$(MODELNAME)\" -i \"$(TARGET_ID)\" -o "rockbox.tar" -z "tar -cf" -r "$(ROOTDIR)" --rbdir="$(RBDIR)" $(TARGET) $(BINARY)
290 bzip2: tar
291 $(SILENT)bzip2 -f9 rockbox.tar
293 gzip: tar
294 $(SILENT)gzip -f9 rockbox.tar
296 manual manual-pdf:
297 $(SILENT)$(MAKE) -C $(MANUALDIR) OBJDIR=$(BUILDDIR)/manual manual-pdf
298 manual-html:
299 $(SILENT)$(MAKE) -C $(MANUALDIR) OBJDIR=$(BUILDDIR)/manual manual-html
300 manual-zhtml: manual-zip
301 manual-txt:
302 $(SILENT)$(MAKE) -C $(MANUALDIR) OBJDIR=$(BUILDDIR)/manual manual-txt
303 manual-ztxt:
304 $(SILENT)$(MAKE) -C $(MANUALDIR) OBJDIR=$(BUILDDIR)/manual manual-txt-zip
305 manual-zip:
306 $(SILENT)$(MAKE) -C $(MANUALDIR) OBJDIR=$(BUILDDIR)/manual manual-zip
308 ifdef TTS_ENGINE
310 voice: voicetools $(BUILDDIR)/apps/features
311 $(SILENT)for f in `cat $(BUILDDIR)/apps/features`; do feat="$$feat:$$f" ; done ; \
312 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 \
314 endif
316 ifeq (,$(findstring android, $(APP_TYPE)))
317 bininstall: $(BUILDDIR)/$(BINARY)
318 @echo "Installing your rockbox binary in your '$(RBPREFIX)' dir"
319 $(SILENT)cp $(BINARY) "$(RBPREFIX)/.rockbox/"
321 install:
322 @echo "Installing your build in your '$(RBPREFIX)' dir"
323 $(SILENT)$(TOOLSDIR)/buildzip.pl $(VERBOSEOPT) --app=$(APPLICATION) -m "$(MODELNAME)" -i "$(TARGET_ID)" $(INSTALL) -z "zip -r0" -r "$(ROOTDIR)" --rbdir="$(RBDIR)" -f 0 $(TARGET) $(BINARY)
325 fullinstall:
326 @echo "Installing a full setup in your '$(RBPREFIX)' dir"
327 $(SILENT)$(TOOLSDIR)/buildzip.pl $(VERBOSEOPT) --app=$(APPLICATION) -m "$(MODELNAME)" -i "$(TARGET_ID)" $(INSTALL) -z "zip -r0" -r "$(ROOTDIR)" --rbdir="$(RBDIR)" -f 2 $(TARGET) $(BINARY)
329 symlinkinstall:
330 @echo "Installing a full setup with links in your '$(RBPREFIX)' dir"
331 $(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
332 endif
334 help:
335 @echo "A few helpful make targets"
336 @echo ""
337 @echo "all - builds a full Rockbox (default), including tools"
338 @echo "bin - builds only the Rockbox.<target name> file"
339 @echo "rocks - builds only plugins"
340 @echo "codecs - builds only codecs"
341 @echo "dep - regenerates make dependency database"
342 @echo "clean - cleans a build directory (not tools)"
343 @echo "veryclean - cleans the build and tools directories"
344 @echo "manual - builds a manual (pdf)"
345 @echo "manual-html - HTML manual"
346 @echo "manual-zip - HTML manual (zipped)"
347 @echo "manual-txt - txt manual"
348 @echo "fullzip - creates a rockbox.zip of your build with fonts"
349 @echo "zip - creates a rockbox.zip of your build (no fonts)"
350 @echo "gzip - creates a rockbox.tar.gz of your build (no fonts)"
351 @echo "bzip2 - creates a rockbox.tar.bz2 of your build (no fonts)"
352 @echo "7zip - creates a rockbox.7z of your build (no fonts)"
353 @echo "fontzip - creates rockbox-fonts.zip"
354 @echo "mapzip - creates rockbox-maps.zip with all .map files"
355 @echo "elfzip - creates rockbox-elfs.zip with all .elf files"
356 @echo "pnd - creates rockbox.pnd archive (Pandora builds only)"
357 @echo "tools - builds the tools only"
358 @echo "voice - creates the voice clips (voice builds only)"
359 @echo "voicetools - builds the voice tools only"
360 @echo "install - installs your build (at PREFIX, defaults to simdisk/ for simulators (no fonts))"
361 @echo "fullinstall - installs your build (like install, but with fonts)"
362 @echo "symlinkinstall - like fullinstall, but with links instead of copying files. (Good for developing on simulator)"
363 @echo "reconf - rerun configure with the same selection"
365 ### general compile rules:
367 # when source and object are in different locations (normal):
368 $(BUILDDIR)/%.o: $(ROOTDIR)/%.c
369 $(SILENT)mkdir -p $(dir $@)
370 $(call PRINTS,CC $(subst $(ROOTDIR)/,,$<))$(CC) $(CFLAGS) -c $< -o $@
372 $(BUILDDIR)/%.o: $(ROOTDIR)/%.S
373 $(SILENT)mkdir -p $(dir $@)
374 $(call PRINTS,CC $(subst $(ROOTDIR)/,,$<))$(CC) $(CFLAGS) $(ASMFLAGS) -c $< -o $@
376 # generated definitions for use in .S files
377 $(BUILDDIR)/%_asmdefs.h: $(ROOTDIR)/%_asmdefs.c
378 $(call PRINTS,ASMDEFS $(@F))
379 $(SILENT)mkdir -p $(dir $@)
380 $(call asmdefs2file,$<,$@)
382 # when source and object are both in BUILDDIR (generated code):
383 %.o: %.c
384 $(SILENT)mkdir -p $(dir $@)
385 $(call PRINTS,CC $(subst $(ROOTDIR)/,,$<))$(CC) $(CFLAGS) -c $< -o $@
387 %.o: %.S
388 $(SILENT)mkdir -p $(dir $@)
389 $(call PRINTS,CC $(subst $(ROOTDIR)/,,$<))$(CC) $(CFLAGS) $(ASMFLAGS) -c $< -o $@
391 Makefile: $(TOOLSDIR)/configure
392 ifneq (reconf,$(MAKECMDGOALS))
393 $(SILENT)echo "*** tools/configure is newer than Makefile. You should run 'make reconf'."
394 endif
396 reconf:
397 $(SILENT$)$(TOOLSDIR)/configure $(CONFIGURE_OPTIONS)