]> rtime.felk.cvut.cz Git - coffee/buildroot.git/blob - fs/common.mk
fs: use a common tarball as base for the other filesystems
[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 # 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.
29
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))
36
37 ifeq ($(BR2_REPRODUCIBLE),y)
38 define ROOTFS_REPRODUCIBLE
39         find $(TARGET_DIR) -print0 | xargs -0 -r touch -hd @$(SOURCE_DATE_EPOCH)
40 endef
41 endif
42
43 ROOTFS_COMMON_TAR = $(FS_DIR)/rootfs.common.tar
44
45 # Command to create the common tarball from the base target directory.
46 define ROOTFS_COMMON_TAR_CMD
47         tar cf $(ROOTFS_COMMON_TAR) --numeric-owner \
48                 --exclude=$(notdir $(TARGET_DIR_WARNING_FILE)) \
49                 -C $(TARGET_DIR) .
50 endef
51
52 # Command to extract the common tarball into the per-rootfs target directory
53 define ROOTFS_COMMON_UNTAR_CMD
54         mkdir -p $(TARGET_DIR)
55         tar xf $(ROOTFS_COMMON_TAR) -C $(TARGET_DIR)
56 endef
57
58 .PHONY: rootfs-common
59 rootfs-common: $(ROOTFS_COMMON_TAR)
60
61 ROOTFS_COMMON_DEPENDENCIES = \
62         host-fakeroot host-makedevs \
63         $(if $(PACKAGES_USERS)$(ROOTFS_USERS_TABLES),host-mkpasswd)
64
65 # When doing the common tarball, we're not really doing a rootfs.
66 $(ROOTFS_COMMON_TAR): ROOTFS=
67 $(ROOTFS_COMMON_TAR): FAKEROOT_SCRIPT=$(FS_DIR)/fakeroot.fs
68 $(ROOTFS_COMMON_TAR): $(ROOTFS_COMMON_DEPENDENCIES) target-finalize
69         @$(call MESSAGE,"Generating common rootfs tarball")
70         rm -rf $(FS_DIR)
71         mkdir -p $(FS_DIR)
72         echo '#!/bin/sh' > $(FAKEROOT_SCRIPT)
73         echo "set -e" >> $(FAKEROOT_SCRIPT)
74         echo "chown -h -R 0:0 $(TARGET_DIR)" >> $(FAKEROOT_SCRIPT)
75 ifneq ($(ROOTFS_USERS_TABLES),)
76         cat $(ROOTFS_USERS_TABLES) >> $(USERS_TABLE)
77 endif
78         $(call PRINTF,$(PACKAGES_USERS)) >> $(USERS_TABLE)
79         PATH=$(BR_PATH) $(TOPDIR)/support/scripts/mkusers $(USERS_TABLE) $(TARGET_DIR) >> $(FAKEROOT_SCRIPT)
80 ifneq ($(ROOTFS_DEVICE_TABLES),)
81         cat $(ROOTFS_DEVICE_TABLES) > $(FULL_DEVICE_TABLE)
82 ifeq ($(BR2_ROOTFS_DEVICE_CREATION_STATIC),y)
83         $(call PRINTF,$(PACKAGES_DEVICES_TABLE)) >> $(FULL_DEVICE_TABLE)
84 endif
85 endif
86         $(call PRINTF,$(PACKAGES_PERMISSIONS_TABLE)) >> $(FULL_DEVICE_TABLE)
87         echo "$(HOST_DIR)/bin/makedevs -d $(FULL_DEVICE_TABLE) $(TARGET_DIR)" >> $(FAKEROOT_SCRIPT)
88         $(foreach s,$(call qstrip,$(BR2_ROOTFS_POST_FAKEROOT_SCRIPT)),\
89                 echo "echo '$(TERM_BOLD)>>>   Executing fakeroot script $(s)$(TERM_RESET)'" >> $(FAKEROOT_SCRIPT); \
90                 echo $(EXTRA_ENV) $(s) $(TARGET_DIR) $(BR2_ROOTFS_POST_SCRIPT_ARGS) >> $(FAKEROOT_SCRIPT)$(sep))
91         $(foreach hook,$(ROOTFS_PRE_CMD_HOOKS),\
92                 $(call PRINTF,$($(hook))) >> $(FAKEROOT_SCRIPT)$(sep))
93         $(call PRINTF,$(ROOTFS_COMMON_TAR_CMD)) >> $(FAKEROOT_SCRIPT)
94         $(foreach hook,$(ROOTFS_POST_CMD_HOOKS),\
95                 $(call PRINTF,$($(hook))) >> $(FAKEROOT_SCRIPT)$(sep))
96         chmod a+x $(FAKEROOT_SCRIPT)
97         PATH=$(BR_PATH) $(HOST_DIR)/bin/fakeroot -- $(FAKEROOT_SCRIPT)
98
99 rootfs-common-show-depends:
100         @echo $(ROOTFS_COMMON_DEPENDENCIES)
101
102 # Since this function will be called from within an $(eval ...)
103 # all variable references except the arguments must be $$-quoted.
104 define inner-rootfs
105
106 ROOTFS_$(2)_DIR = $$(FS_DIR)/$(1)
107 ROOTFS_$(2)_TARGET_DIR = $$(ROOTFS_$(2)_DIR)/target
108
109 ROOTFS_$(2)_DEPENDENCIES += rootfs-common
110
111 ifeq ($$(BR2_TARGET_ROOTFS_$(2)_GZIP),y)
112 ROOTFS_$(2)_COMPRESS_EXT = .gz
113 ROOTFS_$(2)_COMPRESS_CMD = gzip -9 -c
114 endif
115 ifeq ($$(BR2_TARGET_ROOTFS_$(2)_BZIP2),y)
116 ROOTFS_$(2)_COMPRESS_EXT = .bz2
117 ROOTFS_$(2)_COMPRESS_CMD = bzip2 -9 -c
118 endif
119 ifeq ($$(BR2_TARGET_ROOTFS_$(2)_LZMA),y)
120 ROOTFS_$(2)_DEPENDENCIES += host-lzma
121 ROOTFS_$(2)_COMPRESS_EXT = .lzma
122 ROOTFS_$(2)_COMPRESS_CMD = $$(LZMA) -9 -c
123 endif
124 ifeq ($$(BR2_TARGET_ROOTFS_$(2)_LZ4),y)
125 ROOTFS_$(2)_DEPENDENCIES += host-lz4
126 ROOTFS_$(2)_COMPRESS_EXT = .lz4
127 ROOTFS_$(2)_COMPRESS_CMD = lz4 -l -9 -c
128 endif
129 ifeq ($$(BR2_TARGET_ROOTFS_$(2)_LZO),y)
130 ROOTFS_$(2)_DEPENDENCIES += host-lzop
131 ROOTFS_$(2)_COMPRESS_EXT = .lzo
132 ROOTFS_$(2)_COMPRESS_CMD = $$(LZOP) -9 -c
133 endif
134 ifeq ($$(BR2_TARGET_ROOTFS_$(2)_XZ),y)
135 ROOTFS_$(2)_DEPENDENCIES += host-xz
136 ROOTFS_$(2)_COMPRESS_EXT = .xz
137 ROOTFS_$(2)_COMPRESS_CMD = xz -9 -C crc32 -c
138 endif
139
140 $$(BINARIES_DIR)/rootfs.$(1): ROOTFS=$(2)
141 $$(BINARIES_DIR)/rootfs.$(1): FAKEROOT_SCRIPT=$$(ROOTFS_$(2)_DIR)/fakeroot
142 $$(BINARIES_DIR)/rootfs.$(1): $$(ROOTFS_$(2)_DEPENDENCIES)
143         @$$(call MESSAGE,"Generating root filesystem image rootfs.$(1)")
144         rm -rf $$(ROOTFS_$(2)_DIR)
145         mkdir -p $$(ROOTFS_$(2)_DIR)
146         echo '#!/bin/sh' > $$(FAKEROOT_SCRIPT)
147         echo "set -e" >> $$(FAKEROOT_SCRIPT)
148         $$(call PRINTF,$$(ROOTFS_COMMON_UNTAR_CMD)) >> $$(FAKEROOT_SCRIPT)
149         $$(foreach hook,$$(ROOTFS_$(2)_PRE_GEN_HOOKS),\
150                 $$(call PRINTF,$$($$(hook))) >> $$(FAKEROOT_SCRIPT)$$(sep))
151         $$(call PRINTF,$$(ROOTFS_REPRODUCIBLE)) >> $$(FAKEROOT_SCRIPT)
152         $$(call PRINTF,$$(ROOTFS_$(2)_CMD)) >> $$(FAKEROOT_SCRIPT)
153         chmod a+x $$(FAKEROOT_SCRIPT)
154         PATH=$$(BR_PATH) $$(HOST_DIR)/bin/fakeroot -- $$(FAKEROOT_SCRIPT)
155 ifneq ($$(ROOTFS_$(2)_COMPRESS_CMD),)
156         PATH=$$(BR_PATH) $$(ROOTFS_$(2)_COMPRESS_CMD) $$@ > $$@$$(ROOTFS_$(2)_COMPRESS_EXT)
157 endif
158         $$(foreach hook,$$(ROOTFS_$(2)_POST_GEN_HOOKS),$$(call $$(hook))$$(sep))
159
160 rootfs-$(1)-show-depends:
161         @echo $$(ROOTFS_$(2)_DEPENDENCIES)
162
163 rootfs-$(1): $$(BINARIES_DIR)/rootfs.$(1)
164
165 .PHONY: rootfs-$(1) rootfs-$(1)-show-depends
166
167 ifeq ($$(BR2_TARGET_ROOTFS_$(2)),y)
168 TARGETS_ROOTFS += rootfs-$(1)
169 PACKAGES += $$(filter-out rootfs-%,$$(ROOTFS_$(2)_DEPENDENCIES))
170 endif
171
172 # Check for legacy POST_TARGETS rules
173 ifneq ($$(ROOTFS_$(2)_POST_TARGETS),)
174 $$(error Filesystem $(1) uses post-target rules, which are no longer supported.\
175         Update $(1) to use post-gen hooks instead)
176 endif
177
178 endef
179
180 # $(pkgname) also works well to return the filesystem name
181 rootfs = $(call inner-rootfs,$(pkgname),$(call UPPERCASE,$(pkgname)))
182
183 include $(sort $(wildcard fs/*/*.mk))