ghc-7.8.4.ebuild 20 KB

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