refind-0.10.4-r2.ebuild 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. # Copyright 1999-2017 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=6
  4. inherit toolchain-funcs flag-o-matic versionator
  5. DESCRIPTION="The rEFInd UEFI Boot Manager by Rod Smith"
  6. HOMEPAGE="http://www.rodsbooks.com/refind/"
  7. SRC_URI="mirror://sourceforge/project/${PN}/${PV}/${PN}-src-${PV}.tar.gz"
  8. LICENSE="BSD GPL-2 GPL-3 FDL-1.3"
  9. SLOT="0"
  10. KEYWORDS="amd64 x86"
  11. FS_USE="btrfs +ext2 +ext4 hfs +iso9660 ntfs reiserfs"
  12. IUSE="${FS_USE} -gnuefi doc -custom-cflags"
  13. DEPEND="gnuefi? ( >=sys-boot/gnu-efi-3.0.2 )
  14. !gnuefi? ( >=sys-boot/udk-2015 )"
  15. DOCS="NEWS.txt README.txt docs/refind docs/Styles"
  16. pkg_pretend() {
  17. if use custom-cflags; then
  18. ewarn
  19. ewarn "You have enabled building with USE=custom-cflags. Be aware that"
  20. ewarn "using this can result in EFI binaries that fail to run and may"
  21. ewarn "fail to build at all. This is strongly advised against by upstream."
  22. ewarn
  23. ewarn "See https://bugs.gentoo.org/598587#c3 for more information"
  24. ewarn
  25. fi
  26. }
  27. pkg_setup() {
  28. if use x86 ; then
  29. export EFIARCH=ia32
  30. export BUILDARCH=ia32
  31. elif use amd64; then
  32. export EFIARCH=x64
  33. export BUILDARCH=x86_64
  34. else
  35. # Try to support anyway
  36. export BUILDARCH=$( uname -m | sed s,i[3456789]86,ia32, )
  37. if [[ ${BUILDARCH} == "x86_64" ]] ; then
  38. export EFIARCH=x64
  39. else
  40. export EFIARCH=${ARCH}
  41. fi
  42. fi
  43. }
  44. src_prepare() {
  45. default
  46. # bug 598647 - PIE not supported
  47. sed -e 's:CFLAGS =:& -fno-PIE:' -i "${S}/Make.common" || die
  48. local f
  49. for f in "${S}"/*/Make.tiano "${S}"/Make.common; do
  50. sed -i -e 's/^\(include .*target.txt.*\)$/#\1/' \
  51. -e 's@^\(TIANO_INCLUDE_DIRS\s*=\s*-I\s*\).*$@\1/usr/include/udk \\@' \
  52. -e '/^\s*-I \$(EDK2BASE).*$/d' \
  53. "${f}" || die "Failed to patch Tianocore make file in" \
  54. $(basename $(dirname ${f}))
  55. done
  56. for f in "${S}"/*/Make.tiano; do
  57. sed -i -e 's@^\(EFILIB\s*=\s*\).*$@\1/usr/lib@' \
  58. -e 's@\$(EFILIB).*/\([^/]*\).lib@-l\1@' \
  59. -e 's/\(--start-group\s*\$(ALL_EFILIBS)\)/-L \$(EFILIB) \1/' \
  60. "${f}" || die "Failed to patch Tianocore make file in" \
  61. $(basename $(dirname ${f}))
  62. done
  63. sed -i -e '/Guids/i#include "AutoGen.h"\n' "${S}/filesystems/AutoGen.c" \
  64. || die "Failed to patch AutoGen.c"
  65. for f in "${S}"/*/AutoGen.c; do
  66. cat >>"${f}" <<-EOF || die "Failed to patch AutoGen.c"
  67. #define _PCD_TOKEN_PcdFixedDebugPrintErrorLevel 11U
  68. #define _PCD_SIZE_PcdFixedDebugPrintErrorLevel 4
  69. #define _PCD_GET_MODE_SIZE_PcdFixedDebugPrintErrorLevel _PCD_SIZE_PcdFixedDebugPrintErrorLevel
  70. #define _PCD_VALUE_PcdFixedDebugPrintErrorLevel 0xFFFFFFFFU
  71. GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPcd_FixedAtBuild_PcdFixedDebugPrintErrorLevel = _PCD_VALUE_PcdFixedDebugPrintErrorLevel;
  72. extern const UINT32 _gPcd_FixedAtBuild_PcdFixedDebugPrintErrorLevel;
  73. #define _PCD_GET_MODE_32_PcdFixedDebugPrintErrorLevel _gPcd_FixedAtBuild_PcdFixedDebugPrintErrorLevel
  74. //#define _PCD_SET_MODE_32_PcdFixedDebugPrintErrorLevel ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD
  75. EOF
  76. done
  77. }
  78. src_compile() {
  79. # Prepare flags
  80. local pecoff_header_size
  81. [[ $EFIARCH == x64 ]] && pecoff_header_size='0x228' \
  82. || pecoff_header_size='0x220'
  83. local make_flags=(
  84. ARCH="${BUILDARCH}"
  85. GENFW="/usr/bin/GenFw"
  86. CC="$(tc-getCC)"
  87. AS="$(tc-getAS)"
  88. LD="$(tc-getLD)"
  89. AR="$(tc-getAR)"
  90. RANLIB="$(tc-getRANLIB)"
  91. OBJCOPY="$(tc-getOBJCOPY)"
  92. GNUEFI_LDFLAGS="-T \$(GNUEFI_LDSCRIPT) -shared -nostdlib -Bsymbolic \
  93. -L\$(EFILIB) -L\$(GNUEFILIB) \$(CRTOBJS) -znocombreloc -zdefs"
  94. TIANO_LDSCRIPT="/usr/lib/GccBase.lds"
  95. TIANO_LDFLAGS="-n -q --gc-sections -nostdlib \
  96. --script=\$(TIANO_LDSCRIPT) \
  97. --defsym=PECOFF_HEADER_SIZE=${pecoff_header_size} \
  98. --entry \$(ENTRYPOINT) -u \$(ENTRYPOINT) -m \$(LD_CODE)"
  99. )
  100. # Make main EFI
  101. local all_target
  102. use gnuefi && all_target="gnuefi" || all_target="tiano"
  103. if use custom-cflags; then
  104. emake CFLAGS="${CFLAGS}" "${make_flags[@]}" ${all_target}
  105. else
  106. emake "${make_flags[@]}" ${all_target}
  107. fi
  108. # Make filesystem drivers
  109. local gnuefi_target
  110. use gnuefi && gnuefi_target="_gnuefi"
  111. local fs
  112. for fs in ${FS_USE}; do
  113. fs=${fs#+}
  114. if use "${fs}"; then
  115. einfo "Building ${fs} filesystem driver"
  116. if use custom-cflags; then
  117. emake CFLAGS="${CFLAGS}" "${make_flags[@]}" -C "${S}/filesystems" ${fs}${gnuefi_target}
  118. else
  119. emake "${make_flags[@]}" -C "${S}/filesystems" ${fs}${gnuefi_target}
  120. fi
  121. fi
  122. done
  123. }
  124. src_install() {
  125. exeinto "/usr/share/${P}"
  126. doexe refind-install
  127. dosym "/usr/share/${P}/refind-install" "/usr/sbin/refind-install"
  128. dodoc "${S}"/{COPYING.txt,LICENSE.txt,CREDITS.txt}
  129. if use doc; then
  130. doman "${S}/docs/man/"*
  131. dodoc -r ${DOCS}
  132. fi
  133. insinto "/usr/share/${P}/refind"
  134. doins "${S}/refind/refind_${EFIARCH}.efi"
  135. doins "${S}/refind.conf-sample"
  136. doins -r images icons fonts banners
  137. if [[ -d "${S}/drivers_${EFIARCH}" ]]; then
  138. doins -r "${S}/drivers_${EFIARCH}"
  139. fi
  140. insinto "/usr/share/${P}/refind/tools_${EFIARCH}"
  141. doins "${S}/gptsync/gptsync_${EFIARCH}.efi"
  142. insinto "/etc/refind.d"
  143. doins -r "${S}/keys"
  144. dosbin "${S}/mkrlconf"
  145. dosbin "${S}/mvrefind"
  146. dosbin "${S}/refind-mkdefault"
  147. }
  148. pkg_postinst() {
  149. elog "rEFInd has been built and installed into ${EROOT%/}/usr/share/${P}"
  150. elog "You will need to use the command 'refind-install' to install"
  151. elog "the binaries into your EFI System Partition"
  152. elog ""
  153. if [[ -z "${REPLACING_VERSIONS}" ]]; then
  154. elog "refind-install requires additional packages to be fully functional:"
  155. elog " app-crypt/sbsigntool for binary signing for use with SecureBoot"
  156. elog " sys-boot/efibootmgr for writing to NVRAM"
  157. elog " sys-block/parted for automatic ESP location and mount"
  158. elog ""
  159. elog "refind-mkdefault requires >=dev-lang/python-3"
  160. elog ""
  161. elog "A sample configuration can be found at"
  162. elog "${EROOT%}/usr/share/${P}/refind/refind.conf-sample"
  163. else
  164. if ! version_is_at_least "0.10.3" "${REPLACING_VERSIONS}"; then
  165. elog "The new refind-mkdefault script requires >=dev-lang/python-3"
  166. elog "to be installed"
  167. elog ""
  168. fi
  169. ewarn "Note that this installation will not update any EFI binaries"
  170. ewarn "on your EFI System Partition - this needs to be done manually"
  171. fi
  172. }