| 1 | # Copyright 1999-2006 Gentoo Foundation |
1 | # Copyright 1999-2006 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.15 2009/07/27 19:03:20 kolmodin Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/haskell-cabal.eclass,v 1.20 2010/03/30 22:18:37 kolmodin Exp $ |
| 4 | # |
4 | # |
| 5 | # Original authors: Andres Loeh <kosmikus@gentoo.org> |
5 | # Original authors: Andres Loeh <kosmikus@gentoo.org> |
| 6 | # Duncan Coutts <dcoutts@gentoo.org> |
6 | # Duncan Coutts <dcoutts@gentoo.org> |
| 7 | # Maintained by: Haskell herd <haskell@gentoo.org> |
7 | # Maintained by: Haskell herd <haskell@gentoo.org> |
| 8 | # |
8 | # |
| … | |
… | |
| 24 | # cpphs -- C preprocessor clone written in Haskell |
24 | # cpphs -- C preprocessor clone written in Haskell |
| 25 | # profile -- if package supports to build profiling-enabled libraries |
25 | # profile -- if package supports to build profiling-enabled libraries |
| 26 | # bootstrap -- only used for the cabal package itself |
26 | # bootstrap -- only used for the cabal package itself |
| 27 | # bin -- the package installs binaries |
27 | # bin -- the package installs binaries |
| 28 | # lib -- the package installs libraries |
28 | # lib -- the package installs libraries |
|
|
29 | # nocabaldep -- don't add dependency on cabal. |
|
|
30 | # only used for packages that _must_ not pull the dependency |
|
|
31 | # on cabal, but still use this eclass (e.g. haskell-updater). |
| 29 | # |
32 | # |
| 30 | # Dependencies on other cabal packages have to be specified |
33 | # Dependencies on other cabal packages have to be specified |
| 31 | # correctly. |
34 | # correctly. |
| 32 | # |
35 | # |
| 33 | # Cabal libraries should usually be SLOTted with "${PV}". |
36 | # Cabal libraries should usually be SLOTted with "${PV}". |
| … | |
… | |
| 40 | # Special flags to Cabal Configure can now be set by using |
43 | # Special flags to Cabal Configure can now be set by using |
| 41 | # CABAL_CONFIGURE_FLAGS |
44 | # CABAL_CONFIGURE_FLAGS |
| 42 | |
45 | |
| 43 | inherit ghc-package multilib |
46 | inherit ghc-package multilib |
| 44 | |
47 | |
|
|
48 | HASKELL_CABAL_EXPF="pkg_setup src_compile src_test src_install" |
|
|
49 | |
|
|
50 | case "${EAPI:-0}" in |
|
|
51 | 2|3|4) HASKELL_CABAL_EXPF+=" src_configure" ;; |
|
|
52 | *) ;; |
|
|
53 | esac |
|
|
54 | |
|
|
55 | EXPORT_FUNCTIONS ${HASKELL_CABAL_EXPF} |
| 45 | |
56 | |
| 46 | for feature in ${CABAL_FEATURES}; do |
57 | for feature in ${CABAL_FEATURES}; do |
| 47 | case ${feature} in |
58 | case ${feature} in |
| 48 | haddock) CABAL_USE_HADDOCK=yes;; |
59 | haddock) CABAL_USE_HADDOCK=yes;; |
| 49 | alex) CABAL_USE_ALEX=yes;; |
60 | alex) CABAL_USE_ALEX=yes;; |
| 50 | happy) CABAL_USE_HAPPY=yes;; |
61 | happy) CABAL_USE_HAPPY=yes;; |
| 51 | c2hs) CABAL_USE_C2HS=yes;; |
62 | c2hs) CABAL_USE_C2HS=yes;; |
| 52 | cpphs) CABAL_USE_CPPHS=yes;; |
63 | cpphs) CABAL_USE_CPPHS=yes;; |
| 53 | profile) CABAL_USE_PROFILE=yes;; |
64 | profile) CABAL_USE_PROFILE=yes;; |
| 54 | bootstrap) CABAL_BOOTSTRAP=yes;; |
65 | bootstrap) CABAL_BOOTSTRAP=yes;; |
| 55 | bin) CABAL_HAS_BINARIES=yes;; |
66 | bin) CABAL_HAS_BINARIES=yes;; |
| 56 | lib) CABAL_HAS_LIBRARIES=yes;; |
67 | lib) CABAL_HAS_LIBRARIES=yes;; |
|
|
68 | nocabaldep) CABAL_FROM_GHC=yes;; |
| 57 | *) CABAL_UNKNOWN="${CABAL_UNKNOWN} ${feature}";; |
69 | *) CABAL_UNKNOWN="${CABAL_UNKNOWN} ${feature}";; |
| 58 | esac |
70 | esac |
| 59 | done |
71 | done |
| 60 | |
72 | |
| 61 | if [[ -n "${CABAL_USE_HADDOCK}" ]]; then |
73 | if [[ -n "${CABAL_USE_HADDOCK}" ]]; then |
| … | |
… | |
| 90 | # We always use a standalone version of Cabal, rather than the one that comes |
102 | # We always use a standalone version of Cabal, rather than the one that comes |
| 91 | # with GHC. But of course we can't depend on cabal when building cabal itself. |
103 | # with GHC. But of course we can't depend on cabal when building cabal itself. |
| 92 | if [[ -z ${CABAL_MIN_VERSION} ]]; then |
104 | if [[ -z ${CABAL_MIN_VERSION} ]]; then |
| 93 | CABAL_MIN_VERSION=1.1.4 |
105 | CABAL_MIN_VERSION=1.1.4 |
| 94 | fi |
106 | fi |
| 95 | if [[ -z "${CABAL_BOOTSTRAP}" ]]; then |
107 | if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]]; then |
| 96 | DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}" |
108 | DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}" |
| 97 | fi |
109 | fi |
| 98 | |
110 | |
| 99 | # Libraries require GHC to be installed. |
111 | # Libraries require GHC to be installed. |
| 100 | if [[ -n "${CABAL_HAS_LIBRARIES}" ]]; then |
112 | if [[ -n "${CABAL_HAS_LIBRARIES}" ]]; then |
| … | |
… | |
| 107 | if [[ -z "${_CABAL_VERSION_CACHE}" ]]; then |
119 | if [[ -z "${_CABAL_VERSION_CACHE}" ]]; then |
| 108 | if [[ "${CABAL_BOOTSTRAP}" ]]; then |
120 | if [[ "${CABAL_BOOTSTRAP}" ]]; then |
| 109 | # We're bootstrapping cabal, so the cabal version is the version |
121 | # We're bootstrapping cabal, so the cabal version is the version |
| 110 | # of this package itself. |
122 | # of this package itself. |
| 111 | _CABAL_VERSION_CACHE="${PV}" |
123 | _CABAL_VERSION_CACHE="${PV}" |
|
|
124 | elif [[ "${CABAL_FROM_GHC}" ]]; then |
|
|
125 | # We can't assume there's a version of Cabal installed by ebuild as |
|
|
126 | # this might be a first time install of GHC (for packages that |
|
|
127 | # use the shipped Cabal like haskell-updater). |
|
|
128 | |
|
|
129 | # The user is likely to only have one version of Cabal, provided |
|
|
130 | # by GHC. Note that dev-haskell/cabal can be a dummy package, only |
|
|
131 | # using the version provided by GHC. If the user has another version |
|
|
132 | # of Cabal too (more recent than the one GHC provides through |
|
|
133 | # dev-haskell/cabal, or possibly older if he used an old |
|
|
134 | # Cabal package) the most recent is used (expected to be the last |
|
|
135 | # one in the ghc-pkg output). |
|
|
136 | _CABAL_VERSION_CACHE="$(ghc-pkg field Cabal version | tail -n 1)" |
|
|
137 | |
|
|
138 | # Strip out the "version: " prefix |
|
|
139 | _CABAL_VERSION_CACHE="${_CABAL_VERSION_CACHE#"version: "}" |
| 112 | else |
140 | else |
| 113 | # We ask portage, not ghc, so that we only pick up |
141 | # We ask portage, not ghc, so that we only pick up |
| 114 | # portage-installed cabal versions. |
142 | # portage-installed cabal versions. |
| 115 | _CABAL_VERSION_CACHE="$(ghc-extractportageversion dev-haskell/cabal)" |
143 | _CABAL_VERSION_CACHE="$(ghc-extractportageversion dev-haskell/cabal)" |
| 116 | fi |
144 | fi |
| … | |
… | |
| 171 | cabalconf="${cabalconf} --enable-library-profiling" |
199 | cabalconf="${cabalconf} --enable-library-profiling" |
| 172 | fi |
200 | fi |
| 173 | # Building GHCi libs on ppc64 causes "TOC overflow". |
201 | # Building GHCi libs on ppc64 causes "TOC overflow". |
| 174 | if use ppc64; then |
202 | if use ppc64; then |
| 175 | cabalconf="${cabalconf} --disable-library-for-ghci" |
203 | cabalconf="${cabalconf} --disable-library-for-ghci" |
|
|
204 | fi |
|
|
205 | |
|
|
206 | if version_is_at_least "1.4" "$(cabal-version)"; then |
|
|
207 | # disable executable stripping for the executables, as portage will |
|
|
208 | # strip by itself, and pre-stripping gives a QA warning. |
|
|
209 | # cabal versions previous to 1.4 does not strip executables, and does |
|
|
210 | # not accept the flag. |
|
|
211 | # this fixes numerous bugs, amongst them; |
|
|
212 | # bug #251881, bug #251882, bug #251884, bug #251886, bug #299494 |
|
|
213 | cabalconf="${cabalconf} --disable-executable-stripping" |
| 176 | fi |
214 | fi |
| 177 | |
215 | |
| 178 | if version_is_at_least "1.2.0" "$(cabal-version)"; then |
216 | if version_is_at_least "1.2.0" "$(cabal-version)"; then |
| 179 | cabalconf="${cabalconf} --docdir=/usr/share/doc/${PF}" |
217 | cabalconf="${cabalconf} --docdir=/usr/share/doc/${PF}" |
| 180 | # As of Cabal 1.2, configure is quite quiet. For diagnostic purposes |
218 | # As of Cabal 1.2, configure is quite quiet. For diagnostic purposes |
| … | |
… | |
| 271 | |
309 | |
| 272 | # exported function: check if cabal is correctly installed for |
310 | # exported function: check if cabal is correctly installed for |
| 273 | # the currently active ghc (we cannot guarantee this with portage) |
311 | # the currently active ghc (we cannot guarantee this with portage) |
| 274 | haskell-cabal_pkg_setup() { |
312 | haskell-cabal_pkg_setup() { |
| 275 | ghc-package_pkg_setup |
313 | ghc-package_pkg_setup |
| 276 | if [[ -z "${CABAL_BOOTSTRAP}" ]] && ! ghc-sanecabal "${CABAL_MIN_VERSION}"; then |
314 | if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]] && ! ghc-sanecabal "${CABAL_MIN_VERSION}"; then |
| 277 | eerror "The package dev-haskell/cabal is not correctly installed for" |
315 | eerror "The package dev-haskell/cabal is not correctly installed for" |
| 278 | eerror "the currently active version of ghc ($(ghc-version)). Please" |
316 | eerror "the currently active version of ghc ($(ghc-version)). Please" |
| 279 | eerror "run ghc-updater or re-emerge dev-haskell/cabal." |
317 | eerror "run ghc-updater or haskell-updater or re-build dev-haskell/cabal." |
| 280 | die "cabal is not correctly installed" |
318 | die "cabal is not correctly installed" |
| 281 | fi |
319 | fi |
| 282 | if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then |
320 | if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then |
| 283 | eerror "QA: Neither bin nor lib are in CABAL_FEATURES." |
321 | eerror "QA: Neither bin nor lib are in CABAL_FEATURES." |
| 284 | fi |
322 | fi |
| … | |
… | |
| 286 | ewarn "Unknown entry in CABAL_FEATURES: ${CABAL_UNKNOWN}" |
324 | ewarn "Unknown entry in CABAL_FEATURES: ${CABAL_UNKNOWN}" |
| 287 | fi |
325 | fi |
| 288 | if cabal-is-dummy-lib; then |
326 | if cabal-is-dummy-lib; then |
| 289 | einfo "${P} is included in ghc-${CABAL_CORE_LIB_GHC_PV}, nothing to install." |
327 | einfo "${P} is included in ghc-${CABAL_CORE_LIB_GHC_PV}, nothing to install." |
| 290 | fi |
328 | fi |
|
|
329 | } |
|
|
330 | |
|
|
331 | haskell-cabal_src_configure() { |
|
|
332 | pushd "${S}" > /dev/null |
|
|
333 | |
|
|
334 | cabal-bootstrap |
|
|
335 | cabal-configure "$@" |
|
|
336 | |
|
|
337 | popd > /dev/null |
|
|
338 | } |
|
|
339 | |
|
|
340 | # exported function: nice alias |
|
|
341 | cabal_src_configure() { |
|
|
342 | haskell-cabal_src_configure "$@" |
| 291 | } |
343 | } |
| 292 | |
344 | |
| 293 | # exported function: cabal-style bootstrap configure and compile |
345 | # exported function: cabal-style bootstrap configure and compile |
| 294 | cabal_src_compile() { |
346 | cabal_src_compile() { |
| 295 | if ! cabal-is-dummy-lib; then |
347 | if ! cabal-is-dummy-lib; then |
| 296 | cabal-bootstrap |
348 | has src_configure ${HASKELL_CABAL_EXPF} || haskell-cabal_src_configure "$@" |
| 297 | cabal-configure |
|
|
| 298 | cabal-build |
349 | cabal-build |
| 299 | |
350 | |
| 300 | if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then |
351 | if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then |
| 301 | cabal-haddock |
352 | cabal-haddock |
| 302 | fi |
353 | fi |
| 303 | fi |
354 | fi |
| 304 | } |
355 | } |
|
|
356 | |
| 305 | haskell-cabal_src_compile() { |
357 | haskell-cabal_src_compile() { |
|
|
358 | pushd "${S}" > /dev/null |
|
|
359 | |
| 306 | cabal_src_compile |
360 | cabal_src_compile "$@" |
|
|
361 | |
|
|
362 | popd > /dev/null |
|
|
363 | } |
|
|
364 | |
|
|
365 | haskell-cabal_src_test() { |
|
|
366 | pushd "${S}" > /dev/null |
|
|
367 | |
|
|
368 | if cabal-is-dummy-lib; then |
|
|
369 | einfo ">>> No tests for dummy library: ${CATEGORY}/${PF}" |
|
|
370 | else |
|
|
371 | einfo ">>> Test phase [cabal test]: ${CATEGORY}/${PF}" |
|
|
372 | ./setup test || die "cabal test failed" |
|
|
373 | fi |
|
|
374 | |
|
|
375 | popd > /dev/null |
| 307 | } |
376 | } |
| 308 | |
377 | |
| 309 | # exported function: cabal-style copy and register |
378 | # exported function: cabal-style copy and register |
| 310 | cabal_src_install() { |
379 | cabal_src_install() { |
| 311 | if cabal-is-dummy-lib; then |
380 | if cabal-is-dummy-lib; then |
| … | |
… | |
| 321 | dohtml -r dist/doc/html/* |
390 | dohtml -r dist/doc/html/* |
| 322 | fi |
391 | fi |
| 323 | fi |
392 | fi |
| 324 | fi |
393 | fi |
| 325 | } |
394 | } |
|
|
395 | |
| 326 | haskell-cabal_src_install() { |
396 | haskell-cabal_src_install() { |
|
|
397 | pushd "${S}" > /dev/null |
|
|
398 | |
| 327 | cabal_src_install |
399 | cabal_src_install |
| 328 | } |
|
|
| 329 | |
400 | |
| 330 | EXPORT_FUNCTIONS pkg_setup src_compile src_install |
401 | popd > /dev/null |
|
|
402 | } |
|
|
403 | |
|
|
404 | # ebuild.sh:use_enable() taken as base |
|
|
405 | # |
|
|
406 | # Usage examples: |
|
|
407 | # |
|
|
408 | # CABAL_CONFIGURE_FLAGS=$(cabal_flag gui) |
|
|
409 | # leads to "--flags=gui" or "--flags=-gui" (useflag 'gui') |
|
|
410 | # |
|
|
411 | # CABAL_CONFIGURE_FLAGS=$(cabal_flag gtk gui) |
|
|
412 | # also leads to "--flags=gui" or " --flags=-gui" (useflag 'gtk') |
|
|
413 | # |
|
|
414 | cabal_flag() { |
|
|
415 | if [[ -z "$1" ]]; then |
|
|
416 | echo "!!! cabal_flag() called without a parameter." >&2 |
|
|
417 | echo "!!! cabal_flag() <USEFLAG> [<cabal_flagname>]" >&2 |
|
|
418 | return 1 |
|
|
419 | fi |
|
|
420 | |
|
|
421 | local UWORD=${2:-$1} |
|
|
422 | |
|
|
423 | if use "$1"; then |
|
|
424 | echo "--flags=${UWORD}" |
|
|
425 | else |
|
|
426 | echo "--flags=-${UWORD}" |
|
|
427 | fi |
|
|
428 | |
|
|
429 | return 0 |
|
|
430 | } |