ghc-7.10.3.ebuild 22 KB

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