| 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.17 2009/10/28 23:46:16 kolmodin Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/haskell-cabal.eclass,v 1.21 2010/08/07 12:06:27 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 | # |
| … | |
… | |
| 16 | # reflect the tools and features that the package makes |
16 | # reflect the tools and features that the package makes |
| 17 | # use of. |
17 | # use of. |
| 18 | # |
18 | # |
| 19 | # Currently supported features: |
19 | # Currently supported features: |
| 20 | # haddock -- for documentation generation |
20 | # haddock -- for documentation generation |
|
|
21 | # hscolour -- generation of colourised sources |
| 21 | # alex -- lexer/scanner generator |
22 | # alex -- lexer/scanner generator |
| 22 | # happy -- parser generator |
23 | # happy -- parser generator |
| 23 | # c2hs -- C interface generator |
24 | # c2hs -- C interface generator |
| 24 | # cpphs -- C preprocessor clone written in Haskell |
25 | # cpphs -- C preprocessor clone written in Haskell |
| 25 | # profile -- if package supports to build profiling-enabled libraries |
26 | # profile -- if package supports to build profiling-enabled libraries |
| … | |
… | |
| 43 | # Special flags to Cabal Configure can now be set by using |
44 | # Special flags to Cabal Configure can now be set by using |
| 44 | # CABAL_CONFIGURE_FLAGS |
45 | # CABAL_CONFIGURE_FLAGS |
| 45 | |
46 | |
| 46 | inherit ghc-package multilib |
47 | inherit ghc-package multilib |
| 47 | |
48 | |
|
|
49 | HASKELL_CABAL_EXPF="pkg_setup src_compile src_test src_install" |
|
|
50 | |
|
|
51 | case "${EAPI:-0}" in |
|
|
52 | 2|3|4) HASKELL_CABAL_EXPF+=" src_configure" ;; |
|
|
53 | *) ;; |
|
|
54 | esac |
|
|
55 | |
|
|
56 | EXPORT_FUNCTIONS ${HASKELL_CABAL_EXPF} |
| 48 | |
57 | |
| 49 | for feature in ${CABAL_FEATURES}; do |
58 | for feature in ${CABAL_FEATURES}; do |
| 50 | case ${feature} in |
59 | case ${feature} in |
| 51 | haddock) CABAL_USE_HADDOCK=yes;; |
60 | haddock) CABAL_USE_HADDOCK=yes;; |
|
|
61 | hscolour) CABAL_USE_HSCOLOUR=yes;; |
| 52 | alex) CABAL_USE_ALEX=yes;; |
62 | alex) CABAL_USE_ALEX=yes;; |
| 53 | happy) CABAL_USE_HAPPY=yes;; |
63 | happy) CABAL_USE_HAPPY=yes;; |
| 54 | c2hs) CABAL_USE_C2HS=yes;; |
64 | c2hs) CABAL_USE_C2HS=yes;; |
| 55 | cpphs) CABAL_USE_CPPHS=yes;; |
65 | cpphs) CABAL_USE_CPPHS=yes;; |
| 56 | profile) CABAL_USE_PROFILE=yes;; |
66 | profile) CABAL_USE_PROFILE=yes;; |
| … | |
… | |
| 65 | if [[ -n "${CABAL_USE_HADDOCK}" ]]; then |
75 | if [[ -n "${CABAL_USE_HADDOCK}" ]]; then |
| 66 | IUSE="${IUSE} doc" |
76 | IUSE="${IUSE} doc" |
| 67 | DEPEND="${DEPEND} doc? ( dev-haskell/haddock )" |
77 | DEPEND="${DEPEND} doc? ( dev-haskell/haddock )" |
| 68 | fi |
78 | fi |
| 69 | |
79 | |
|
|
80 | if [[ -n "${CABAL_USE_HSCOLOUR}" ]]; then |
|
|
81 | IUSE="${IUSE} hscolour" |
|
|
82 | DEPEND="${DEPEND} hscolour? ( dev-haskell/hscolour )" |
|
|
83 | fi |
|
|
84 | |
| 70 | if [[ -n "${CABAL_USE_ALEX}" ]]; then |
85 | if [[ -n "${CABAL_USE_ALEX}" ]]; then |
| 71 | DEPEND="${DEPEND} dev-haskell/alex" |
86 | DEPEND="${DEPEND} dev-haskell/alex" |
| 72 | cabalconf="${cabalconf} --with-alex=/usr/bin/alex" |
87 | cabalconf="${cabalconf} --with-alex=/usr/bin/alex" |
| 73 | fi |
88 | fi |
| 74 | |
89 | |
| … | |
… | |
| 177 | |
192 | |
| 178 | echo 'import Distribution.Simple; main = defaultMainWithHooks defaultUserHooks' \ |
193 | echo 'import Distribution.Simple; main = defaultMainWithHooks defaultUserHooks' \ |
| 179 | > $setupdir/Setup.hs |
194 | > $setupdir/Setup.hs |
| 180 | } |
195 | } |
| 181 | |
196 | |
|
|
197 | cabal-hscolour() { |
|
|
198 | ./setup hscolour || die "setup hscolour failed" |
|
|
199 | } |
|
|
200 | |
| 182 | cabal-haddock() { |
201 | cabal-haddock() { |
| 183 | ./setup haddock || die "setup haddock failed" |
202 | ./setup haddock || die "setup haddock failed" |
|
|
203 | } |
|
|
204 | |
|
|
205 | cabal-hscolour-haddock() { |
|
|
206 | # --hyperlink-source implies calling 'setup hscolour' |
|
|
207 | ./setup haddock --hyperlink-source || die "setup haddock failed" |
| 184 | } |
208 | } |
| 185 | |
209 | |
| 186 | cabal-configure() { |
210 | cabal-configure() { |
| 187 | if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then |
211 | if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then |
| 188 | cabalconf="${cabalconf} --with-haddock=/usr/bin/haddock" |
212 | cabalconf="${cabalconf} --with-haddock=/usr/bin/haddock" |
| … | |
… | |
| 191 | cabalconf="${cabalconf} --enable-library-profiling" |
215 | cabalconf="${cabalconf} --enable-library-profiling" |
| 192 | fi |
216 | fi |
| 193 | # Building GHCi libs on ppc64 causes "TOC overflow". |
217 | # Building GHCi libs on ppc64 causes "TOC overflow". |
| 194 | if use ppc64; then |
218 | if use ppc64; then |
| 195 | cabalconf="${cabalconf} --disable-library-for-ghci" |
219 | cabalconf="${cabalconf} --disable-library-for-ghci" |
|
|
220 | fi |
|
|
221 | |
|
|
222 | if version_is_at_least "1.4" "$(cabal-version)"; then |
|
|
223 | # disable executable stripping for the executables, as portage will |
|
|
224 | # strip by itself, and pre-stripping gives a QA warning. |
|
|
225 | # cabal versions previous to 1.4 does not strip executables, and does |
|
|
226 | # not accept the flag. |
|
|
227 | # this fixes numerous bugs, amongst them; |
|
|
228 | # bug #251881, bug #251882, bug #251884, bug #251886, bug #299494 |
|
|
229 | cabalconf="${cabalconf} --disable-executable-stripping" |
| 196 | fi |
230 | fi |
| 197 | |
231 | |
| 198 | if version_is_at_least "1.2.0" "$(cabal-version)"; then |
232 | if version_is_at_least "1.2.0" "$(cabal-version)"; then |
| 199 | cabalconf="${cabalconf} --docdir=/usr/share/doc/${PF}" |
233 | cabalconf="${cabalconf} --docdir=/usr/share/doc/${PF}" |
| 200 | # As of Cabal 1.2, configure is quite quiet. For diagnostic purposes |
234 | # As of Cabal 1.2, configure is quite quiet. For diagnostic purposes |
| … | |
… | |
| 308 | if cabal-is-dummy-lib; then |
342 | if cabal-is-dummy-lib; then |
| 309 | einfo "${P} is included in ghc-${CABAL_CORE_LIB_GHC_PV}, nothing to install." |
343 | einfo "${P} is included in ghc-${CABAL_CORE_LIB_GHC_PV}, nothing to install." |
| 310 | fi |
344 | fi |
| 311 | } |
345 | } |
| 312 | |
346 | |
|
|
347 | haskell-cabal_src_configure() { |
|
|
348 | pushd "${S}" > /dev/null |
|
|
349 | |
|
|
350 | cabal-bootstrap |
|
|
351 | cabal-configure "$@" |
|
|
352 | |
|
|
353 | popd > /dev/null |
|
|
354 | } |
|
|
355 | |
|
|
356 | # exported function: nice alias |
|
|
357 | cabal_src_configure() { |
|
|
358 | haskell-cabal_src_configure "$@" |
|
|
359 | } |
|
|
360 | |
| 313 | # exported function: cabal-style bootstrap configure and compile |
361 | # exported function: cabal-style bootstrap configure and compile |
| 314 | cabal_src_compile() { |
362 | cabal_src_compile() { |
| 315 | if ! cabal-is-dummy-lib; then |
363 | if ! cabal-is-dummy-lib; then |
| 316 | cabal-bootstrap |
364 | has src_configure ${HASKELL_CABAL_EXPF} || haskell-cabal_src_configure "$@" |
| 317 | cabal-configure |
|
|
| 318 | cabal-build |
365 | cabal-build |
| 319 | |
366 | |
| 320 | if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then |
367 | if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then |
|
|
368 | if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then |
|
|
369 | # hscolour and haddock |
|
|
370 | cabal-hscolour-haddock |
|
|
371 | else |
|
|
372 | # just haddock |
| 321 | cabal-haddock |
373 | cabal-haddock |
|
|
374 | fi |
|
|
375 | else |
|
|
376 | if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then |
|
|
377 | # just hscolour |
|
|
378 | cabal-hscolour |
|
|
379 | fi |
| 322 | fi |
380 | fi |
| 323 | fi |
381 | fi |
| 324 | } |
382 | } |
| 325 | |
383 | |
| 326 | haskell-cabal_src_compile() { |
384 | haskell-cabal_src_compile() { |
|
|
385 | pushd "${S}" > /dev/null |
|
|
386 | |
| 327 | cabal_src_compile |
387 | cabal_src_compile "$@" |
|
|
388 | |
|
|
389 | popd > /dev/null |
|
|
390 | } |
|
|
391 | |
|
|
392 | haskell-cabal_src_test() { |
|
|
393 | pushd "${S}" > /dev/null |
|
|
394 | |
|
|
395 | if cabal-is-dummy-lib; then |
|
|
396 | einfo ">>> No tests for dummy library: ${CATEGORY}/${PF}" |
|
|
397 | else |
|
|
398 | einfo ">>> Test phase [cabal test]: ${CATEGORY}/${PF}" |
|
|
399 | ./setup test || die "cabal test failed" |
|
|
400 | fi |
|
|
401 | |
|
|
402 | popd > /dev/null |
| 328 | } |
403 | } |
| 329 | |
404 | |
| 330 | # exported function: cabal-style copy and register |
405 | # exported function: cabal-style copy and register |
| 331 | cabal_src_install() { |
406 | cabal_src_install() { |
| 332 | if cabal-is-dummy-lib; then |
407 | if cabal-is-dummy-lib; then |
| … | |
… | |
| 342 | dohtml -r dist/doc/html/* |
417 | dohtml -r dist/doc/html/* |
| 343 | fi |
418 | fi |
| 344 | fi |
419 | fi |
| 345 | fi |
420 | fi |
| 346 | } |
421 | } |
|
|
422 | |
| 347 | haskell-cabal_src_install() { |
423 | haskell-cabal_src_install() { |
|
|
424 | pushd "${S}" > /dev/null |
|
|
425 | |
| 348 | cabal_src_install |
426 | cabal_src_install |
| 349 | } |
|
|
| 350 | |
427 | |
| 351 | EXPORT_FUNCTIONS pkg_setup src_compile src_install |
428 | popd > /dev/null |
|
|
429 | } |
|
|
430 | |
|
|
431 | # ebuild.sh:use_enable() taken as base |
|
|
432 | # |
|
|
433 | # Usage examples: |
|
|
434 | # |
|
|
435 | # CABAL_CONFIGURE_FLAGS=$(cabal_flag gui) |
|
|
436 | # leads to "--flags=gui" or "--flags=-gui" (useflag 'gui') |
|
|
437 | # |
|
|
438 | # CABAL_CONFIGURE_FLAGS=$(cabal_flag gtk gui) |
|
|
439 | # also leads to "--flags=gui" or " --flags=-gui" (useflag 'gtk') |
|
|
440 | # |
|
|
441 | cabal_flag() { |
|
|
442 | if [[ -z "$1" ]]; then |
|
|
443 | echo "!!! cabal_flag() called without a parameter." >&2 |
|
|
444 | echo "!!! cabal_flag() <USEFLAG> [<cabal_flagname>]" >&2 |
|
|
445 | return 1 |
|
|
446 | fi |
|
|
447 | |
|
|
448 | local UWORD=${2:-$1} |
|
|
449 | |
|
|
450 | if use "$1"; then |
|
|
451 | echo "--flags=${UWORD}" |
|
|
452 | else |
|
|
453 | echo "--flags=-${UWORD}" |
|
|
454 | fi |
|
|
455 | |
|
|
456 | return 0 |
|
|
457 | } |