ghc-8.0.2.ebuild 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. # Copyright 1999-2017 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=5
  4. # to make make a crosscompiler use crossdev and symlink ghc tree into
  5. # cross overlay. result would look like 'cross-sparc-unknown-linux-gnu/ghc'
  6. #
  7. # 'CTARGET' definition and 'is_crosscompile' are taken from 'toolchain.eclass'
  8. export CTARGET=${CTARGET:-${CHOST}}
  9. if [[ ${CTARGET} = ${CHOST} ]] ; then
  10. if [[ ${CATEGORY/cross-} != ${CATEGORY} ]] ; then
  11. export CTARGET=${CATEGORY/cross-}
  12. fi
  13. fi
  14. inherit autotools bash-completion-r1 eutils flag-o-matic ghc-package
  15. inherit multilib pax-utils toolchain-funcs versionator prefix
  16. DESCRIPTION="The Glasgow Haskell Compiler"
  17. HOMEPAGE="http://www.haskell.org/ghc/"
  18. # we don't have any binaries yet
  19. arch_binaries=""
  20. # sorted!
  21. arch_binaries="$arch_binaries alpha? ( http://code.haskell.org/~slyfox/ghc-alpha/ghc-bin-${PV}-alpha.tbz2 )"
  22. #arch_binaries="$arch_binaries arm? ( http://code.haskell.org/~slyfox/ghc-arm/ghc-bin-${PV}-arm.tbz2 )"
  23. arch_binaries="$arch_binaries arm64? ( http://code.haskell.org/~slyfox/ghc-arm64/ghc-bin-${PV}-arm64.tbz2 )"
  24. arch_binaries="$arch_binaries amd64? ( http://code.haskell.org/~slyfox/ghc-amd64/ghc-bin-${PV}-amd64.tbz2 )"
  25. #arch_binaries="$arch_binaries ia64? ( http://code.haskell.org/~slyfox/ghc-ia64/ghc-bin-${PV}-ia64-fixed-fiw.tbz2 )"
  26. #arch_binaries="$arch_binaries ppc? ( http://code.haskell.org/~slyfox/ghc-ppc/ghc-bin-${PV}-ppc.tbz2 )"
  27. #arch_binaries="$arch_binaries ppc64? ( http://code.haskell.org/~slyfox/ghc-ppc64/ghc-bin-${PV}-ppc64.tbz2 )"
  28. #arch_binaries="$arch_binaries sparc? ( http://code.haskell.org/~slyfox/ghc-sparc/ghc-bin-${PV}-sparc.tbz2 )"
  29. arch_binaries="$arch_binaries x86? ( http://code.haskell.org/~slyfox/ghc-x86/ghc-bin-${PV}-x86.tbz2 )"
  30. # various ports:
  31. #arch_binaries="$arch_binaries x86-fbsd? ( http://code.haskell.org/~slyfox/ghc-x86-fbsd/ghc-bin-${PV}-x86-fbsd.tbz2 )"
  32. # 0 - yet
  33. yet_binary() {
  34. case "${ARCH}" in
  35. alpha) return 0 ;;
  36. arm64) return 0 ;;
  37. #arm)
  38. # ewarn "ARM binary is built on armv5tel-eabi toolchain. Use with caution."
  39. # return 0
  40. #;;
  41. amd64) return 0 ;;
  42. #ia64) return 0 ;;
  43. #ppc) return 0 ;;
  44. #ppc64) return 0 ;;
  45. #sparc) return 0 ;;
  46. x86) return 0 ;;
  47. *) return 1 ;;
  48. esac
  49. }
  50. GHC_PV=${PV}
  51. #GHC_PV=8.0.1.20161213 # uncomment only for -rc ebuilds
  52. GHC_P=${PN}-${GHC_PV} # using ${P} is almost never correct
  53. SRC_URI="!binary? ( http://downloads.haskell.org/~ghc/${PV/_rc/-rc}/${GHC_P}-src.tar.xz )"
  54. S="${WORKDIR}"/${GHC_P}
  55. [[ -n $arch_binaries ]] && SRC_URI+=" !ghcbootstrap? ( $arch_binaries )"
  56. BUMP_LIBRARIES=(
  57. # "hackage-name hackage-version"
  58. )
  59. LICENSE="BSD"
  60. SLOT="0/${PV}"
  61. KEYWORDS="~alpha ~amd64 ~x86 ~amd64-linux ~x86-linux"
  62. IUSE="doc ghcbootstrap ghcmakebinary +gmp +profile"
  63. IUSE+=" binary"
  64. RDEPEND="
  65. >=dev-lang/perl-5.6.1
  66. dev-libs/gmp:0=
  67. sys-libs/ncurses:=[unicode]
  68. !ghcmakebinary? ( virtual/libffi:= )
  69. "
  70. # gentoo binaries are built against ncurses-6
  71. RDEPEND+="
  72. binary? (
  73. || (
  74. sys-libs/ncurses:0/6
  75. sys-libs/ncurses:5/6
  76. )
  77. )
  78. "
  79. DEPEND="${RDEPEND}
  80. doc? ( app-text/docbook-xml-dtd:4.2
  81. app-text/docbook-xml-dtd:4.5
  82. app-text/docbook-xsl-stylesheets
  83. dev-python/sphinx
  84. >=dev-libs/libxslt-1.1.2 )
  85. "
  86. PDEPEND="!ghcbootstrap? ( =app-admin/haskell-updater-1.2* )"
  87. REQUIRED_USE="?? ( ghcbootstrap binary )"
  88. # haskell libraries built with cabal in configure mode, #515354
  89. QA_CONFIGURE_OPTIONS+=" --with-compiler --with-gcc"
  90. is_crosscompile() {
  91. [[ ${CHOST} != ${CTARGET} ]]
  92. }
  93. # returns tool prefix for crosscompiler.
  94. # Example:
  95. # CTARGET=armv7a-unknown-linux-gnueabi
  96. # CHOST=x86_64-pc-linux-gnu
  97. # "armv7a-unknown-linux-gnueabi-"
  98. # CTARGET=${CHOST}
  99. # ""
  100. # Used in tools and library prefix:
  101. # "${ED}"/usr/bin/$(cross)haddock
  102. # "${ED}/usr/$(get_libdir)/$(cross)${GHC_P}/package.conf.d"
  103. cross() {
  104. if is_crosscompile; then
  105. echo "${CTARGET}-"
  106. else
  107. echo ""
  108. fi
  109. }
  110. append-ghc-cflags() {
  111. local persistent compile assemble link
  112. local flag ghcflag
  113. for flag in $*; do
  114. case ${flag} in
  115. persistent) persistent="yes";;
  116. compile) compile="yes";;
  117. assemble) assemble="yes";;
  118. link) link="yes";;
  119. *)
  120. [[ ${compile} ]] && ghcflag="-optc${flag}" CFLAGS+=" ${flag}" && GHC_FLAGS+=" ${ghcflag}" &&
  121. [[ ${persistent} ]] && GHC_PERSISTENT_FLAGS+=" ${ghcflag}"
  122. [[ ${assemble} ]] && ghcflag="-opta${flag}" CFLAGS+=" ${flag}" && GHC_FLAGS+=" ${ghcflag}" &&
  123. [[ ${persistent} ]] && GHC_PERSISTENT_FLAGS+=" ${ghcflag}"
  124. [[ ${link} ]] && ghcflag="-optl${flag}" LDFLAGS+=" ${flag}" && GHC_FLAGS+=" ${ghcflag}" &&
  125. [[ ${persistent} ]] && GHC_PERSISTENT_FLAGS+=" ${ghcflag}"
  126. ;;
  127. esac
  128. done
  129. }
  130. # $1 - lib name (under libraries/)
  131. # $2 - lib version
  132. # example: bump_lib "transformers" "0.4.2.0"
  133. bump_lib() {
  134. local pn=$1 pv=$2
  135. local p=${pn}-${pv}
  136. local f
  137. einfo "Bumping ${pn} up to ${pv}"
  138. for f in ghc.mk GNUmakefile; do
  139. mv libraries/"${pn}"/$f "${WORKDIR}"/"${p}"/$f || die
  140. done
  141. mv libraries/"${pn}" "${WORKDIR}"/"${pn}".old || die
  142. mv "${WORKDIR}"/"${p}" libraries/"${pn}" || die
  143. }
  144. update_SRC_URI() {
  145. local p pn pv
  146. for p in "${BUMP_LIBRARIES[@]}"; do
  147. set -- $p
  148. pn=$1 pv=$2
  149. SRC_URI+=" mirror://hackage/package/${pn}/${pn}-${pv}.tar.gz"
  150. done
  151. }
  152. update_SRC_URI
  153. bump_libs() {
  154. local p pn pv
  155. for p in "${BUMP_LIBRARIES[@]}"; do
  156. set -- $p
  157. pn=$1 pv=$2
  158. bump_lib "${pn}" "${pv}"
  159. done
  160. }
  161. ghc_setup_cflags() {
  162. if is_crosscompile; then
  163. export CFLAGS=${GHC_CFLAGS-"-O2 -pipe"}
  164. export LDFLAGS=${GHC_LDFLAGS-"-Wl,-O1"}
  165. einfo "Crosscompiling mode:"
  166. einfo " CHOST: ${CHOST}"
  167. einfo " CTARGET: ${CTARGET}"
  168. einfo " CFLAGS: ${CFLAGS}"
  169. einfo " LDFLAGS: ${LDFLAGS}"
  170. einfo " prefix: $(cross)"
  171. return
  172. fi
  173. # We need to be very careful with the CFLAGS we ask ghc to pass through to
  174. # gcc. There are plenty of flags which will make gcc produce output that
  175. # breaks ghc in various ways. The main ones we want to pass through are
  176. # -mcpu / -march flags. These are important for arches like alpha & sparc.
  177. # We also use these CFLAGS for building the C parts of ghc, ie the rts.
  178. strip-flags
  179. strip-unsupported-flags
  180. # Cmm can't parse line numbers #482086
  181. replace-flags -ggdb[3-9] -ggdb2
  182. GHC_FLAGS=""
  183. GHC_PERSISTENT_FLAGS=""
  184. for flag in ${CFLAGS}; do
  185. case ${flag} in
  186. # Ignore extra optimisation (ghc passes -O to gcc anyway)
  187. # -O2 and above break on too many systems
  188. -O*) ;;
  189. # Arch and ABI flags are what we're really after
  190. -m*) append-ghc-cflags compile assemble ${flag};;
  191. # Sometimes it's handy to see backtrace of RTS
  192. # to get an idea what happens there
  193. -g*) append-ghc-cflags compile ${flag};;
  194. # Ignore all other flags, including all -f* flags
  195. esac
  196. done
  197. for flag in ${LDFLAGS}; do
  198. append-ghc-cflags link ${flag}
  199. done
  200. # hardened-gcc needs to be disabled, because our prebuilt binaries/libraries
  201. # are not built with fPIC, bug #606666
  202. gcc-specs-pie && append-ghc-cflags persistent compile link -nopie
  203. tc-is-gcc && version_is_at_least 6.3 $(gcc-version) && if ! use ghcbootstrap; then
  204. # gcc-6.3 has support for -no-pie upstream, but spelling differs from
  205. # gentoo-specific '-nopie'. We enable it in non-bootstrap to allow
  206. # hardened users try '-pie' in USE=ghcbootstrap mode.
  207. append-ghc-cflags compile link -no-pie
  208. fi
  209. # prevent from failind building unregisterised ghc:
  210. # http://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg171602.html
  211. use ppc64 && append-ghc-cflags persistent compile -mminimal-toc
  212. }
  213. # substitutes string $1 to $2 in files $3 $4 ...
  214. relocate_path() {
  215. local from=$1
  216. local to=$2
  217. shift 2
  218. local file=
  219. for file in "$@"
  220. do
  221. sed -i -e "s|$from|$to|g" \
  222. "$file" || die "path relocation failed for '$file'"
  223. done
  224. }
  225. # changes hardcoded ghc paths and updates package index
  226. # $1 - new absolute root path
  227. relocate_ghc() {
  228. local to=$1
  229. # libdir for prebuilt binary and for current system may mismatch
  230. # It does for prefix installation for example: bug #476998
  231. local bin_ghc_prefix=${WORKDIR}/usr
  232. local bin_libpath=$(echo "${bin_ghc_prefix}"/lib*)
  233. local bin_libdir=${bin_libpath#${bin_ghc_prefix}/}
  234. # backup original script to use it later after relocation
  235. local gp_back="${T}/ghc-pkg-${GHC_PV}-orig"
  236. cp "${WORKDIR}/usr/bin/$(cross)ghc-pkg-${GHC_PV}" "$gp_back" || die "unable to backup ghc-pkg wrapper"
  237. if [[ ${bin_libdir} != $(get_libdir) ]]; then
  238. einfo "Relocating '${bin_libdir}' to '$(get_libdir)' (bug #476998)"
  239. # moving the dir itself is not strictly needed
  240. # but then USE=binary would result in installing
  241. # in '${bin_libdir}'
  242. mv "${bin_ghc_prefix}/${bin_libdir}" "${bin_ghc_prefix}/$(get_libdir)" || die
  243. relocate_path "/usr/${bin_libdir}" "/usr/$(get_libdir)" \
  244. "${WORKDIR}/usr/bin/$(cross)ghc-${GHC_PV}" \
  245. "${WORKDIR}/usr/bin/$(cross)ghci-${GHC_PV}" \
  246. "${WORKDIR}/usr/bin/$(cross)ghc-pkg-${GHC_PV}" \
  247. "${WORKDIR}/usr/bin/$(cross)hsc2hs" \
  248. "${WORKDIR}/usr/bin/$(cross)runghc-${GHC_PV}" \
  249. "$gp_back" \
  250. "${WORKDIR}/usr/$(get_libdir)/$(cross)${GHC_P}/package.conf.d/"*
  251. fi
  252. # Relocate from /usr to ${EPREFIX}/usr
  253. relocate_path "/usr" "${to}/usr" \
  254. "${WORKDIR}/usr/bin/$(cross)ghc-${GHC_PV}" \
  255. "${WORKDIR}/usr/bin/$(cross)ghci-${GHC_PV}" \
  256. "${WORKDIR}/usr/bin/$(cross)ghc-pkg-${GHC_PV}" \
  257. "${WORKDIR}/usr/bin/$(cross)hsc2hs" \
  258. "${WORKDIR}/usr/bin/$(cross)runghc-${GHC_PV}" \
  259. "${WORKDIR}/usr/$(get_libdir)/$(cross)${GHC_P}/package.conf.d/"*
  260. # this one we will use to regenerate cache
  261. # so it should point to current tree location
  262. relocate_path "/usr" "${WORKDIR}/usr" "$gp_back"
  263. if use prefix; then
  264. # and insert LD_LIBRARY_PATH entry to EPREFIX dir tree
  265. # TODO: add the same for darwin's CHOST and it's DYLD_
  266. local new_ldpath='LD_LIBRARY_PATH="'${EPREFIX}/$(get_libdir):${EPREFIX}/usr/$(get_libdir)'${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}"\nexport LD_LIBRARY_PATH'
  267. sed -i -e '2i'"$new_ldpath" \
  268. "${WORKDIR}/usr/bin/$(cross)ghc-${GHC_PV}" \
  269. "${WORKDIR}/usr/bin/$(cross)ghci-${GHC_PV}" \
  270. "${WORKDIR}/usr/bin/$(cross)ghc-pkg-${GHC_PV}" \
  271. "${WORKDIR}/usr/bin/$(cross)hsc2hs" \
  272. "${WORKDIR}/usr/bin/$(cross)runghc-${GHC_PV}" \
  273. "$gp_back" \
  274. || die "Adding LD_LIBRARY_PATH for wrappers failed"
  275. hprefixify "${bin_libpath}"/${PN}*/settings
  276. fi
  277. # regenerate the binary package cache
  278. "$gp_back" recache || die "failed to update cache after relocation"
  279. rm "$gp_back"
  280. }
  281. pkg_setup() {
  282. # quiet portage about prebuilt binaries
  283. use binary && QA_PREBUILT="*"
  284. [[ ${MERGE_TYPE} == binary ]] && return
  285. if use ghcbootstrap; then
  286. ewarn "You requested ghc bootstrapping, this is usually only used"
  287. ewarn "by Gentoo developers to make binary .tbz2 packages."
  288. [[ -z $(type -P ghc) ]] && \
  289. die "Could not find a ghc to bootstrap with."
  290. else
  291. if ! yet_binary; then
  292. eerror "Please try emerging with USE=ghcbootstrap and report build"
  293. eerror "sucess or failure to the haskell team (haskell@gentoo.org)"
  294. die "No binary available for '${ARCH}' arch yet, USE=ghcbootstrap"
  295. fi
  296. fi
  297. }
  298. src_unpack() {
  299. # Create the ${S} dir if we're using the binary version
  300. use binary && mkdir "${S}"
  301. # the Solaris and Darwin binaries from ghc (maeder) need to be
  302. # unpacked separately, so prevent them from being unpacked
  303. local ONLYA=${A}
  304. case ${CHOST} in
  305. *-darwin* | *-solaris*) ONLYA=${GHC_P}-src.tar.bz2 ;;
  306. esac
  307. unpack ${ONLYA}
  308. }
  309. src_prepare() {
  310. ghc_setup_cflags
  311. if ! use ghcbootstrap && [[ ${CHOST} != *-darwin* && ${CHOST} != *-solaris* ]]; then
  312. # Modify the wrapper script from the binary tarball to use GHC_PERSISTENT_FLAGS.
  313. # See bug #313635.
  314. sed -i -e "s|\"\$topdir\"|\"\$topdir\" ${GHC_PERSISTENT_FLAGS}|" \
  315. "${WORKDIR}/usr/bin/$(cross)ghc-${GHC_PV}"
  316. # allow hardened users use vanilla binary to bootstrap ghc
  317. # ghci uses mmap with rwx protection at it implements dynamic
  318. # linking on it's own (bug #299709)
  319. pax-mark -m "${WORKDIR}/usr/$(get_libdir)/$(cross)${GHC_P}/bin/ghc"
  320. fi
  321. if use binary; then
  322. if use prefix; then
  323. relocate_ghc "${EPREFIX}"
  324. fi
  325. # Move unpacked files to the expected place
  326. mv "${WORKDIR}/usr" "${S}"
  327. else
  328. if ! use ghcbootstrap; then
  329. case ${CHOST} in
  330. *-darwin* | *-solaris*)
  331. # UPDATE ME for ghc-7
  332. mkdir "${WORKDIR}"/ghc-bin-installer || die
  333. pushd "${WORKDIR}"/ghc-bin-installer > /dev/null || die
  334. use sparc-solaris && unpack ghc-6.10.4-sparc-sun-solaris2.tar.bz2
  335. use x86-solaris && unpack ghc-7.0.3-i386-unknown-solaris2.tar.bz2
  336. use x86-macos && unpack ghc-7.4.1-i386-apple-darwin.tar.bz2
  337. use x64-macos && unpack ghc-7.4.1-x86_64-apple-darwin.tar.bz2
  338. popd > /dev/null
  339. pushd "${WORKDIR}"/ghc-bin-installer/ghc-[67].?*.? > /dev/null || die
  340. # fix the binaries so they run, on Solaris we need an
  341. # LD_LIBRARY_PATH which has our prefix libdirs, on
  342. # Darwin we need to replace the frameworks with our libs
  343. # from the prefix fix before installation, because some
  344. # of the tools are actually used during configure/make
  345. if [[ ${CHOST} == *-solaris* ]] ; then
  346. export LD_LIBRARY_PATH="${EPREFIX}/$(get_libdir):${EPREFIX}/usr/$(get_libdir):${LD_LIBRARY_PATH}"
  347. elif [[ ${CHOST} == *-darwin* ]] ; then
  348. local readline_framework=GNUreadline.framework/GNUreadline
  349. local gmp_framework=/opt/local/lib/libgmp.10.dylib
  350. local ncurses_file=/opt/local/lib/libncurses.5.dylib
  351. for binary in $(scanmacho -BRE MH_EXECUTE -F '%F' .) ; do
  352. install_name_tool -change \
  353. ${readline_framework} \
  354. "${EPREFIX}"/lib/libreadline.dylib \
  355. ${binary} || die
  356. install_name_tool -change \
  357. ${gmp_framework} \
  358. "${EPREFIX}"/usr/lib/libgmp.dylib \
  359. ${binary} || die
  360. install_name_tool -change \
  361. ${ncurses_file} \
  362. "${EPREFIX}"/usr/lib/libncurses.dylib \
  363. ${binary} || die
  364. done
  365. # we don't do frameworks!
  366. sed -i \
  367. -e 's/\(frameworks = \)\["GMP"\]/\1[]/g' \
  368. -e 's/\(extraLibraries = \)\["m"\]/\1["m","gmp"]/g' \
  369. rts/package.conf.in || die
  370. fi
  371. # it is autoconf, but we really don't want to give it too
  372. # much arguments, in fact we do the make in-place anyway
  373. ./configure --prefix="${WORKDIR}"/usr || die
  374. make install || die
  375. popd > /dev/null
  376. ;;
  377. *)
  378. relocate_ghc "${WORKDIR}"
  379. ;;
  380. esac
  381. fi
  382. sed -i -e "s|\"\$topdir\"|\"\$topdir\" ${GHC_PERSISTENT_FLAGS}|" \
  383. "${S}/ghc/ghc.wrapper"
  384. cd "${S}" # otherwise epatch will break
  385. epatch "${FILESDIR}"/${PN}-7.0.4-CHOST-prefix.patch
  386. epatch "${FILESDIR}"/${PN}-8.0.1_rc1-cgen-constify.patch
  387. epatch "${FILESDIR}"/${PN}-7.8.3-prim-lm.patch
  388. epatch "${FILESDIR}"/${PN}-8.0.1-limit-jN.patch
  389. epatch "${FILESDIR}"/${PN}-8.0.1-ww-args-limit.patch
  390. epatch "${FILESDIR}"/${PN}-8.0.1-par-g0-on-A32.patch
  391. epatch "${FILESDIR}"/${PN}-8.0.2_rc2-old-sphinx.patch
  392. epatch "${FILESDIR}"/${PN}-8.0.2-libffi-alpha.patch
  393. if use prefix; then
  394. # Make configure find docbook-xsl-stylesheets from Prefix
  395. sed -e '/^FP_DIR_DOCBOOK_XSL/s:\[.*\]:['"${EPREFIX}"'/usr/share/sgml/docbook/xsl-stylesheets/]:' \
  396. -i utils/haddock/doc/configure.ac || die
  397. fi
  398. bump_libs
  399. # as we have changed the build system
  400. eautoreconf
  401. fi
  402. }
  403. src_configure() {
  404. if ! use binary; then
  405. # initialize build.mk
  406. echo '# Gentoo changes' > mk/build.mk
  407. # Put docs into the right place, ie /usr/share/doc/ghc-${GHC_PV}
  408. echo "docdir = ${EPREFIX}/usr/share/doc/${P}" >> mk/build.mk
  409. echo "htmldir = ${EPREFIX}/usr/share/doc/${P}" >> mk/build.mk
  410. # We also need to use the GHC_FLAGS flags when building ghc itself
  411. echo "SRC_HC_OPTS+=${HCFLAGS} ${GHC_FLAGS}" >> mk/build.mk
  412. echo "SRC_CC_OPTS+=${CFLAGS}" >> mk/build.mk
  413. echo "SRC_LD_OPTS+=${LDFLAGS}" >> mk/build.mk
  414. # Speed up initial Cabal bootstrap
  415. echo "utils/ghc-cabal_dist_EXTRA_HC_OPTS+=$(ghc-make-args)" >> mk/build.mk
  416. # We can't depend on haddock except when bootstrapping when we
  417. # must build docs and include them into the binary .tbz2 package
  418. # app-text/dblatex is not in portage, can not build PDF or PS
  419. echo "BUILD_SPHINX_PDF = NO" >> mk/build.mk
  420. echo "BUILD_SPHINX_HTML = $(usex doc YES NO)" >> mk/build.mk
  421. # this controls presence on 'xhtml' and 'haddock' in final install
  422. echo "HADDOCK_DOCS = YES" >> mk/build.mk
  423. # allows overriding build flavours for libraries:
  424. # v - vanilla (static libs)
  425. # p - profiled
  426. # dyn - shared libraries
  427. # example: GHC_LIBRARY_WAYS="v dyn"
  428. if [[ -n ${GHC_LIBRARY_WAYS} ]]; then
  429. echo "GhcLibWays=${GHC_LIBRARY_WAYS}" >> mk/build.mk
  430. fi
  431. echo "BUILD_PROF_LIBS = $(usex profile YES NO)" >> mk/build.mk
  432. # Get ghc from the unpacked binary .tbz2
  433. # except when bootstrapping we just pick ghc up off the path
  434. if ! use ghcbootstrap; then
  435. export PATH="${WORKDIR}/usr/bin:${PATH}"
  436. fi
  437. echo "INTEGER_LIBRARY = $(usex gmp integer-gmp integer-simple)" >> mk/build.mk
  438. # don't strip anything. Very useful when stage2 SIGSEGVs on you
  439. echo "STRIP_CMD = :" >> mk/build.mk
  440. local econf_args=()
  441. # GHC embeds 'gcc' it was built by and uses it later.
  442. # Don't allow things like ccache or versioned binary slip.
  443. # We use stable thing across gcc upgrades.
  444. is_crosscompile || econf_args+=(--with-gcc=${CHOST}-gcc)
  445. if use ghcmakebinary; then
  446. # When building booting libary we are trying to
  447. # bundle or restrict most of external depends
  448. # with unstable ABI:
  449. # - embed libffi (default GHC behaviour)
  450. # - disable ncurses support for ghci (via haskeline)
  451. # https://bugs.gentoo.org/557478
  452. # - disable ncurses support for ghc-pkg
  453. echo "libraries/haskeline_CONFIGURE_OPTS += --flag=-terminfo" >> mk/build.mk
  454. echo "utils/ghc-pkg_HC_OPTS += -DBOOTSTRAPPING" >> mk/build.mk
  455. else
  456. econf_args+=(--with-system-libffi)
  457. econf_args+=(--with-ffi-includes=$(pkg-config libffi --cflags-only-I | sed -e 's@^-I@@'))
  458. fi
  459. elog "Final mk/build.mk:"
  460. cat mk/build.mk || die
  461. econf ${econf_args[@]} --enable-bootstrap-with-devel-snapshot
  462. if [[ ${PV} == *9999* ]]; then
  463. GHC_PV="$(grep 'S\[\"PACKAGE_VERSION\"\]' config.status | sed -e 's@^.*=\"\(.*\)\"@\1@')"
  464. GHC_P=${PN}-${GHC_PV}
  465. fi
  466. fi # ! use binary
  467. }
  468. src_compile() {
  469. if ! use binary; then
  470. # 1. build/pax-mark compiler binary first
  471. emake ghc/stage2/build/tmp/ghc-stage2
  472. pax-mark -m ghc/stage2/build/tmp/ghc-stage2
  473. # 2. build/pax-mark haddock using ghc-stage2
  474. emake utils/haddock/dist/build/tmp/haddock
  475. pax-mark -m utils/haddock/dist/build/tmp/haddock
  476. # 3. and then all the rest
  477. emake all
  478. fi # ! use binary
  479. }
  480. src_install() {
  481. if use binary; then
  482. use prefix && mkdir -p "${ED}"
  483. mv "${S}/usr" "${ED}"
  484. else
  485. emake install DESTDIR="${D}"
  486. dodoc "distrib/README" "ANNOUNCE" "LICENSE" "VERSION"
  487. # rename ghc-shipped files to avoid collision
  488. # of external packages. Motivating example:
  489. # user had installed:
  490. # dev-lang/ghc-7.8.4-r0 (with transformers-0.3.0.0)
  491. # dev-haskell/transformers-0.4.2.0
  492. # then user tried to update to
  493. # dev-lang/ghc-7.8.4-r1 (with transformers-0.4.2.0)
  494. # this will lead to single .conf file collision.
  495. local shipped_conf renamed_conf
  496. local package_confdir="${ED}/usr/$(get_libdir)/$(cross)${GHC_P}/package.conf.d"
  497. for shipped_conf in "${package_confdir}"/*.conf; do
  498. # rename 'pkg-ver-id.conf' to 'pkg-ver-id-gentoo-${PF}.conf'
  499. renamed_conf=${shipped_conf%.conf}-gentoo-${PF}.conf
  500. mv "${shipped_conf}" "${renamed_conf}" || die
  501. done
  502. # remove link, but leave 'haddock-${GHC_P}'
  503. rm -f "${ED}"/usr/bin/$(cross)haddock
  504. if [[ ! -f "${S}/VERSION" ]]; then
  505. echo "${GHC_PV}" > "${S}/VERSION" \
  506. || die "Could not create file ${S}/VERSION"
  507. fi
  508. if ! is_crosscompile; then
  509. newbashcomp "${FILESDIR}"/ghc-bash-completion ghc-pkg
  510. newbashcomp utils/completion/ghc.bash ghc
  511. fi
  512. fi
  513. # path to the package.cache
  514. local package_confdir="${ED}/usr/$(get_libdir)/$(cross)${GHC_P}/package.conf.d"
  515. PKGCACHE="${package_confdir}"/package.cache
  516. # copy the package.conf.d, including timestamp, save it so we can help
  517. # users that have a broken package.conf.d
  518. cp -pR "${package_confdir}"{,.initial} || die "failed to backup intial package.conf.d"
  519. # copy the package.conf, including timestamp, save it so we later can put it
  520. # back before uninstalling, or when upgrading.
  521. cp -p "${PKGCACHE}"{,.shipped} \
  522. || die "failed to copy package.conf.d/package.cache"
  523. }
  524. pkg_preinst() {
  525. # have we got an earlier version of ghc installed?
  526. if has_version "<${CATEGORY}/${PF}"; then
  527. haskell_updater_warn="1"
  528. fi
  529. }
  530. pkg_postinst() {
  531. ghc-reregister
  532. # path to the package.cache
  533. PKGCACHE="${EROOT}/usr/$(get_libdir)/$(cross)${GHC_P}/package.conf.d/package.cache"
  534. # give the cache a new timestamp, it must be as recent as
  535. # the package.conf.d directory.
  536. touch "${PKGCACHE}"
  537. if [[ "${haskell_updater_warn}" == "1" ]]; then
  538. ewarn
  539. ewarn "\e[1;31m************************************************************************\e[0m"
  540. ewarn
  541. ewarn "You have just upgraded from an older version of GHC."
  542. ewarn "You may have to run"
  543. ewarn " 'haskell-updater'"
  544. ewarn "to rebuild all ghc-based Haskell libraries."
  545. ewarn
  546. ewarn "\e[1;31m************************************************************************\e[0m"
  547. ewarn
  548. fi
  549. }
  550. pkg_prerm() {
  551. PKGCACHE="${EROOT}/usr/$(get_libdir)/$(cross)${GHC_P}/package.conf.d/package.cache"
  552. rm -rf "${PKGCACHE}"
  553. cp -p "${PKGCACHE}"{.shipped,}
  554. }
  555. pkg_postrm() {
  556. ghc-package_pkg_postrm
  557. }