/[gentoo-x86]/eclass/haskell-cabal.eclass
Gentoo

Diff of /eclass/haskell-cabal.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.37 Revision 1.46
1# Copyright 1999-2012 Gentoo Foundation 1# Copyright 1999-2014 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/haskell-cabal.eclass,v 1.37 2012/11/19 21:27:56 slyfox Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/haskell-cabal.eclass,v 1.46 2014/06/27 07:26:18 slyfox Exp $
4 4
5# @ECLASS: haskell-cabal.eclass 5# @ECLASS: haskell-cabal.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Haskell herd <haskell@gentoo.org> 7# Haskell herd <haskell@gentoo.org>
8# @AUTHOR: 8# @AUTHOR:
31# nocabaldep -- don't add dependency on cabal. 31# nocabaldep -- don't add dependency on cabal.
32# only used for packages that _must_ not pull the dependency 32# only used for packages that _must_ not pull the dependency
33# on cabal, but still use this eclass (e.g. haskell-updater). 33# on cabal, but still use this eclass (e.g. haskell-updater).
34# test-suite -- add support for cabal test-suites (introduced in Cabal-1.8) 34# test-suite -- add support for cabal test-suites (introduced in Cabal-1.8)
35 35
36inherit ghc-package multilib 36inherit eutils ghc-package multilib multiprocessing
37 37
38# @ECLASS-VARIABLE: CABAL_EXTRA_CONFIGURE_FLAGS 38# @ECLASS-VARIABLE: CABAL_EXTRA_CONFIGURE_FLAGS
39# @DESCRIPTION: 39# @DESCRIPTION:
40# User-specified additional parameters passed to 'setup configure'. 40# User-specified additional parameters passed to 'setup configure'.
41# example: /etc/make.conf: CABAL_EXTRA_CONFIGURE_FLAGS=--enable-shared 41# example: /etc/portage/make.conf: CABAL_EXTRA_CONFIGURE_FLAGS=--enable-shared
42: ${CABAL_EXTRA_CONFIGURE_FLAGS:=} 42: ${CABAL_EXTRA_CONFIGURE_FLAGS:=}
43 43
44# @ECLASS-VARIABLE: CABAL_EXTRA_BUILD_FLAGS 44# @ECLASS-VARIABLE: CABAL_EXTRA_BUILD_FLAGS
45# @DESCRIPTION: 45# @DESCRIPTION:
46# User-specified additional parameters passed to 'setup build'. 46# User-specified additional parameters passed to 'setup build'.
47# example: /etc/make.conf: CABAL_EXTRA_BUILD_FLAGS=-v 47# example: /etc/portage/make.conf: CABAL_EXTRA_BUILD_FLAGS=-v
48: ${CABAL_EXTRA_BUILD_FLAGS:=} 48: ${CABAL_EXTRA_BUILD_FLAGS:=}
49 49
50# @ECLASS-VARIABLE: GHC_BOOTSTRAP_FLAGS 50# @ECLASS-VARIABLE: GHC_BOOTSTRAP_FLAGS
51# @DESCRIPTION: 51# @DESCRIPTION:
52# User-specified additional parameters for ghc when building 52# User-specified additional parameters for ghc when building
53# _only_ 'setup' binary bootstrap. 53# _only_ 'setup' binary bootstrap.
54# example: /etc/make.conf: GHC_BOOTSTRAP_FLAGS=-dynamic to make 54# example: /etc/portage/make.conf: GHC_BOOTSTRAP_FLAGS=-dynamic to make
55# linking 'setup' faster. 55# linking 'setup' faster.
56: ${GHC_BOOTSTRAP_FLAGS:=} 56: ${GHC_BOOTSTRAP_FLAGS:=}
57 57
58# @ECLASS-VARIABLE: CABAL_DEBUG_LOOSENING 58# @ECLASS-VARIABLE: CABAL_DEBUG_LOOSENING
59# @DESCRIPTION: 59# @DESCRIPTION:
60# Show debug output for 'cabal_chdeps' function if set. 60# Show debug output for 'cabal_chdeps' function if set.
61# Needs working 'diff'. 61# Needs working 'diff'.
62: ${CABAL_DEBUG_LOOSENING:=} 62: ${CABAL_DEBUG_LOOSENING:=}
63 63
64HASKELL_CABAL_EXPF="pkg_setup src_compile src_test src_install" 64HASKELL_CABAL_EXPF="pkg_setup src_compile src_test src_install"
65
66# 'dev-haskell/cabal' passes those options with ./configure-based
67# configuration, but most packages don't need/don't accept it:
68# #515362, #515362
69QA_CONFIGURE_OPTIONS+=" --with-compiler --with-hc --with-hc-pkg --with-gcc"
65 70
66case "${EAPI:-0}" in 71case "${EAPI:-0}" in
67 2|3|4|5) HASKELL_CABAL_EXPF+=" src_configure" ;; 72 2|3|4|5) HASKELL_CABAL_EXPF+=" src_configure" ;;
68 *) ;; 73 *) ;;
69esac 74esac
132fi 137fi
133if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]]; then 138if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]]; then
134 DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}" 139 DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}"
135fi 140fi
136 141
137# Libraries require GHC to be installed.
138if [[ -n "${CABAL_HAS_LIBRARIES}" ]]; then
139 RDEPEND="${RDEPEND} dev-lang/ghc"
140fi
141
142# returns the version of cabal currently in use 142# returns the version of cabal currently in use
143_CABAL_VERSION_CACHE="" 143_CABAL_VERSION_CACHE=""
144cabal-version() { 144cabal-version() {
145 if [[ -z "${_CABAL_VERSION_CACHE}" ]]; then 145 if [[ -z "${_CABAL_VERSION_CACHE}" ]]; then
146 if [[ "${CABAL_BOOTSTRAP}" ]]; then 146 if [[ "${CABAL_BOOTSTRAP}" ]]; then
183 cabalpackage=Cabal-$(cabal-version) 183 cabalpackage=Cabal-$(cabal-version)
184 einfo "Using cabal-$(cabal-version)." 184 einfo "Using cabal-$(cabal-version)."
185 185
186 make_setup() { 186 make_setup() {
187 set -- -package "${cabalpackage}" --make "${setupmodule}" \ 187 set -- -package "${cabalpackage}" --make "${setupmodule}" \
188 ${HCFLAGS} \
188 ${GHC_BOOTSTRAP_FLAGS} \ 189 ${GHC_BOOTSTRAP_FLAGS} \
189 "$@" \ 190 "$@" \
190 -o setup 191 -o setup
191 echo $(ghc-getghc) ${HCFLAGS} "$@" 192 echo $(ghc-getghc) "$@"
192 $(ghc-getghc) "$@" 193 $(ghc-getghc) "$@"
193 } 194 }
194 if $(ghc-supports-shared-libraries); then 195 if $(ghc-supports-shared-libraries); then
195 # # some custom build systems might use external libraries, 196 # # some custom build systems might use external libraries,
196 # # for which we don't have shared libs, so keep static fallback 197 # # for which we don't have shared libs, so keep static fallback
212 make_setup "$@" || die "compiling ${setupmodule} failed" 213 make_setup "$@" || die "compiling ${setupmodule} failed"
213 fi 214 fi
214} 215}
215 216
216cabal-mksetup() { 217cabal-mksetup() {
217 local setupdir 218 local setupdir=${1:-${S}}
219 local setup_src=${setupdir}/Setup.hs
218 220
219 if [[ -n $1 ]]; then
220 setupdir=$1
221 else
222 setupdir=${S}
223 fi
224
225 rm -f "${setupdir}"/Setup.{lhs,hs} 221 rm -vf "${setupdir}"/Setup.{lhs,hs}
222 elog "Creating 'Setup.hs' for 'Simple' build type."
226 223
227 echo 'import Distribution.Simple; main = defaultMainWithHooks defaultUserHooks' \ 224 echo 'import Distribution.Simple; main = defaultMainWithHooks defaultUserHooks' \
228 > $setupdir/Setup.hs || die "failed to create default Setup.hs" 225 > "${setup_src}" || die "failed to create default Setup.hs"
229} 226}
230 227
231cabal-hscolour() { 228cabal-hscolour() {
232 set -- hscolour "$@" 229 set -- hscolour "$@"
233 echo ./setup "$@" 230 echo ./setup "$@"
245 set -- haddock --hyperlink-source 242 set -- haddock --hyperlink-source
246 echo ./setup "$@" 243 echo ./setup "$@"
247 ./setup "$@" --hyperlink-source || die "setup haddock --hyperlink-source failed" 244 ./setup "$@" --hyperlink-source || die "setup haddock --hyperlink-source failed"
248} 245}
249 246
247cabal-die-if-nonempty() {
248 local breakage_type=$1
249 shift
250
251 [[ "${#@}" == 0 ]] && return 0
252 eerror "Detected ${breakage_type} packages: ${@}"
253 die "//==-- Please, run 'haskell-updater' to fix ${breakage_type} packages --==//"
254}
255
256cabal-show-brokens() {
257 elog "ghc-pkg check: 'checking for other broken packages:'"
258 # pretty-printer
259 $(ghc-getghcpkg) check 2>&1 \
260 | egrep -v '^Warning: haddock-(html|interfaces): ' \
261 | egrep -v '^Warning: include-dirs: ' \
262 | head -n 20
263
264 cabal-die-if-nonempty 'broken' \
265 $($(ghc-getghcpkg) check --simple-output)
266}
267
268cabal-show-old() {
269 cabal-die-if-nonempty 'outdated' \
270 $("${EPREFIX}"/usr/sbin/haskell-updater --quiet --upgrade --list-only)
271}
272
273cabal-show-brokens-and-die() {
274 cabal-show-brokens
275 cabal-show-old
276
277 die "$@"
278}
279
250cabal-configure() { 280cabal-configure() {
281 local cabalconf=()
251 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX= 282 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
252 283
253 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then 284 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
254 cabalconf="${cabalconf} --with-haddock=${EPREFIX}/usr/bin/haddock" 285 cabalconf+=(--with-haddock=${EPREFIX}/usr/bin/haddock)
255 fi 286 fi
256 if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then 287 if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then
257 cabalconf="${cabalconf} --enable-library-profiling" 288 cabalconf+=(--enable-library-profiling)
258 fi 289 fi
259 if [[ -n "${CABAL_USE_ALEX}" ]]; then 290 if [[ -n "${CABAL_USE_ALEX}" ]]; then
260 cabalconf="${cabalconf} --with-alex=${EPREFIX}/usr/bin/alex" 291 cabalconf+=(--with-alex=${EPREFIX}/usr/bin/alex)
261 fi 292 fi
262 293
263 if [[ -n "${CABAL_USE_HAPPY}" ]]; then 294 if [[ -n "${CABAL_USE_HAPPY}" ]]; then
264 cabalconf="${cabalconf} --with-happy=${EPREFIX}/usr/bin/happy" 295 cabalconf+=(--with-happy=${EPREFIX}/usr/bin/happy)
265 fi 296 fi
266 297
267 if [[ -n "${CABAL_USE_C2HS}" ]]; then 298 if [[ -n "${CABAL_USE_C2HS}" ]]; then
268 cabalconf="${cabalconf} --with-c2hs=${EPREFIX}/usr/bin/c2hs" 299 cabalconf+=(--with-c2hs=${EPREFIX}/usr/bin/c2hs)
269 fi 300 fi
270 if [[ -n "${CABAL_USE_CPPHS}" ]]; then 301 if [[ -n "${CABAL_USE_CPPHS}" ]]; then
271 cabalconf="${cabalconf} --with-cpphs=${EPREFIX}/usr/bin/cpphs" 302 cabalconf+=(--with-cpphs=${EPREFIX}/usr/bin/cpphs)
272 fi 303 fi
273 if [[ -n "${CABAL_TEST_SUITE}" ]]; then 304 if [[ -n "${CABAL_TEST_SUITE}" ]]; then
274 cabalconf="${cabalconf} $(use_enable test tests)" 305 cabalconf+=($(use_enable test tests))
275 fi 306 fi
276 307
277 local option 308 local option
278 for option in ${HCFLAGS} 309 for option in ${HCFLAGS}
279 do 310 do
280 cabalconf+=" --ghc-option=$option" 311 cabalconf+=(--ghc-option="$option")
281 done 312 done
313
314 # parallel on all available cores
315 if ghc-supports-parallel-make; then
316 local max_jobs=$(makeopts_jobs)
317
318 # limit to very small value, as parallelism
319 # helps slightly, but makes things severely worse
320 # when amount of threads is Very Large.
321 [[ ${max_jobs} -gt 4 ]] && max_jobs=4
322
323 cabalconf+=(--ghc-option=-j"$max_jobs")
324 fi
282 325
283 # Building GHCi libs on ppc64 causes "TOC overflow". 326 # Building GHCi libs on ppc64 causes "TOC overflow".
284 if use ppc64; then 327 if use ppc64; then
285 cabalconf="${cabalconf} --disable-library-for-ghci" 328 cabalconf+=(--disable-library-for-ghci)
286 fi 329 fi
287 330
288 # currently cabal does not respect CFLAGS and LDFLAGS on it's own (bug #333217) 331 # currently cabal does not respect CFLAGS and LDFLAGS on it's own (bug #333217)
289 # so translate LDFLAGS to ghc parameters (without filtering) 332 # so translate LDFLAGS to ghc parameters (without filtering)
290 local flag 333 local flag
291 for flag in $LDFLAGS; do cabalconf="${cabalconf} --ghc-option=-optl$flag"; done 334 for flag in $LDFLAGS; do cabalconf+=(--ghc-option="-optl$flag"); done
292 335
293 # disable executable stripping for the executables, as portage will 336 # disable executable stripping for the executables, as portage will
294 # strip by itself, and pre-stripping gives a QA warning. 337 # strip by itself, and pre-stripping gives a QA warning.
295 # cabal versions previous to 1.4 does not strip executables, and does 338 # cabal versions previous to 1.4 does not strip executables, and does
296 # not accept the flag. 339 # not accept the flag.
297 # this fixes numerous bugs, amongst them; 340 # this fixes numerous bugs, amongst them;
298 # bug #251881, bug #251882, bug #251884, bug #251886, bug #299494 341 # bug #251881, bug #251882, bug #251884, bug #251886, bug #299494
299 cabalconf="${cabalconf} --disable-executable-stripping" 342 cabalconf+=(--disable-executable-stripping)
300 343
301 cabalconf="${cabalconf} --docdir=${EPREFIX}/usr/share/doc/${PF}" 344 cabalconf+=(--docdir="${EPREFIX}"/usr/share/doc/${PF})
302 # As of Cabal 1.2, configure is quite quiet. For diagnostic purposes 345 # As of Cabal 1.2, configure is quite quiet. For diagnostic purposes
303 # it's better if the configure chatter is in the build logs: 346 # it's better if the configure chatter is in the build logs:
304 cabalconf="${cabalconf} --verbose" 347 cabalconf+=(--verbose)
305 348
306 # We build shared version of our Cabal where ghc ships it's shared 349 # We build shared version of our Cabal where ghc ships it's shared
307 # version of it. We will link ./setup as dynamic binary againt Cabal later. 350 # version of it. We will link ./setup as dynamic binary againt Cabal later.
308 [[ ${CATEGORY}/${PN} == "dev-haskell/cabal" ]] && \ 351 [[ ${CATEGORY}/${PN} == "dev-haskell/cabal" ]] && \
309 $(ghc-supports-shared-libraries) && \ 352 $(ghc-supports-shared-libraries) && \
310 cabalconf="${cabalconf} --enable-shared" 353 cabalconf+=(--enable-shared)
311 354
312 if $(ghc-supports-shared-libraries); then 355 if $(ghc-supports-shared-libraries); then
313 # maybe a bit lower 356 # maybe a bit lower
314 if version_is_at_least "7.7.20121114" "$(ghc-version)"; then 357 if $(ghc-supports-dynamic-by-default); then
315 cabalconf="${cabalconf} --enable-shared" 358 cabalconf+=(--enable-shared)
316 fi 359 fi
360 fi
361
362 # --sysconfdir appeared in Cabal-1.18+
363 if ./setup configure --help | grep -q -- --sysconfdir; then
364 cabalconf+=(--sysconfdir="${EPREFIX}"/etc)
365 fi
366
367 # appeared in Cabal-1.18+ (see '--disable-executable-stripping')
368 if ./setup configure --help | grep -q -- --disable-library-stripping; then
369 cabalconf+=(--disable-library-stripping)
317 fi 370 fi
318 371
319 set -- configure \ 372 set -- configure \
320 --ghc --prefix="${EPREFIX}"/usr \ 373 --ghc --prefix="${EPREFIX}"/usr \
321 --with-compiler="$(ghc-getghc)" \ 374 --with-compiler="$(ghc-getghc)" \
323 --prefix="${EPREFIX}"/usr \ 376 --prefix="${EPREFIX}"/usr \
324 --libdir="${EPREFIX}"/usr/$(get_libdir) \ 377 --libdir="${EPREFIX}"/usr/$(get_libdir) \
325 --libsubdir=${P}/ghc-$(ghc-version) \ 378 --libsubdir=${P}/ghc-$(ghc-version) \
326 --datadir="${EPREFIX}"/usr/share/ \ 379 --datadir="${EPREFIX}"/usr/share/ \
327 --datasubdir=${P}/ghc-$(ghc-version) \ 380 --datasubdir=${P}/ghc-$(ghc-version) \
328 ${cabalconf} \ 381 "${cabalconf[@]}" \
329 ${CABAL_CONFIGURE_FLAGS} \ 382 ${CABAL_CONFIGURE_FLAGS} \
330 ${CABAL_EXTRA_CONFIGURE_FLAGS} \ 383 ${CABAL_EXTRA_CONFIGURE_FLAGS} \
331 "$@" 384 "$@"
332 echo ./setup "$@" 385 echo ./setup "$@"
333 ./setup "$@" || die "setup configure failed" 386 ./setup "$@" || cabal-show-brokens-and-die "setup configure failed"
334} 387}
335 388
336cabal-build() { 389cabal-build() {
337 unset LANG LC_ALL LC_MESSAGES
338 set -- build ${CABAL_EXTRA_BUILD_FLAGS} "$@" 390 set -- build ${CABAL_EXTRA_BUILD_FLAGS} "$@"
339 echo ./setup "$@" 391 echo ./setup "$@"
340 ./setup "$@" \ 392 ./setup "$@" \
341 || die "setup build failed" 393 || die "setup build failed"
342} 394}
382} 434}
383 435
384# exported function: check if cabal is correctly installed for 436# exported function: check if cabal is correctly installed for
385# the currently active ghc (we cannot guarantee this with portage) 437# the currently active ghc (we cannot guarantee this with portage)
386haskell-cabal_pkg_setup() { 438haskell-cabal_pkg_setup() {
439 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
440 [[ ${RDEPEND} == *dev-lang/ghc* ]] || eqawarn "QA Notice: A library does not have runtime dependency on dev-lang/ghc."
441 fi
387 if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then 442 if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then
388 eqawarn "QA Notice: Neither bin nor lib are in CABAL_FEATURES." 443 eqawarn "QA Notice: Neither bin nor lib are in CABAL_FEATURES."
389 fi 444 fi
390 if [[ -n "${CABAL_UNKNOWN}" ]]; then 445 if [[ -n "${CABAL_UNKNOWN}" ]]; then
391 eqawarn "QA Notice: Unknown entry in CABAL_FEATURES: ${CABAL_UNKNOWN}" 446 eqawarn "QA Notice: Unknown entry in CABAL_FEATURES: ${CABAL_UNKNOWN}"
512 cabal_src_install 567 cabal_src_install
513 568
514 popd > /dev/null 569 popd > /dev/null
515} 570}
516 571
572# @FUNCTION: cabal_flag
573# @DESCRIPTION:
517# ebuild.sh:use_enable() taken as base 574# ebuild.sh:use_enable() taken as base
518# 575#
519# Usage examples: 576# Usage examples:
520# 577#
521# CABAL_CONFIGURE_FLAGS=$(cabal_flag gui) 578# CABAL_CONFIGURE_FLAGS=$(cabal_flag gui)
565# CABAL_FILE=${S}/${MY_PN}-tools.cabal cabal_chdeps \ 622# CABAL_FILE=${S}/${MY_PN}-tools.cabal cabal_chdeps \
566# 'base == 3.*' 'base >= 4.2 && < 4.7' 623# 'base == 3.*' 'base >= 4.2 && < 4.7'
567#} 624#}
568# 625#
569cabal_chdeps() { 626cabal_chdeps() {
627 local cabal_fn=${MY_PN:-${PN}}.cabal
570 local cf=${CABAL_FILE:-${S}/${PN}.cabal} 628 local cf=${CABAL_FILE:-${S}/${cabal_fn}}
571 local from_ss # ss - substring 629 local from_ss # ss - substring
572 local to_ss 630 local to_ss
573 local orig_c # c - contents 631 local orig_c # c - contents
574 local new_c 632 local new_c
575 633
605 done 663 done
606 664
607 echo "${new_c}" > "$cf" || 665 echo "${new_c}" > "$cf" ||
608 die "failed to update" 666 die "failed to update"
609} 667}
668
669# @FUNCTION: replace-hcflags
670# @USAGE: <old> <new>
671# @DESCRIPTION:
672# Replace the <old> flag with <new> in HCFLAGS. Accepts shell globs for <old>.
673# The implementation is picked from flag-o-matic.eclass:replace-flags()
674replace-hcflags() {
675 [[ $# != 2 ]] && die "Usage: replace-hcflags <old flag> <new flag>"
676
677 local f new=()
678 for f in ${HCFLAGS} ; do
679 # Note this should work with globs like -O*
680 if [[ ${f} == ${1} ]]; then
681 einfo "HCFLAGS: replacing '${f}' to '${2}'"
682 f=${2}
683 fi
684 new+=( "${f}" )
685 done
686 export HCFLAGS="${new[*]}"
687
688 return 0
689}

Legend:
Removed from v.1.37  
changed lines
  Added in v.1.46

  ViewVC Help
Powered by ViewVC 1.1.20