common.mk 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. ROOTFS_DEVICE_TABLE = $(call qstrip,$(BR2_ROOTFS_DEVICE_TABLE))
  35. define ROOTFS_TARGET_INTERNAL
  36. # extra deps
  37. $(eval ROOTFS_$(2)_DEPENDENCIES += host-fakeroot host-makedevs $(if $(BR2_TARGET_ROOTFS_$(2)_LZMA),host-lzma))
  38. $(BINARIES_DIR)/rootfs.$(1): $(ROOTFS_$(2)_DEPENDENCIES)
  39. @$(call MESSAGE,"Generating root filesystem image rootfs.$(1)")
  40. $(foreach hook,$(ROOTFS_$(2)_PRE_GEN_HOOKS),$(call $(hook))$(sep))
  41. rm -f $(FAKEROOT_SCRIPT)
  42. touch $(BUILD_DIR)/.fakeroot.00000
  43. cat $(BUILD_DIR)/.fakeroot* > $(FAKEROOT_SCRIPT)
  44. echo "chown -R 0:0 $(TARGET_DIR)" >> $(FAKEROOT_SCRIPT)
  45. ifneq ($(ROOTFS_DEVICE_TABLE),)
  46. echo "$(HOST_DIR)/usr/bin/makedevs -d $(ROOTFS_DEVICE_TABLE) $(TARGET_DIR)" >> $(FAKEROOT_SCRIPT)
  47. endif
  48. echo "$(ROOTFS_$(2)_CMD)" >> $(FAKEROOT_SCRIPT)
  49. chmod a+x $(FAKEROOT_SCRIPT)
  50. $(HOST_DIR)/usr/bin/fakeroot -- $(FAKEROOT_SCRIPT)
  51. -@rm -f $(FAKEROOT_SCRIPT)
  52. $(foreach hook,$(ROOTFS_$(2)_POST_GEN_HOOKS),$(call $(hook))$(sep))
  53. ifeq ($$(BR2_TARGET_ROOTFS_$(2)_GZIP),y)
  54. gzip -9 -c $$@ > $$@.gz
  55. endif
  56. ifeq ($$(BR2_TARGET_ROOTFS_$(2)_BZIP2),y)
  57. bzip2 -9 -c $$@ > $$@.bz2
  58. endif
  59. ifeq ($$(BR2_TARGET_ROOTFS_$(2)_LZMA),y)
  60. $(LZMA) -9 -c $$@ > $$@.lzma
  61. endif
  62. rootfs-$(1)-show-depends:
  63. @echo $(ROOTFS_$(2)_DEPENDENCIES)
  64. rootfs-$(1): $(BINARIES_DIR)/rootfs.$(1) $(ROOTFS_$(2)_POST_TARGETS)
  65. ifeq ($$(BR2_TARGET_ROOTFS_$(2)),y)
  66. TARGETS += rootfs-$(1)
  67. endif
  68. endef
  69. define ROOTFS_TARGET
  70. $(call ROOTFS_TARGET_INTERNAL,$(1),$(call UPPERCASE,$(1)))
  71. endef
  72. include fs/*/*.mk