-
Notifications
You must be signed in to change notification settings - Fork 59
/
Makefile
409 lines (352 loc) · 12.6 KB
/
Makefile
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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
############################################################################
#
# Makefile -- Top level dist makefile.
#
# Copyright (c) 2001-2007, SnapGear (www.snapgear.com)
# Copyright (c) 2001, Lineo
#
############################################################################
#
# Lets work out what the user wants, and if they have configured us yet
#
ifeq (.config,$(wildcard .config))
all: tools automake subdirs romfs image romfs.img squashfs.img
else
all: config_error
endif
ROOTDIR = $(shell pwd)
include vendors/config/common/config.arch
############################################################################
DIRS = $(VENDOR_TOPDIRS) include lib include user
.PHONY: tools
tools: ucfront cksum
chmod +x tools/romfs-inst.sh tools/modules-alias.sh tools/build-udev-perms.sh
.PHONY: ucfront
ucfront: tools/ucfront/*.c
$(MAKE) -C tools/ucfront
ln -sf $(ROOTDIR)/tools/ucfront/ucfront tools/ucfront-gcc
ln -sf $(ROOTDIR)/tools/ucfront/ucfront tools/ucfront-g++
ln -sf $(ROOTDIR)/tools/ucfront/ucfront-ld tools/ucfront-ld
ln -sf $(ROOTDIR)/tools/ucfront/jlibtool tools/jlibtool
.PHONY: cksum
cksum: tools/cksum
tools/cksum: tools/sg-cksum/*.c
$(MAKE) -C tools/sg-cksum
ln -sf $(ROOTDIR)/tools/sg-cksum/cksum tools/cksum
.PHONY: automake
automake:
$(MAKE) -C config automake
############################################################################
#
# Config stuff, we recall ourselves to load the new config.arch before
# running the kernel and other config scripts
#
.PHONY: Kconfig
Kconfig:
@chmod u+x config/mkconfig
config/mkconfig > Kconfig
include config/Makefile.conf
SCRIPTS_BINARY_config = conf
SCRIPTS_BINARY_menuconfig = mconf
SCRIPTS_BINARY_qconfig = qconf
SCRIPTS_BINARY_gconfig = gconf
SCRIPTS_BINARY_xconfig = gconf
.PHONY: config menuconfig qconfig gconfig xconfig
menuconfig: mconf
qconfig: qconf
gconfig: gconf
xconfig: $(SCRIPTS_BINARY_xconfig)
config menuconfig qconfig gconfig xconfig: Kconfig conf
KCONFIG_NOTIMESTAMP=1 $(SCRIPTSDIR)/$(SCRIPTS_BINARY_$@) Kconfig
@if [ ! -f .config ]; then \
echo; \
echo "You have not saved your config, please re-run 'make $@'"; \
echo; \
exit 1; \
fi
@chmod u+x config/setconfig
@config/setconfig defaults
@if egrep "^CONFIG_DEFAULTS_KERNEL=y" .config > /dev/null; then \
$(MAKE) linux_$@; \
fi
@if egrep "^CONFIG_DEFAULTS_MODULES=y" .config > /dev/null; then \
$(MAKE) modules_$@; \
fi
@if egrep "^CONFIG_DEFAULTS_VENDOR=y" .config > /dev/null; then \
$(MAKE) myconfig_$@; \
fi
@config/setconfig final
.PHONY: oldconfig
oldconfig: Kconfig conf
KCONFIG_NOTIMESTAMP=1 $(SCRIPTSDIR)/conf -o Kconfig
@chmod u+x config/setconfig
@config/setconfig defaults
@$(MAKE) oldconfig_linux
@$(MAKE) oldconfig_modules
@$(MAKE) oldconfig_config
@$(MAKE) oldconfig_uClibc
@config/setconfig final
.PHONY: generated_headers
generated_headers:
if [ ! -f $(LINUXDIR)/include/linux/autoconf.h ] ; then \
ln -sf $(ROOTDIR)/$(LINUXDIR)/include/generated/autoconf.h $(LINUXDIR)/include/linux/autoconf.h ; \
fi
.PHONY: modules
modules: generated_headers
. $(LINUXDIR)/.config; if [ "$$CONFIG_MODULES" = "y" ]; then \
[ -d $(LINUXDIR)/modules ] || mkdir $(LINUXDIR)/modules; \
$(MAKEARCH_KERNEL) -j$(HOST_NCPU) -C $(LINUXDIR) modules || exit 1; \
fi
.PHONY: modules_install
modules_install:
. $(LINUX_CONFIG); \
. $(CONFIG_CONFIG); \
if [ "$$CONFIG_MODULES" = "y" ]; then \
[ -d $(ROMFSDIR)/lib/modules ] || mkdir -p $(ROMFSDIR)/lib/modules; \
$(MAKEARCH_KERNEL) -C $(LINUXDIR) INSTALL_MOD_CMD="$(ROMFSINST) -S -r \"\"" INSTALL_MOD_PATH=$(ROMFSDIR) DEPMOD="$(ROOTDIR)/user/busybox/examples/depmod.pl" modules_install; \
rm -f $(ROMFSDIR)/lib/modules/*/build; \
rm -f $(ROMFSDIR)/lib/modules/*/source; \
find $(ROMFSDIR)/lib/modules -type f -name "*o" | xargs -r $(STRIP) -R .comment -R .note -g --strip-unneeded; \
if [ "$$CONFIG_USER_BUSYBOX_FEATURE_MODPROBE_FANCY_ALIAS" = "y" ]; \
then \
find $(ROMFSDIR)/lib/modules -type f -name "*o" | \
/bin/sh $(ROOTDIR)/tools/modules-alias.sh \
$(ROMFSDIR)/etc/modprobe.conf;\
fi; \
fi
linux_%:
KCONFIG_NOTIMESTAMP=1 $(MAKEARCH_KERNEL) -C $(LINUXDIR) $(patsubst linux_%,%,$@)
modules_%:
[ ! -d modules ] || KCONFIG_NOTIMESTAMP=1 $(MAKEARCH) -C modules $(patsubst modules_%,%,$@)
myconfig_%:
KCONFIG_NOTIMESTAMP=1 $(MAKEARCH) -C config $(patsubst myconfig_%,%,$@)
oldconfig_config: myconfig_oldconfig
oldconfig_modules: modules_oldconfig
oldconfig_linux: linux_oldconfig
oldconfig_uClibc:
[ -z "$(findstring uClibc,$(LIBCDIR))" ] || KCONFIG_NOTIMESTAMP=1 $(MAKEARCH) -C $(LIBCDIR) oldconfig
############################################################################
#
# normal make targets
#
.PHONY: romfs
romfs: romfs.newlog romfs.subdirs modules_install romfs.post
.PHONY: romfs.newlog
romfs.newlog:
rm -f $(IMAGEDIR)/romfs-inst.log
.PHONY: romfs.subdirs
romfs.subdirs:
for dir in vendors $(DIRS) ; do [ ! -d $$dir ] || $(MAKEARCH) -C $$dir romfs || exit 1 ; done
.PHONY: romfs.post
romfs.post:
$(MAKEARCH) -C vendors romfs.post
-find $(ROMFSDIR)/. -name CVS | xargs -r rm -rf
. $(LINUXDIR)/.config; if [ "$$CONFIG_INITRAMFS_SOURCE" != "" ]; then \
$(MAKEARCH_KERNEL) -j$(HOST_NCPU) -C $(LINUXDIR) $(LINUXTARGET) || exit 1; \
fi
romfs.img: romfs/ romfs/* romfs/*/*
genromfs -f romfs.img -d romfs
@echo "The ROMFS image romfs.img is ready"
#cramfs.img: romfs.img
# mkcramfs romfs/ cramfs.img
# @echo "The CRAMFS image cramfs.img is ready"
squashfs.img: romfs.img
mksquashfs romfs/ squashfs.img -no-exports -no-xattrs -all-root -noappend
@echo "The SQUASHFS image squashfs.img is ready"
.PHONY: image
image:
[ -d $(IMAGEDIR) ] || mkdir $(IMAGEDIR)
make linux
$(MAKEARCH) -C vendors image
.PHONY: release
release:
$(MAKE) -C release release
.PHONY: single
single:
$(MAKE) NON_SMP_BUILD=1
%_fullrelease:
@echo "This target no longer works"
@echo "Do a make -C release $@"
exit 1
#
# fancy target that allows a vendor to have other top level
# make targets, for example "make vendor_flash" will run the
# vendor_flash target in the vendors directory
#
vendor_%:
$(MAKEARCH) -C vendors $@
.PHONY: linux
linux linux%_only:
. $(LINUXDIR)/.config; if [ "$$CONFIG_INITRAMFS_SOURCE" != "" ]; then \
mkdir -p `dirname $$CONFIG_INITRAMFS_SOURCE`; \
touch $$CONFIG_INITRAMFS_SOURCE || exit 1; \
fi
@if expr "$(LINUXDIR)" : 'linux-2\.[0-4].*' > /dev/null && \
[ ! -f $(LINUXDIR)/.depend ] ; then \
echo "ERROR: you need to do a 'make dep' first" ; \
exit 1 ; \
fi
$(MAKEARCH_KERNEL) -j$(HOST_NCPU) -C $(LINUXDIR) $(LINUXTARGET) || exit 1
@if expr "$(LINUXDIR)" : 'linux-\(2.6\|3\).*' > /dev/null ; then \
: ignore failure in headers_install; \
$(MAKEARCH_KERNEL) -j$(HOST_NCPU) -C $(LINUXDIR) headers_install || true; \
fi
if [ -f $(LINUXDIR)/vmlinux ]; then \
ln -f $(LINUXDIR)/vmlinux $(LINUXDIR)/linux ; \
fi
.PHONY: sparse
sparse:
$(MAKEARCH_KERNEL) -C $(LINUXDIR) C=1 $(LINUXTARGET) || exit 1
.PHONY: sparseall
sparseall:
$(MAKEARCH_KERNEL) -C $(LINUXDIR) C=2 $(LINUXTARGET) || exit 1
.PHONY: subdirs
subdirs: linux modules
for dir in $(DIRS) ; do [ ! -d $$dir ] || $(MAKEARCH) -C $$dir || exit 1 ; done
dep:
@if [ ! -f $(LINUXDIR)/.config ] ; then \
echo "ERROR: you need to do a 'make config' first" ; \
exit 1 ; \
fi
$(MAKEARCH_KERNEL) -C $(LINUXDIR) dep
# This one removes all executables from the tree and forces their relinking
.PHONY: relink
relink:
find user prop vendors -type f -name '*.gdb' | sed 's/^\(.*\)\.gdb/\1 \1.gdb/' | xargs rm -f
clean: modules_clean
for dir in $(LINUXDIR) $(DIRS); do [ ! -d $$dir ] || $(MAKEARCH) -C $$dir clean ; done
rm -rf $(ROMFSDIR)/*
rm -rf $(STAGEDIR)/*
rm -rf $(IMAGEDIR)/*
rm -f $(LINUXDIR)/linux
rm -f $(LINUXDIR)/include/asm
rm -f $(LINUXDIR)/include/linux/autoconf.h
rm -rf $(LINUXDIR)/net/ipsec/alg/libaes $(LINUXDIR)/net/ipsec/alg/perlasm
real_clean mrproper: clean
[ -d "$(LINUXDIR)" ] && $(MAKEARCH_KERNEL) -C $(LINUXDIR) mrproper || :
[ -d uClibc ] && $(MAKEARCH) -C uClibc distclean || :
[ -d modules ] && $(MAKEARCH) -C modules distclean || :
[ -d "$(RELDIR)" ] && $(MAKEARCH) -C $(RELDIR) clean || :
-$(MAKEARCH) -C config clean
rm -rf romfs Kconfig config.arch images
rm -rf .config .config.old .oldconfig autoconf.h auto.conf
distclean: mrproper
-$(MAKEARCH_KERNEL) -C $(LINUXDIR) distclean
-rm -f user/tinylogin/applet_source_list user/tinylogin/config.h
-rm -f lib/uClibc lib/glibc
-$(MAKE) -C tools/ucfront clean
-rm -f tools/ucfront-gcc tools/ucfront-g++ tools/ucfront-ld tools/jlibtool
-$(MAKE) -C tools/sg-cksum clean
-rm -f tools/cksum
.PHONY: bugreport
bugreport:
rm -rf ./bugreport.tar.gz ./bugreport
mkdir bugreport
$(HOSTCC) -v 2> ./bugreport/host_vers
$(CROSS_COMPILE)gcc -v 2> ./bugreport/toolchain_vers
cp .config bugreport/
mkdir bugreport/$(LINUXDIR)
cp $(LINUXDIR)/.config bugreport/$(LINUXDIR)/
if [ -f $(LIBCDIR)/.config ] ; then \
set -e ; \
mkdir bugreport/$(LIBCDIR) ; \
cp $(LIBCDIR)/.config bugreport/$(LIBCDIR)/ ; \
fi
mkdir bugreport/config
cp config/.config bugreport/config/
tar czf bugreport.tar.gz bugreport
rm -rf ./bugreport
%_only:
@case "$(@)" in \
single*) $(MAKE) NON_SMP_BUILD=1 `expr $(@) : 'single[_]*\(.*\)'` ;; \
*/*) d=`expr $(@) : '\([^/]*\)/.*'`; \
t=`expr $(@) : '[^/]*/\(.*\)'`; \
$(MAKEARCH) -C $$d $$t;; \
*) $(MAKEARCH) -C $(*);; \
esac
%_clean:
@case "$(@)" in \
single*) $(MAKE) NON_SMP_BUILD=1 `expr $(@) : 'single[_]*\(.*\)'` ;; \
*/*) d=`expr $(@) : '\([^/]*\)/.*'`; \
t=`expr $(@) : '[^/]*/\(.*\)'`; \
$(MAKEARCH) -C $$d $$t;; \
*) $(MAKEARCH) -C $(*) clean;; \
esac
%_romfs:
@case "$(@)" in \
single*) $(MAKE) NON_SMP_BUILD=1 `expr $(@) : 'single[_]*\(.*\)'` ;; \
*/*) d=`expr $(@) : '\([^/]*\)/.*'`; \
t=`expr $(@) : '[^/]*/\(.*\)'`; \
$(MAKEARCH) -C $$d $$t;; \
*) $(MAKEARCH) -C $(*) romfs;; \
esac
vendors/%_defconfig:
$(MAKE) $(*)_defconfig
%_defconfig: conf
@if [ ! -f "vendors/$(*)/config.device" ]; then \
echo "vendors/$(*)/config.device must exist first"; \
exit 1; \
fi
-$(MAKE) clean > /dev/null 2>&1
cp vendors/$(*)/config.device .config
chmod u+x config/setconfig
yes "" | config/setconfig defaults
config/setconfig final
$(MAKE) dep
%_default: conf
$(MAKE) $(*)_defconfig
$(MAKE)
config_error:
@echo "*************************************************"
@echo "You have not run make config."
@echo "The build sequence for this source tree is:"
@echo "1. 'make config' or 'make xconfig'"
@echo "2. 'make dep'"
@echo "3. 'make'"
@echo "*************************************************"
@exit 1
prune: ucfront
@for i in `ls -d linux-* | grep -v $(LINUXDIR)`; do \
rm -fr $$i; \
done
$(MAKE) -C lib prune
$(MAKE) -C user prune
$(MAKE) -C vendors prune
dist-prep:
-find $(ROOTDIR) -name 'Makefile*.bin' | while read t; do \
$(MAKEARCH) -C `dirname $$t` -f `basename $$t` $@; \
done
help:
@echo "Quick reference for various supported make commands."
@echo "----------------------------------------------------"
@echo ""
@echo "make xconfig Configure the target etc"
@echo "make config \""
@echo "make menuconfig \""
@echo "make qconfig \""
@echo "make gconfig \""
@echo "make dep 2.4 and earlier kernels need this step"
@echo "make build the entire tree and final images"
@echo "make clean clean out compiled files, but not config"
@echo "make distclean clean out all non-distributed files"
@echo "make oldconfig re-run the config without interaction"
@echo "make linux compile the selected kernel only"
@echo "make romfs install all files to romfs directory"
@echo "make image combine romfs and kernel into final image"
@echo "make modules build all modules"
@echo "make modules_install install modules into romfs"
@echo "make DIR_only build just the directory DIR"
@echo "make DIR_romfs install files from directory DIR to romfs"
@echo "make DIR_clean clean just the directory DIR"
@echo "make single non-parallelised build"
@echo "make single[make-target] non-parallelised build of \"make-target\""
@echo "make V/P_default full default build for V=Vendor/P=Product"
@echo "make prune clean out uncompiled source (be careful)"
@echo ""
@echo "Typically you want to start with this sequence before experimenting."
@echo ""
@echo "make config select platform, kernel, etc, customise nothing."
@echo "make dep optional but safe even on newer kernels."
@echo "make build it as the creators intended."
@exit 0
############################################################################