]> rtime.felk.cvut.cz Git - coffee/buildroot.git/blob - fs/common.mk
fs: add missing $$(sep) to pre- and post-command hooks code
[coffee/buildroot.git] / fs / common.mk
1 #
2 # Macro that builds the needed Makefile target to create a root
3 # filesystem image.
4 #
5 # The following variable must be defined before calling this macro
6 #
7 #  ROOTFS_$(FSTYPE)_CMD, the command that generates the root
8 #  filesystem image. A single command is allowed. The filename of the
9 #  filesystem image that it must generate is $$@.
10 #
11 # The following variables can optionaly be defined
12 #
13 #  ROOTFS_$(FSTYPE)_DEPENDENCIES, the list of dependencies needed to
14 #  build the root filesystem (usually host tools)
15 #
16 #  ROOTFS_$(FSTYPE)_PRE_GEN_HOOKS, a list of hooks to call before
17 #  generating the filesystem image
18 #
19 #  ROOTFS_$(FSTYPE)_POST_GEN_HOOKS, a list of hooks to call after
20 #  generating the filesystem image
21 #
22 #  ROOTFS_$(FSTYPE)_POST_TARGETS, the list of targets that should be
23 #  run after running the main filesystem target. This is useful for
24 #  initramfs, to rebuild the kernel once the initramfs is generated.
25 #
26 # In terms of configuration option, this macro assumes that the
27 # BR2_TARGET_ROOTFS_$(FSTYPE) config option allows to enable/disable
28 # the generation of a filesystem image of a particular type. If
29 # the configuration options BR2_TARGET_ROOTFS_$(FSTYPE)_GZIP,
30 # BR2_TARGET_ROOTFS_$(FSTYPE)_BZIP2 or
31 # BR2_TARGET_ROOTFS_$(FSTYPE)_LZMA exist and are enabled, then the
32 # macro will automatically generate a compressed filesystem image.
33
34 FAKEROOT_SCRIPT = $(BUILD_DIR)/_fakeroot.fs
35 FULL_DEVICE_TABLE = $(BUILD_DIR)/_device_table.txt
36 ROOTFS_DEVICE_TABLES = $(call qstrip,$(BR2_ROOTFS_DEVICE_TABLE) \
37         $(BR2_ROOTFS_STATIC_DEVICE_TABLE))
38 USERS_TABLE = $(BUILD_DIR)/_users_table.txt
39 ROOTFS_USERS_TABLES = $(call qstrip,$(BR2_ROOTFS_USERS_TABLES))
40
41 # Since this function will be called from within an $(eval ...)
42 # all variable references except the arguments must be $$-quoted.
43 define ROOTFS_TARGET_INTERNAL
44
45 # extra deps
46 ROOTFS_$(2)_DEPENDENCIES += host-fakeroot host-makedevs \
47         $$(if $$(PACKAGES_USERS)$$(ROOTFS_USERS_TABLES),host-mkpasswd)
48
49 ifeq ($$(BR2_TARGET_ROOTFS_$(2)_GZIP),y)
50 ROOTFS_$(2)_COMPRESS_EXT = .gz
51 ROOTFS_$(2)_COMPRESS_CMD = gzip -9 -c
52 endif
53 ifeq ($$(BR2_TARGET_ROOTFS_$(2)_BZIP2),y)
54 ROOTFS_$(2)_COMPRESS_EXT = .bz2
55 ROOTFS_$(2)_COMPRESS_CMD = bzip2 -9 -c
56 endif
57 ifeq ($$(BR2_TARGET_ROOTFS_$(2)_LZMA),y)
58 ROOTFS_$(2)_DEPENDENCIES += host-lzma
59 ROOTFS_$(2)_COMPRESS_EXT = .lzma
60 ROOTFS_$(2)_COMPRESS_CMD = $$(LZMA) -9 -c
61 endif
62 ifeq ($$(BR2_TARGET_ROOTFS_$(2)_LZO),y)
63 ROOTFS_$(2)_DEPENDENCIES += host-lzop
64 ROOTFS_$(2)_COMPRESS_EXT = .lzo
65 ROOTFS_$(2)_COMPRESS_CMD = $$(LZOP) -9 -c
66 endif
67 ifeq ($$(BR2_TARGET_ROOTFS_$(2)_XZ),y)
68 ROOTFS_$(2)_DEPENDENCIES += host-xz
69 ROOTFS_$(2)_COMPRESS_EXT = .xz
70 ROOTFS_$(2)_COMPRESS_CMD = xz -9 -C crc32 -c
71 endif
72
73 $$(BINARIES_DIR)/rootfs.$(1): target-finalize $$(ROOTFS_$(2)_DEPENDENCIES)
74         @$$(call MESSAGE,"Generating root filesystem image rootfs.$(1)")
75         $$(foreach hook,$$(ROOTFS_$(2)_PRE_GEN_HOOKS),$$(call $$(hook))$$(sep))
76         rm -f $$(FAKEROOT_SCRIPT)
77         rm -f $$(TARGET_DIR_WARNING_FILE)
78         rm -f $$(USERS_TABLE)
79         echo '#!/bin/sh' > $$(FAKEROOT_SCRIPT)
80         echo "set -e" >> $$(FAKEROOT_SCRIPT)
81         echo "chown -h -R 0:0 $$(TARGET_DIR)" >> $$(FAKEROOT_SCRIPT)
82 ifneq ($$(ROOTFS_USERS_TABLES),)
83         cat $$(ROOTFS_USERS_TABLES) >> $$(USERS_TABLE)
84 endif
85         $$(call PRINTF,$$(PACKAGES_USERS)) >> $$(USERS_TABLE)
86         PATH=$$(BR_PATH) $$(TOPDIR)/support/scripts/mkusers $$(USERS_TABLE) $$(TARGET_DIR) >> $$(FAKEROOT_SCRIPT)
87 ifneq ($$(ROOTFS_DEVICE_TABLES),)
88         cat $$(ROOTFS_DEVICE_TABLES) > $$(FULL_DEVICE_TABLE)
89 ifeq ($$(BR2_ROOTFS_DEVICE_CREATION_STATIC),y)
90         $$(call PRINTF,$$(PACKAGES_DEVICES_TABLE)) >> $$(FULL_DEVICE_TABLE)
91 endif
92 endif
93         $$(call PRINTF,$$(PACKAGES_PERMISSIONS_TABLE)) >> $$(FULL_DEVICE_TABLE)
94         echo "$$(HOST_DIR)/bin/makedevs -d $$(FULL_DEVICE_TABLE) $$(TARGET_DIR)" >> $$(FAKEROOT_SCRIPT)
95         $$(foreach s,$$(call qstrip,$$(BR2_ROOTFS_POST_FAKEROOT_SCRIPT)),\
96                 echo "echo '$$(TERM_BOLD)>>>   Executing fakeroot script $$(s)$$(TERM_RESET)'" >> $$(FAKEROOT_SCRIPT); \
97                 echo $$(s) $$(TARGET_DIR) $$(BR2_ROOTFS_POST_SCRIPT_ARGS) >> $$(FAKEROOT_SCRIPT)$$(sep))
98         $$(foreach hook,$$(ROOTFS_PRE_CMD_HOOKS),\
99                 $$(call PRINTF,$$($$(hook))) >> $$(FAKEROOT_SCRIPT)$$(sep))
100 ifeq ($$(BR2_REPRODUCIBLE),y)
101         echo "find $$(TARGET_DIR) -print0 | xargs -0 -r touch -hd @$$(SOURCE_DATE_EPOCH)" >> $$(FAKEROOT_SCRIPT)
102 endif
103         $$(call PRINTF,$$(ROOTFS_$(2)_CMD)) >> $$(FAKEROOT_SCRIPT)
104         $$(foreach hook,$$(ROOTFS_POST_CMD_HOOKS),\
105                 $$(call PRINTF,$$($$(hook))) >> $$(FAKEROOT_SCRIPT)$$(sep))
106         chmod a+x $$(FAKEROOT_SCRIPT)
107         PATH=$$(BR_PATH) $$(HOST_DIR)/bin/fakeroot -- $$(FAKEROOT_SCRIPT)
108         $$(INSTALL) -m 0644 support/misc/target-dir-warning.txt $$(TARGET_DIR_WARNING_FILE)
109         -@rm -f $$(FAKEROOT_SCRIPT) $$(FULL_DEVICE_TABLE)
110 ifneq ($$(ROOTFS_$(2)_COMPRESS_CMD),)
111         PATH=$$(BR_PATH) $$(ROOTFS_$(2)_COMPRESS_CMD) $$@ > $$@$$(ROOTFS_$(2)_COMPRESS_EXT)
112 endif
113         $$(foreach hook,$$(ROOTFS_$(2)_POST_GEN_HOOKS),$$(call $$(hook))$$(sep))
114
115 rootfs-$(1)-show-depends:
116         @echo $$(ROOTFS_$(2)_DEPENDENCIES)
117
118 rootfs-$(1): $$(BINARIES_DIR)/rootfs.$(1) $$(ROOTFS_$(2)_POST_TARGETS)
119
120 .PHONY: rootfs-$(1) rootfs-$(1)-show-depends
121
122 ifeq ($$(BR2_TARGET_ROOTFS_$(2)),y)
123 TARGETS_ROOTFS += rootfs-$(1)
124 PACKAGES += $$(filter-out rootfs-%,$$(ROOTFS_$(2)_DEPENDENCIES))
125 endif
126 endef
127
128 define ROOTFS_TARGET
129         $(call ROOTFS_TARGET_INTERNAL,$(1),$(call UPPERCASE,$(1)))
130 endef
131
132 include $(sort $(wildcard fs/*/*.mk))