Thomas Petazzoni | 21f3bcc | 2010-03-10 00:11:58 +0100 | [diff] [blame] | 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 | # |
Thomas Petazzoni | 15a53b9 | 2015-07-31 10:23:20 +0200 | [diff] [blame] | 19 | # ROOTFS_$(FSTYPE)_POST_GEN_HOOKS, a list of hooks to call after |
| 20 | # generating the filesystem image |
| 21 | # |
Thomas Petazzoni | f507921 | 2010-06-13 19:19:38 +0200 | [diff] [blame] | 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 | # |
Thomas Petazzoni | 21f3bcc | 2010-03-10 00:11:58 +0100 | [diff] [blame] | 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 |
Brian 'redbeard' Harrington | b2dcb2d | 2016-05-07 20:27:48 -0700 | [diff] [blame] | 29 | # the configuration options BR2_TARGET_ROOTFS_$(FSTYPE)_GZIP, |
Thomas Petazzoni | 21f3bcc | 2010-03-10 00:11:58 +0100 | [diff] [blame] | 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 |
Thomas Petazzoni | 4e005c4 | 2011-03-02 14:52:54 +0100 | [diff] [blame] | 35 | FULL_DEVICE_TABLE = $(BUILD_DIR)/_device_table.txt |
Ezequiel Garcia | 402d147 | 2013-03-13 02:28:16 +0000 | [diff] [blame] | 36 | ROOTFS_DEVICE_TABLES = $(call qstrip,$(BR2_ROOTFS_DEVICE_TABLE) \ |
Jerzy Grzegorek | 1769933 | 2014-10-25 20:29:31 +0200 | [diff] [blame] | 37 | $(BR2_ROOTFS_STATIC_DEVICE_TABLE)) |
Yann E. MORIN | 1f3af04 | 2013-04-12 07:14:18 +0000 | [diff] [blame] | 38 | USERS_TABLE = $(BUILD_DIR)/_users_table.txt |
Eric Le Bihan | b019490 | 2014-04-20 19:33:09 +0200 | [diff] [blame] | 39 | ROOTFS_USERS_TABLES = $(call qstrip,$(BR2_ROOTFS_USERS_TABLES)) |
Thomas Petazzoni | 21f3bcc | 2010-03-10 00:11:58 +0100 | [diff] [blame] | 40 | |
Thomas De Schampheleire | 54456cc | 2014-06-11 21:12:24 +0200 | [diff] [blame] | 41 | # Since this function will be called from within an $(eval ...) |
| 42 | # all variable references except the arguments must be $$-quoted. |
Thomas Petazzoni | 21f3bcc | 2010-03-10 00:11:58 +0100 | [diff] [blame] | 43 | define ROOTFS_TARGET_INTERNAL |
| 44 | |
Peter Korsgaard | 094b293 | 2010-11-19 15:05:20 +0100 | [diff] [blame] | 45 | # extra deps |
Peter Korsgaard | 79061fe | 2016-11-27 21:13:54 +0100 | [diff] [blame] | 46 | ROOTFS_$(2)_DEPENDENCIES += host-fakeroot host-makedevs \ |
Thomas Petazzoni | 95bd0ad | 2015-07-21 17:36:07 +0200 | [diff] [blame] | 47 | $$(if $$(PACKAGES_USERS)$$(ROOTFS_USERS_TABLES),host-mkpasswd) |
Arnout Vandecappelle | bd8ef7a | 2013-11-07 00:12:32 +0100 | [diff] [blame] | 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) |
Thomas De Schampheleire | 26e0d50 | 2015-03-09 10:34:13 +0100 | [diff] [blame] | 68 | ROOTFS_$(2)_DEPENDENCIES += host-xz |
Arnout Vandecappelle | bd8ef7a | 2013-11-07 00:12:32 +0100 | [diff] [blame] | 69 | ROOTFS_$(2)_COMPRESS_EXT = .xz |
Peter Korsgaard | 28b514a | 2014-06-04 08:33:17 +0200 | [diff] [blame] | 70 | ROOTFS_$(2)_COMPRESS_CMD = xz -9 -C crc32 -c |
Arnout Vandecappelle | bd8ef7a | 2013-11-07 00:12:32 +0100 | [diff] [blame] | 71 | endif |
Peter Korsgaard | 094b293 | 2010-11-19 15:05:20 +0100 | [diff] [blame] | 72 | |
Fabio Porcedda | a248775 | 2014-02-14 10:55:06 +0100 | [diff] [blame] | 73 | $$(BINARIES_DIR)/rootfs.$(1): target-finalize $$(ROOTFS_$(2)_DEPENDENCIES) |
Arnout Vandecappelle (Essensium/Mind) | 847895d | 2013-01-20 15:03:13 +0100 | [diff] [blame] | 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) |
Thomas De Schampheleire | 54456cc | 2014-06-11 21:12:24 +0200 | [diff] [blame] | 78 | rm -f $$(USERS_TABLE) |
Yann E. MORIN | 974e83a | 2016-06-07 22:09:41 +0200 | [diff] [blame] | 79 | echo '#!/bin/sh' > $$(FAKEROOT_SCRIPT) |
Stefan Sørensen | 6b577b3 | 2015-02-24 16:47:34 +0100 | [diff] [blame] | 80 | echo "set -e" >> $$(FAKEROOT_SCRIPT) |
Yann E. MORIN | 3fbd988 | 2014-06-08 22:02:23 +0200 | [diff] [blame] | 81 | echo "chown -h -R 0:0 $$(TARGET_DIR)" >> $$(FAKEROOT_SCRIPT) |
Yann E. MORIN | 3f28a38 | 2016-01-21 22:23:36 +0100 | [diff] [blame] | 82 | ifneq ($$(ROOTFS_USERS_TABLES),) |
| 83 | cat $$(ROOTFS_USERS_TABLES) >> $$(USERS_TABLE) |
| 84 | endif |
Yann E. MORIN | 6dd7bbb | 2016-06-06 22:43:39 +0200 | [diff] [blame] | 85 | $$(call PRINTF,$$(PACKAGES_USERS)) >> $$(USERS_TABLE) |
Yann E. MORIN | 3f28a38 | 2016-01-21 22:23:36 +0100 | [diff] [blame] | 86 | PATH=$$(BR_PATH) $$(TOPDIR)/support/scripts/mkusers $$(USERS_TABLE) $$(TARGET_DIR) >> $$(FAKEROOT_SCRIPT) |
Arnout Vandecappelle (Essensium/Mind) | 847895d | 2013-01-20 15:03:13 +0100 | [diff] [blame] | 87 | ifneq ($$(ROOTFS_DEVICE_TABLES),) |
| 88 | cat $$(ROOTFS_DEVICE_TABLES) > $$(FULL_DEVICE_TABLE) |
| 89 | ifeq ($$(BR2_ROOTFS_DEVICE_CREATION_STATIC),y) |
Yann E. MORIN | 6dd7bbb | 2016-06-06 22:43:39 +0200 | [diff] [blame] | 90 | $$(call PRINTF,$$(PACKAGES_DEVICES_TABLE)) >> $$(FULL_DEVICE_TABLE) |
Maxime Ripard | 2444085 | 2012-01-11 18:53:38 +0100 | [diff] [blame] | 91 | endif |
Yann E. MORIN | 5b272e3 | 2016-12-14 23:28:10 +0100 | [diff] [blame] | 92 | endif |
Yann E. MORIN | 6dd7bbb | 2016-06-06 22:43:39 +0200 | [diff] [blame] | 93 | $$(call PRINTF,$$(PACKAGES_PERMISSIONS_TABLE)) >> $$(FULL_DEVICE_TABLE) |
Arnout Vandecappelle (Essensium/Mind) | 847895d | 2013-01-20 15:03:13 +0100 | [diff] [blame] | 94 | echo "$$(HOST_DIR)/usr/bin/makedevs -d $$(FULL_DEVICE_TABLE) $$(TARGET_DIR)" >> $$(FAKEROOT_SCRIPT) |
Yann E. MORIN | 9cdb281 | 2016-07-03 17:08:19 +0200 | [diff] [blame] | 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)) |
Jérôme Pouiller | 68db721 | 2016-11-23 13:58:47 +0100 | [diff] [blame] | 98 | ifeq ($$(BR2_REPRODUCIBLE),y) |
| 99 | echo "find $$(TARGET_DIR) -print0 | xargs -0 -r touch -hd @$$(SOURCE_DATE_EPOCH)" >> $$(FAKEROOT_SCRIPT) |
| 100 | endif |
Yann E. MORIN | 6dd7bbb | 2016-06-06 22:43:39 +0200 | [diff] [blame] | 101 | $$(call PRINTF,$$(ROOTFS_$(2)_CMD)) >> $$(FAKEROOT_SCRIPT) |
Arnout Vandecappelle (Essensium/Mind) | 847895d | 2013-01-20 15:03:13 +0100 | [diff] [blame] | 102 | chmod a+x $$(FAKEROOT_SCRIPT) |
Peter Korsgaard | 79061fe | 2016-11-27 21:13:54 +0100 | [diff] [blame] | 103 | PATH=$$(BR_PATH) $$(HOST_DIR)/usr/bin/fakeroot -- $$(FAKEROOT_SCRIPT) |
Thomas De Schampheleire | 54456cc | 2014-06-11 21:12:24 +0200 | [diff] [blame] | 104 | $$(INSTALL) -m 0644 support/misc/target-dir-warning.txt $$(TARGET_DIR_WARNING_FILE) |
Arnout Vandecappelle (Essensium/Mind) | 847895d | 2013-01-20 15:03:13 +0100 | [diff] [blame] | 105 | -@rm -f $$(FAKEROOT_SCRIPT) $$(FULL_DEVICE_TABLE) |
Arnout Vandecappelle | bd8ef7a | 2013-11-07 00:12:32 +0100 | [diff] [blame] | 106 | ifneq ($$(ROOTFS_$(2)_COMPRESS_CMD),) |
Thomas De Schampheleire | 54456cc | 2014-06-11 21:12:24 +0200 | [diff] [blame] | 107 | PATH=$$(BR_PATH) $$(ROOTFS_$(2)_COMPRESS_CMD) $$@ > $$@$$(ROOTFS_$(2)_COMPRESS_EXT) |
Gustavo Zacarias | 5419651 | 2013-01-22 01:03:43 +0000 | [diff] [blame] | 108 | endif |
Thomas Petazzoni | 15a53b9 | 2015-07-31 10:23:20 +0200 | [diff] [blame] | 109 | $$(foreach hook,$$(ROOTFS_$(2)_POST_GEN_HOOKS),$$(call $$(hook))$$(sep)) |
Thomas Petazzoni | 21f3bcc | 2010-03-10 00:11:58 +0100 | [diff] [blame] | 110 | |
Peter Korsgaard | 0a0cb99 | 2010-11-19 15:01:13 +0100 | [diff] [blame] | 111 | rootfs-$(1)-show-depends: |
Arnout Vandecappelle (Essensium/Mind) | 847895d | 2013-01-20 15:03:13 +0100 | [diff] [blame] | 112 | @echo $$(ROOTFS_$(2)_DEPENDENCIES) |
Thomas Petazzoni | 949db6a | 2010-05-13 19:20:21 +0200 | [diff] [blame] | 113 | |
Arnout Vandecappelle (Essensium/Mind) | 847895d | 2013-01-20 15:03:13 +0100 | [diff] [blame] | 114 | rootfs-$(1): $$(BINARIES_DIR)/rootfs.$(1) $$(ROOTFS_$(2)_POST_TARGETS) |
Thomas Petazzoni | 21f3bcc | 2010-03-10 00:11:58 +0100 | [diff] [blame] | 115 | |
Thomas Petazzoni | 2aef771 | 2015-04-12 18:37:46 +0200 | [diff] [blame] | 116 | .PHONY: rootfs-$(1) rootfs-$(1)-show-depends |
| 117 | |
Thomas Petazzoni | 21f3bcc | 2010-03-10 00:11:58 +0100 | [diff] [blame] | 118 | ifeq ($$(BR2_TARGET_ROOTFS_$(2)),y) |
Fabio Porcedda | a248775 | 2014-02-14 10:55:06 +0100 | [diff] [blame] | 119 | TARGETS_ROOTFS += rootfs-$(1) |
Thomas Petazzoni | 54640e8 | 2015-04-26 11:50:59 +0200 | [diff] [blame] | 120 | PACKAGES += $$(filter-out rootfs-%,$$(ROOTFS_$(2)_DEPENDENCIES)) |
Thomas Petazzoni | 21f3bcc | 2010-03-10 00:11:58 +0100 | [diff] [blame] | 121 | endif |
| 122 | endef |
| 123 | |
| 124 | define ROOTFS_TARGET |
Jerzy Grzegorek | 5d47340 | 2014-12-09 16:14:31 +0100 | [diff] [blame] | 125 | $(call ROOTFS_TARGET_INTERNAL,$(1),$(call UPPERCASE,$(1))) |
Thomas Petazzoni | d2b0791 | 2010-03-10 22:11:21 +0100 | [diff] [blame] | 126 | endef |
Thomas Petazzoni | 0585241 | 2010-03-10 22:30:06 +0100 | [diff] [blame] | 127 | |
Jérôme Pouiller | 741cbcc | 2013-09-03 10:45:41 +0200 | [diff] [blame] | 128 | include $(sort $(wildcard fs/*/*.mk)) |