first step at building the main binary
[kugel-rb.git] / tools / root.make
blob8f311374740000a626797a9123f4f0ff9235cfa4
1 # __________ __ ___.
2 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
3 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6 # \/ \/ \/ \/ \/
7 # $Id$
10 include $(TOOLSDIR)/functions.make
12 DEFINES = -DROCKBOX -DMEMORYSIZE=$(MEMORYSIZE) -DMEM=$(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
20 TOOLS = $(TOOLSDIR)/rdf2binary $(TOOLSDIR)/convbdf \
21 $(TOOLSDIR)/codepages $(TOOLSDIR)/scramble $(TOOLSDIR)/bmp2rb \
22 $(TOOLSDIR)/uclpack $(TOOLSDIR)/mkboot $(TOOLSDIR)/iaudio_bl_flash.c \
23 $(TOOLSDIR)/iaudio_bl_flash.h
26 ifeq (,$(PREFIX))
27 ifdef APP_TYPE
28 # for sims, set simdisk/ as default
29 ifeq ($(APP_TYPE),sdl-sim)
30 RBPREFIX = simdisk
31 else ifeq ($(APP_TYPE),sdl-app)
32 RBPREFIX = /usr/local
33 endif
35 INSTALL = --install="$(RBPREFIX)"
36 else
37 # /dev/null as magic to tell it wasn't set, error out later in buildzip.pl
38 INSTALL = --install=/dev/null
39 endif
40 else
41 RBPREFIX = $(PREFIX)
42 INSTALL = --install="$(RBPREFIX)"
43 endif
45 RBINFO = $(BUILDDIR)/rockbox-info.txt
47 # list suffixes to be understood by $*
48 .SUFFIXES: .rock .codec .map .elf .c .S .o .bmp .a
50 .PHONY: all clean tags zip tools manual bin build info langs
52 ifeq (,$(filter clean veryclean reconf tags voice voicetools manual manual-pdf manual-html manual-zhtml manual-txt manual-ztxt manual-zip help fontzip ,$(MAKECMDGOALS)))
53 # none of the above
54 DEPFILE = $(BUILDDIR)/make.dep
56 endif
58 all: $(DEPFILE) build
60 # Subdir makefiles. their primary purpose is to populate SRC, OTHER_SRC &
61 # ASMDEFS_SRC but they also define special dependencies and compile rules
62 include $(TOOLSDIR)/tools.make
64 ifeq (,$(findstring checkwps,$(APPSDIR)))
65 ifeq (,$(findstring database,$(APPSDIR)))
66 include $(FIRMDIR)/firmware.make
67 include $(ROOTDIR)/lib/skin_parser/skin_parser.make
68 include $(ROOTDIR)/apps/bitmaps/bitmaps.make
69 endif
70 endif
72 ifneq (,$(findstring bootloader,$(APPSDIR)))
73 include $(APPSDIR)/bootloader.make
74 else ifneq (,$(findstring bootbox,$(APPSDIR)))
75 BOOTBOXLDOPTS = -Wl,--gc-sections
76 include $(APPSDIR)/bootbox.make
77 else ifneq (,$(findstring checkwps,$(APPSDIR)))
78 include $(APPSDIR)/checkwps.make
79 else ifneq (,$(findstring database,$(APPSDIR)))
80 include $(APPSDIR)/database.make
81 else
82 include $(APPSDIR)/apps.make
83 include $(APPSDIR)/lang/lang.make
85 ifdef SOFTWARECODECS
86 include $(APPSDIR)/codecs/codecs.make
87 endif
89 ifdef ENABLEDPLUGINS
90 include $(APPSDIR)/plugins/bitmaps/pluginbitmaps.make
91 include $(APPSDIR)/plugins/plugins.make
92 endif
94 ifdef APP_TYPE
95 include $(ROOTDIR)/uisimulator/uisimulator.make
96 endif
97 endif # bootloader
99 OBJ := $(SRC:.c=.o)
100 OBJ := $(OBJ:.S=.o)
101 OBJ += $(BMP:.bmp=.o)
102 OBJ := $(subst $(ROOTDIR),$(BUILDDIR),$(OBJ))
104 build: $(TOOLS) $(BUILDDIR)/$(BINARY) $(CODECS) $(ROCKS) $(ARCHOSROM) $(RBINFO)
106 $(RBINFO): $(BUILDDIR)/$(BINARY)
107 $(SILENT)echo Creating $(@F)
108 $(SILENT)$(TOOLSDIR)/mkinfo.pl $@
110 $(DEPFILE) dep:
111 $(call PRINTS,Generating dependencies)
112 @echo foo > /dev/null # there must be a "real" command in the rule
113 $(call mkdepfile,$(DEPFILE),$(SRC))
114 $(call mkdepfile,$(DEPFILE),$(OTHER_SRC:%.lua=))
115 $(call mkdepfile,$(DEPFILE),$(ASMDEFS_SRC))
116 @mv $(DEPFILE)_ $(DEPFILE)
117 $(call bmpdepfile,$(DEPFILE),$(BMP) $(PBMP))
119 bin: $(DEPFILE) $(TOOLS) $(BUILDDIR)/$(BINARY) $(RBINFO)
120 rocks: $(DEPFILE) $(TOOLS) $(ROCKS)
121 codecs: $(DEPFILE) $(TOOLS) $(CODECS)
122 tools: $(TOOLS)
124 -include $(DEPFILE)
126 veryclean: clean
127 $(SILENT)rm -rf $(TOOLS)
129 clean:
130 $(SILENT)echo Cleaning build directory
131 $(SILENT)rm -rf rockbox.zip rockbox.7z rockbox.tar rockbox.tar.gz \
132 rockbox.tar.bz2 TAGS apps firmware tools comsim sim lang lib \
133 manual *.pdf *.a credits.raw rockbox.ipod bitmaps \
134 pluginbitmaps UI256.bmp rockbox-full.zip html txt \
135 rockbox-manual*.zip sysfont.h rockbox-info.txt voicefontids \
136 *.wav *.mp3 *.voice $(CLEANOBJS) \
137 $(LINKRAM) $(LINKROM) rockbox.elf rockbox.map rockbox.bin \
138 make.dep rombox.elf rombox.map rombox.bin rombox.ucl romstart.txt \
139 $(BINARY) $(FLASHFILE) uisimulator bootloader flash $(BOOTLINK)
141 #### linking the binaries: ####
143 .SECONDEXPANSION:
145 ifeq (,$(findstring bootloader,$(APPSDIR)))
146 # not bootloader
148 OBJ += $(LANG_O)
150 ifndef APP_TYPE
152 ## target build
153 CONFIGFILE := $(FIRMDIR)/export/config/$(MODELNAME).h
154 RAMLDS := $(FIRMDIR)/target/$(CPU)/$(MANUFACTURER)/app.lds
155 LINKRAM := $(BUILDDIR)/ram.link
156 ROMLDS := $(FIRMDIR)/rom.lds
157 LINKROM := $(BUILDDIR)/rom.link
160 $(LINKRAM): $(RAMLDS) $(CONFIGFILE)
161 $(call PRINTS,PP $(@F))
162 $(call preprocess2file,$<,$@,-DLOADADDRESS=$(LOADADDRESS))
164 $(LINKROM): $(ROMLDS)
165 $(call PRINTS,PP $(@F))
166 $(call preprocess2file,$<,$@,-DLOADADDRESS=$(LOADADDRESS))
168 $(BUILDDIR)/rockbox.elf : $$(OBJ) $$(FIRMLIB) $$(VOICESPEEXLIB) $$(SKINLIB) $$(LINKRAM)
169 $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -Os -nostdlib -o $@ $(OBJ) \
170 -L$(BUILDDIR)/firmware -lfirmware \
171 -L$(BUILDDIR)/lib -lskin_parser \
172 -L$(BUILDDIR)/apps/codecs $(VOICESPEEXLIB:lib%.a=-l%) \
173 -lgcc $(BOOTBOXLDOPTS) $(GLOBAL_LDOPTS) \
174 -T$(LINKRAM) -Wl,-Map,$(BUILDDIR)/rockbox.map
176 $(BUILDDIR)/rombox.elf : $$(OBJ) $$(FIRMLIB) $$(VOICESPEEXLIB) $$(SKINLIB) $$(LINKROM)
177 $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -Os -nostdlib -o $@ $(OBJ) \
178 $(VOICESPEEXLIB) $(FIRMLIB) -lgcc $(GLOBAL_LDOPTS) \
179 -L$(BUILDDIR)/firmware -T$(LINKROM) -Wl,-Map,$(BUILDDIR)/rombox.map
181 $(BUILDDIR)/rockbox.bin : $(BUILDDIR)/rockbox.elf
182 $(call PRINTS,OC $(@F))$(OC) $(if $(filter yes, $(USE_ELF)), -S -x, -O binary) $< $@
184 $(BUILDDIR)/rombox.bin : $(BUILDDIR)/rombox.elf
185 $(call PRINTS,OC $(@F))$(OC) -O binary $< $@
188 # If there's a flashfile defined for this target (rockbox.ucl for Archos
189 # models) Then check if the mkfirmware script fails, as then it is (likely)
190 # because the image is too big and we need to create a compressed image
191 # instead.
193 $(BUILDDIR)/$(BINARY) : $(BUILDDIR)/rockbox.bin $(FLASHFILE)
194 $(call PRINTS,SCRAMBLE $(notdir $@))($(MKFIRMWARE) $< $@; \
195 stat=$$?; \
196 if test -n "$(FLASHFILE)"; then \
197 if test "$$stat" -ne 0; then \
198 echo "Image too big, making a compressed version!"; \
199 $(MAKE) -C $(FIRMDIR)/decompressor OBJDIR=$(BUILDDIR)/firmware/decompressor; \
200 $(MKFIRMWARE) $(BUILDDIR)/firmware/decompressor/compressed.bin $@; \
201 fi \
202 fi )
204 # archos
205 $(BUILDDIR)/rockbox.ucl: $(BUILDDIR)/rockbox.bin
206 $(call PRINTS,UCLPACK $(@F))$(TOOLSDIR)/uclpack --best --2e -b1048576 $< $@ >/dev/null
208 MAXINFILE = $(BUILDDIR)/temp.txt
209 MAXOUTFILE = $(BUILDDIR)/romstart.txt
211 $(BUILDDIR)/rombox.ucl: $(BUILDDIR)/rombox.bin $(MAXOUTFILE)
212 $(call PRINTS,UCLPACK $(@F))$(TOOLSDIR)/uclpack --none $< $@ >/dev/null; \
213 perl $(TOOLSDIR)/romsizetest.pl `cat $(MAXOUTFILE)` $<; \
214 if test $$? -ne 0; then \
215 echo "removing UCL file again, making it a fake one"; \
216 echo "fake" > $@; \
219 $(MAXOUTFILE):
220 $(call PRINTS,Creating $(@F))
221 $(SILENT)$(shell echo '#include "config.h"' > $(MAXINFILE))
222 $(SILENT)$(shell echo "ROM_START" >> $(MAXINFILE))
223 $(call preprocess2file,$(MAXINFILE),$(MAXOUTFILE))
224 $(SILENT)rm $(MAXINFILE)
226 # iriver
227 $(BUILDDIR)/rombox.iriver: $(BUILDDIR)/rombox.bin
228 $(call PRINTS,Build ROM file)$(MKFIRMWARE) $< $@
230 endif # !APP_TYPE
231 endif # !bootloader
234 voicetools:
235 $(SILENT)$(MAKE) -C $(TOOLSDIR) CC=$(HOSTCC) AR=$(HOSTAR) rbspeexenc voicefont wavtrim
237 tags:
238 $(SILENT)rm -f TAGS
239 $(SILENT)etags -o $(BUILDDIR)/TAGS $(filter-out %.o,$(SRC) $(OTHER_SRC))
241 fontzip:
242 $(SILENT)$(TOOLSDIR)/buildzip.pl $(VERBOSEOPT) -m \"$(MODELNAME)\" -r "$(ROOTDIR)" --rbdir="$(RBDIR)" -f 1 -o rockbox-fonts.zip $(TARGET) $(BINARY)
244 zip:
245 $(SILENT)$(TOOLSDIR)/buildzip.pl $(VERBOSEOPT) -m \"$(MODELNAME)\" -i \"$(TARGET_ID)\" -r "$(ROOTDIR)" --rbdir="$(RBDIR)" $(TARGET) $(BINARY)
247 mapzip:
248 $(SILENT)find . -name "*.map" | xargs zip rockbox-maps.zip
250 fullzip:
251 $(SILENT)$(TOOLSDIR)/buildzip.pl $(VERBOSEOPT) -m \"$(MODELNAME)\" -i \"$(TARGET_ID)\" -r "$(ROOTDIR)" --rbdir="$(RBDIR)" -f 2 -o rockbox-full.zip $(TARGET) $(BINARY)
253 7zip:
254 $(SILENT)$(TOOLSDIR)/buildzip.pl $(VERBOSEOPT) -m \"$(MODELNAME)\" -i \"$(TARGET_ID)\" -o "rockbox.7z" -z "7za a -mx=9" -r "$(ROOTDIR)" --rbdir="$(RBDIR)" $(TARGET) $(BINARY)
256 tar:
257 $(SILENT)rm -f rockbox.tar
258 $(SILENT)$(TOOLSDIR)/buildzip.pl $(VERBOSEOPT) -m \"$(MODELNAME)\" -i \"$(TARGET_ID)\" -o "rockbox.tar" -z "tar -cf" -r "$(ROOTDIR)" --rbdir="$(RBDIR)" $(TARGET) $(BINARY)
260 bzip2: tar
261 $(SILENT)bzip2 -f9 rockbox.tar
263 gzip: tar
264 $(SILENT)gzip -f9 rockbox.tar
266 manual manual-pdf:
267 $(SILENT)$(MAKE) -C $(MANUALDIR) OBJDIR=$(BUILDDIR)/manual manual-pdf
268 manual-html:
269 $(SILENT)$(MAKE) -C $(MANUALDIR) OBJDIR=$(BUILDDIR)/manual manual-html
270 manual-zhtml: manual-zip
271 manual-txt:
272 $(SILENT)$(MAKE) -C $(MANUALDIR) OBJDIR=$(BUILDDIR)/manual manual-txt
273 manual-ztxt:
274 $(SILENT)$(MAKE) -C $(MANUALDIR) OBJDIR=$(BUILDDIR)/manual manual-txt-zip
275 manual-zip:
276 $(SILENT)$(MAKE) -C $(MANUALDIR) OBJDIR=$(BUILDDIR)/manual manual-zip
278 ifdef TTS_ENGINE
280 voice: voicetools $(BUILDDIR)/apps/features
281 $(SILENT)for f in `cat $(BUILDDIR)/apps/features`; do feat="$$feat:$$f" ; done ; \
282 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 \
284 endif
286 bininstall: $(BUILDDIR)/$(BINARY)
287 @echo "Installing your rockbox binary in your '$(RBPREFIX)' dir"
288 $(SILENT)cp $(BINARY) "$(RBPREFIX)/.rockbox/"
290 install:
291 @echo "Installing your build in your '$(PREFIX)' dir"
292 $(SILENT)$(TOOLSDIR)/buildzip.pl $(VERBOSEOPT) -m "$(MODELNAME)" -i "$(TARGET_ID)" $(INSTALL) -z "zip -r0" -r "$(ROOTDIR)" --rbdir="$(RBDIR)" -f 0 $(TARGET) $(BINARY)
294 fullinstall:
295 @echo "Installing a full setup in your '$(PREFIX)' dir"
296 $(SILENT)$(TOOLSDIR)/buildzip.pl $(VERBOSEOPT) -m "$(MODELNAME)" -i "$(TARGET_ID)" $(INSTALL) -z "zip -r0" -r "$(ROOTDIR)" --rbdir="$(RBDIR)" -f 2 $(TARGET) $(BINARY)
298 help:
299 @echo "A few helpful make targets"
300 @echo ""
301 @echo "all - builds a full Rockbox (default), including tools"
302 @echo "bin - builds only the Rockbox.<target name> file"
303 @echo "rocks - builds only plugins"
304 @echo "codecs - builds only codecs"
305 @echo "dep - regenerates make dependency database"
306 @echo "clean - cleans a build directory (not tools)"
307 @echo "veryclean - cleans the build and tools directories"
308 @echo "manual - builds a manual (pdf)"
309 @echo "manual-html - HTML manual"
310 @echo "manual-zip - HTML manual (zipped)"
311 @echo "manual-txt - txt manual"
312 @echo "fullzip - creates a rockbox.zip of your build with fonts"
313 @echo "zip - creates a rockbox.zip of your build (no fonts)"
314 @echo "gzip - creates a rockbox.tar.gz of your build (no fonts)"
315 @echo "bzip2 - creates a rockbox.tar.bz2 of your build (no fonts)"
316 @echo "7zip - creates a rockbox.7z of your build (no fonts)"
317 @echo "fontzip - creates rockbox-fonts.zip"
318 @echo "mapzip - creates rockbox-maps.zip with all .map files"
319 @echo "tools - builds the tools only"
320 @echo "voice - creates the voice clips (voice builds only)"
321 @echo "voicetools - builds the voice tools only"
322 @echo "install - installs your build (at PREFIX, defaults to simdisk/ for simulators (no fonts))"
323 @echo "fullinstall - installs your build (like install, but with fonts)"
324 @echo "reconf - rerun configure with the same selection"
326 ### general compile rules:
328 # when source and object are in different locations (normal):
329 $(BUILDDIR)/%.o: $(ROOTDIR)/%.c
330 $(SILENT)mkdir -p $(dir $@)
331 $(call PRINTS,CC $(subst $(ROOTDIR)/,,$<))$(CC) $(CFLAGS) -c $< -o $@
333 $(BUILDDIR)/%.o: $(ROOTDIR)/%.S
334 $(SILENT)mkdir -p $(dir $@)
335 $(call PRINTS,CC $(subst $(ROOTDIR)/,,$<))$(CC) $(CFLAGS) -c $< -o $@
337 # generated definitions for use in .S files
338 $(BUILDDIR)/%_asmdefs.h: $(ROOTDIR)/%_asmdefs.c
339 $(call PRINTS,ASMDEFS $(@F))
340 $(SILENT)mkdir -p $(dir $@)
341 $(call asmdefs2file,$<,$@)
343 # when source and object are both in BUILDDIR (generated code):
344 %.o: %.c
345 $(SILENT)mkdir -p $(dir $@)
346 $(call PRINTS,CC $(subst $(ROOTDIR)/,,$<))$(CC) $(CFLAGS) -c $< -o $@
348 %.o: %.S
349 $(SILENT)mkdir -p $(dir $@)
350 $(call PRINTS,CC $(subst $(ROOTDIR)/,,$<))$(CC) $(CFLAGS) -c $< -o $@
352 Makefile: $(TOOLSDIR)/configure
353 ifneq (reconf,$(MAKECMDGOALS))
354 $(SILENT)echo "*** tools/configure is newer than Makefile. You should run 'make reconf'."
355 endif
357 reconf:
358 $(SILENT$)$(TOOLSDIR)/configure $(CONFIGURE_OPTIONS)