Gentoo Archives: gentoo-commits

From: "Sergei Trofimovich (slyfox)" <slyfox@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in dev-lang/ghc: ghc-7.6.3-r1.ebuild ChangeLog
Date: Thu, 01 Aug 2013 13:15:39
Message-Id: 20130801131533.3CB1821710@flycatcher.gentoo.org
1 slyfox 13/08/01 13:15:33
2
3 Modified: ChangeLog
4 Added: ghc-7.6.3-r1.ebuild
5 Log:
6 Fixed CFLAGS=-Os ghci failure (bug #452442 by Jason Mours). Added weak symbol processing into ghci. Limit maximum parallel job count down to 4 workers (-j1 is too slow on mmodern boxes, but -j12 kills the build almost always). Does not eliminate failures completely, but reduces them significantly (bug #456386).
7
8 (Portage version: 2.2.0_alpha186/cvs/Linux x86_64, signed Manifest commit with key 611FF3AA)
9
10 Revision Changes Path
11 1.245 dev-lang/ghc/ChangeLog
12
13 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-lang/ghc/ChangeLog?rev=1.245&view=markup
14 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-lang/ghc/ChangeLog?rev=1.245&content-type=text/plain
15 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-lang/ghc/ChangeLog?r1=1.244&r2=1.245
16
17 Index: ChangeLog
18 ===================================================================
19 RCS file: /var/cvsroot/gentoo-x86/dev-lang/ghc/ChangeLog,v
20 retrieving revision 1.244
21 retrieving revision 1.245
22 diff -u -r1.244 -r1.245
23 --- ChangeLog 19 Jul 2013 10:21:35 -0000 1.244
24 +++ ChangeLog 1 Aug 2013 13:15:33 -0000 1.245
25 @@ -1,6 +1,16 @@
26 # ChangeLog for dev-lang/ghc
27 # Copyright 1999-2013 Gentoo Foundation; Distributed under the GPL v2
28 -# $Header: /var/cvsroot/gentoo-x86/dev-lang/ghc/ChangeLog,v 1.244 2013/07/19 10:21:35 slyfox Exp $
29 +# $Header: /var/cvsroot/gentoo-x86/dev-lang/ghc/ChangeLog,v 1.245 2013/08/01 13:15:33 slyfox Exp $
30 +
31 +*ghc-7.6.3-r1 (01 Aug 2013)
32 +
33 + 01 Aug 2013; Sergei Trofimovich <slyfox@g.o>
34 + +files/ghc-7.6.3-trac-3333-weak-syms.patch, +ghc-7.6.3-r1.ebuild:
35 + Fixed CFLAGS=-Os ghci failure (bug #452442 by Jason Mours). Added weak symbol
36 + processing into ghci. Limit maximum parallel job count down to 4 workers (-j1
37 + is too slow on mmodern boxes, but -j12 kills the build almost always). Does
38 + not eliminate failures completely, but reduces them significantly (bug
39 + #456386).
40
41 19 Jul 2013; Sergei Trofimovich <slyfox@g.o> ghc-7.6.3.ebuild:
42 Fix building on systems where libdir differs from the one we have built GHC
43
44
45
46 1.1 dev-lang/ghc/ghc-7.6.3-r1.ebuild
47
48 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-lang/ghc/ghc-7.6.3-r1.ebuild?rev=1.1&view=markup
49 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-lang/ghc/ghc-7.6.3-r1.ebuild?rev=1.1&content-type=text/plain
50
51 Index: ghc-7.6.3-r1.ebuild
52 ===================================================================
53 # Copyright 1999-2013 Gentoo Foundation
54 # Distributed under the terms of the GNU General Public License v2
55 # $Header: /var/cvsroot/gentoo-x86/dev-lang/ghc/ghc-7.6.3-r1.ebuild,v 1.1 2013/08/01 13:15:33 slyfox Exp $
56
57 # Brief explanation of the bootstrap logic:
58 #
59 # Previous ghc ebuilds have been split into two: ghc and ghc-bin,
60 # where ghc-bin was primarily used for bootstrapping purposes.
61 # From now on, these two ebuilds have been combined, with the
62 # binary USE flag used to determine whether or not the pre-built
63 # binary package should be emerged or whether ghc should be compiled
64 # from source. If the latter, then the relevant ghc-bin for the
65 # arch in question will be used in the working directory to compile
66 # ghc from source.
67 #
68 # This solution has the advantage of allowing us to retain the one
69 # ebuild for both packages, and thus phase out virtual/ghc.
70
71 # Note to users of hardened gcc-3.x:
72 #
73 # If you emerge ghc with hardened gcc it should work fine (because we
74 # turn off the hardened features that would otherwise break ghc).
75 # However, emerging ghc while using a vanilla gcc and then switching to
76 # hardened gcc (using gcc-config) will leave you with a broken ghc. To
77 # fix it you would need to either switch back to vanilla gcc or re-emerge
78 # ghc (or ghc-bin). Note that also if you are using hardened gcc-3.x and
79 # you switch to gcc-4.x that this will also break ghc and you'll need to
80 # re-emerge ghc (or ghc-bin). People using vanilla gcc can switch between
81 # gcc-3.x and 4.x with no problems.
82
83 EAPI="5"
84
85 # to make make a crosscompiler use crossdev and symlink ghc tree into
86 # cross overlay. result would look like 'cross-sparc-unknown-linux-gnu/ghc'
87 #
88 # 'CTARGET' definition and 'is_crosscompile' are taken from 'toolchain.eclass'
89 export CTARGET=${CTARGET:-${CHOST}}
90 if [[ ${CTARGET} = ${CHOST} ]] ; then
91 if [[ ${CATEGORY/cross-} != ${CATEGORY} ]] ; then
92 export CTARGET=${CATEGORY/cross-}
93 fi
94 fi
95
96 inherit autotools bash-completion-r1 eutils flag-o-matic ghc-package
97 inherit multilib multiprocessing pax-utils toolchain-funcs versionator
98
99 DESCRIPTION="The Glasgow Haskell Compiler"
100 HOMEPAGE="http://www.haskell.org/ghc/"
101
102 # we don't have any binaries yet
103 arch_binaries=""
104
105 # sorted!
106 arch_binaries="$arch_binaries alpha? ( http://code.haskell.org/~slyfox/ghc-alpha/ghc-bin-${PV}-alpha.tbz2 )"
107 #arch_binaries="$arch_binaries arm? ( http://code.haskell.org/~slyfox/ghc-arm/ghc-bin-${PV}-arm.tbz2 )"
108 arch_binaries="$arch_binaries amd64? ( http://code.haskell.org/~slyfox/ghc-amd64/ghc-bin-${PV}-amd64.tbz2 )"
109 arch_binaries="$arch_binaries ia64? ( http://code.haskell.org/~slyfox/ghc-ia64/ghc-bin-${PV}-ia64.tbz2 )"
110 #arch_binaries="$arch_binaries ppc? ( http://code.haskell.org/~slyfox/ghc-ppc/ghc-bin-${PV}-ppc.tbz2 )"
111 #arch_binaries="$arch_binaries ppc64? ( http://code.haskell.org/~slyfox/ghc-ppc64/ghc-bin-${PV}-ppc64.tbz2 )"
112 #arch_binaries="$arch_binaries sparc? ( http://code.haskell.org/~slyfox/ghc-sparc/ghc-bin-${PV}-sparc.tbz2 )"
113 arch_binaries="$arch_binaries x86? ( http://code.haskell.org/~slyfox/ghc-x86/ghc-bin-${PV}-x86.tbz2 )"
114
115 # various ports:
116 #arch_binaries="$arch_binaries x86-fbsd? ( http://code.haskell.org/~slyfox/ghc-x86-fbsd/ghc-bin-${PV}-x86-fbsd.tbz2 )"
117
118 # 0 - yet
119 yet_binary() {
120 case "${ARCH}" in
121 alpha) return 0 ;;
122 #arm)
123 # ewarn "ARM binary is built on armv5tel-eabi toolchain. Use with caution."
124 # return 0
125 #;;
126 amd64) return 0 ;;
127 ia64) return 0 ;;
128 #ppc) return 0 ;;
129 #ppc64) return 0 ;;
130 #sparc) return 0 ;;
131 x86) return 0 ;;
132 *) return 1 ;;
133 esac
134 }
135
136 SRC_URI="!binary? ( http://www.haskell.org/ghc/dist/${PV}/${P}-src.tar.bz2 )"
137 [[ -n $arch_binaries ]] && SRC_URI+=" !ghcbootstrap? ( $arch_binaries )"
138 LICENSE="BSD"
139 SLOT="0/${PV}"
140 KEYWORDS="~amd64 ~x86 ~amd64-linux ~x86-linux ~ppc-macos ~x86-macos ~sparc-solaris ~x86-solaris"
141 IUSE="doc ghcbootstrap ghcmakebinary +gmp llvm"
142 IUSE+=" binary" # don't forget about me later!
143 IUSE+=" elibc_glibc" # system stuff
144
145 RDEPEND="
146 !kernel_Darwin? ( >=sys-devel/gcc-2.95.3 )
147 kernel_linux? ( >=sys-devel/binutils-2.17 )
148 kernel_SunOS? ( >=sys-devel/binutils-2.17 )
149 >=dev-lang/perl-5.6.1
150 >=dev-libs/gmp-5
151 virtual/libffi
152 !<dev-haskell/haddock-2.4.2
153 sys-libs/ncurses[unicode]"
154 # earlier versions than 2.4.2 of haddock only works with older ghc releases
155
156 # force dependency on >=gmp-5, even if >=gmp-4.1 would be enough. this is due to
157 # that we want the binaries to use the latest versioun available, and not to be
158 # built against gmp-4
159
160 # similar for glibc. we have bootstrapped binaries against glibc-2.14
161 DEPEND="${RDEPEND}
162 ghcbootstrap? ( >=dev-haskell/alex-2.3
163 >=dev-haskell/happy-1.18
164 doc? ( app-text/docbook-xml-dtd:4.2
165 app-text/docbook-xml-dtd:4.5
166 app-text/docbook-xsl-stylesheets
167 >=dev-libs/libxslt-1.1.2 ) )
168 !ghcbootstrap? ( !prefix? ( elibc_glibc? ( >=sys-libs/glibc-2.15 ) ) )"
169
170 PDEPEND="!ghcbootstrap? ( =app-admin/haskell-updater-1.2* )"
171 PDEPEND="
172 ${PDEPEND}
173 llvm? ( sys-devel/llvm )"
174
175 # ia64 fails to return from STG GMP primitives (stage2 always SIGSEGVs)
176 REQUIRED_USE="ia64? ( !gmp )"
177
178 is_crosscompile() {
179 [[ ${CHOST} != ${CTARGET} ]]
180 }
181
182 append-ghc-cflags() {
183 local flag compile assemble link
184 for flag in $*; do
185 case ${flag} in
186 compile) compile="yes";;
187 assemble) assemble="yes";;
188 link) link="yes";;
189 *)
190 [[ ${compile} ]] && GHC_FLAGS="${GHC_FLAGS} -optc${flag}" CFLAGS="${CFLAGS} ${flag}"
191 [[ ${assemble} ]] && GHC_FLAGS="${GHC_FLAGS} -opta${flag}" CFLAGS="${CFLAGS} ${flag}"
192 [[ ${link} ]] && GHC_FLAGS="${GHC_FLAGS} -optl${flag}" FILTERED_LDFLAGS="${FILTERED_LDFLAGS} ${flag}";;
193 esac
194 done
195 }
196
197 ghc_setup_cflags() {
198 if is_crosscompile; then
199 export CFLAGS=${GHC_CFLAGS-"-O2 -pipe"}
200 export LDFLAGS=${GHC_LDFLAGS-"-Wl,-O1"}
201 einfo "Crosscompiling mode:"
202 einfo " CHOST: ${CHOST}"
203 einfo " CTARGET: ${CTARGET}"
204 einfo " CFLAGS: ${CFLAGS}"
205 einfo " LDFLAGS: ${LDFLAGS}"
206 return
207 fi
208 # We need to be very careful with the CFLAGS we ask ghc to pass through to
209 # gcc. There are plenty of flags which will make gcc produce output that
210 # breaks ghc in various ways. The main ones we want to pass through are
211 # -mcpu / -march flags. These are important for arches like alpha & sparc.
212 # We also use these CFLAGS for building the C parts of ghc, ie the rts.
213 strip-flags
214 strip-unsupported-flags
215
216 GHC_FLAGS=""
217 for flag in ${CFLAGS}; do
218 case ${flag} in
219
220 # Ignore extra optimisation (ghc passes -O to gcc anyway)
221 # -O2 and above break on too many systems
222 -O*) ;;
223
224 # Arch and ABI flags are what we're really after
225 -m*) append-ghc-cflags compile assemble ${flag};;
226
227 # Sometimes it's handy to see backtrace of RTS
228 # to get an idea what happens there
229 -g*) append-ghc-cflags compile ${flag};;
230
231 # Ignore all other flags, including all -f* flags
232 esac
233 done
234
235 FILTERED_LDFLAGS=""
236 for flag in ${LDFLAGS}; do
237 case ${flag} in
238 # Pass the canary. we don't quite respect LDFLAGS, but we have an excuse!
239 "-Wl,--hash-style="*) append-ghc-cflags link ${flag};;
240
241 # Ignore all other flags
242 esac
243 done
244
245 # hardened-gcc needs to be disabled, because the mangler doesn't accept
246 # its output.
247 gcc-specs-pie && append-ghc-cflags compile link -nopie
248 gcc-specs-ssp && append-ghc-cflags compile -fno-stack-protector
249
250 # prevent from failind building unregisterised ghc:
251 # http://www.mail-archive.com/debian-bugs-dist@××××××××××××.org/msg171602.html
252 use ppc64 && append-ghc-cflags compile -mminimal-toc
253 # fix the similar issue as ppc64 TOC on ia64. ia64 has limited size of small data
254 # currently ghc fails to build haddock
255 # http://osdir.com/ml/gnu.binutils.bugs/2004-10/msg00050.html
256 use ia64 && append-ghc-cflags compile -G0 -Os
257
258 # Unfortunately driver/split/ghc-split.lprl is dumb
259 # enough to preserve stack marking for each split object
260 # and it flags stack marking violation:
261 # * !WX --- --- usr/lib64/ghc-7.4.1/base-4.5.0.0/libHSbase-4.5.0.0.a:Fingerprint__1.o
262 # * !WX --- --- usr/lib64/ghc-7.4.1/base-4.5.0.0/libHSbase-4.5.0.0.a:Fingerprint__2.o
263 # * !WX --- --- usr/lib64/ghc-7.4.1/base-4.5.0.0/libHSbase-4.5.0.0.a:Fingerprint__3.o
264 case $($(tc-getAS) -v 2>&1 </dev/null) in
265 *"GNU Binutils"*) # GNU ld
266 append-ghc-cflags compile assemble -Wa,--noexecstack
267 ;;
268 esac
269 }
270
271 # substitutes string $1 to $2 in files $3 $4 ...
272 relocate_path() {
273 local from=$1
274 local to=$2
275 shift 2
276 local file=
277 for file in "$@"
278 do
279 sed -i -e "s|$from|$to|g" \
280 "$file" || die "path relocation failed for '$file'"
281 done
282 }
283
284 # changes hardcoded ghc paths and updates package index
285 # $1 - new absolute root path
286 relocate_ghc() {
287 local to=$1
288
289 # libdir for prebuilt binary and for current system may mismatch
290 # It does for prefix installation for example: bug #476998
291 local bin_ghc_prefix=${WORKDIR}/usr
292 local bin_libpath=$(echo "${bin_ghc_prefix}"/lib*)
293 local bin_libdir=${bin_libpath#${bin_ghc_prefix}/}
294
295 # backup original script to use it later after relocation
296 local gp_back="${T}/ghc-pkg-${PV}-orig"
297 cp "${WORKDIR}/usr/bin/ghc-pkg-${PV}" "$gp_back" || die "unable to backup ghc-pkg wrapper"
298
299 if [[ ${bin_libdir} != $(get_libdir) ]]; then
300 einfo "Relocating '${bin_libdir}' to '$(get_libdir)' (bug #476998)"
301 # moving the dir itself is not strictly needed
302 # but then USE=binary would result in installing
303 # in '${bin_libdir}'
304 mv "${bin_ghc_prefix}/${bin_libdir}" "${bin_ghc_prefix}/$(get_libdir)" || die
305
306 relocate_path "/usr/${bin_libdir}" "/usr/$(get_libdir)" \
307 "${WORKDIR}/usr/bin/ghc-${PV}" \
308 "${WORKDIR}/usr/bin/ghci-${PV}" \
309 "${WORKDIR}/usr/bin/ghc-pkg-${PV}" \
310 "${WORKDIR}/usr/bin/hsc2hs" \
311 "${WORKDIR}/usr/bin/runghc-${PV}" \
312 "$gp_back" \
313 "${WORKDIR}/usr/$(get_libdir)/${P}/package.conf.d/"*
314 fi
315
316 # Relocate from /usr to ${EPREFIX}/usr
317 relocate_path "/usr" "${to}/usr" \
318 "${WORKDIR}/usr/bin/ghc-${PV}" \
319 "${WORKDIR}/usr/bin/ghci-${PV}" \
320 "${WORKDIR}/usr/bin/ghc-pkg-${PV}" \
321 "${WORKDIR}/usr/bin/hsc2hs" \
322 "${WORKDIR}/usr/bin/runghc-${PV}" \
323 "${WORKDIR}/usr/$(get_libdir)/${P}/package.conf.d/"*
324
325 # this one we will use to regenerate cache
326 # so it should point to current tree location
327 relocate_path "/usr" "${WORKDIR}/usr" "$gp_back"
328
329 if use prefix; then
330 # and insert LD_LIBRARY_PATH entry to EPREFIX dir tree
331 # TODO: add the same for darwin's CHOST and it's DYLD_
332 local new_ldpath='LD_LIBRARY_PATH="'${EPREFIX}/$(get_libdir):${EPREFIX}/usr/$(get_libdir)'${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}"\nexport LD_LIBRARY_PATH'
333 sed -i -e '2i'"$new_ldpath" \
334 "${WORKDIR}/usr/bin/ghc-${PV}" \
335 "${WORKDIR}/usr/bin/ghci-${PV}" \
336 "${WORKDIR}/usr/bin/ghc-pkg-${PV}" \
337 "${WORKDIR}/usr/bin/hsc2hs" \
338 "${WORKDIR}/usr/bin/runghc-${PV}" \
339 "$gp_back" \
340 || die "Adding LD_LIBRARY_PATH for wrappers failed"
341 fi
342
343 # regenerate the binary package cache
344 "$gp_back" recache || die "failed to update cache after relocation"
345 rm "$gp_back"
346 }
347
348 pkg_setup() {
349 if use ghcbootstrap; then
350 ewarn "You requested ghc bootstrapping, this is usually only used"
351 ewarn "by Gentoo developers to make binary .tbz2 packages for"
352 ewarn "use with the ghc ebuild's USE=\"binary\" feature."
353 use binary && \
354 die "USE=\"ghcbootstrap binary\" is not a valid combination."
355 [[ -z $(type -P ghc) ]] && \
356 die "Could not find a ghc to bootstrap with."
357 else
358 if ! yet_binary; then
359 eerror "Please try emerging with USE=ghcbootstrap and report build"
360 eerror "sucess or failure to the haskell team (haskell@g.o)"
361 die "No binary available for '${ARCH}' arch yet, USE=ghcbootstrap"
362 fi
363 fi
364 }
365
366 src_unpack() {
367 # Create the ${S} dir if we're using the binary version
368 use binary && mkdir "${S}"
369
370 # the Solaris and Darwin binaries from ghc (maeder) need to be
371 # unpacked separately, so prevent them from being unpacked
372 local ONLYA=${A}
373 case ${CHOST} in
374 *-darwin* | *-solaris*) ONLYA=${P}-src.tar.bz2 ;;
375 esac
376 unpack ${ONLYA}
377 }
378
379 src_prepare() {
380 ghc_setup_cflags
381
382 if ! use ghcbootstrap && [[ ${CHOST} != *-darwin* && ${CHOST} != *-solaris* ]]; then
383 # Modify the wrapper script from the binary tarball to use GHC_FLAGS.
384 # See bug #313635.
385 sed -i -e "s|\"\$topdir\"|\"\$topdir\" ${GHC_FLAGS}|" \
386 "${WORKDIR}/usr/bin/ghc-${PV}"
387
388 # allow hardened users use vanilla binary to bootstrap ghc
389 # ghci uses mmap with rwx protection at it implements dynamic
390 # linking on it's own (bug #299709)
391 pax-mark -m "${WORKDIR}/usr/$(get_libdir)/${P}/ghc"
392 fi
393
394 if use binary; then
395 if use prefix; then
396 relocate_ghc "${EPREFIX}"
397 fi
398
399 # Move unpacked files to the expected place
400 mv "${WORKDIR}/usr" "${S}"
401 else
402 if ! use ghcbootstrap; then
403 case ${CHOST} in
404 *-darwin* | *-solaris*)
405 # UPDATE ME for ghc-7
406 mkdir "${WORKDIR}"/ghc-bin-installer || die
407 pushd "${WORKDIR}"/ghc-bin-installer > /dev/null || die
408 use sparc-solaris && unpack ghc-6.10.4-sparc-sun-solaris2.tar.bz2
409 use x86-solaris && unpack ghc-7.0.3-i386-unknown-solaris2.tar.bz2
410 use x86-macos && unpack ghc-7.4.1-i386-apple-darwin.tar.bz2
411 use x64-macos && unpack ghc-7.4.1-x86_64-apple-darwin.tar.bz2
412 popd > /dev/null
413
414 pushd "${WORKDIR}"/ghc-bin-installer/ghc-[67].?*.? > /dev/null || die
415 # fix the binaries so they run, on Solaris we need an
416 # LD_LIBRARY_PATH which has our prefix libdirs, on
417 # Darwin we need to replace the frameworks with our libs
418 # from the prefix fix before installation, because some
419 # of the tools are actually used during configure/make
420 if [[ ${CHOST} == *-solaris* ]] ; then
421 export LD_LIBRARY_PATH="${EPREFIX}/$(get_libdir):${EPREFIX}/usr/$(get_libdir):${LD_LIBRARY_PATH}"
422 elif [[ ${CHOST} == *-darwin* ]] ; then
423 local readline_framework=GNUreadline.framework/GNUreadline
424 local gmp_framework=/opt/local/lib/libgmp.10.dylib
425 local ncurses_file=/opt/local/lib/libncurses.5.dylib
426 for binary in $(scanmacho -BRE MH_EXECUTE -F '%F' .) ; do
427 install_name_tool -change \
428 ${readline_framework} \
429 "${EPREFIX}"/lib/libreadline.dylib \
430 ${binary} || die
431 install_name_tool -change \
432 ${gmp_framework} \
433 "${EPREFIX}"/usr/lib/libgmp.dylib \
434 ${binary} || die
435 install_name_tool -change \
436 ${ncurses_file} \
437 "${EPREFIX}"/usr/lib/libncurses.dylib \
438 ${binary} || die
439 done
440 # we don't do frameworks!
441 sed -i \
442 -e 's/\(frameworks = \)\["GMP"\]/\1[]/g' \
443 -e 's/\(extraLibraries = \)\["m"\]/\1["m","gmp"]/g' \
444 rts/package.conf.in || die
445 fi
446
447 # it is autoconf, but we really don't want to give it too
448 # much arguments, in fact we do the make in-place anyway
449 ./configure --prefix="${WORKDIR}"/usr || die
450 make install || die
451 popd > /dev/null
452 ;;
453 *)
454 relocate_ghc "${WORKDIR}"
455 ;;
456 esac
457 fi
458
459 sed -i -e "s|\"\$topdir\"|\"\$topdir\" ${GHC_FLAGS}|" \
460 "${S}/ghc/ghc.wrapper"
461
462 cd "${S}" # otherwise epatch will break
463
464 epatch "${FILESDIR}/ghc-7.0.4-CHOST-prefix.patch"
465
466 # epatch "${FILESDIR}"/${PN}-7.0.4-darwin8.patch
467 # failed to apply. FIXME
468 #epatch "${FILESDIR}"/${PN}-6.12.3-mach-o-relocation-limit.patch
469
470 # epatch "${FILESDIR}"/${PN}-7.4-rc2-macos-prefix-respect-gcc.patch
471 # epatch "${FILESDIR}"/${PN}-7.2.1-freebsd-CHOST.patch
472
473 we_want_libffi_workaround() {
474 use ghcmakebinary && return 1
475
476 # pick only registerised arches
477 # http://bugs.gentoo.org/463814
478 use amd64 && return 0
479 use x86 && return 0
480 return 1
481 }
482 # one mode external depend with unstable ABI be careful to stash it
483 # avoid external libffi runtime when we build binaries
484 we_want_libffi_workaround && epatch "${FILESDIR}"/${PN}-7.5.20120505-system-libffi.patch
485
486 epatch "${FILESDIR}"/${PN}-7.4.1-ticket-7339-fix-unaligned-unreg.patch
487 epatch "${FILESDIR}"/${PN}-7.6.2-integer-simple-div-mod.patch
488 # ghc-7.8 changed linker code and likely fixed it
489 epatch "${FILESDIR}"/${PN}-7.6.3-trac-3333-weak-syms.patch
490
491 if use prefix; then
492 # Make configure find docbook-xsl-stylesheets from Prefix
493 sed -e '/^FP_DIR_DOCBOOK_XSL/s:\[.*\]:['"${EPREFIX}"'/usr/share/sgml/docbook/xsl-stylesheets/]:' \
494 -i utils/haddock/doc/configure.ac || die
495 fi
496
497 # as we have changed the build system
498 eautoreconf
499 fi
500 }
501
502 src_configure() {
503 GHC_PV=${PV} # overrided in live ebuilds
504
505 if ! use binary; then
506 # initialize build.mk
507 echo '# Gentoo changes' > mk/build.mk
508
509 # Put docs into the right place, ie /usr/share/doc/ghc-${PV}
510 echo "docdir = ${EPREFIX}/usr/share/doc/${P}" >> mk/build.mk
511 echo "htmldir = ${EPREFIX}/usr/share/doc/${P}" >> mk/build.mk
512
513 # We also need to use the GHC_FLAGS flags when building ghc itself
514 echo "SRC_HC_OPTS+=${GHC_FLAGS}" >> mk/build.mk
515 echo "SRC_CC_OPTS+=${CFLAGS}" >> mk/build.mk
516 echo "SRC_LD_OPTS+=${FILTERED_LDFLAGS}" >> mk/build.mk
517
518 # We can't depend on haddock except when bootstrapping when we
519 # must build docs and include them into the binary .tbz2 package
520 # app-text/dblatex is not in portage, can not build PDF or PS
521 if use ghcbootstrap && use doc; then
522 echo "BUILD_DOCBOOK_PDF = NO" >> mk/build.mk
523 echo "BUILD_DOCBOOK_PS = NO" >> mk/build.mk
524 echo "BUILD_DOCBOOK_HTML = YES" >> mk/build.mk
525 if is_crosscompile; then
526 # TODO this is a workaround for this build error with the live ebuild with haddock:
527 # make[1]: *** No rule to make target `compiler/stage2/build/Module.hi',
528 # needed by `utils/haddock/dist/build/Main.o'. Stop.
529 echo "HADDOCK_DOCS = NO" >> mk/build.mk
530 else
531 echo "HADDOCK_DOCS = YES" >> mk/build.mk
532 fi
533 else
534 echo "BUILD_DOCBOOK_PDF = NO" >> mk/build.mk
535 echo "BUILD_DOCBOOK_PS = NO" >> mk/build.mk
536 echo "BUILD_DOCBOOK_HTML = NO" >> mk/build.mk
537 echo "HADDOCK_DOCS = NO" >> mk/build.mk
538 fi
539
540 # circumvent a very strange bug that seems related with ghc producing
541 # too much output while being filtered through tee (e.g. due to
542 # portage logging) reported as bug #111183
543 echo "SRC_HC_OPTS+=-w" >> mk/build.mk
544
545 # some arches do not support ELF parsing for ghci module loading
546 # PPC64: never worked (should be easy to implement)
547 # alpha: never worked
548 # arm: http://hackage.haskell.org/trac/ghc/changeset/27302c9094909e04eb73f200d52d5e9370c34a8a
549 if use alpha || use ppc64; then
550 echo "GhcWithInterpreter=NO" >> mk/build.mk
551 fi
552
553 # we have to tell it to build unregisterised on some arches
554 # ppc64: EvilMangler currently does not understand some TOCs
555 # ia64: EvilMangler bitrot
556 # set GHC_IS_UNREG if you like to build slow unregisterised
557 # host compiler. Handy if you plan to user resulting
558 # host compiler as a booting compiler for crosscompiler
559 # which can work only in unregisterised mode.
560 if use alpha || use ia64 || use ppc64 || [[ -n ${GHC_IS_UNREG} ]]; then
561 echo "GhcUnregisterised=YES" >> mk/build.mk
562 echo "GhcWithNativeCodeGen=NO" >> mk/build.mk
563 echo "SplitObjs=NO" >> mk/build.mk
564 echo "GhcRTSWays := debug" >> mk/build.mk
565 echo "GhcNotThreaded=YES" >> mk/build.mk
566 fi
567
568 # arm: no EvilMangler support, no NCG support
569 if use arm; then
570 echo "GhcUnregisterised=YES" >> mk/build.mk
571 echo "GhcWithNativeCodeGen=NO" >> mk/build.mk
572 fi
573
574 # Have "ld -r --relax" problem with split-objs on sparc:
575 if use sparc; then
576 echo "SplitObjs=NO" >> mk/build.mk
577 fi
578
579 if ! use llvm; then
580 echo "GhcWithLlvmCodeGen=NO" >> mk/build.mk
581 fi
582
583 # allows overriding build flavours for libraries:
584 # v - vanilla (static libs)
585 # p - profiled
586 # dyn - shared libraries
587 # example: GHC_LIBRARY_WAYS="v dyn"
588 if [[ -n ${GHC_LIBRARY_WAYS} ]]; then
589 echo "GhcLibWays=${GHC_LIBRARY_WAYS}" >> mk/build.mk
590 fi
591
592 # Get ghc from the unpacked binary .tbz2
593 # except when bootstrapping we just pick ghc up off the path
594 if ! use ghcbootstrap; then
595 export PATH="${WORKDIR}/usr/bin:${PATH}"
596 fi
597
598 if use gmp; then
599 echo "INTEGER_LIBRARY=integer-gmp" >> mk/build.mk
600 else
601 echo "INTEGER_LIBRARY=integer-simple" >> mk/build.mk
602 fi
603
604 # Since GHC 6.12.2 the GHC wrappers store which GCC version GHC was
605 # compiled with, by saving the path to it. The purpose is to make sure
606 # that GHC will use the very same gcc version when it compiles haskell
607 # sources, as the extra-gcc-opts files contains extra gcc options which
608 # match only this GCC version.
609 # However, this is not required in Gentoo, as only modern GCCs are used
610 # (>4).
611 # Instead, this causes trouble when for example ccache is used during
612 # compilation, but we don't want the wrappers to point to ccache.
613 # Due to the above, we simply set GCC to be "gcc". When compiling ghc it
614 # might point to ccache, once installed it will point to the users
615 # regular gcc.
616
617 local econf_args=()
618
619 is_crosscompile || econf_args+=--with-gcc=${CHOST}-gcc
620
621 econf ${econf_args[@]} --enable-bootstrap-with-devel-snapshot \
622 || die "econf failed"
623
624 [[ ${PV} == *9999* ]] && GHC_PV="$(grep 'S\[\"PACKAGE_VERSION\"\]' config.status | sed -e 's@^.*=\"\(.*\)\"@\1@')"
625 GHC_TPF="$(grep 'S\[\"TargetPlatformFull\"\]' config.status | sed -e 's@^.*=\"\(.*\)\"@\1@')"
626 fi # ! use binary
627 }
628
629 src_compile() {
630 if ! use binary; then
631 limit_jobs() {
632 local user_jobs=$(makeopts_jobs)
633 local max_nonbreaking_jobs=$1
634
635 [[ ${user_jobs} -le ${max_nonbreaking_jobs} ]] && return
636
637 if [[ -n ${I_DEMAND_MY_CORES_LOADED} ]]; then
638 ewarn "You have requested parallel build which is known to break."
639 ewarn "Please report all breakages upstream."
640 return
641 else
642 ewarn "Limiting MAKEOPTS -j${user_jobs} -> -j${max_nonbreaking_jobs} (bug #456386)"
643 user_jobs=${max_nonbreaking_jobs}
644 fi
645 echo -j${user_jobs}
646 }
647 # ghc massively parallel make: #409631, #409873
648 # but let users screw it by setting 'I_DEMAND_MY_CORES_LOADED'
649 # 4 parallel jobs usually does not break
650 emake $(limit_jobs 4) all
651 emake all V=1
652
653 if is_crosscompile; then
654 # runghc does not work for a stage1 compiler, we can build it anyway
655 # so it will print the error message: not built for interactive use
656 pushd "${S}/utils/runghc" || die "Could not cd to utils/runghc"
657 if [ ! -f Setup.hs ]; then
658 echo 'import Distribution.Simple; main = defaultMainWithHooks defaultUserHooks' \
659 > Setup.hs || die "failed to create default Setup.hs"
660 fi
661 ghc -o setup --make Setup.hs || die "setup build failed"
662 ./setup configure || die "runghc configure failed"
663 sed -e "s@VERSION@\"${GHC_PV}\"@" -i runghc.hs
664 ./setup build || die "runghc build failed"
665 popd
666 fi
667 fi # ! use binary
668 }
669
670 ghc-needs-c_nonshared-for-interpreter-libs() {
671 local sample_test=${T}/c_nonshared-test.c
672 echo "int main() {} " > "${sample_test}" || die
673 $(tc-getCC) -o "${sample_test}".result "${sample_test}" \
674 -L"${ROOT}"/usr/$(get_libdir) -lc_nonshared
675 }
676
677 add-c_nonshared-to-ghci-libs() {
678 local ghci_lib
679 local nonshared_dir=${T}/libc_nonshared_objects
680
681 is_crosscompile && return
682 ghc-needs-c_nonshared-for-interpreter-libs || return
683
684 get-nonshared-objects() {
685 # ns - 'nonshared'
686 local ns_objects=" "
687 local ns_sym
688 local ns_srco
689 local ns_dsto
690
691 # extract
692 mkdir "${nonshared_dir}" || die
693 pushd "${nonshared_dir}" >/dev/null || die
694 $(tc-getAR) x "${ROOT}"/usr/$(get_libdir)/libc_nonshared.a
695 popd >/dev/null || die
696
697 for ns_sym in \
698 stat fstat lstat mknod \
699 stat64 fstat64 lstat64 \
700 fstatat fstatat64 mknodat
701 do
702 ns_srco=${nonshared_dir}/${ns_sym}.oS
703 ns_dsto=${nonshared_dir}/${ns_sym}_weakened.o
704 [[ -f ${ns_srco} ]] || continue
705 # here we do The Magic:
706 # 1. --keep-global-symbol= hides everything to adoid double definition
707 # of stuff like __stat, __fstat and
708 # 2. --weaken converts exported symbols to weak symbols to be available
709 # for redefinition
710 $(tc-getOBJCOPY) \
711 --weaken --keep-global-symbol=${ns_sym} \
712 "${ns_srco}" "${ns_dsto}" || die
713
714 ns_objects+=" ${ns_dsto}"
715 done
716
717 echo "${ns_objects}"
718 }
719 # bug #452442: when building libraries for ghci
720 # ghc basically glues them together:
721 # $ ld -r -o result foo.o bar.o ...
722 # that way some symbols defined in libc_nonshared.a
723 # do not get included into final HS*.o files
724 # We piggyback on one of early loaded wired-in library
725 # loaded before 'base'.
726 while read ghci_lib
727 do
728 einfo "relinking '${ghci_lib}' with c_includes"
729 mv "${ghci_lib}" "${ghci_lib}".unrelinked.o || die
730 $(tc-getLD) -r -o "${ghci_lib}" \
731 "${ghci_lib}".unrelinked.o \
732 $(get-nonshared-objects) || die
733 rm -r "${nonshared_dir}" || die
734 rm "${ghci_lib}".unrelinked.o || die
735 done < <(find "${ED}"/usr/$(get_libdir)/${P}/ -name 'HSghc-prim*.o')
736 }
737
738 src_install() {
739 if use binary; then
740 use prefix && mkdir -p "${ED}"
741 mv "${S}/usr" "${ED}"
742
743 # Remove the docs if not requested
744 if ! use doc; then
745 rm -rf "${ED}/usr/share/doc/${P}/*/" \
746 "${ED}/usr/share/doc/${P}/*.html" \
747 || die "could not remove docs (P vs PF revision mismatch?)"
748 fi
749 else
750 local insttarget="install"
751
752 # We only built docs if we were bootstrapping, otherwise
753 # we copy them out of the unpacked binary .tbz2
754 if use doc && ! use ghcbootstrap; then
755 mkdir -p "${ED}/usr/share/doc"
756 mv "${WORKDIR}/usr/share/doc/${P}" "${ED}/usr/share/doc" \
757 || die "failed to copy docs"
758 else
759 dodoc "${S}/README" "${S}/ANNOUNCE" "${S}/LICENSE" "${S}/VERSION"
760 fi
761
762 emake -j1 ${insttarget} \
763 DESTDIR="${D}" \
764 || die "make ${insttarget} failed"
765
766 # remove wrapper and linker
767 rm -f "${ED}"/usr/bin/haddock*
768
769 add-c_nonshared-to-ghci-libs
770
771 # ghci uses mmap with rwx protection at it implements dynamic
772 # linking on it's own (bug #299709)
773 # so mark resulting binary
774 pax-mark -m "${ED}/usr/$(get_libdir)/${P}/ghc"
775
776 if [[ ! -f "${S}/VERSION" ]]; then
777 echo "${GHC_PV}" > "${S}/VERSION" \
778 || die "Could not create file ${S}/VERSION"
779 fi
780 dobashcomp "${FILESDIR}/ghc-bash-completion"
781
782 fi
783
784 # path to the package.cache
785 local package_confdir="${ED}/usr/$(get_libdir)/${PN}-${GHC_PV}/package.conf.d"
786 PKGCACHE="${package_confdir}"/package.cache
787 # copy the package.conf.d, including timestamp, save it so we can help
788 # users that have a broken package.conf.d
789 cp -pR "${package_confdir}"{,.initial} || die "failed to backup intial package.conf.d"
790
791 # copy the package.conf, including timestamp, save it so we later can put it
792 # back before uninstalling, or when upgrading.
793 cp -p "${PKGCACHE}"{,.shipped} \
794 || die "failed to copy package.conf.d/package.cache"
795 }
796
797 pkg_preinst() {
798 # have we got an earlier version of ghc installed?
799 if has_version "<${CATEGORY}/${PF}"; then
800 haskell_updater_warn="1"
801 fi
802 }
803
804 pkg_postinst() {
805 ghc-reregister
806
807 # path to the package.cache
808 PKGCACHE="${EROOT}/usr/$(get_libdir)/${P}/package.conf.d/package.cache"
809
810 # give the cache a new timestamp, it must be as recent as
811 # the package.conf.d directory.
812 touch "${PKGCACHE}"
813
814 if [[ "${haskell_updater_warn}" == "1" ]]; then
815 ewarn
816 ewarn "\e[1;31m************************************************************************\e[0m"
817 ewarn
818 ewarn "You have just upgraded from an older version of GHC."
819 ewarn "You may have to run"
820 ewarn " 'haskell-updater --upgrade'"
821 ewarn "to rebuild all ghc-based Haskell libraries."
822 ewarn
823 ewarn "\e[1;31m************************************************************************\e[0m"
824 ewarn
825 fi
826 if is_crosscompile; then
827 ewarn
828 ewarn "\e[1;31m************************************************************************\e[0m"
829 ewarn
830 ewarn "GHC built as a cross compiler. The interpreter, ghci and runghc, do"
831 ewarn "not work for a cross compiler."
832 ewarn "For the ghci error: \"<command line>: not built for interactive use\" see:"
833 ewarn "http://www.haskell.org/haskellwiki/GHC:FAQ#When_I_try_to_start_ghci_.28probably_one_I_compiled_myself.29_it_says_ghc-5.02:_not_built_for_interactive_use"
834 ewarn
835 ewarn "\e[1;31m************************************************************************\e[0m"
836 ewarn
837 fi
838 }
839
840 pkg_prerm() {
841 # Be very careful here... Call order when upgrading is (according to PMS):
842 # * src_install for new package
843 # * pkg_preinst for new package
844 # * pkg_postinst for new package
845 # * pkg_prerm for the package being replaced
846 # * pkg_postrm for the package being replaced
847 # so you'll actually be touching the new packages files, not the one you
848 # uninstall, due to that or installation directory ${P} will be the same for
849 # both packages.
850
851 # Call order for reinstalling is (according to PMS):
852 # * src_install
853 # * pkg_preinst
854 # * pkg_prerm for the package being replaced
855 # * pkg_postrm for the package being replaced
856 # * pkg_postinst
857
858 # Overwrite the modified package.cache with a copy of the
859 # original one, so that it will be removed during uninstall.
860
861 PKGCACHE="${EROOT}/usr/$(get_libdir)/${P}/package.conf.d/package.cache"
862 rm -rf "${PKGCACHE}"
863
864 cp -p "${PKGCACHE}"{.shipped,}
865 }