2 # Macro that builds the needed Makefile target to create a root
5 # The following variable must be defined before calling this macro
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 $$@.
11 # The following variables can optionaly be defined
13 # ROOTFS_$(FSTYPE)_DEPENDENCIES, the list of dependencies needed to
14 # build the root filesystem (usually host tools)
16 # ROOTFS_$(FSTYPE)_PRE_GEN_HOOKS, a list of hooks to call before
17 # generating the filesystem image
19 # ROOTFS_$(FSTYPE)_POST_GEN_HOOKS, a list of hooks to call after
20 # generating the filesystem image
22 # In terms of configuration option, this macro assumes that the
23 # BR2_TARGET_ROOTFS_$(FSTYPE) config option allows to enable/disable
24 # the generation of a filesystem image of a particular type. If
25 # the configuration options BR2_TARGET_ROOTFS_$(FSTYPE)_GZIP,
26 # BR2_TARGET_ROOTFS_$(FSTYPE)_BZIP2 or
27 # BR2_TARGET_ROOTFS_$(FSTYPE)_LZMA exist and are enabled, then the
28 # macro will automatically generate a compressed filesystem image.
30 FS_DIR = $(BUILD_DIR)/buildroot-fs
31 FULL_DEVICE_TABLE = $(FS_DIR)/device_table.txt
32 ROOTFS_DEVICE_TABLES = $(call qstrip,$(BR2_ROOTFS_DEVICE_TABLE) \
33 $(BR2_ROOTFS_STATIC_DEVICE_TABLE))
34 USERS_TABLE = $(FS_DIR)/users_table.txt
35 ROOTFS_USERS_TABLES = $(call qstrip,$(BR2_ROOTFS_USERS_TABLES))
37 # Since this function will be called from within an $(eval ...)
38 # all variable references except the arguments must be $$-quoted.
41 ROOTFS_$(2)_DIR = $$(FS_DIR)/$(1)
42 ROOTFS_$(2)_TARGET_DIR = $$(BASE_TARGET_DIR)
45 ROOTFS_$(2)_DEPENDENCIES += host-fakeroot host-makedevs \
46 $$(if $$(PACKAGES_USERS)$$(ROOTFS_USERS_TABLES),host-mkpasswd)
48 ifeq ($$(BR2_TARGET_ROOTFS_$(2)_GZIP),y)
49 ROOTFS_$(2)_COMPRESS_EXT = .gz
50 ROOTFS_$(2)_COMPRESS_CMD = gzip -9 -c
52 ifeq ($$(BR2_TARGET_ROOTFS_$(2)_BZIP2),y)
53 ROOTFS_$(2)_COMPRESS_EXT = .bz2
54 ROOTFS_$(2)_COMPRESS_CMD = bzip2 -9 -c
56 ifeq ($$(BR2_TARGET_ROOTFS_$(2)_LZMA),y)
57 ROOTFS_$(2)_DEPENDENCIES += host-lzma
58 ROOTFS_$(2)_COMPRESS_EXT = .lzma
59 ROOTFS_$(2)_COMPRESS_CMD = $$(LZMA) -9 -c
61 ifeq ($$(BR2_TARGET_ROOTFS_$(2)_LZ4),y)
62 ROOTFS_$(2)_DEPENDENCIES += host-lz4
63 ROOTFS_$(2)_COMPRESS_EXT = .lz4
64 ROOTFS_$(2)_COMPRESS_CMD = lz4 -l -9 -c
66 ifeq ($$(BR2_TARGET_ROOTFS_$(2)_LZO),y)
67 ROOTFS_$(2)_DEPENDENCIES += host-lzop
68 ROOTFS_$(2)_COMPRESS_EXT = .lzo
69 ROOTFS_$(2)_COMPRESS_CMD = $$(LZOP) -9 -c
71 ifeq ($$(BR2_TARGET_ROOTFS_$(2)_XZ),y)
72 ROOTFS_$(2)_DEPENDENCIES += host-xz
73 ROOTFS_$(2)_COMPRESS_EXT = .xz
74 ROOTFS_$(2)_COMPRESS_CMD = xz -9 -C crc32 -c
77 $$(BINARIES_DIR)/rootfs.$(1): ROOTFS=$(2)
78 $$(BINARIES_DIR)/rootfs.$(1): FAKEROOT_SCRIPT=$$(ROOTFS_$(2)_DIR)/fakeroot
79 $$(BINARIES_DIR)/rootfs.$(1): target-finalize
80 $$(BINARIES_DIR)/rootfs.$(1): $$(ROOTFS_$(2)_DEPENDENCIES)
81 @$$(call MESSAGE,"Generating root filesystem image rootfs.$(1)")
82 rm -rf $(FS_DIR) $$(ROOTFS_$(2)_DIR)
83 mkdir -p $(FS_DIR) $$(ROOTFS_$(2)_DIR)
84 echo '#!/bin/sh' > $$(FAKEROOT_SCRIPT)
85 echo "set -e" >> $$(FAKEROOT_SCRIPT)
86 $$(foreach hook,$$(ROOTFS_$(2)_PRE_GEN_HOOKS),\
87 $$(call PRINTF,$$($$(hook))) >> $$(FAKEROOT_SCRIPT)$$(sep))
88 echo "chown -h -R 0:0 $$(TARGET_DIR)" >> $$(FAKEROOT_SCRIPT)
89 ifneq ($$(ROOTFS_USERS_TABLES),)
90 cat $$(ROOTFS_USERS_TABLES) >> $$(USERS_TABLE)
92 $$(call PRINTF,$$(PACKAGES_USERS)) >> $$(USERS_TABLE)
93 PATH=$$(BR_PATH) $$(TOPDIR)/support/scripts/mkusers $$(USERS_TABLE) $$(TARGET_DIR) >> $$(FAKEROOT_SCRIPT)
94 ifneq ($$(ROOTFS_DEVICE_TABLES),)
95 cat $$(ROOTFS_DEVICE_TABLES) > $$(FULL_DEVICE_TABLE)
96 ifeq ($$(BR2_ROOTFS_DEVICE_CREATION_STATIC),y)
97 $$(call PRINTF,$$(PACKAGES_DEVICES_TABLE)) >> $$(FULL_DEVICE_TABLE)
100 $$(call PRINTF,$$(PACKAGES_PERMISSIONS_TABLE)) >> $$(FULL_DEVICE_TABLE)
101 echo "$$(HOST_DIR)/bin/makedevs -d $$(FULL_DEVICE_TABLE) $$(TARGET_DIR)" >> $$(FAKEROOT_SCRIPT)
102 $$(foreach s,$$(call qstrip,$$(BR2_ROOTFS_POST_FAKEROOT_SCRIPT)),\
103 echo "echo '$$(TERM_BOLD)>>> Executing fakeroot script $$(s)$$(TERM_RESET)'" >> $$(FAKEROOT_SCRIPT); \
104 echo $$(EXTRA_ENV) $$(s) $$(TARGET_DIR) $$(BR2_ROOTFS_POST_SCRIPT_ARGS) >> $$(FAKEROOT_SCRIPT)$$(sep))
105 $$(foreach hook,$$(ROOTFS_PRE_CMD_HOOKS),\
106 $$(call PRINTF,$$($$(hook))) >> $$(FAKEROOT_SCRIPT)$$(sep))
107 ifeq ($$(BR2_REPRODUCIBLE),y)
108 echo "find $$(TARGET_DIR) -print0 | xargs -0 -r touch -hd @$$(SOURCE_DATE_EPOCH)" >> $$(FAKEROOT_SCRIPT)
110 $$(call PRINTF,$$(ROOTFS_$(2)_CMD)) >> $$(FAKEROOT_SCRIPT)
111 $$(foreach hook,$$(ROOTFS_POST_CMD_HOOKS),\
112 $$(call PRINTF,$$($$(hook))) >> $$(FAKEROOT_SCRIPT)$$(sep))
113 chmod a+x $$(FAKEROOT_SCRIPT)
114 rm -f $$(TARGET_DIR_WARNING_FILE)
115 PATH=$$(BR_PATH) $$(HOST_DIR)/bin/fakeroot -- $$(FAKEROOT_SCRIPT)
116 $$(INSTALL) -m 0644 support/misc/target-dir-warning.txt $$(TARGET_DIR_WARNING_FILE)
117 ifneq ($$(ROOTFS_$(2)_COMPRESS_CMD),)
118 PATH=$$(BR_PATH) $$(ROOTFS_$(2)_COMPRESS_CMD) $$@ > $$@$$(ROOTFS_$(2)_COMPRESS_EXT)
120 $$(foreach hook,$$(ROOTFS_$(2)_POST_GEN_HOOKS),$$(call $$(hook))$$(sep))
122 rootfs-$(1)-show-depends:
123 @echo $$(ROOTFS_$(2)_DEPENDENCIES)
125 rootfs-$(1): $$(BINARIES_DIR)/rootfs.$(1)
127 .PHONY: rootfs-$(1) rootfs-$(1)-show-depends
129 ifeq ($$(BR2_TARGET_ROOTFS_$(2)),y)
130 TARGETS_ROOTFS += rootfs-$(1)
131 PACKAGES += $$(filter-out rootfs-%,$$(ROOTFS_$(2)_DEPENDENCIES))
134 # Check for legacy POST_TARGETS rules
135 ifneq ($$(ROOTFS_$(2)_POST_TARGETS),)
136 $$(error Filesystem $(1) uses post-target rules, which are no longer supported.\
137 Update $(1) to use post-gen hooks instead)
142 # $(pkgname) also works well to return the filesystem name
143 rootfs = $(call inner-rootfs,$(pkgname),$(call UPPERCASE,$(pkgname)))
145 include $(sort $(wildcard fs/*/*.mk))