common.mk 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. # 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. #
  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
  29. # configura options BR2_TARGET_ROOTFS_$(FSTYPE)_GZIP,
  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. FAKEROOT_SCRIPT = $(BUILD_DIR)/_fakeroot.fs
  34. FULL_DEVICE_TABLE = $(BUILD_DIR)/_device_table.txt
  35. ROOTFS_DEVICE_TABLES = $(call qstrip,$(BR2_ROOTFS_DEVICE_TABLE) \
  36. $(BR2_ROOTFS_STATIC_DEVICE_TABLE))
  37. USERS_TABLE = $(BUILD_DIR)/_users_table.txt
  38. define ROOTFS_TARGET_INTERNAL
  39. # extra deps
  40. ROOTFS_$(2)_DEPENDENCIES += host-fakeroot host-makedevs $$(if $$(BR2_TARGET_ROOTFS_$(2)_LZMA),host-lzma) $$(if $$(BR2_TARGET_ROOTFS_$(2)_LZO),host-lzop) $$(if $$(BR2_TARGET_ROOTFS_$(2)_XZ),host-xz)
  41. $$(BINARIES_DIR)/rootfs.$(1): $$(ROOTFS_$(2)_DEPENDENCIES)
  42. @$$(call MESSAGE,"Generating root filesystem image rootfs.$(1)")
  43. $$(foreach hook,$$(ROOTFS_$(2)_PRE_GEN_HOOKS),$$(call $$(hook))$$(sep))
  44. rm -f $$(FAKEROOT_SCRIPT)
  45. rm -f $$(TARGET_DIR_WARNING_FILE)
  46. echo "chown -R 0:0 $$(TARGET_DIR)" >> $$(FAKEROOT_SCRIPT)
  47. ifneq ($$(ROOTFS_DEVICE_TABLES),)
  48. cat $$(ROOTFS_DEVICE_TABLES) > $$(FULL_DEVICE_TABLE)
  49. ifeq ($$(BR2_ROOTFS_DEVICE_CREATION_STATIC),y)
  50. printf '$$(subst $$(sep),\n,$$(PACKAGES_DEVICES_TABLE))' >> $$(FULL_DEVICE_TABLE)
  51. endif
  52. printf '$$(subst $$(sep),\n,$$(PACKAGES_PERMISSIONS_TABLE))' >> $$(FULL_DEVICE_TABLE)
  53. echo "$$(HOST_DIR)/usr/bin/makedevs -d $$(FULL_DEVICE_TABLE) $$(TARGET_DIR)" >> $$(FAKEROOT_SCRIPT)
  54. endif
  55. printf '$(subst $(sep),\n,$(PACKAGES_USERS))' > $(USERS_TABLE)
  56. $(TOPDIR)/support/scripts/mkusers $(USERS_TABLE) $(TARGET_DIR) >> $(FAKEROOT_SCRIPT)
  57. echo "$$(ROOTFS_$(2)_CMD)" >> $$(FAKEROOT_SCRIPT)
  58. chmod a+x $$(FAKEROOT_SCRIPT)
  59. $$(HOST_DIR)/usr/bin/fakeroot -- $$(FAKEROOT_SCRIPT)
  60. cp support/misc/target-dir-warning.txt $$(TARGET_DIR_WARNING_FILE)
  61. -@rm -f $$(FAKEROOT_SCRIPT) $$(FULL_DEVICE_TABLE)
  62. $$(foreach hook,$$(ROOTFS_$(2)_POST_GEN_HOOKS),$$(call $$(hook))$$(sep))
  63. ifeq ($$(BR2_TARGET_ROOTFS_$(2)_GZIP),y)
  64. gzip -9 -c $$@ > $$@.gz
  65. endif
  66. ifeq ($$(BR2_TARGET_ROOTFS_$(2)_BZIP2),y)
  67. bzip2 -9 -c $$@ > $$@.bz2
  68. endif
  69. ifeq ($$(BR2_TARGET_ROOTFS_$(2)_LZMA),y)
  70. $$(LZMA) -9 -c $$@ > $$@.lzma
  71. endif
  72. ifeq ($$(BR2_TARGET_ROOTFS_$(2)_LZO),y)
  73. $$(LZOP) -9 -c $$@ > $$@.lzo
  74. endif
  75. ifeq ($$(BR2_TARGET_ROOTFS_$(2)_XZ),y)
  76. $(XZ) -9 -C crc32 -c $$@ > $$@.xz
  77. endif
  78. rootfs-$(1)-show-depends:
  79. @echo $$(ROOTFS_$(2)_DEPENDENCIES)
  80. rootfs-$(1): $$(BINARIES_DIR)/rootfs.$(1) $$(ROOTFS_$(2)_POST_TARGETS)
  81. ifeq ($$(BR2_TARGET_ROOTFS_$(2)),y)
  82. TARGETS += rootfs-$(1)
  83. endif
  84. endef
  85. define ROOTFS_TARGET
  86. $(call ROOTFS_TARGET_INTERNAL,$(1),$(call UPPERCASE,$(1)))
  87. endef
  88. include $(sort $(wildcard fs/*/*.mk))