forked from pelrun/CHDK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile.inc
369 lines (307 loc) · 9.37 KB
/
makefile.inc
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
MEMISOSIZE="(&_end-&_start)"
# override this on the command line or in buildconf to use PRIMARY.BIN from a different tree
# should be an absolute path
PRIMARY_ROOT=$(topdir)platform
include $(topdir)buildconf.inc
# optional local version of buildconf.inc, not in SVN so it can be used in autobuilds
# and to avoid getting accidentally included in svn diffs
# you may also set your default camera here
-include $(topdir)localbuildconf.inc
include $(topdir)version.inc
-include $(topdir)revision.inc
ifndef OPT_DE_VERSION
VER=CHDK
ifndef OPT_DEFAULT_LANG
OPT_DEFAULT_LANG=english
endif
else
VER=CHDK_DE
ifndef OPT_DEFAULT_LANG
OPT_DEFAULT_LANG=german
endif
endif
ifdef PLATFORM
ifdef PLATFORMSUB
include $(topdir)platform/$(PLATFORM)/sub/$(PLATFORMSUB)/makefile.inc
ifeq ($(PLATFORMOSVER),)
PLATFORMOSVER=0
endif
endif
endif
# Used in gui_debug.c for controlling memory browser allowed address ranges
# override in platform/$(PLATFORM)/sub/$(PLATFORMSUB)/makefile.inc to set camera specific value
ifdef MAXRAMADDR
PLFLAGS+=-DMAXRAMADDR=$(MAXRAMADDR)
else
PLFLAGS+=-DMAXRAMADDR=0x1FFFFFF
endif
ifdef ROMBASEADDR
PLFLAGS+=-DROMBASEADDR=$(ROMBASEADDR)
else
PLFLAGS+=-DROMBASEADDR=0xFFC00000
endif
ifdef OPT_FI2
include $(topdir)platform/fi2.inc
endif
SILENT=SILENT
NOZERO100K=TRUE
##########################################################################
##########################################################################
##########################################################################
ESED = sed -r
# keep sort order consistent
export LC_ALL=C
ifndef OSTYPE
HOSTPLATFORM:=$(patsubst MINGW%,MINGW,$(shell uname -s))
ifeq ($(HOSTPLATFORM),MINGW)
OSTYPE = Windows
EXE = .exe
SH = sh
DEVNULL = NUL
OLDSEPARATOR = \\\\
NEWSEPARATOR = /
SORT := $(dir $(shell which uniq.exe | sed 's_$(OLDSEPARATOR)_$(NEWSEPARATOR)_g'))/sort.exe
else
ifeq ($(HOSTPLATFORM),Linux)
OSTYPE = Linux
EXE =
SH =
DEVNULL = /dev/null
SORT = sort
else
ifeq ($(HOSTPLATFORM),Darwin)
OSTYPE = Darwin
EXE =
SH =
DEVNULL = /dev/null
SORT = sort
ESED = sed -E
else
OSTYPE = Other
EXE =
SH =
DEVNULL = /dev/null
SORT = sort
endif
endif
endif
else
EXE =
SH =
DEVNULL = /dev/null
SORT = sort
endif
# detect GNU Awk, which needs an extra switch to handle hex input
AWK_OPT_NONDECIMAL:=$(shell if [ `awk -Wv | grep -c "GNU Awk"` -ne 0 ] ; then echo "--non-decimal-data"; fi)
##########################################################################
##########################################################################
##########################################################################
HOSTCC=gcc
HOSTCFLAGS=-g -O2 -Wall
HOSTAR=ar
PAKWIF=$(topdir)tools/pakwif$(EXE)
PAKFI2=$(topdir)tools/packfi2/fi2enc$(EXE)
ENCODE_DISKBOOT=$(topdir)tools/dancingbits$(EXE)
##########################################################################
CROSS_COMPILE=arm-elf-
CC=$(CROSS_COMPILE)gcc
OBJCOPY=$(CROSS_COMPILE)objcopy
OBJDUMP=$(CROSS_COMPILE)objdump
STRIP=$(CROSS_COMPILE)strip
NM=$(CROSS_COMPILE)nm
AR=$(CROSS_COMPILE)ar
RANLIB=$(CROSS_COMPILE)ranlib
SIZE=$(CROSS_COMPILE)size
GCC_VERSION=$(shell $(CC) -dumpversion)
GCC_VERSION_MAJOR=$(firstword $(subst ., ,$(GCC_VERSION)))
# -msoft-float is used per default but object files are marked as hard-float
# -fno-schedule-insns2 for this gcc bug http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38644
# technically not required for gcc >= 4.6.3, and probably not required for vxworks cams
# see http://chdk.setepontos.com/index.php?topic=8273.msg100205#msg100205
CFLAGS=-fno-inline -Os -fno-strict-aliasing -fno-schedule-insns2
# flags for gcc v4
# CFLAGS+=-mcpu=arm946e-s
# for gcc v3, we use to allow use of strd etc
ifeq ($(GCC_VERSION_MAJOR),3)
CFLAGS+=-march=armv5te
else
ifeq ($(GCC_VERSION_MAJOR),4)
# TODO should be -mcpu, but breaks things ATM
CFLAGS+=-mtune=arm946e-s
endif
endif
CTHUMB=-mthumb
CFLAGS+=-mthumb-interwork
CFLAGS+=-I$(topdir)include -I$(topdir)core -I$(topdir)modules -I$(topdir)platform/$(PLATFORM) $(PLFLAGS) $(CPPFLAGS)
ifndef SKIPPLATFORMCHECK
CFLAGS+=-DPLATFORM=\"$(PLATFORM)\" -DPLATFORMSUB=\"$(PLATFORMSUB)\" -DPLATFORMID=$(PLATFORMID) -DCAMERA_$(PLATFORM)=1
endif
CFLAGS+=-DVER_$(VER) -DHDK_VERSION=\"$(VER)\" -DBUILD_NUMBER=\"$(BUILD_NUMBER)\" -DBUILD_SVNREV=\"$(BUILD_SVNREV)\"
CFLAGS+=-Wall -Wno-unused -Wno-format
LDFLAGS=-L$(topdir)lib/math -L$(topdir)lib/font
LDFLAGS+=-L$(topdir)lib/libc -L$(topdir)lib/ubasic
LDFLAGS+=-L$(topdir)platform/$(PLATFORM) -L$(topdir)platform/$(PLATFORM)/sub/$(PLATFORMSUB)
ifdef OPT_GAMES
CFLAGS+=-DOPT_GAMES
endif
ifdef OPT_CURVES
CFLAGS+=-DOPT_CURVES
endif
ifdef OPT_EDGEOVERLAY
CFLAGS+=-DOPT_EDGEOVERLAY
endif
ifdef OPT_MD_DEBUG
CFLAGS+=-DOPT_MD_DEBUG
endif
ifdef OPT_DEBUGGING
CFLAGS+=-DOPT_DEBUGGING
endif
ifdef OPT_PTP
CFLAGS+=-DOPT_PTP
endif
ifdef OPT_FORCE_LUA_CALL_NATIVE
CFLAGS+=-DOPT_FORCE_LUA_CALL_NATIVE
endif
ifdef OPT_EXMEM_MALLOC
CFLAGS+=-DOPT_EXMEM_MALLOC
# Only allow OPT_CHDK_IN_EXMEM when OPT_EXMEM_MALLOC is also defined
ifdef OPT_CHDK_IN_EXMEM
CFLAGS+=-DOPT_CHDK_IN_EXMEM
endif
endif # OPT_EXMEM_MALLOC
ifdef OPT_EXMEM_TESTING
CFLAGS+=-DOPT_EXMEM_TESTING
endif
ifdef EXMEM_HEAP_SKIP
CFLAGS+=-DEXMEM_HEAP_SKIP=$(EXMEM_HEAP_SKIP)
endif
ifdef EXMEM_BUFFER_SIZE
CFLAGS+=-DEXMEM_BUFFER_SIZE=$(EXMEM_BUFFER_SIZE)
endif
ifdef OPT_DBG_LUA_ASSERT
CFLAGS+=-DOPT_DBG_LUA_ASSERT
endif
ifdef OPT_WARNINGS
ifeq ($(GCC_VERSION_MAJOR),3)
CFLAGS+=-Wwrite-strings -Wsign-compare -Wunused -Wno-unused-parameter
HOSTCFLAGS+=-Wwrite-strings -Wsign-compare -Wunused -Wno-unused-parameter
endif
ifeq ($(GCC_VERSION_MAJOR),4)
CFLAGS+=-Wextra -fdiagnostics-show-option -Wno-missing-field-initializers -Wunused -Wno-unused-parameter
#HOSTCFLAGS+=-Wextra -fdiagnostics-show-option -Wno-missing-field-initializers -Wunused -Wno-unused-parameter
endif
endif
ifdef OPT_EXPIRE_TEST
# convert +n days to unix-ish timestamp
EXPIRE_TIME:=$(shell expr `date +%s` + $(OPT_EXPIRE_TEST) '*' 86400)
CFLAGS+= -DOPT_EXPIRE_TEST=$(EXPIRE_TIME)
endif
##########################################################################
.PHONY: default
default: all
ifndef SKIPBUILDRULES
# rule for building .o from .c in the same directory
%.o: %.c
@echo $< \-\> $@
$(CC) $(CFLAGS) -nostdinc -c -o $@ $<
# rule for building .o from .c in the same directory - forces THUMB build
%.thm.o: %.c
@echo $< \-\> $@
$(CC) $(CFLAGS) $(CTHUMB) -nostdinc -c -o $@ $<
# rule for building .o from .c in the 'core' directory
%.o: $(topdir)core/%.c
@echo $< \-\> $@
$(CC) $(CFLAGS) -nostdinc -c -o $@ $<
# rule for building .o from .c in the 'core' directory - forces THUMB build
%.thm.o: $(topdir)core/%.c
@echo $< \-\> $@
$(CC) $(CFLAGS) $(CTHUMB) -nostdinc -c -o $@ $<
# rule for building .o from .c in the 'modules' directory
%.o: $(topdir)modules/%.c
@echo $< \-\> $@
$(CC) $(CFLAGS) -nostdinc -c -o $@ $<
# rule for building .o from .S in the same directory
%.o: %.S
@echo $< \-\> $@
$(CC) $(CFLAGS) -nostdinc -c -o $@ $<
# rule for building .a
%.a:
@echo $^ \-\> $@
$(AR) rcs $@ $^
%.bin: %.elf
@echo $< \-\> $@
$(OBJDUMP) -j .text -j .rodata.str1.1 -j .data -j .bss -z -d -r -f -h $< > [email protected]
$(OBJCOPY) -O binary $< $@
%.elf:
@echo \-\> $@
$(CC) $(CFLAGS) -o $@ $^ $(LDLIBS) $(LDFLAGS) $(LDOPTS)
( $(NM) $@ | grep ' U ' > [email protected] ) && exit 1 || exit 0
.dep/%.d: %.c .dep
$(CC) $(CFLAGS) -M $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
.dep/%.d: %.S .dep
$(CC) $(CFLAGS) -M $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
endif
.PHONY: all
all: all-recursive
.PHONY: clean
clean: clean-recursive
.PHONY: distclean
distclean: distclean-recursive
.dep:
mkdir .dep
clean-recursive:
@for i in $(SUBDIRS); do \
echo \>\> Cleaning in $(FOLDER)$$i; \
$(MAKE) -C $$i FOLDER="$(FOLDER)$$i/" clean || exit 1; \
done
distclean-recursive:
@for i in $(SUBDIRS); do \
echo \>\> Distcleaning in $(FOLDER)$$i; \
$(MAKE) -C $$i FOLDER="$(FOLDER)$$i/" distclean || exit 1; \
done
all-recursive:
ifndef SKIPPLATFORMCHECK
ifndef PLATFORM
$(error PLATFORM has not been defined. Specify the PLATFORM to build on the command line or in localbuildconf.inc)
endif
ifndef PLATFORMSUB
$(error PLATFORMSUB has not been defined. Specify the PLATFORMSUB to build on the command line or in localbuildconf.inc)
endif
endif
@for i in $(SUBDIRS); do \
echo \>\> Entering to $(FOLDER)$$i; \
$(MAKE) -C $$i FOLDER="$(FOLDER)$$i/" || exit 1; \
echo \<\< Leaving $(FOLDER)$$i; \
done
depend-recursive:
@for i in $(SUBDIRS); do \
echo \>\> Entering to $(FOLDER)$$i; \
$(MAKE) -C $$i FOLDER="$(FOLDER)$$i/" depend || exit 1; \
echo \<\< Leaving $(FOLDER)$$i; \
done
ifdef SILENT
.SILENT:
endif
# Define empty recipes for source files (including the makefiles)
# to prevent make from trying implicit rules to create them. Speeds up build process
Makefile: ;
makefile: ;
$(topdir)makefile.inc: ;
$(topdir)buildconf.inc: ;
$(topdir)localbuildconf.inc: ;
$(topdir)version.inc: ;
$(topdir)revision.inc: ;
$(topdir)platform/$(PLATFORM)/sub/$(PLATFORMSUB)/makefile.inc: ;
$(topdir)platform/fi2.inc: ;
*.c: ;
*.txt: ;
*.sh: ;
reversebytes.S: ;
callfunc.S: ;
setjmp.S: ;
stubs_min.S: ;
stubs_entry_2.S: ;