build: include homebrew include/library directory in cflags/ldflags on mac os x
[openwrt/svn-archive/archive.git] / include / image.mk
1 #
2 # Copyright (C) 2006-2010 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
8 override TARGET_BUILD=
9 include $(INCLUDE_DIR)/prereq.mk
10 include $(INCLUDE_DIR)/kernel.mk
11 include $(INCLUDE_DIR)/host.mk
12 include $(INCLUDE_DIR)/version.mk
13
14 override MAKE:=$(_SINGLE)$(SUBMAKE)
15 override NO_TRACE_MAKE:=$(_SINGLE)$(NO_TRACE_MAKE)
16
17 KDIR=$(KERNEL_BUILD_DIR)
18 KDIR_TMP=$(KDIR)/tmp
19 DTS_DIR:=$(LINUX_DIR)/arch/$(ARCH)/boot/dts/
20
21 IMG_PREFIX:=openwrt-$(if $(CONFIG_VERSION_FILENAMES),$(VERSION_NUMBER)-)$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))
22
23 MKFS_DEVTABLE_OPT := -D $(INCLUDE_DIR)/device_table.txt
24
25 ifneq ($(CONFIG_BIG_ENDIAN),)
26 JFFS2OPTS := --big-endian --squash-uids -v
27 else
28 JFFS2OPTS := --little-endian --squash-uids -v
29 endif
30
31 ifeq ($(CONFIG_JFFS2_RTIME),y)
32 JFFS2OPTS += -X rtime
33 endif
34 ifeq ($(CONFIG_JFFS2_ZLIB),y)
35 JFFS2OPTS += -X zlib
36 endif
37 ifeq ($(CONFIG_JFFS2_LZMA),y)
38 JFFS2OPTS += -X lzma --compression-mode=size
39 endif
40 ifneq ($(CONFIG_JFFS2_RTIME),y)
41 JFFS2OPTS += -x rtime
42 endif
43 ifneq ($(CONFIG_JFFS2_ZLIB),y)
44 JFFS2OPTS += -x zlib
45 endif
46 ifneq ($(CONFIG_JFFS2_LZMA),y)
47 JFFS2OPTS += -x lzma
48 endif
49
50 JFFS2OPTS += $(MKFS_DEVTABLE_OPT)
51
52 SQUASHFS_BLOCKSIZE := $(CONFIG_TARGET_SQUASHFS_BLOCK_SIZE)k
53 SQUASHFSOPT := -b $(SQUASHFS_BLOCKSIZE)
54 SQUASHFSOPT += -p '/dev d 755 0 0' -p '/dev/console c 600 0 0 5 1'
55 SQUASHFSCOMP := gzip
56 LZMA_XZ_OPTIONS := -Xpreset 9 -Xe -Xlc 0 -Xlp 2 -Xpb 2
57 ifeq ($(CONFIG_SQUASHFS_LZMA),y)
58 SQUASHFSCOMP := lzma $(LZMA_XZ_OPTIONS)
59 endif
60 ifeq ($(CONFIG_SQUASHFS_XZ),y)
61 ifneq ($(filter arm x86 powerpc sparc,$(LINUX_KARCH)),)
62 BCJ_FILTER:=-Xbcj $(LINUX_KARCH)
63 endif
64 SQUASHFSCOMP := xz $(LZMA_XZ_OPTIONS) $(BCJ_FILTER)
65 endif
66
67 JFFS2_BLOCKSIZE ?= 64k 128k
68
69 fs-types-$(CONFIG_TARGET_ROOTFS_SQUASHFS) += squashfs
70 fs-types-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addprefix jffs2-,$(JFFS2_BLOCKSIZE))
71 fs-types-$(CONFIG_TARGET_ROOTFS_JFFS2_NAND) += $(addprefix jffs2-nand-,$(NAND_BLOCKSIZE))
72 fs-types-$(CONFIG_TARGET_ROOTFS_EXT4FS) += ext4
73 fs-types-$(CONFIG_TARGET_ROOTFS_ISO) += iso
74 fs-subtypes-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addsuffix -raw,$(addprefix jffs2-,$(JFFS2_BLOCKSIZE)))
75 fs-subtypes-$(CONFIG_TARGET_ROOTFS_CPIOGZ) += cpiogz
76 fs-subtypes-$(CONFIG_TARGET_ROOTFS_TARGZ) += targz
77
78 TARGET_FILESYSTEMS := $(fs-types-y)
79
80 FS_64K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-64k
81 FS_128K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-128k
82 FS_256K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-256k
83
84 define add_jffs2_mark
85 echo -ne '\xde\xad\xc0\xde' >> $(1)
86 endef
87
88 define toupper
89 $(shell echo $(1) | tr '[:lower:]' '[:upper:]')
90 endef
91
92 define split_args
93 $(foreach data, \
94 $(subst |,$(space),\
95 $(subst $(space),^,$(1))), \
96 $(call $(2),$(strip $(subst ^,$(space),$(data)))))
97 endef
98
99 define build_cmd
100 $(if $(Build/$(word 1,$(1))),,$(error Missing Build/$(word 1,$(1))))
101 $(call Build/$(word 1,$(1)),$(wordlist 2,$(words $(1)),$(1)))
102
103 endef
104
105 define concat_cmd
106 $(call split_args,$(1),build_cmd)
107 endef
108
109 # pad to 4k, 8k, 16k, 64k, 128k, 256k and add jffs2 end-of-filesystem mark
110 define prepare_generic_squashfs
111 $(STAGING_DIR_HOST)/bin/padjffs2 $(1) 4 8 16 64 128 256
112 endef
113
114 define Image/BuildKernel/Initramfs
115 $(call Image/Build/Initramfs)
116 endef
117
118 define Image/BuildKernel/MkuImage
119 mkimage -A $(ARCH) -O linux -T kernel -C $(1) -a $(2) -e $(3) \
120 -n '$(call toupper,$(ARCH)) OpenWrt Linux-$(LINUX_VERSION)' -d $(4) $(5)
121 endef
122
123 define Image/BuildKernel/MkFIT
124 $(TOPDIR)/scripts/mkits.sh \
125 -D $(1) -o $(KDIR)/fit-$(1).its -k $(2) $(if $(3),-d $(3)) -C $(4) -a $(5) -e $(6) \
126 -A $(ARCH) -v $(LINUX_VERSION)
127 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $(KDIR)/fit-$(1).its $(KDIR)/fit-$(1)$(7).itb
128 endef
129
130 # $(1) source dts file
131 # $(2) target dtb file
132 # $(3) extra CPP flags
133 # $(4) extra DTC flags
134 define Image/BuildDTB
135 $(CPP) -nostdinc -x assembler-with-cpp \
136 -I$(LINUX_DIR)/arch/$(ARCH)/boot/dts \
137 -I$(LINUX_DIR)/arch/$(ARCH)/boot/dts/include \
138 -undef -D__DTS__ $(3) \
139 -o $(2).tmp $(1)
140 $(LINUX_DIR)/scripts/dtc/dtc -O dtb \
141 -i$(dir $(1)) $(4) \
142 -o $(2) $(2).tmp
143 $(RM) $(2).tmp
144 endef
145
146 define Image/mkfs/jffs2/sub
147 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 $(3) --pad -e $(patsubst %k,%KiB,$(1)) -o $(KDIR)/root.jffs2-$(2) -d $(TARGET_DIR) -v 2>&1 1>/dev/null | awk '/^.+$$$$/'
148 $(call add_jffs2_mark,$(KDIR)/root.jffs2-$(2))
149 endef
150
151 define Image/mkfs/jffs2/sub-raw
152 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 $(3) -e $(patsubst %k,%KiB,$(1)) -o $(KDIR)/root.jffs2-$(2)-raw -d $(TARGET_DIR) -v 2>&1 1>/dev/null | awk '/^.+$$$$/'
153 endef
154
155 define Image/mkfs/jffs2/template
156 Image/mkfs/jffs2-$(1) = $$(call Image/mkfs/jffs2/sub,$(1),$(1),$(JFFS2OPTS))
157 Image/mkfs/jffs2-$(1)-raw = $$(call Image/mkfs/jffs2/sub-raw,$(1),$(1),$(JFFS2OPTS))
158
159 endef
160
161 define Image/mkfs/jffs2-nand/template
162 Image/mkfs/jffs2-nand-$(1) = \
163 $$(call Image/mkfs/jffs2/sub, \
164 $(word 2,$(subst -, ,$(1))),nand-$(1), \
165 $(JFFS2OPTS) --no-cleanmarkers --pagesize=$(word 1,$(subst -, ,$(1))))
166
167 endef
168
169 $(eval $(foreach S,$(JFFS2_BLOCKSIZE),$(call Image/mkfs/jffs2/template,$(S))))
170 $(eval $(foreach S,$(NAND_BLOCKSIZE),$(call Image/mkfs/jffs2-nand/template,$(S))))
171
172 define Image/mkfs/squashfs
173 $(STAGING_DIR_HOST)/bin/mksquashfs4 $(TARGET_DIR) $(KDIR)/root.squashfs -nopad -noappend -root-owned -comp $(SQUASHFSCOMP) $(SQUASHFSOPT) -processors $(if $(CONFIG_PKG_BUILD_JOBS),$(CONFIG_PKG_BUILD_JOBS),1)
174 endef
175
176 # $(1): board name
177 # $(2): rootfs type
178 # $(3): kernel image
179 ifneq ($(CONFIG_NAND_SUPPORT),)
180 define Image/Build/SysupgradeNAND
181 mkdir -p "$(KDIR_TMP)/sysupgrade-$(1)/"
182 echo "BOARD=$(1)" > "$(KDIR_TMP)/sysupgrade-$(1)/CONTROL"
183 [ -z "$(2)" ] || $(CP) "$(KDIR)/root.$(2)" "$(KDIR_TMP)/sysupgrade-$(1)/root"
184 [ -z "$(3)" ] || $(CP) "$(3)" "$(KDIR_TMP)/sysupgrade-$(1)/kernel"
185 (cd "$(KDIR_TMP)"; $(TAR) cvf \
186 "$(BIN_DIR)/$(IMG_PREFIX)-$(1)-$(2)-sysupgrade.tar" sysupgrade-$(1))
187 endef
188
189 # $(1) board name
190 # $(2) ubinize-image options (e.g. --uboot-env and/or --kernel kernelimage)
191 # $(3) rootfstype (e.g. squashfs or ubifs)
192 # $(4) options to pass-through to ubinize (i.e. $($(PROFILE)_UBI_OPTS)))
193 define Image/Build/UbinizeImage
194 sh $(TOPDIR)/scripts/ubinize-image.sh $(2) \
195 "$(KDIR)/root.$(3)" \
196 "$(KDIR)/$(IMG_PREFIX)-$(1)-$(3)-ubinized.bin" \
197 $(4)
198 endef
199
200 endif
201
202 ifneq ($(CONFIG_TARGET_ROOTFS_UBIFS),)
203 define Image/mkfs/ubifs/generate
204 $(CP) ./ubinize$(1).cfg $(KDIR)
205 ( cd $(KDIR); \
206 $(STAGING_DIR_HOST)/bin/ubinize \
207 $(if $($(PROFILE)_UBI_OPTS), \
208 $(shell echo $($(PROFILE)_UBI_OPTS)), \
209 $(shell echo $(UBI_OPTS)) \
210 ) \
211 -o $(KDIR)/root$(1).ubi \
212 ubinize$(1).cfg \
213 )
214 endef
215
216 define Image/mkfs/ubifs
217
218 ifneq ($($(PROFILE)_UBIFS_OPTS)$(UBIFS_OPTS),)
219 $(STAGING_DIR_HOST)/bin/mkfs.ubifs \
220 $(if $($(PROFILE)_UBIFS_OPTS), \
221 $(shell echo $($(PROFILE)_UBIFS_OPTS)), \
222 $(shell echo $(UBIFS_OPTS)) \
223 ) \
224 $(if $(CONFIG_TARGET_UBIFS_FREE_SPACE_FIXUP),--space-fixup) \
225 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_NONE),--force-compr=none) \
226 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_LZO),--force-compr=lzo) \
227 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_ZLIB),--force-compr=zlib) \
228 $(if $(shell echo $(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)),--jrn-size=$(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)) \
229 --squash-uids \
230 -o $(KDIR)/root.ubifs \
231 -d $(TARGET_DIR)
232 endif
233 $(call Image/Build,ubifs)
234
235 ifneq ($($(PROFILE)_UBI_OPTS)$(UBI_OPTS),)
236 $(if $(wildcard ./ubinize.cfg),$(call Image/mkfs/ubifs/generate,))
237 $(if $(wildcard ./ubinize-overlay.cfg),$(call Image/mkfs/ubifs/generate,-overlay))
238 endif
239 $(if $(wildcard ./ubinize.cfg),$(call Image/Build,ubi))
240 endef
241 endif
242
243 define Image/mkfs/cpiogz
244 ( cd $(TARGET_DIR); find . | cpio -o -H newc | gzip -9n >$(BIN_DIR)/$(IMG_PREFIX)-rootfs.cpio.gz )
245 endef
246
247 define Image/mkfs/targz
248 $(TAR) -czpf $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE),-$(PROFILE))-rootfs.tar.gz --numeric-owner --owner=0 --group=0 --sort=name -C $(TARGET_DIR)/ .
249 endef
250
251 E2SIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_PARTSIZE)*1024*1024)))
252
253 define Image/mkfs/ext4
254 $(STAGING_DIR_HOST)/bin/make_ext4fs \
255 -l $(E2SIZE) -b $(CONFIG_TARGET_EXT4_BLOCKSIZE) \
256 -i $(CONFIG_TARGET_EXT4_MAXINODE) \
257 -m $(CONFIG_TARGET_EXT4_RESERVED_PCT) \
258 $(if $(CONFIG_TARGET_EXT4_JOURNAL),,-J) \
259 $(KDIR)/root.ext4 $(TARGET_DIR)/
260 endef
261
262 define Image/mkfs/prepare/default
263 # Use symbolic permissions to avoid clobbering SUID/SGID/sticky bits
264 - $(FIND) $(TARGET_DIR) -type f -not -perm /0100 -not -name 'ssh_host*' -not -name 'shadow' -print0 | $(XARGS) -0 chmod u+rw,g+r,o+r
265 - $(FIND) $(TARGET_DIR) -type f -perm /0100 -print0 | $(XARGS) -0 chmod u+rwx,g+rx,o+rx
266 - $(FIND) $(TARGET_DIR) -type d -print0 | $(XARGS) -0 chmod u+rwx,g+rx,o+rx
267 $(INSTALL_DIR) $(TARGET_DIR)/tmp $(TARGET_DIR)/overlay
268 chmod 1777 $(TARGET_DIR)/tmp
269 endef
270
271 define Image/mkfs/prepare
272 $(call Image/mkfs/prepare/default)
273 endef
274
275
276 define Image/Checksum
277 ( cd ${BIN_DIR} ; \
278 $(FIND) -maxdepth 1 -type f \! -name 'md5sums' -printf "%P\n" | sort | xargs $1 > $2 \
279 )
280 endef
281
282 define BuildImage/mkfs
283 install: mkfs-$(1)
284 .PHONY: mkfs-$(1)
285 mkfs-$(1): mkfs_prepare
286 $(Image/mkfs/$(1))
287 $(call Build/mkfs/default,$(1))
288 $(call Build/mkfs/$(1),$(1))
289 $(KDIR)/root.$(1): mkfs-$(1)
290
291 endef
292
293 # Build commands that can be called from Device/* templates
294 define Build/uImage
295 mkimage -A $(LINUX_KARCH) \
296 -O linux -T kernel \
297 -C $(1) -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
298 -n '$(call toupper,$(LINUX_KARCH)) OpenWrt Linux-$(LINUX_VERSION)' -d $@ $@.new
299 @mv $@.new $@
300 endef
301
302 define Build/netgear-chk
303 $(STAGING_DIR_HOST)/bin/mkchkimg \
304 -o $@.new \
305 -k $@ \
306 -b $(NETGEAR_BOARD_ID) \
307 -r $(NETGEAR_REGION)
308 mv $@.new $@
309 endef
310
311 define Build/netgear-dni
312 $(STAGING_DIR_HOST)/bin/mkdniimg \
313 -B $(NETGEAR_BOARD_ID) -v OpenWrt.$(REVISION) \
314 $(if $(NETGEAR_HW_ID),-H $(NETGEAR_HW_ID)) \
315 -r "$(1)" \
316 -i $@ -o $@.new
317 mv $@.new $@
318 endef
319
320 define Build/fit
321 $(TOPDIR)/scripts/mkits.sh \
322 -D $(DEVICE_NAME) -o $@.its -k $@ \
323 $(if $(word 2,$(1)),-d $(word 2,$(1))) -C $(word 1,$(1)) \
324 -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
325 -A $(ARCH) -v $(LINUX_VERSION)
326 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $@.its $@.new
327 @mv $@.new $@
328 endef
329
330 define Build/lzma
331 $(STAGING_DIR_HOST)/bin/lzma e $@ -lc1 -lp2 -pb2 $(1) $@.new
332 @mv $@.new $@
333 endef
334
335 define Build/gzip
336 gzip -9n -c $@ $(1) > $@.new
337 @mv $@.new $@
338 endef
339
340 define Build/kernel-bin
341 rm -f $@
342 cp $^ $@
343 endef
344
345 define Build/patch-cmdline
346 $(STAGING_DIR_HOST)/bin/patch-cmdline $@ '$(CMDLINE)'
347 endef
348
349 define Build/append-kernel
350 dd if=$(word 1,$^) $(if $(1),bs=$(1) conv=sync) >> $@
351 endef
352
353 define Build/append-rootfs
354 dd if=$(word 2,$^) $(if $(1),bs=$(1) conv=sync) >> $@
355 endef
356
357 define Build/append-ubi
358 sh $(TOPDIR)/scripts/ubinize-image.sh \
359 $(if $(KERNEL_IN_UBI),--kernel $(word 1,$^)) \
360 $(word 2,$^) \
361 $@.tmp \
362 -p $(BLOCKSIZE) -m $(PAGESIZE) -E 5
363 cat $@.tmp >> $@
364 rm $@.tmp
365 endef
366
367 define Build/pad-to
368 dd if=$@ of=$@.new bs=$(1) conv=sync
369 mv $@.new $@
370 endef
371
372 define Build/pad-rootfs
373 $(call prepare_generic_squashfs,$@ $(1))
374 endef
375
376 define Build/pad-offset
377 let \
378 size="$$(stat -c%s $@)" \
379 pad="$(word 1, $(1))" \
380 offset="$(word 2, $(1))" \
381 pad="(pad - ((size + offset) % pad)) % pad" \
382 newsize='size + pad'; \
383 dd if=$@ of=$@.new bs=$$newsize count=1 conv=sync
384 mv $@.new $@
385 endef
386
387 define Build/check-size
388 @[ $$(($(subst k,* 1024,$(subst m, * 1024k,$(1))))) -ge "$$(stat -c%s $@)" ] || { \
389 echo "WARNING: Image file $@ is too big" >&2; \
390 rm -f $@; \
391 }
392 endef
393
394 define Build/combined-image
395 -sh $(TOPDIR)/scripts/combined-image.sh \
396 "$(word 1,$^)" \
397 "$@" \
398 "$@.new"
399 @mv $@.new $@
400 endef
401
402 define Build/sysupgrade-nand
403 sh $(TOPDIR)/scripts/sysupgrade-nand.sh \
404 --board $(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)) \
405 --kernel $(word 1,$^) \
406 --rootfs $(word 2,$^) \
407 $@
408 endef
409
410 define Device/Init
411 PROFILES := $(PROFILE)
412 DEVICE_NAME := $(1)
413 KERNEL:=
414 KERNEL_INITRAMFS = $$(KERNEL)
415 KERNEL_SIZE:=
416 CMDLINE:=
417
418 IMAGE_PREFIX := $(IMG_PREFIX)-$(1)
419 IMAGE_NAME = $$(IMAGE_PREFIX)-$$(1)-$$(2)
420 KERNEL_PREFIX = $(1)
421 KERNEL_SUFFIX := -kernel.bin
422 KERNEL_IMAGE = $$(KERNEL_PREFIX)$$(KERNEL_SUFFIX)
423 KERNEL_INITRAMFS_PREFIX = $$(IMAGE_PREFIX)-initramfs
424 KERNEL_INITRAMFS_IMAGE = $$(KERNEL_INITRAMFS_PREFIX)$$(KERNEL_SUFFIX)
425 KERNEL_INSTALL :=
426 KERNEL_NAME := vmlinux
427 KERNEL_SIZE :=
428
429 FILESYSTEMS := $(TARGET_FILESYSTEMS)
430 endef
431
432 define Device/ExportVar
433 $(1) : $(2):=$$($(2))
434
435 endef
436 define Device/Export
437 $(foreach var,$(DEVICE_VARS) DEVICE_NAME KERNEL KERNEL_INITRAMFS,$(call Device/ExportVar,$(1),$(var)))
438 $(1) : FILESYSTEM:=$(2)
439 endef
440
441 define Device/Check
442 _TARGET = $$(if $$(filter $(PROFILE),$$(PROFILES)),install,install-disabled)
443 _COMPILE_TARGET = $$(if $(if $(IB),,$(CONFIG_IB)$$(filter $(PROFILE),$$(PROFILES))),compile,compile-disabled)
444 endef
445
446 ifndef IB
447 define Device/Build/initramfs
448 $(call Device/Export,$(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE),$(1))
449 $$(_TARGET): $(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE)
450
451 $(KDIR)/$$(KERNEL_NAME)-initramfs: image_prepare
452 $(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE)
453 cp $$^ $$@
454
455 $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/$$(KERNEL_NAME)-initramfs
456 @rm -f $$@
457 $$(call concat_cmd,$$(KERNEL_INITRAMFS))
458 endef
459 endif
460
461 define Device/Build/check_size
462 @[ $$(($(subst k,* 1024,$(subst m, * 1024k,$(1))))) -ge "$$(stat -c%s $@)" ] || { \
463 echo "WARNING: Image file $@ is too big" >&2; \
464 rm -f $@; \
465 }
466 endef
467
468 define Device/Build/compile
469 $$(_COMPILE_TARGET): $(KDIR)/$(1)
470 $(eval $(call Device/Export,$(KDIR)/$(1)))
471 $(KDIR)/$(1):
472 $$(call concat_cmd,$(COMPILE/$(1)))
473
474 endef
475
476 define Device/Build/kernel
477 _KERNEL_IMAGES += $(KDIR)/$$(KERNEL_NAME)
478 $(KDIR)/$$(KERNEL_NAME): image_prepare
479 $$(_TARGET): $$(if $$(KERNEL_INSTALL),$(BIN_DIR)/$$(KERNEL_IMAGE))
480 $(call Device/Export,$(KDIR)/$$(KERNEL_IMAGE),$(1))
481 $(BIN_DIR)/$$(KERNEL_IMAGE): $(KDIR)/$$(KERNEL_IMAGE)
482 cp $$^ $$@
483 ifndef IB
484 ifdef CONFIG_IB
485 install: $(KDIR)/$$(KERNEL_IMAGE)
486 endif
487 $(KDIR)/$$(KERNEL_IMAGE): $(KDIR)/$$(KERNEL_NAME)
488 @rm -f $$@
489 $$(call concat_cmd,$$(KERNEL))
490 $$(if $$(KERNEL_SIZE),$$(call Device/Build/check_size,$$(KERNEL_SIZE)))
491 endif
492 endef
493
494 define Device/Build/image
495 $$(_TARGET): $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
496 $(eval $(call Device/Export,$(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)),$(1)))
497 $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/$$(KERNEL_IMAGE) $(KDIR)/root.$(1)
498 @rm -f $$@
499 [ -f $$(word 1,$$^) -a -f $$(word 2,$$^) ]
500 $$(call concat_cmd,$(if $(IMAGE/$(2)/$(1)),$(IMAGE/$(2)/$(1)),$(IMAGE/$(2))))
501
502 .IGNORE: $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
503 $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
504 cp $$^ $$@
505
506 endef
507
508 define Device/Build
509 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Device/Build/initramfs,$(1)))
510 $(call Device/Build/kernel,$(1))
511
512 $$(eval $$(foreach compile,$$(COMPILE), \
513 $$(call Device/Build/compile,$$(compile),$(1))))
514
515 $$(eval $$(foreach image,$$(IMAGES), \
516 $$(foreach fs,$$(filter $(TARGET_FILESYSTEMS),$$(FILESYSTEMS)), \
517 $$(call Device/Build/image,$$(fs),$$(image),$(1)))))
518 endef
519
520 define Device
521 $(call Device/Init,$(1))
522 $(call Device/Default,$(1))
523 $(call Device/Check,$(1))
524 $(call Device/$(1),$(1))
525 $(call Device/Build,$(1))
526
527 endef
528
529 define BuildImage
530
531 download:
532 prepare:
533 compile:
534 clean:
535 image_prepare:
536
537 ifeq ($(IB),)
538 .PHONY: download prepare compile clean image_prepare mkfs_prepare kernel_prepare install
539 compile:
540 $(call Build/Compile)
541
542 clean:
543 $(call Build/Clean)
544
545 image_prepare: compile
546 mkdir -p $(KDIR)/tmp
547 $(call Image/Prepare)
548 else
549 image_prepare:
550 mkdir -p $(KDIR)/tmp
551 endif
552
553 mkfs_prepare: image_prepare
554 $(call Image/mkfs/prepare)
555
556 kernel_prepare: mkfs_prepare
557 $(call Image/BuildKernel)
558 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(if $(IB),,$(call Image/BuildKernel/Initramfs)))
559 $(call Image/InstallKernel)
560
561 $(foreach device,$(TARGET_DEVICES),$(call Device,$(device)))
562 $(foreach fs,$(TARGET_FILESYSTEMS) $(fs-subtypes-y),$(call BuildImage/mkfs,$(fs)))
563
564 $$(sort $$(_KERNEL_IMAGES)):
565 @touch $$@
566
567 install: kernel_prepare
568 $(foreach fs,$(TARGET_FILESYSTEMS),
569 $(call Image/Build,$(fs))
570 )
571 $(call Image/mkfs/ubifs)
572 $(call Image/Checksum,md5sum --binary,md5sums)
573 $(call Image/Checksum,openssl dgst -sha256,sha256sums)
574
575 endef