grub-9999.ebuild 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. # Copyright 1999-2017 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=6
  4. if [[ ${PV} == 9999 ]]; then
  5. GRUB_AUTOGEN=1
  6. fi
  7. if [[ -n ${GRUB_AUTOGEN} ]]; then
  8. PYTHON_COMPAT=( python{2_7,3_3,3_4,3_5} )
  9. WANT_LIBTOOL=none
  10. inherit autotools python-any-r1
  11. fi
  12. inherit autotools bash-completion-r1 flag-o-matic multibuild pax-utils toolchain-funcs versionator
  13. if [[ ${PV} != 9999 ]]; then
  14. if [[ ${PV} == *_alpha* || ${PV} == *_beta* || ${PV} == *_rc* ]]; then
  15. # The quote style is to work with <=bash-4.2 and >=bash-4.3 #503860
  16. MY_P=${P/_/'~'}
  17. SRC_URI="mirror://gnu-alpha/${PN}/${MY_P}.tar.xz"
  18. S=${WORKDIR}/${MY_P}
  19. else
  20. SRC_URI="mirror://gnu/${PN}/${P}.tar.xz"
  21. S=${WORKDIR}/${P%_*}
  22. fi
  23. KEYWORDS="~amd64 ~arm64 ~x86"
  24. else
  25. inherit git-r3
  26. EGIT_REPO_URI="git://git.sv.gnu.org/grub.git
  27. http://git.savannah.gnu.org/r/grub.git"
  28. fi
  29. PATCHES=(
  30. "${FILESDIR}"/gfxpayload.patch
  31. "${FILESDIR}"/grub-2.02_beta2-KERNEL_GLOBS.patch
  32. )
  33. DEJAVU=dejavu-sans-ttf-2.37
  34. UNIFONT=unifont-9.0.06
  35. SRC_URI+=" fonts? ( mirror://gnu/unifont/${UNIFONT}/${UNIFONT}.pcf.gz )
  36. themes? ( mirror://sourceforge/dejavu/${DEJAVU}.zip )"
  37. DESCRIPTION="GNU GRUB boot loader"
  38. HOMEPAGE="https://www.gnu.org/software/grub/"
  39. # Includes licenses for dejavu and unifont
  40. LICENSE="GPL-3 fonts? ( GPL-2-with-font-exception ) themes? ( BitstreamVera )"
  41. SLOT="2/${PVR}"
  42. IUSE="debug device-mapper doc efiemu +fonts mount multislot nls static sdl test +themes truetype libzfs"
  43. GRUB_ALL_PLATFORMS=( coreboot efi-32 efi-64 emu ieee1275 loongson multiboot qemu qemu-mips pc uboot xen xen-32 )
  44. IUSE+=" ${GRUB_ALL_PLATFORMS[@]/#/grub_platforms_}"
  45. REQUIRED_USE="
  46. grub_platforms_coreboot? ( fonts )
  47. grub_platforms_qemu? ( fonts )
  48. grub_platforms_ieee1275? ( fonts )
  49. grub_platforms_loongson? ( fonts )
  50. "
  51. # os-prober: Used on runtime to detect other OSes
  52. # xorriso (dev-libs/libisoburn): Used on runtime for mkrescue
  53. RDEPEND="
  54. app-arch/xz-utils
  55. >=sys-libs/ncurses-5.2-r5:0=
  56. debug? (
  57. sdl? ( media-libs/libsdl )
  58. )
  59. device-mapper? ( >=sys-fs/lvm2-2.02.45 )
  60. libzfs? ( sys-fs/zfs )
  61. mount? ( sys-fs/fuse )
  62. truetype? ( media-libs/freetype:2= )
  63. ppc? ( sys-apps/ibm-powerpc-utils sys-apps/powerpc-utils )
  64. ppc64? ( sys-apps/ibm-powerpc-utils sys-apps/powerpc-utils )
  65. "
  66. DEPEND="${RDEPEND}
  67. ${PYTHON_DEPS}
  68. app-misc/pax-utils
  69. sys-devel/flex
  70. sys-devel/bison
  71. sys-apps/help2man
  72. sys-apps/texinfo
  73. fonts? ( media-libs/freetype:2 )
  74. grub_platforms_xen? ( app-emulation/xen-tools:= )
  75. grub_platforms_xen-32? ( app-emulation/xen-tools:= )
  76. static? (
  77. app-arch/xz-utils[static-libs(+)]
  78. truetype? (
  79. app-arch/bzip2[static-libs(+)]
  80. media-libs/freetype[static-libs(+)]
  81. sys-libs/zlib[static-libs(+)]
  82. )
  83. )
  84. test? (
  85. app-admin/genromfs
  86. app-arch/cpio
  87. app-arch/lzop
  88. app-emulation/qemu
  89. dev-libs/libisoburn
  90. sys-apps/miscfiles
  91. sys-block/parted
  92. sys-fs/squashfs-tools
  93. )
  94. themes? (
  95. app-arch/unzip
  96. media-libs/freetype:2
  97. )
  98. "
  99. RDEPEND+="
  100. kernel_linux? (
  101. grub_platforms_efi-32? ( sys-boot/efibootmgr )
  102. grub_platforms_efi-64? ( sys-boot/efibootmgr )
  103. )
  104. !multislot? ( !sys-boot/grub:0 !sys-boot/grub-static )
  105. nls? ( sys-devel/gettext )
  106. "
  107. DEPEND+=" !!=media-libs/freetype-2.5.4"
  108. RESTRICT="strip !test? ( test )"
  109. QA_EXECSTACK="usr/bin/grub*-emu* usr/lib/grub/*"
  110. QA_WX_LOAD="usr/lib/grub/*"
  111. QA_MULTILIB_PATHS="usr/lib/grub/.*"
  112. src_unpack() {
  113. if [[ ${PV} == 9999 ]]; then
  114. git-r3_src_unpack
  115. fi
  116. default
  117. }
  118. src_prepare() {
  119. default
  120. sed -i -e /autoreconf/d autogen.sh || die
  121. if use multislot; then
  122. # fix texinfo file name, bug 416035
  123. sed -i -e 's/^\* GRUB:/* GRUB2:/' -e 's/(grub)/(grub2)/' docs/grub.texi || die
  124. fi
  125. # Nothing in Gentoo packages 'american-english' in the exact path
  126. # wanted for the test, but all that is needed is a compressible text
  127. # file, and we do have 'words' from miscfiles in the same path.
  128. sed -i \
  129. -e '/CFILESSRC.*=/s,american-english,words,' \
  130. tests/util/grub-fs-tester.in \
  131. || die
  132. if [[ -n ${GRUB_AUTOGEN} ]]; then
  133. python_setup
  134. bash autogen.sh || die
  135. autopoint() { :; }
  136. eautoreconf
  137. fi
  138. }
  139. grub_do() {
  140. multibuild_foreach_variant run_in_build_dir "$@"
  141. }
  142. grub_do_once() {
  143. multibuild_for_best_variant run_in_build_dir "$@"
  144. }
  145. grub_configure() {
  146. local platform
  147. case ${MULTIBUILD_VARIANT} in
  148. efi*) platform=efi ;;
  149. xen*) platform=xen ;;
  150. guessed) ;;
  151. *) platform=${MULTIBUILD_VARIANT} ;;
  152. esac
  153. case ${MULTIBUILD_VARIANT} in
  154. *-32)
  155. if [[ ${CTARGET:-${CHOST}} == x86_64* ]]; then
  156. local CTARGET=i386
  157. fi ;;
  158. *-64)
  159. if [[ ${CTARGET:-${CHOST}} == i?86* ]]; then
  160. local CTARGET=x86_64
  161. local -x TARGET_CFLAGS="-Os -march=x86-64 ${TARGET_CFLAGS}"
  162. local -x TARGET_CPPFLAGS="-march=x86-64 ${TARGET_CPPFLAGS}"
  163. fi ;;
  164. esac
  165. local myeconfargs=(
  166. --disable-werror
  167. --program-prefix=
  168. --libdir="${EPREFIX}"/usr/lib
  169. --htmldir="${EPREFIX}"/usr/share/doc/${PF}/html
  170. $(use_enable debug mm-debug)
  171. $(use_enable device-mapper)
  172. $(use_enable mount grub-mount)
  173. $(use_enable nls)
  174. $(use_enable themes grub-themes)
  175. $(use_enable truetype grub-mkfont)
  176. $(use_enable libzfs)
  177. $(use sdl && use_enable debug grub-emu-sdl)
  178. ${platform:+--with-platform=}${platform}
  179. # Let configure detect this where supported
  180. $(usex efiemu '' '--disable-efiemu')
  181. )
  182. if use multislot; then
  183. myeconfargs+=( --program-transform-name="s,grub,grub2," )
  184. fi
  185. # Set up font symlinks
  186. ln -s "${WORKDIR}/${UNIFONT}.pcf" unifont.pcf || die
  187. if use themes; then
  188. ln -s "${WORKDIR}/${DEJAVU}/ttf/DejaVuSans.ttf" DejaVuSans.ttf || die
  189. fi
  190. local ECONF_SOURCE="${S}"
  191. econf "${myeconfargs[@]}"
  192. }
  193. src_configure() {
  194. # Bug 508758.
  195. replace-flags -O3 -O2
  196. # We don't want to leak flags onto boot code.
  197. export HOST_CCASFLAGS=${CCASFLAGS}
  198. export HOST_CFLAGS=${CFLAGS}
  199. export HOST_CPPFLAGS=${CPPFLAGS}
  200. export HOST_LDFLAGS=${LDFLAGS}
  201. unset CCASFLAGS CFLAGS CPPFLAGS LDFLAGS
  202. use static && HOST_LDFLAGS+=" -static"
  203. tc-ld-disable-gold #439082 #466536 #526348
  204. export TARGET_LDFLAGS="${TARGET_LDFLAGS} ${LDFLAGS}"
  205. unset LDFLAGS
  206. tc-export CC NM OBJCOPY RANLIB STRIP
  207. tc-export BUILD_CC # Bug 485592
  208. MULTIBUILD_VARIANTS=()
  209. local p
  210. for p in "${GRUB_ALL_PLATFORMS[@]}"; do
  211. use "grub_platforms_${p}" && MULTIBUILD_VARIANTS+=( "${p}" )
  212. done
  213. [[ ${#MULTIBUILD_VARIANTS[@]} -eq 0 ]] && MULTIBUILD_VARIANTS=( guessed )
  214. grub_do grub_configure
  215. }
  216. src_compile() {
  217. # Sandbox bug 404013.
  218. use libzfs && addpredict /etc/dfs:/dev/zfs
  219. grub_do emake
  220. use doc && grub_do_once emake -C docs html
  221. }
  222. src_test() {
  223. # The qemu dependency is a bit complex.
  224. # You will need to adjust QEMU_SOFTMMU_TARGETS to match the cpu/platform.
  225. grub_do emake check
  226. }
  227. src_install() {
  228. grub_do emake install DESTDIR="${D}" bashcompletiondir="$(get_bashcompdir)"
  229. use doc && grub_do_once emake -C docs install-html DESTDIR="${D}"
  230. einstalldocs
  231. if use multislot; then
  232. mv "${ED%/}"/usr/share/info/grub{,2}.info || die
  233. fi
  234. insinto /etc/default
  235. newins "${FILESDIR}"/grub.default-3 grub
  236. }
  237. pkg_postinst() {
  238. elog "For information on how to configure GRUB2 please refer to the guide:"
  239. elog " https://wiki.gentoo.org/wiki/GRUB2_Quick_Start"
  240. if has_version 'sys-boot/grub:0'; then
  241. elog "A migration guide for GRUB Legacy users is available:"
  242. elog " https://wiki.gentoo.org/wiki/GRUB2_Migration"
  243. fi
  244. if [[ -z ${REPLACING_VERSIONS} ]]; then
  245. elog
  246. elog "You may consider installing the following optional packages:"
  247. optfeature "Detect other operating systems (grub-mkconfig)" sys-boot/os-prober
  248. optfeature "Create rescue media (grub-mkrescue)" dev-libs/libisoburn
  249. optfeature "Enable RAID device detection" sys-fs/mdadm
  250. fi
  251. }