grub2.mk 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. ################################################################################
  2. #
  3. # grub2
  4. #
  5. ################################################################################
  6. GRUB2_VERSION = 2.02
  7. GRUB2_SITE = http://ftp.gnu.org/gnu/grub
  8. GRUB2_SOURCE = grub-$(GRUB2_VERSION).tar.xz
  9. GRUB2_LICENSE = GPL-3.0+
  10. GRUB2_LICENSE_FILES = COPYING
  11. GRUB2_DEPENDENCIES = host-bison host-flex
  12. GRUB2_BUILTIN_MODULES = $(call qstrip,$(BR2_TARGET_GRUB2_BUILTIN_MODULES))
  13. GRUB2_BUILTIN_CONFIG = $(call qstrip,$(BR2_TARGET_GRUB2_BUILTIN_CONFIG))
  14. GRUB2_BOOT_PARTITION = $(call qstrip,$(BR2_TARGET_GRUB2_BOOT_PARTITION))
  15. ifeq ($(BR2_TARGET_GRUB2_I386_PC),y)
  16. GRUB2_IMAGE = $(BINARIES_DIR)/grub.img
  17. GRUB2_CFG = $(TARGET_DIR)/boot/grub/grub.cfg
  18. GRUB2_PREFIX = ($(GRUB2_BOOT_PARTITION))/boot/grub
  19. GRUB2_TUPLE = i386-pc
  20. GRUB2_TARGET = i386
  21. GRUB2_PLATFORM = pc
  22. else ifeq ($(BR2_TARGET_GRUB2_I386_EFI),y)
  23. GRUB2_IMAGE = $(BINARIES_DIR)/efi-part/EFI/BOOT/bootia32.efi
  24. GRUB2_CFG = $(BINARIES_DIR)/efi-part/EFI/BOOT/grub.cfg
  25. GRUB2_PREFIX = /EFI/BOOT
  26. GRUB2_TUPLE = i386-efi
  27. GRUB2_TARGET = i386
  28. GRUB2_PLATFORM = efi
  29. else ifeq ($(BR2_TARGET_GRUB2_X86_64_EFI),y)
  30. GRUB2_IMAGE = $(BINARIES_DIR)/efi-part/EFI/BOOT/bootx64.efi
  31. GRUB2_CFG = $(BINARIES_DIR)/efi-part/EFI/BOOT/grub.cfg
  32. GRUB2_PREFIX = /EFI/BOOT
  33. GRUB2_TUPLE = x86_64-efi
  34. GRUB2_TARGET = x86_64
  35. GRUB2_PLATFORM = efi
  36. endif
  37. # Grub2 is kind of special: it considers CC, LD and so on to be the
  38. # tools to build the native tools (i.e to be executed on the build
  39. # machine), and uses TARGET_CC, TARGET_CFLAGS, TARGET_CPPFLAGS,
  40. # TARGET_LDFLAGS to build the bootloader itself. However, to add to
  41. # the confusion, it also uses NM, OBJCOPY and STRIP to build the
  42. # bootloader itself; none of these are used to build the native
  43. # tools.
  44. #
  45. # NOTE: TARGET_STRIP is overridden by !BR2_STRIP_strip, so always
  46. # use the cross compile variant to ensure grub2 builds
  47. GRUB2_CONF_ENV = \
  48. $(HOST_CONFIGURE_OPTS) \
  49. CPP="$(HOSTCC) -E" \
  50. TARGET_CC="$(TARGET_CC)" \
  51. TARGET_CFLAGS="$(TARGET_CFLAGS) -fno-stack-protector" \
  52. TARGET_CPPFLAGS="$(TARGET_CPPFLAGS)" \
  53. TARGET_LDFLAGS="$(TARGET_LDFLAGS)" \
  54. NM="$(TARGET_NM)" \
  55. OBJCOPY="$(TARGET_OBJCOPY)" \
  56. STRIP="$(TARGET_CROSS)strip"
  57. GRUB2_CONF_OPTS = \
  58. --target=$(GRUB2_TARGET) \
  59. --with-platform=$(GRUB2_PLATFORM) \
  60. --prefix=/ \
  61. --exec-prefix=/ \
  62. --disable-grub-mkfont \
  63. --enable-efiemu=no \
  64. ac_cv_lib_lzma_lzma_code=no \
  65. --enable-device-mapper=no \
  66. --enable-libzfs=no \
  67. --disable-werror
  68. # We don't want all the native tools and Grub2 modules to be installed
  69. # in the target. So we in fact install everything into the host
  70. # directory, and the image generation process (below) will use the
  71. # grub-mkimage tool and Grub2 modules from the host directory.
  72. GRUB2_INSTALL_TARGET_OPTS = DESTDIR=$(HOST_DIR) install
  73. ifeq ($(BR2_TARGET_GRUB2_I386_PC),y)
  74. define GRUB2_IMAGE_INSTALL_ELTORITO
  75. cat $(HOST_DIR)/lib/grub/$(GRUB2_TUPLE)/cdboot.img $(GRUB2_IMAGE) > \
  76. $(BINARIES_DIR)/grub-eltorito.img
  77. endef
  78. endif
  79. define GRUB2_IMAGE_INSTALLATION
  80. mkdir -p $(dir $(GRUB2_IMAGE))
  81. $(HOST_DIR)/bin/grub-mkimage \
  82. -d $(HOST_DIR)/lib/grub/$(GRUB2_TUPLE) \
  83. -O $(GRUB2_TUPLE) \
  84. -o $(GRUB2_IMAGE) \
  85. -p "$(GRUB2_PREFIX)" \
  86. $(if $(GRUB2_BUILTIN_CONFIG),-c $(GRUB2_BUILTIN_CONFIG)) \
  87. $(GRUB2_BUILTIN_MODULES)
  88. mkdir -p $(dir $(GRUB2_CFG))
  89. $(INSTALL) -D -m 0644 boot/grub2/grub.cfg $(GRUB2_CFG)
  90. $(GRUB2_IMAGE_INSTALL_ELTORITO)
  91. endef
  92. GRUB2_POST_INSTALL_TARGET_HOOKS += GRUB2_IMAGE_INSTALLATION
  93. ifeq ($(GRUB2_PLATFORM),efi)
  94. define GRUB2_EFI_STARTUP_NSH
  95. echo $(notdir $(GRUB2_IMAGE)) > \
  96. $(BINARIES_DIR)/efi-part/startup.nsh
  97. endef
  98. GRUB2_POST_INSTALL_TARGET_HOOKS += GRUB2_EFI_STARTUP_NSH
  99. endif
  100. $(eval $(autotools-package))