common.mk 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_TARGETS, the list of targets that should be
  20. # run after running the main filesystem target. This is useful for
  21. # initramfs, to rebuild the kernel once the initramfs is generated.
  22. #
  23. # In terms of configuration option, this macro assumes that the
  24. # BR2_TARGET_ROOTFS_$(FSTYPE) config option allows to enable/disable
  25. # the generation of a filesystem image of a particular type. If
  26. # configura options BR2_TARGET_ROOTFS_$(FSTYPE)_GZIP,
  27. # BR2_TARGET_ROOTFS_$(FSTYPE)_BZIP2 or
  28. # BR2_TARGET_ROOTFS_$(FSTYPE)_LZMA exist and are enabled, then the
  29. # macro will automatically generate a compressed filesystem image.
  30. FAKEROOT_SCRIPT = $(BUILD_DIR)/_fakeroot.fs
  31. FULL_DEVICE_TABLE = $(BUILD_DIR)/_device_table.txt
  32. ROOTFS_DEVICE_TABLES = $(call qstrip,$(BR2_ROOTFS_DEVICE_TABLE) \
  33. $(BR2_ROOTFS_STATIC_DEVICE_TABLE))
  34. USERS_TABLE = $(BUILD_DIR)/_users_table.txt
  35. define ROOTFS_TARGET_INTERNAL
  36. # extra deps
  37. ROOTFS_$(2)_DEPENDENCIES += host-fakeroot host-makedevs
  38. ifeq ($$(BR2_TARGET_ROOTFS_$(2)_GZIP),y)
  39. ROOTFS_$(2)_COMPRESS_EXT = .gz
  40. ROOTFS_$(2)_COMPRESS_CMD = gzip -9 -c
  41. endif
  42. ifeq ($$(BR2_TARGET_ROOTFS_$(2)_BZIP2),y)
  43. ROOTFS_$(2)_COMPRESS_EXT = .bz2
  44. ROOTFS_$(2)_COMPRESS_CMD = bzip2 -9 -c
  45. endif
  46. ifeq ($$(BR2_TARGET_ROOTFS_$(2)_LZMA),y)
  47. ROOTFS_$(2)_DEPENDENCIES += host-lzma
  48. ROOTFS_$(2)_COMPRESS_EXT = .lzma
  49. ROOTFS_$(2)_COMPRESS_CMD = $$(LZMA) -9 -c
  50. endif
  51. ifeq ($$(BR2_TARGET_ROOTFS_$(2)_LZO),y)
  52. ROOTFS_$(2)_DEPENDENCIES += host-lzop
  53. ROOTFS_$(2)_COMPRESS_EXT = .lzo
  54. ROOTFS_$(2)_COMPRESS_CMD = $$(LZOP) -9 -c
  55. endif
  56. ifeq ($$(BR2_TARGET_ROOTFS_$(2)_XZ),y)
  57. ROOTFS_$(2)_DEPENDENCIES += host-xz
  58. ROOTFS_$(2)_COMPRESS_EXT = .xz
  59. ROOTFS_$(2)_COMPRESS_CMD = $$(XZ) -9 -C crc32 -c
  60. endif
  61. $$(BINARIES_DIR)/rootfs.$(1): $$(ROOTFS_$(2)_DEPENDENCIES)
  62. @$$(call MESSAGE,"Generating root filesystem image rootfs.$(1)")
  63. $$(foreach hook,$$(ROOTFS_$(2)_PRE_GEN_HOOKS),$$(call $$(hook))$$(sep))
  64. rm -f $$(FAKEROOT_SCRIPT)
  65. rm -f $$(TARGET_DIR_WARNING_FILE)
  66. echo "chown -R 0:0 $$(TARGET_DIR)" >> $$(FAKEROOT_SCRIPT)
  67. ifneq ($$(ROOTFS_DEVICE_TABLES),)
  68. cat $$(ROOTFS_DEVICE_TABLES) > $$(FULL_DEVICE_TABLE)
  69. ifeq ($$(BR2_ROOTFS_DEVICE_CREATION_STATIC),y)
  70. printf '$$(subst $$(sep),\n,$$(PACKAGES_DEVICES_TABLE))' >> $$(FULL_DEVICE_TABLE)
  71. endif
  72. printf '$$(subst $$(sep),\n,$$(PACKAGES_PERMISSIONS_TABLE))' >> $$(FULL_DEVICE_TABLE)
  73. echo "$$(HOST_DIR)/usr/bin/makedevs -d $$(FULL_DEVICE_TABLE) $$(TARGET_DIR)" >> $$(FAKEROOT_SCRIPT)
  74. endif
  75. printf '$(subst $(sep),\n,$(PACKAGES_USERS))' > $(USERS_TABLE)
  76. $(TOPDIR)/support/scripts/mkusers $(USERS_TABLE) $(TARGET_DIR) >> $(FAKEROOT_SCRIPT)
  77. echo "$$(ROOTFS_$(2)_CMD)" >> $$(FAKEROOT_SCRIPT)
  78. chmod a+x $$(FAKEROOT_SCRIPT)
  79. $$(HOST_DIR)/usr/bin/fakeroot -- $$(FAKEROOT_SCRIPT)
  80. cp support/misc/target-dir-warning.txt $$(TARGET_DIR_WARNING_FILE)
  81. -@rm -f $$(FAKEROOT_SCRIPT) $$(FULL_DEVICE_TABLE)
  82. ifneq ($$(ROOTFS_$(2)_COMPRESS_CMD),)
  83. $$(ROOTFS_$(2)_COMPRESS_CMD) $$@ > $$@$$(ROOTFS_$(2)_COMPRESS_EXT)
  84. endif
  85. rootfs-$(1)-show-depends:
  86. @echo $$(ROOTFS_$(2)_DEPENDENCIES)
  87. rootfs-$(1): $$(BINARIES_DIR)/rootfs.$(1) $$(ROOTFS_$(2)_POST_TARGETS)
  88. ifeq ($$(BR2_TARGET_ROOTFS_$(2)),y)
  89. TARGETS += rootfs-$(1)
  90. endif
  91. endef
  92. define ROOTFS_TARGET
  93. $(call ROOTFS_TARGET_INTERNAL,$(1),$(call UPPERCASE,$(1)))
  94. endef
  95. include $(sort $(wildcard fs/*/*.mk))