]>
Commit | Line | Data |
---|---|---|
21f3bcc1 TP |
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 | # | |
15a53b93 TP |
19 | # ROOTFS_$(FSTYPE)_POST_GEN_HOOKS, a list of hooks to call after |
20 | # generating the filesystem image | |
21 | # | |
21f3bcc1 TP |
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 | |
b2dcb2d6 | 25 | # the configuration options BR2_TARGET_ROOTFS_$(FSTYPE)_GZIP, |
21f3bcc1 TP |
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. | |
29 | ||
917508e6 | 30 | FS_DIR = $(BUILD_DIR)/buildroot-fs |
402d1476 | 31 | ROOTFS_DEVICE_TABLES = $(call qstrip,$(BR2_ROOTFS_DEVICE_TABLE) \ |
1769933d | 32 | $(BR2_ROOTFS_STATIC_DEVICE_TABLE)) |
6b50f988 | 33 | |
b019490a | 34 | ROOTFS_USERS_TABLES = $(call qstrip,$(BR2_ROOTFS_USERS_TABLES)) |
21f3bcc1 | 35 | |
93434aed | 36 | ROOTFS_FULL_DEVICES_TABLE = $(FS_DIR)/full_devices_table.txt |
6b50f988 YM |
37 | ROOTFS_FULL_USERS_TABLE = $(FS_DIR)/full_users_table.txt |
38 | ||
4d83c723 YM |
39 | ROOTFS_COMMON_NAME = rootfs-common |
40 | ROOTFS_COMMON_TYPE = rootfs | |
98d1e7f9 YM |
41 | ROOTFS_COMMON_DEPENDENCIES = \ |
42 | host-fakeroot host-makedevs \ | |
89c92487 | 43 | $(BR2_TAR_HOST_DEPENDENCY) \ |
98d1e7f9 YM |
44 | $(if $(PACKAGES_USERS)$(ROOTFS_USERS_TABLES),host-mkpasswd) |
45 | ||
b0f3d229 AT |
46 | ifeq ($(BR2_REPRODUCIBLE),y) |
47 | define ROOTFS_REPRODUCIBLE | |
48 | find $(TARGET_DIR) -print0 | xargs -0 -r touch -hd @$(SOURCE_DATE_EPOCH) | |
49 | endef | |
50 | endif | |
51 | ||
b843d781 AT |
52 | ifeq ($(BR2_PACKAGE_REFPOLICY),y) |
53 | define ROOTFS_SELINUX | |
54 | $(HOST_DIR)/sbin/setfiles -m -r $(TARGET_DIR) \ | |
55 | -c $(TARGET_DIR)/etc/selinux/targeted/policy/policy.$(BR2_PACKAGE_LIBSEPOL_POLICY_VERSION) \ | |
56 | $(TARGET_DIR)/etc/selinux/targeted/contexts/files/file_contexts \ | |
57 | $(TARGET_DIR) | |
58 | endef | |
59 | ROOTFS_COMMON_DEPENDENCIES += host-policycoreutils | |
60 | endif | |
61 | ||
d62e46ac YM |
62 | ROOTFS_COMMON_FINAL_RECURSIVE_DEPENDENCIES = $(sort \ |
63 | $(if $(filter undefined,$(origin ROOTFS_COMMON_FINAL_RECURSIVE_DEPENDENCIES__X)), \ | |
64 | $(eval ROOTFS_COMMON_FINAL_RECURSIVE_DEPENDENCIES__X := \ | |
65 | $(foreach p, \ | |
66 | $(ROOTFS_COMMON_DEPENDENCIES), \ | |
67 | $(p) \ | |
68 | $($(call UPPERCASE,$(p))_FINAL_RECURSIVE_DEPENDENCIES) \ | |
69 | ) \ | |
70 | ) \ | |
71 | ) \ | |
72 | $(ROOTFS_COMMON_FINAL_RECURSIVE_DEPENDENCIES__X)) | |
73 | ||
409d4c3f YM |
74 | .PHONY: rootfs-common |
75 | rootfs-common: $(ROOTFS_COMMON_DEPENDENCIES) target-finalize | |
76 | @$(call MESSAGE,"Generating root filesystems common tables") | |
118534fe YM |
77 | rm -rf $(FS_DIR) |
78 | mkdir -p $(FS_DIR) | |
c3edec00 | 79 | |
6b50f988 | 80 | $(call PRINTF,$(PACKAGES_USERS)) >> $(ROOTFS_FULL_USERS_TABLE) |
118534fe | 81 | ifneq ($(ROOTFS_USERS_TABLES),) |
6b50f988 | 82 | cat $(ROOTFS_USERS_TABLES) >> $(ROOTFS_FULL_USERS_TABLE) |
118534fe | 83 | endif |
b67f0a99 YM |
84 | |
85 | $(call PRINTF,$(PACKAGES_PERMISSIONS_TABLE)) > $(ROOTFS_FULL_DEVICES_TABLE) | |
118534fe | 86 | ifneq ($(ROOTFS_DEVICE_TABLES),) |
b67f0a99 | 87 | cat $(ROOTFS_DEVICE_TABLES) >> $(ROOTFS_FULL_DEVICES_TABLE) |
ac3b476b | 88 | endif |
118534fe | 89 | ifeq ($(BR2_ROOTFS_DEVICE_CREATION_STATIC),y) |
93434aed | 90 | $(call PRINTF,$(PACKAGES_DEVICES_TABLE)) >> $(ROOTFS_FULL_DEVICES_TABLE) |
118534fe | 91 | endif |
98d1e7f9 YM |
92 | |
93 | rootfs-common-show-depends: | |
94 | @echo $(ROOTFS_COMMON_DEPENDENCIES) | |
95 | ||
5abb8821 YM |
96 | .PHONY: rootfs-common-show-info |
97 | rootfs-common-show-info: | |
98 | @: | |
99 | $(info $(call clean-json,{ $(call json-info,ROOTFS_COMMON) })) | |
100 | ||
54456cc6 TDS |
101 | # Since this function will be called from within an $(eval ...) |
102 | # all variable references except the arguments must be $$-quoted. | |
b6842c40 | 103 | define inner-rootfs |
21f3bcc1 | 104 | |
4d83c723 YM |
105 | ROOTFS_$(2)_NAME = rootfs-$(1) |
106 | ROOTFS_$(2)_TYPE = rootfs | |
21c6fb25 CS |
107 | ROOTFS_$(2)_IMAGE_NAME ?= rootfs.$(1) |
108 | ROOTFS_$(2)_FINAL_IMAGE_NAME = $$(strip $$(ROOTFS_$(2)_IMAGE_NAME)) | |
0c7adf75 | 109 | ROOTFS_$(2)_DIR = $$(FS_DIR)/$(1) |
118534fe | 110 | ROOTFS_$(2)_TARGET_DIR = $$(ROOTFS_$(2)_DIR)/target |
0c7adf75 | 111 | |
98d1e7f9 | 112 | ROOTFS_$(2)_DEPENDENCIES += rootfs-common |
bd8ef7a0 | 113 | |
d62e46ac YM |
114 | ROOTFS_$(2)_FINAL_RECURSIVE_DEPENDENCIES = $$(sort \ |
115 | $$(if $$(filter undefined,$$(origin ROOTFS_$(2)_FINAL_RECURSIVE_DEPENDENCIES__X)), \ | |
116 | $$(eval ROOTFS_$(2)_FINAL_RECURSIVE_DEPENDENCIES__X := \ | |
117 | $$(foreach p, \ | |
118 | $$(ROOTFS_$(2)_DEPENDENCIES), \ | |
119 | $$(p) \ | |
120 | $$($$(call UPPERCASE,$$(p))_FINAL_RECURSIVE_DEPENDENCIES) \ | |
121 | ) \ | |
122 | ) \ | |
123 | ) \ | |
124 | $$(ROOTFS_$(2)_FINAL_RECURSIVE_DEPENDENCIES__X)) | |
125 | ||
bd8ef7a0 AV |
126 | ifeq ($$(BR2_TARGET_ROOTFS_$(2)_GZIP),y) |
127 | ROOTFS_$(2)_COMPRESS_EXT = .gz | |
44d17dd1 | 128 | ROOTFS_$(2)_COMPRESS_CMD = gzip -9 -c -n |
bd8ef7a0 AV |
129 | endif |
130 | ifeq ($$(BR2_TARGET_ROOTFS_$(2)_BZIP2),y) | |
131 | ROOTFS_$(2)_COMPRESS_EXT = .bz2 | |
132 | ROOTFS_$(2)_COMPRESS_CMD = bzip2 -9 -c | |
133 | endif | |
134 | ifeq ($$(BR2_TARGET_ROOTFS_$(2)_LZMA),y) | |
135 | ROOTFS_$(2)_DEPENDENCIES += host-lzma | |
136 | ROOTFS_$(2)_COMPRESS_EXT = .lzma | |
137 | ROOTFS_$(2)_COMPRESS_CMD = $$(LZMA) -9 -c | |
138 | endif | |
51fa8d8e PK |
139 | ifeq ($$(BR2_TARGET_ROOTFS_$(2)_LZ4),y) |
140 | ROOTFS_$(2)_DEPENDENCIES += host-lz4 | |
141 | ROOTFS_$(2)_COMPRESS_EXT = .lz4 | |
142 | ROOTFS_$(2)_COMPRESS_CMD = lz4 -l -9 -c | |
143 | endif | |
bd8ef7a0 AV |
144 | ifeq ($$(BR2_TARGET_ROOTFS_$(2)_LZO),y) |
145 | ROOTFS_$(2)_DEPENDENCIES += host-lzop | |
146 | ROOTFS_$(2)_COMPRESS_EXT = .lzo | |
147 | ROOTFS_$(2)_COMPRESS_CMD = $$(LZOP) -9 -c | |
148 | endif | |
149 | ifeq ($$(BR2_TARGET_ROOTFS_$(2)_XZ),y) | |
26e0d500 | 150 | ROOTFS_$(2)_DEPENDENCIES += host-xz |
bd8ef7a0 | 151 | ROOTFS_$(2)_COMPRESS_EXT = .xz |
28b514a5 | 152 | ROOTFS_$(2)_COMPRESS_CMD = xz -9 -C crc32 -c |
36fb6d17 JH |
153 | ifeq ($(BR2_REPRODUCIBLE),) |
154 | ROOTFS_$(2)_COMPRESS_CMD += -T $(PARALLEL_JOBS) | |
155 | endif | |
bd8ef7a0 | 156 | endif |
b7179520 JLSR |
157 | ifeq ($(BR2_TARGET_ROOTFS_$(2)_ZSTD),y) |
158 | ROOTFS_$(2)_DEPENDENCIES += host-zstd | |
159 | ROOTFS_$(2)_COMPRESS_EXT = .zst | |
160 | ROOTFS_$(2)_COMPRESS_CMD = zstd -19 -z -f -T$(PARALLEL_JOBS) | |
161 | endif | |
094b2938 | 162 | |
21c6fb25 CS |
163 | $$(BINARIES_DIR)/$$(ROOTFS_$(2)_FINAL_IMAGE_NAME): ROOTFS=$(2) |
164 | $$(BINARIES_DIR)/$$(ROOTFS_$(2)_FINAL_IMAGE_NAME): FAKEROOT_SCRIPT=$$(ROOTFS_$(2)_DIR)/fakeroot | |
165 | $$(BINARIES_DIR)/$$(ROOTFS_$(2)_FINAL_IMAGE_NAME): $$(ROOTFS_$(2)_DEPENDENCIES) | |
166 | @$$(call MESSAGE,"Generating filesystem image $$(ROOTFS_$(2)_FINAL_IMAGE_NAME)") | |
d0f4f95e | 167 | mkdir -p $$(@D) |
118534fe YM |
168 | rm -rf $$(ROOTFS_$(2)_DIR) |
169 | mkdir -p $$(ROOTFS_$(2)_DIR) | |
409d4c3f YM |
170 | rsync -auH \ |
171 | --exclude=/$$(notdir $$(TARGET_DIR_WARNING_FILE)) \ | |
172 | $$(BASE_TARGET_DIR)/ \ | |
173 | $$(TARGET_DIR) | |
174 | ||
974e83a8 | 175 | echo '#!/bin/sh' > $$(FAKEROOT_SCRIPT) |
6b577b3c | 176 | echo "set -e" >> $$(FAKEROOT_SCRIPT) |
409d4c3f YM |
177 | |
178 | echo "chown -h -R 0:0 $$(TARGET_DIR)" >> $$(FAKEROOT_SCRIPT) | |
6b50f988 | 179 | PATH=$$(BR_PATH) $$(TOPDIR)/support/scripts/mkusers $$(ROOTFS_FULL_USERS_TABLE) $$(TARGET_DIR) >> $$(FAKEROOT_SCRIPT) |
93434aed | 180 | echo "$$(HOST_DIR)/bin/makedevs -d $$(ROOTFS_FULL_DEVICES_TABLE) $$(TARGET_DIR)" >> $$(FAKEROOT_SCRIPT) |
4bc4dbd6 CH |
181 | $$(foreach hook,$$(ROOTFS_PRE_CMD_HOOKS),\ |
182 | $$(call PRINTF,$$($$(hook))) >> $$(FAKEROOT_SCRIPT)$$(sep)) | |
409d4c3f YM |
183 | $$(foreach s,$$(call qstrip,$$(BR2_ROOTFS_POST_FAKEROOT_SCRIPT)),\ |
184 | echo "echo '$$(TERM_BOLD)>>> Executing fakeroot script $$(s)$$(TERM_RESET)'" >> $$(FAKEROOT_SCRIPT); \ | |
185 | echo $$(EXTRA_ENV) $$(s) $$(TARGET_DIR) $$(BR2_ROOTFS_POST_SCRIPT_ARGS) >> $$(FAKEROOT_SCRIPT)$$(sep)) | |
409d4c3f | 186 | |
405f9120 YM |
187 | $$(foreach hook,$$(ROOTFS_$(2)_PRE_GEN_HOOKS),\ |
188 | $$(call PRINTF,$$($$(hook))) >> $$(FAKEROOT_SCRIPT)$$(sep)) | |
38c4f6b8 MM |
189 | echo "find $$(TARGET_DIR)/run/ -mindepth 1 -prune -print0 | xargs -0r rm -rf --" >> $$(FAKEROOT_SCRIPT) |
190 | echo "find $$(TARGET_DIR)/tmp/ -mindepth 1 -prune -print0 | xargs -0r rm -rf --" >> $$(FAKEROOT_SCRIPT) | |
31fd0b1c | 191 | $$(call PRINTF,$$(ROOTFS_REPRODUCIBLE)) >> $$(FAKEROOT_SCRIPT) |
b843d781 | 192 | $$(call PRINTF,$$(ROOTFS_SELINUX)) >> $$(FAKEROOT_SCRIPT) |
6dd7bbb5 | 193 | $$(call PRINTF,$$(ROOTFS_$(2)_CMD)) >> $$(FAKEROOT_SCRIPT) |
847895d2 | 194 | chmod a+x $$(FAKEROOT_SCRIPT) |
655acd1d | 195 | PATH=$$(BR_PATH) FAKEROOTDONTTRYCHOWN=1 $$(HOST_DIR)/bin/fakeroot -- $$(FAKEROOT_SCRIPT) |
543107d3 | 196 | $(Q)rm -rf $$(TARGET_DIR) |
bd8ef7a0 | 197 | ifneq ($$(ROOTFS_$(2)_COMPRESS_CMD),) |
54456cc6 | 198 | PATH=$$(BR_PATH) $$(ROOTFS_$(2)_COMPRESS_CMD) $$@ > $$@$$(ROOTFS_$(2)_COMPRESS_EXT) |
5419651b | 199 | endif |
15a53b93 | 200 | $$(foreach hook,$$(ROOTFS_$(2)_POST_GEN_HOOKS),$$(call $$(hook))$$(sep)) |
21f3bcc1 | 201 | |
0a0cb991 | 202 | rootfs-$(1)-show-depends: |
847895d2 | 203 | @echo $$(ROOTFS_$(2)_DEPENDENCIES) |
949db6ac | 204 | |
5abb8821 YM |
205 | rootfs-$(1)-show-info: |
206 | @: | |
207 | $$(info $$(call clean-json,{ $$(call json-info,ROOTFS_$(2)) })) | |
208 | ||
21c6fb25 | 209 | rootfs-$(1): $$(BINARIES_DIR)/$$(ROOTFS_$(2)_FINAL_IMAGE_NAME) |
21f3bcc1 | 210 | |
5abb8821 | 211 | .PHONY: rootfs-$(1) rootfs-$(1)-show-depends rootfs-$(1)-show-info |
2aef771f | 212 | |
21f3bcc1 | 213 | ifeq ($$(BR2_TARGET_ROOTFS_$(2)),y) |
a2487758 | 214 | TARGETS_ROOTFS += rootfs-$(1) |
2b35c717 | 215 | PACKAGES += $$(filter-out rootfs-%,$$(ROOTFS_$(2)_FINAL_RECURSIVE_DEPENDENCIES)) |
21f3bcc1 | 216 | endif |
207c596a YM |
217 | |
218 | # Check for legacy POST_TARGETS rules | |
219 | ifneq ($$(ROOTFS_$(2)_POST_TARGETS),) | |
220 | $$(error Filesystem $(1) uses post-target rules, which are no longer supported.\ | |
221 | Update $(1) to use post-gen hooks instead) | |
222 | endif | |
223 | ||
21f3bcc1 TP |
224 | endef |
225 | ||
b6842c40 YM |
226 | # $(pkgname) also works well to return the filesystem name |
227 | rootfs = $(call inner-rootfs,$(pkgname),$(call UPPERCASE,$(pkgname))) | |
05852415 | 228 | |
741cbccb | 229 | include $(sort $(wildcard fs/*/*.mk)) |