common.mk 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. FS_DIR = $(BUILD_DIR)/buildroot-fs
  30. FAKEROOT_SCRIPT = $(FS_DIR)/fakeroot.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. # Since this function will be called from within an $(eval ...)
  37. # all variable references except the arguments must be $$-quoted.
  38. define inner-rootfs
  39. # extra deps
  40. ROOTFS_$(2)_DEPENDENCIES += host-fakeroot host-makedevs \
  41. $$(if $$(PACKAGES_USERS)$$(ROOTFS_USERS_TABLES),host-mkpasswd)
  42. ifeq ($$(BR2_TARGET_ROOTFS_$(2)_GZIP),y)
  43. ROOTFS_$(2)_COMPRESS_EXT = .gz
  44. ROOTFS_$(2)_COMPRESS_CMD = gzip -9 -c
  45. endif
  46. ifeq ($$(BR2_TARGET_ROOTFS_$(2)_BZIP2),y)
  47. ROOTFS_$(2)_COMPRESS_EXT = .bz2
  48. ROOTFS_$(2)_COMPRESS_CMD = bzip2 -9 -c
  49. endif
  50. ifeq ($$(BR2_TARGET_ROOTFS_$(2)_LZMA),y)
  51. ROOTFS_$(2)_DEPENDENCIES += host-lzma
  52. ROOTFS_$(2)_COMPRESS_EXT = .lzma
  53. ROOTFS_$(2)_COMPRESS_CMD = $$(LZMA) -9 -c
  54. endif
  55. ifeq ($$(BR2_TARGET_ROOTFS_$(2)_LZO),y)
  56. ROOTFS_$(2)_DEPENDENCIES += host-lzop
  57. ROOTFS_$(2)_COMPRESS_EXT = .lzo
  58. ROOTFS_$(2)_COMPRESS_CMD = $$(LZOP) -9 -c
  59. endif
  60. ifeq ($$(BR2_TARGET_ROOTFS_$(2)_XZ),y)
  61. ROOTFS_$(2)_DEPENDENCIES += host-xz
  62. ROOTFS_$(2)_COMPRESS_EXT = .xz
  63. ROOTFS_$(2)_COMPRESS_CMD = xz -9 -C crc32 -c
  64. endif
  65. $$(BINARIES_DIR)/rootfs.$(1): target-finalize $$(ROOTFS_$(2)_DEPENDENCIES)
  66. @$$(call MESSAGE,"Generating root filesystem image rootfs.$(1)")
  67. rm -rf $(FS_DIR)
  68. mkdir -p $(FS_DIR)
  69. $$(foreach hook,$$(ROOTFS_$(2)_PRE_GEN_HOOKS),$$(call $$(hook))$$(sep))
  70. echo '#!/bin/sh' > $$(FAKEROOT_SCRIPT)
  71. echo "set -e" >> $$(FAKEROOT_SCRIPT)
  72. echo "chown -h -R 0:0 $$(TARGET_DIR)" >> $$(FAKEROOT_SCRIPT)
  73. ifneq ($$(ROOTFS_USERS_TABLES),)
  74. cat $$(ROOTFS_USERS_TABLES) >> $$(USERS_TABLE)
  75. endif
  76. $$(call PRINTF,$$(PACKAGES_USERS)) >> $$(USERS_TABLE)
  77. PATH=$$(BR_PATH) $$(TOPDIR)/support/scripts/mkusers $$(USERS_TABLE) $$(TARGET_DIR) >> $$(FAKEROOT_SCRIPT)
  78. ifneq ($$(ROOTFS_DEVICE_TABLES),)
  79. cat $$(ROOTFS_DEVICE_TABLES) > $$(FULL_DEVICE_TABLE)
  80. ifeq ($$(BR2_ROOTFS_DEVICE_CREATION_STATIC),y)
  81. $$(call PRINTF,$$(PACKAGES_DEVICES_TABLE)) >> $$(FULL_DEVICE_TABLE)
  82. endif
  83. endif
  84. $$(call PRINTF,$$(PACKAGES_PERMISSIONS_TABLE)) >> $$(FULL_DEVICE_TABLE)
  85. echo "$$(HOST_DIR)/bin/makedevs -d $$(FULL_DEVICE_TABLE) $$(TARGET_DIR)" >> $$(FAKEROOT_SCRIPT)
  86. $$(foreach s,$$(call qstrip,$$(BR2_ROOTFS_POST_FAKEROOT_SCRIPT)),\
  87. echo "echo '$$(TERM_BOLD)>>> Executing fakeroot script $$(s)$$(TERM_RESET)'" >> $$(FAKEROOT_SCRIPT); \
  88. echo $$(s) $$(TARGET_DIR) $$(BR2_ROOTFS_POST_SCRIPT_ARGS) >> $$(FAKEROOT_SCRIPT)$$(sep))
  89. $$(foreach hook,$$(ROOTFS_PRE_CMD_HOOKS),\
  90. $$(call PRINTF,$$($$(hook))) >> $$(FAKEROOT_SCRIPT)$$(sep))
  91. ifeq ($$(BR2_REPRODUCIBLE),y)
  92. echo "find $$(TARGET_DIR) -print0 | xargs -0 -r touch -hd @$$(SOURCE_DATE_EPOCH)" >> $$(FAKEROOT_SCRIPT)
  93. endif
  94. $$(call PRINTF,$$(ROOTFS_$(2)_CMD)) >> $$(FAKEROOT_SCRIPT)
  95. $$(foreach hook,$$(ROOTFS_POST_CMD_HOOKS),\
  96. $$(call PRINTF,$$($$(hook))) >> $$(FAKEROOT_SCRIPT)$$(sep))
  97. chmod a+x $$(FAKEROOT_SCRIPT)
  98. rm -f $$(TARGET_DIR_WARNING_FILE)
  99. PATH=$$(BR_PATH) $$(HOST_DIR)/bin/fakeroot -- $$(FAKEROOT_SCRIPT)
  100. $$(INSTALL) -m 0644 support/misc/target-dir-warning.txt $$(TARGET_DIR_WARNING_FILE)
  101. ifneq ($$(ROOTFS_$(2)_COMPRESS_CMD),)
  102. PATH=$$(BR_PATH) $$(ROOTFS_$(2)_COMPRESS_CMD) $$@ > $$@$$(ROOTFS_$(2)_COMPRESS_EXT)
  103. endif
  104. $$(foreach hook,$$(ROOTFS_$(2)_POST_GEN_HOOKS),$$(call $$(hook))$$(sep))
  105. rootfs-$(1)-show-depends:
  106. @echo $$(ROOTFS_$(2)_DEPENDENCIES)
  107. rootfs-$(1): $$(BINARIES_DIR)/rootfs.$(1)
  108. .PHONY: rootfs-$(1) rootfs-$(1)-show-depends
  109. ifeq ($$(BR2_TARGET_ROOTFS_$(2)),y)
  110. TARGETS_ROOTFS += rootfs-$(1)
  111. PACKAGES += $$(filter-out rootfs-%,$$(ROOTFS_$(2)_DEPENDENCIES))
  112. endif
  113. # Check for legacy POST_TARGETS rules
  114. ifneq ($$(ROOTFS_$(2)_POST_TARGETS),)
  115. $$(error Filesystem $(1) uses post-target rules, which are no longer supported.\
  116. Update $(1) to use post-gen hooks instead)
  117. endif
  118. endef
  119. # $(pkgname) also works well to return the filesystem name
  120. rootfs = $(call inner-rootfs,$(pkgname),$(call UPPERCASE,$(pkgname)))
  121. include $(sort $(wildcard fs/*/*.mk))