summaryrefslogtreecommitdiff
path: root/apps/Makefile
blob: 3f106d10f645ed9e7c513cef7ef632133c85dd0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#             __________               __   ___.
#   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
#   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
#   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
#   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
#                     \/            \/     \/    \/            \/
# $Id$
#

INCLUDES= -I$(FIRMDIR)/include -I$(FIRMDIR)/export -I. -I$(BUILDDIR)	\
 -I$(OBJDIR)

DEPFILE = $(OBJDIR)/dep-apps
LDS := $(FIRMDIR)/app.lds
ROMLDS := $(FIRMDIR)/rom.lds

ifdef ENABLEDPLUGINS
ROCKS=rocks
endif

ifdef SOFTWARECODECS
CODECS=build-codecs
endif

# Set up the bitmap libraries
BITMAPLIBS = $(BUILDDIR)/libbitmapsmono.a \
             $(BUILDDIR)/libbitmapsnative.a \
             $(BUILDDIR)/libbitmapsremotemono.a \
             $(BUILDDIR)/libbitmapsremotenative.a

LINKBITMAPS = -lbitmapsmono -lbitmapsnative -lbitmapsremotemono -lbitmapsremotenative

# This sets up 'SRC' based on the files mentioned in SOURCES
include $(TOOLSDIR)/makesrc.inc

DEFINES = $(DEBUG)

DIRS = .

ifdef APPEXTRA
   DIRS += $(subst :, ,$(APPEXTRA))
   INCLUDES += $(patsubst %,-I%,$(subst :, ,$(APPEXTRA)))
endif

CFLAGS = $(GCCOPTS) $(INCLUDES) $(TARGET) $(DEFINES) -DTARGET_ID=$(TARGET_ID)	\
 -DAPPSVERSION=\"$(VERSION)\" $(EXTRA_DEFINES) -DMEM=${MEMORYSIZE}

OBJS := $(OBJDIR)/lang.o $(SRC:%.c=$(OBJDIR)/%.o)
SOURCES = $(SRC)
LINKFILE = $(OBJDIR)/linkage.lds
LINKROM = $(OBJDIR)/linkrom.lds
MAXINFILE = $(OBJDIR)/romstart.temp
MAXOUTFILE = $(OBJDIR)/romstart

LIBROCKBOX = $(BUILDDIR)/librockbox.a

ifdef SIMVER
# this is a sim build

all: $(BITMAPLIBS) $(BUILDDIR)/$(BINARY) $(CODECS) $(ROCKS)

else
# regular target build

ifndef DEBUG
# this is not needed to get built when doing debug builds
REALBIN = $(BUILDDIR)/$(BINARY)
endif

all: $(BITMAPLIBS) $(REALBIN) $(FLASHFILE) $(CODECS) $(ROCKS) $(ARCHOSROM)
endif

dep: $(DEPFILE)

build-codecs:
	@$(MAKE) -C codecs/lib OBJDIR=$(OBJDIR)/codecs/lib
	@$(MAKE) -C codecs OBJDIR=$(OBJDIR)/codecs

$(BUILDDIR)/libbitmapsnative.a:
	@echo "MAKE in bitmaps/native"
	$(SILENT)mkdir -p $(OBJDIR)/bitmaps/native
	@$(MAKE) -C bitmaps/native OBJDIR=$(OBJDIR)/bitmaps/native

$(BUILDDIR)/libbitmapsmono.a:
	@echo "MAKE in bitmaps/mono"
	$(SILENT)mkdir -p $(OBJDIR)/bitmaps/mono
	@$(MAKE) -C bitmaps/mono OBJDIR=$(OBJDIR)/bitmaps/mono

$(BUILDDIR)/libbitmapsremotenative.a:
	@echo "MAKE in bitmaps/remote_native"
	$(SILENT)mkdir -p $(OBJDIR)/bitmaps/remote_native
	@$(MAKE) -C bitmaps/remote_native OBJDIR=$(OBJDIR)/bitmaps/remote_native

$(BUILDDIR)/libbitmapsremotemono.a:
	@echo "MAKE in bitmaps/remote_mono"
	$(SILENT)mkdir -p $(OBJDIR)/bitmaps/remote_mono
	@$(MAKE) -C bitmaps/remote_mono OBJDIR=$(OBJDIR)/bitmaps/remote_mono

rocks:
	@$(MAKE) -C plugins/lib OBJDIR=$(OBJDIR)/plugins/lib
	@$(MAKE) -C plugins  OBJDIR=$(OBJDIR)/plugins

$(LINKFILE): $(LDS)
	@echo "Build LDS file"
	@cat $< | $(CC) -DLOADADDRESS=$(LOADADDRESS) -DMEMORYSIZE=$(MEMORYSIZE) $(INCLUDES) $(TARGET) $(DEFINES) -E -P $(ROMBUILD) - >$@

$(LINKROM): $(ROMLDS)
	@echo "Build LDS file for Rombox"
	@cat $< | $(CC) -DMEMORYSIZE=$(MEMORYSIZE) $(INCLUDES) $(TARGET) $(DEFINES) -E -P $(ROMBUILD) - >$@

$(MAXOUTFILE):
	@echo '#include "config.h"' > $(MAXINFILE)
	@echo "ROM_START" >> $(MAXINFILE)
	@cat $(MAXINFILE) | $(CC) -DMEMORYSIZE=$(MEMORYSIZE) $(INCLUDES) $(TARGET) $(DEFINES) -E -P $(ROMBUILD) - > $(MAXOUTFILE)
	@rm $(MAXINFILE)

$(OBJDIR)/rombox.elf : $(OBJS) $(LINKROM) $(DEPFILE) $(LIBROCKBOX) $(BITMAPLIBS)
	@echo "LD rombox.elf"
	@$(CC) $(GCCOPTS) -Os -nostdlib -o $@ $(OBJS) -L$(BUILDDIR) -lrockbox -lgcc $(LINKBITMAPS) -L$(BUILDDIR)/firmware -T$(LINKROM) -Wl,-Map,$(OBJDIR)/rombox.map

ifndef SIMVER

$(OBJDIR)/rockbox.elf : $(OBJS) $(LINKFILE) $(DEPFILE) $(LIBROCKBOX) $(BITMAPLIBS)
	@echo "LD rockbox.elf"
	@$(CC) $(GCCOPTS) -Os -nostdlib -o $@ $(OBJS)  -L$(BUILDDIR)/firmware -L$(BUILDDIR) -lrockbox $(LINKBITMAPS) -lgcc -T$(LINKFILE) -Wl,-Map,$(OBJDIR)/rockbox.map

$(OBJDIR)/rockbox.bin : $(OBJDIR)/rockbox.elf
	@echo "OBJCOPY "`basename $@`
	@$(OC) -O binary $< $@

$(OBJDIR)/rombox.bin : $(OBJDIR)/rombox.elf
	@echo "OBJCOPY "`basename $@`
	@$(OC) -O binary $< $@

$(OBJDIR)/rockbox.asm: $(OBJDIR)/rockbox.bin
	$(TOOLSDIR)/sh2d -sh1 $< > $@

#
# If there's a flashfile defined for this target (rockbox.ucl for Archos
# models) Then check if the mkfirmware script fails, as then it is (likely)
# because the image is too big and we need to create a compressed image
# instead.
#
$(BUILDDIR)/$(BINARY) : $(OBJDIR)/rockbox.bin $(FLASHFILE) 
	@echo "Build firmware file"
	$(SILENT)($(MKFIRMWARE) $< $@; \
	stat=$$?; \
	if test -n "$(FLASHFILE)"; then \
	  if test "$$stat" -ne 0; then \
	    echo "Image too big, making a compressed version!"; \
	    $(MAKE) -C $(FIRMDIR)/decompressor OBJDIR=$(BUILDDIR)/firmware/decompressor; \
	    $(MKFIRMWARE) $(BUILDDIR)/firmware/decompressor/compressed.bin $@; \
	  fi \
	fi )

else
# this is a simulator build

ifeq ($(SIMVER), win32)
# OK, this is ugly but we need it on the link line to make it do right
EXTRAOBJ = $(BUILDDIR)/sim/uisw32-res.o
LDOPTS += -lwinmm
endif


$(BUILDDIR)/$(BINARY) : $(OBJS) $(DEPFILE) $(BUILDDIR)/libsim.a \
	$(BUILDDIR)/libcomsim.a $(LIBROCKBOX)
	@echo "LD $(BINARY)"
	$(SILENT)$(CC) $(GCCOPTS) -o $@ $(OBJS) -L$(BUILDDIR) -lrockbox -lsim -lcomsim $(LINKBITMAPS) $(LDOPTS) $(EXTRAOBJ) -Wl,-Map,$(OBJDIR)/rockbox.map

endif

$(BUILDDIR)/rockbox.ucl: $(OBJDIR)/rockbox.bin
	$(SILENT)(echo "UCLPACK rockbox" ; \
	$(TOOLSDIR)/uclpack --best --2e $< $@ >/dev/null 2>&1;)

$(BUILDDIR)/rombox.ucl: $(OBJDIR)/rombox.bin $(MAXOUTFILE)
	$(SILENT)(echo "UCLPACK rombox" ; \
	$(TOOLSDIR)/uclpack --none $< $@ >/dev/null 2>&1; \
	perl $(TOOLSDIR)/romsizetest.pl `cat $(MAXOUTFILE)` $<; \
	if test $$? -ne 0; then \
	  echo "removing UCL file again, making it a fake one"; \
	  echo "fake" > $@; \
	fi)

include $(TOOLSDIR)/make.inc

$(OBJDIR)/build.lang: lang/$(LANGUAGE).lang $(TOOLSDIR)/uplang
	@echo "UPLANG"
	@mkdir -p `dirname $@`
	@perl $(TOOLSDIR)/uplang lang/english.lang $< > $@

$(OBJDIR)/lang.o: $(OBJDIR)/build.lang $(TOOLSDIR)/genlang
	@echo "GENLANG"
	@mkdir -p `dirname $@`
	@perl -s $(TOOLSDIR)/genlang -p=$(BUILDDIR)/lang $<
	@echo "CC lang.c"
	@$(CC) $(CFLAGS) -c $(BUILDDIR)/lang.c -o $@

clean:
	@echo "cleaning apps"
	@-rm -f $(OBJS) $(BUILDDIR)/$(BINARY) $(OBJDIR)/rockbox.asm	     \
	$(OBJDIR)/rockbox.bin $(OBJDIR)/rockbox.elf $(OBJDIR)/*.map	     \
	$(OBJDIR)/lang.o $(OBJDIR)/build.lang $(BUILDDIR)/lang.[ch]	     \
	$(LINKFILE) $(BUILDDIR)/rockbox.ucl $(LINKROM)                       \
	$(BUILDDIR)/rombox.ucl $(OBJDIR)/rombox.bin $(OBJDIR)/rombox.elf     \
	$(MAXOUTFILE) $(DEPFILE)
	@$(MAKE) -C bitmaps/mono clean OBJDIR=$(OBJDIR)/bitmaps/mono
	@$(MAKE) -C bitmaps/native clean OBJDIR=$(OBJDIR)/bitmaps/native
	@$(MAKE) -C bitmaps/remote_mono clean OBJDIR=$(OBJDIR)/bitmaps/remote_mono
	@$(MAKE) -C bitmaps/remote_native clean OBJDIR=$(OBJDIR)/bitmaps/remote_native
	@$(MAKE) -C plugins clean OBJDIR=$(OBJDIR)/plugins
	@$(MAKE) -C codecs clean OBJDIR=$(OBJDIR)/codecs
	@rm -rf $(OBJDIR)/recorder $(OBJDIR)/player
ifdef SIMVER
	@$(MAKE) -C $(SIMDIR) clean
endif

ifneq ($(MAKECMDGOALS),clean)
-include $(DEPFILE)
endif