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

Contents of /eclass/haskell-cabal.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.49 - (hide annotations) (download)
Sun Mar 15 17:03:27 2015 UTC (2 years, 8 months ago) by slyfox
Branch: MAIN
Changes since 1.48: +21 -7 lines
Respect CFLAGS. New syntax for revisions CABAL_CORE_LIB_GHC_PV="PM:${ghc_PVR}".

1 slyfox 1.47 # Copyright 1999-2015 Gentoo Foundation
2 kosmikus 1.1 # Distributed under the terms of the GNU General Public License v2
3 slyfox 1.49 # $Header: /var/cvsroot/gentoo-x86/eclass/haskell-cabal.eclass,v 1.48 2015/01/02 09:35:02 slyfox Exp $
4 vapier 1.25
5     # @ECLASS: haskell-cabal.eclass
6     # @MAINTAINER:
7     # Haskell herd <haskell@gentoo.org>
8     # @AUTHOR:
9     # Original author: Andres Loeh <kosmikus@gentoo.org>
10     # Original author: Duncan Coutts <dcoutts@gentoo.org>
11     # @BLURB: for packages that make use of the Haskell Common Architecture for Building Applications and Libraries (cabal)
12     # @DESCRIPTION:
13 kosmikus 1.1 # Basic instructions:
14     #
15     # Before inheriting the eclass, set CABAL_FEATURES to
16     # reflect the tools and features that the package makes
17     # use of.
18     #
19     # Currently supported features:
20     # haddock -- for documentation generation
21 kolmodin 1.21 # hscolour -- generation of colourised sources
22 slyfox 1.35 # hoogle -- generation of documentation search index
23 kosmikus 1.1 # alex -- lexer/scanner generator
24     # happy -- parser generator
25     # c2hs -- C interface generator
26     # cpphs -- C preprocessor clone written in Haskell
27     # profile -- if package supports to build profiling-enabled libraries
28     # bootstrap -- only used for the cabal package itself
29 dcoutts 1.3 # bin -- the package installs binaries
30     # lib -- the package installs libraries
31 kolmodin 1.16 # nocabaldep -- don't add dependency on cabal.
32 slyfox 1.23 # only used for packages that _must_ not pull the dependency
33     # on cabal, but still use this eclass (e.g. haskell-updater).
34 slyfox 1.47 # ghcdeps -- constraint dependency on package to ghc onces
35     # only used for packages that use libghc internally and _must_
36     # not pull upper versions
37 slyfox 1.32 # test-suite -- add support for cabal test-suites (introduced in Cabal-1.8)
38 kosmikus 1.1
39 slyfox 1.43 inherit eutils ghc-package multilib multiprocessing
40 kosmikus 1.1
41 slyfox 1.24 # @ECLASS-VARIABLE: CABAL_EXTRA_CONFIGURE_FLAGS
42     # @DESCRIPTION:
43     # User-specified additional parameters passed to 'setup configure'.
44 slyfox 1.49 # example: /etc/portage/make.conf:
45     # CABAL_EXTRA_CONFIGURE_FLAGS="--enable-shared --enable-executable-dynamic"
46 slyfox 1.24 : ${CABAL_EXTRA_CONFIGURE_FLAGS:=}
47    
48 slyfox 1.27 # @ECLASS-VARIABLE: CABAL_EXTRA_BUILD_FLAGS
49     # @DESCRIPTION:
50     # User-specified additional parameters passed to 'setup build'.
51 zmedico 1.39 # example: /etc/portage/make.conf: CABAL_EXTRA_BUILD_FLAGS=-v
52 slyfox 1.27 : ${CABAL_EXTRA_BUILD_FLAGS:=}
53    
54 slyfox 1.24 # @ECLASS-VARIABLE: GHC_BOOTSTRAP_FLAGS
55     # @DESCRIPTION:
56     # User-specified additional parameters for ghc when building
57     # _only_ 'setup' binary bootstrap.
58 zmedico 1.39 # example: /etc/portage/make.conf: GHC_BOOTSTRAP_FLAGS=-dynamic to make
59 slyfox 1.24 # linking 'setup' faster.
60     : ${GHC_BOOTSTRAP_FLAGS:=}
61    
62 slyfox 1.36 # @ECLASS-VARIABLE: CABAL_DEBUG_LOOSENING
63     # @DESCRIPTION:
64     # Show debug output for 'cabal_chdeps' function if set.
65     # Needs working 'diff'.
66     : ${CABAL_DEBUG_LOOSENING:=}
67    
68 slyfox 1.47 HASKELL_CABAL_EXPF="pkg_setup src_compile src_test src_install pkg_postinst pkg_postrm"
69 kolmodin 1.19
70 slyfox 1.45 # 'dev-haskell/cabal' passes those options with ./configure-based
71 slyfox 1.46 # configuration, but most packages don't need/don't accept it:
72     # #515362, #515362
73     QA_CONFIGURE_OPTIONS+=" --with-compiler --with-hc --with-hc-pkg --with-gcc"
74 slyfox 1.45
75 kolmodin 1.19 case "${EAPI:-0}" in
76 axs 1.34 2|3|4|5) HASKELL_CABAL_EXPF+=" src_configure" ;;
77 kolmodin 1.19 *) ;;
78     esac
79    
80     EXPORT_FUNCTIONS ${HASKELL_CABAL_EXPF}
81 kosmikus 1.1
82     for feature in ${CABAL_FEATURES}; do
83     case ${feature} in
84 kolmodin 1.16 haddock) CABAL_USE_HADDOCK=yes;;
85 kolmodin 1.21 hscolour) CABAL_USE_HSCOLOUR=yes;;
86 slyfox 1.26 hoogle) CABAL_USE_HOOGLE=yes;;
87 kolmodin 1.16 alex) CABAL_USE_ALEX=yes;;
88     happy) CABAL_USE_HAPPY=yes;;
89     c2hs) CABAL_USE_C2HS=yes;;
90     cpphs) CABAL_USE_CPPHS=yes;;
91     profile) CABAL_USE_PROFILE=yes;;
92     bootstrap) CABAL_BOOTSTRAP=yes;;
93     bin) CABAL_HAS_BINARIES=yes;;
94     lib) CABAL_HAS_LIBRARIES=yes;;
95     nocabaldep) CABAL_FROM_GHC=yes;;
96 slyfox 1.47 ghcdeps) CABAL_GHC_CONSTRAINT=yes;;
97 slyfox 1.32 test-suite) CABAL_TEST_SUITE=yes;;
98 dcoutts 1.3 *) CABAL_UNKNOWN="${CABAL_UNKNOWN} ${feature}";;
99 kosmikus 1.1 esac
100     done
101    
102     if [[ -n "${CABAL_USE_HADDOCK}" ]]; then
103     IUSE="${IUSE} doc"
104 slyfox 1.28 # don't require depend on itself to build docs.
105     # ebuild bootstraps docs from just built binary
106     [[ ${CATEGORY}/${PN} = "dev-haskell/haddock" ]] || DEPEND="${DEPEND} doc? ( dev-haskell/haddock )"
107 kosmikus 1.1 fi
108    
109 kolmodin 1.21 if [[ -n "${CABAL_USE_HSCOLOUR}" ]]; then
110     IUSE="${IUSE} hscolour"
111     DEPEND="${DEPEND} hscolour? ( dev-haskell/hscolour )"
112     fi
113    
114 slyfox 1.47 if [[ -n "${CABAL_USE_HOOGLE}" ]]; then
115 slyfox 1.49 # enabled only in ::haskell
116 slyfox 1.48 CABAL_USE_HOOGLE=
117 slyfox 1.47 fi
118    
119 kosmikus 1.1 if [[ -n "${CABAL_USE_ALEX}" ]]; then
120     DEPEND="${DEPEND} dev-haskell/alex"
121     fi
122    
123     if [[ -n "${CABAL_USE_HAPPY}" ]]; then
124     DEPEND="${DEPEND} dev-haskell/happy"
125     fi
126    
127     if [[ -n "${CABAL_USE_C2HS}" ]]; then
128     DEPEND="${DEPEND} dev-haskell/c2hs"
129     fi
130    
131     if [[ -n "${CABAL_USE_CPPHS}" ]]; then
132     DEPEND="${DEPEND} dev-haskell/cpphs"
133     fi
134    
135     if [[ -n "${CABAL_USE_PROFILE}" ]]; then
136     IUSE="${IUSE} profile"
137     fi
138    
139 slyfox 1.32 if [[ -n "${CABAL_TEST_SUITE}" ]]; then
140     IUSE="${IUSE} test"
141     fi
142    
143 kosmikus 1.1 # We always use a standalone version of Cabal, rather than the one that comes
144     # with GHC. But of course we can't depend on cabal when building cabal itself.
145 dcoutts 1.14 if [[ -z ${CABAL_MIN_VERSION} ]]; then
146     CABAL_MIN_VERSION=1.1.4
147     fi
148 kolmodin 1.16 if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]]; then
149 dcoutts 1.11 DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}"
150 kosmikus 1.1 fi
151    
152 slyfox 1.49 # returns the version of cabal currently in use.
153     # Rarely it's handy to pin cabal version from outside.
154     : ${_CABAL_VERSION_CACHE:=""}
155 dcoutts 1.14 cabal-version() {
156     if [[ -z "${_CABAL_VERSION_CACHE}" ]]; then
157     if [[ "${CABAL_BOOTSTRAP}" ]]; then
158     # We're bootstrapping cabal, so the cabal version is the version
159     # of this package itself.
160     _CABAL_VERSION_CACHE="${PV}"
161 kolmodin 1.17 elif [[ "${CABAL_FROM_GHC}" ]]; then
162 slyfox 1.47 _CABAL_VERSION_CACHE="$(ghc-cabal-version)"
163 dcoutts 1.14 else
164     # We ask portage, not ghc, so that we only pick up
165     # portage-installed cabal versions.
166     _CABAL_VERSION_CACHE="$(ghc-extractportageversion dev-haskell/cabal)"
167     fi
168     fi
169     echo "${_CABAL_VERSION_CACHE}"
170     }
171    
172 kosmikus 1.1 cabal-bootstrap() {
173     local setupmodule
174 dcoutts 1.14 local cabalpackage
175 kosmikus 1.1 if [[ -f "${S}/Setup.lhs" ]]; then
176     setupmodule="${S}/Setup.lhs"
177 slyfox 1.29 elif [[ -f "${S}/Setup.hs" ]]; then
178     setupmodule="${S}/Setup.hs"
179 kosmikus 1.1 else
180 slyfox 1.29 die "No Setup.lhs or Setup.hs found"
181 kosmikus 1.1 fi
182    
183 slyfox 1.31 if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]] && ! ghc-sanecabal "${CABAL_MIN_VERSION}"; then
184     eerror "The package dev-haskell/cabal is not correctly installed for"
185     eerror "the currently active version of ghc ($(ghc-version)). Please"
186     eerror "run haskell-updater or re-build dev-haskell/cabal."
187     die "cabal is not correctly installed"
188     fi
189    
190 kosmikus 1.1 # We build the setup program using the latest version of
191     # cabal that we have installed
192 slyfox 1.29 cabalpackage=Cabal-$(cabal-version)
193 dcoutts 1.14 einfo "Using cabal-$(cabal-version)."
194 slyfox 1.24
195     make_setup() {
196 slyfox 1.26 set -- -package "${cabalpackage}" --make "${setupmodule}" \
197 slyfox 1.44 ${HCFLAGS} \
198 slyfox 1.24 ${GHC_BOOTSTRAP_FLAGS} \
199     "$@" \
200     -o setup
201 slyfox 1.44 echo $(ghc-getghc) "$@"
202 slyfox 1.26 $(ghc-getghc) "$@"
203 slyfox 1.24 }
204     if $(ghc-supports-shared-libraries); then
205 slyfox 1.30 # # some custom build systems might use external libraries,
206     # # for which we don't have shared libs, so keep static fallback
207     # bug #411789, http://hackage.haskell.org/trac/ghc/ticket/5743#comment:3
208 slyfox 1.35 # http://hackage.haskell.org/trac/ghc/ticket/7062
209     # http://hackage.haskell.org/trac/ghc/ticket/3072
210     # ghc does not set RPATH for extralibs, thus we do it ourselves by hands
211     einfo "Prepending $(ghc-libdir) to LD_LIBRARY_PATH"
212     if [[ ${CHOST} != *-darwin* ]]; then
213     LD_LIBRARY_PATH="$(ghc-libdir)${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}"
214     export LD_LIBRARY_PATH
215     else
216     DYLD_LIBRARY_PATH="$(ghc-libdir)${DYLD_LIBRARY_PATH:+:}${DYLD_LIBRARY_PATH}"
217     export DYLD_LIBRARY_PATH
218     fi
219     { make_setup -dynamic "$@" && ./setup --help >/dev/null; } ||
220 slyfox 1.30 make_setup "$@" || die "compiling ${setupmodule} failed"
221 slyfox 1.24 else
222     make_setup "$@" || die "compiling ${setupmodule} failed"
223     fi
224 kosmikus 1.1 }
225    
226 dcoutts 1.14 cabal-mksetup() {
227 slyfox 1.44 local setupdir=${1:-${S}}
228     local setup_src=${setupdir}/Setup.hs
229 dcoutts 1.14
230 slyfox 1.44 rm -vf "${setupdir}"/Setup.{lhs,hs}
231     elog "Creating 'Setup.hs' for 'Simple' build type."
232 dcoutts 1.14
233     echo 'import Distribution.Simple; main = defaultMainWithHooks defaultUserHooks' \
234 slyfox 1.44 > "${setup_src}" || die "failed to create default Setup.hs"
235 dcoutts 1.14 }
236    
237 kolmodin 1.21 cabal-hscolour() {
238 slyfox 1.26 set -- hscolour "$@"
239     echo ./setup "$@"
240     ./setup "$@" || die "setup hscolour failed"
241 kolmodin 1.21 }
242    
243 kosmikus 1.1 cabal-haddock() {
244 slyfox 1.26 set -- haddock "$@"
245     echo ./setup "$@"
246     ./setup "$@" || die "setup haddock failed"
247 kosmikus 1.1 }
248    
249 slyfox 1.47 cabal-hoogle() {
250     ewarn "hoogle USE flag requires doc USE flag, building without hoogle"
251     }
252    
253 kolmodin 1.21 cabal-hscolour-haddock() {
254     # --hyperlink-source implies calling 'setup hscolour'
255 slyfox 1.26 set -- haddock --hyperlink-source
256     echo ./setup "$@"
257     ./setup "$@" --hyperlink-source || die "setup haddock --hyperlink-source failed"
258 kolmodin 1.21 }
259    
260 slyfox 1.47 cabal-hoogle-haddock() {
261     set -- haddock --hoogle
262     echo ./setup "$@"
263     ./setup "$@" || die "setup haddock --hoogle failed"
264     }
265    
266     cabal-hoogle-hscolour-haddock() {
267     cabal-hscolour-haddock
268     cabal-hoogle-haddock
269     }
270    
271     cabal-hoogle-hscolour() {
272     ewarn "hoogle USE flag requires doc USE flag, building without hoogle"
273     cabal-hscolour
274     }
275    
276 slyfox 1.41 cabal-die-if-nonempty() {
277     local breakage_type=$1
278     shift
279    
280     [[ "${#@}" == 0 ]] && return 0
281     eerror "Detected ${breakage_type} packages: ${@}"
282     die "//==-- Please, run 'haskell-updater' to fix ${breakage_type} packages --==//"
283     }
284    
285 slyfox 1.40 cabal-show-brokens() {
286 slyfox 1.44 elog "ghc-pkg check: 'checking for other broken packages:'"
287 slyfox 1.40 # pretty-printer
288     $(ghc-getghcpkg) check 2>&1 \
289     | egrep -v '^Warning: haddock-(html|interfaces): ' \
290 slyfox 1.44 | egrep -v '^Warning: include-dirs: ' \
291     | head -n 20
292 slyfox 1.40
293 slyfox 1.41 cabal-die-if-nonempty 'broken' \
294     $($(ghc-getghcpkg) check --simple-output)
295     }
296 slyfox 1.40
297 slyfox 1.41 cabal-show-old() {
298     cabal-die-if-nonempty 'outdated' \
299     $("${EPREFIX}"/usr/sbin/haskell-updater --quiet --upgrade --list-only)
300 slyfox 1.40 }
301    
302     cabal-show-brokens-and-die() {
303     cabal-show-brokens
304 slyfox 1.41 cabal-show-old
305 slyfox 1.40
306     die "$@"
307     }
308    
309 kosmikus 1.1 cabal-configure() {
310 slyfox 1.43 local cabalconf=()
311 slyfox 1.23 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
312    
313 dcoutts 1.14 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
314 slyfox 1.43 cabalconf+=(--with-haddock=${EPREFIX}/usr/bin/haddock)
315 dcoutts 1.14 fi
316 kosmikus 1.1 if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then
317 slyfox 1.43 cabalconf+=(--enable-library-profiling)
318 kosmikus 1.1 fi
319 slyfox 1.23 if [[ -n "${CABAL_USE_ALEX}" ]]; then
320 slyfox 1.43 cabalconf+=(--with-alex=${EPREFIX}/usr/bin/alex)
321 slyfox 1.23 fi
322    
323     if [[ -n "${CABAL_USE_HAPPY}" ]]; then
324 slyfox 1.43 cabalconf+=(--with-happy=${EPREFIX}/usr/bin/happy)
325 slyfox 1.23 fi
326    
327     if [[ -n "${CABAL_USE_C2HS}" ]]; then
328 slyfox 1.43 cabalconf+=(--with-c2hs=${EPREFIX}/usr/bin/c2hs)
329 slyfox 1.23 fi
330     if [[ -n "${CABAL_USE_CPPHS}" ]]; then
331 slyfox 1.43 cabalconf+=(--with-cpphs=${EPREFIX}/usr/bin/cpphs)
332 slyfox 1.23 fi
333 slyfox 1.32 if [[ -n "${CABAL_TEST_SUITE}" ]]; then
334 slyfox 1.43 cabalconf+=($(use_enable test tests))
335 slyfox 1.32 fi
336 slyfox 1.23
337 slyfox 1.47 if [[ -n "${CABAL_GHC_CONSTRAINT}" ]]; then
338     cabalconf+=($(cabal-constraint "ghc"))
339     fi
340    
341 slyfox 1.27 local option
342     for option in ${HCFLAGS}
343     do
344 slyfox 1.43 cabalconf+=(--ghc-option="$option")
345 slyfox 1.27 done
346    
347 slyfox 1.43 # parallel on all available cores
348     if ghc-supports-parallel-make; then
349     local max_jobs=$(makeopts_jobs)
350    
351 slyfox 1.44 # limit to very small value, as parallelism
352     # helps slightly, but makes things severely worse
353     # when amount of threads is Very Large.
354     [[ ${max_jobs} -gt 4 ]] && max_jobs=4
355 slyfox 1.43
356     cabalconf+=(--ghc-option=-j"$max_jobs")
357     fi
358    
359 dcoutts 1.6 # Building GHCi libs on ppc64 causes "TOC overflow".
360     if use ppc64; then
361 slyfox 1.43 cabalconf+=(--disable-library-for-ghci)
362 dcoutts 1.5 fi
363 kosmikus 1.1
364 slyfox 1.24 # currently cabal does not respect CFLAGS and LDFLAGS on it's own (bug #333217)
365     # so translate LDFLAGS to ghc parameters (without filtering)
366     local flag
367 slyfox 1.49 for flag in $CFLAGS; do cabalconf+=(--ghc-option="-optc$flag"); done
368     for flag in $LDFLAGS; do cabalconf+=(--ghc-option="-optl$flag"); done
369 slyfox 1.24
370 slyfox 1.29 # disable executable stripping for the executables, as portage will
371     # strip by itself, and pre-stripping gives a QA warning.
372     # cabal versions previous to 1.4 does not strip executables, and does
373     # not accept the flag.
374     # this fixes numerous bugs, amongst them;
375     # bug #251881, bug #251882, bug #251884, bug #251886, bug #299494
376 slyfox 1.43 cabalconf+=(--disable-executable-stripping)
377 slyfox 1.29
378 slyfox 1.43 cabalconf+=(--docdir="${EPREFIX}"/usr/share/doc/${PF})
379 slyfox 1.29 # As of Cabal 1.2, configure is quite quiet. For diagnostic purposes
380     # it's better if the configure chatter is in the build logs:
381 slyfox 1.43 cabalconf+=(--verbose)
382 dcoutts 1.11
383 slyfox 1.24 # We build shared version of our Cabal where ghc ships it's shared
384     # version of it. We will link ./setup as dynamic binary againt Cabal later.
385     [[ ${CATEGORY}/${PN} == "dev-haskell/cabal" ]] && \
386     $(ghc-supports-shared-libraries) && \
387 slyfox 1.43 cabalconf+=(--enable-shared)
388 slyfox 1.24
389 slyfox 1.35 if $(ghc-supports-shared-libraries); then
390     # maybe a bit lower
391 slyfox 1.40 if $(ghc-supports-dynamic-by-default); then
392 slyfox 1.43 cabalconf+=(--enable-shared)
393 slyfox 1.35 fi
394     fi
395    
396 slyfox 1.43 # --sysconfdir appeared in Cabal-1.18+
397     if ./setup configure --help | grep -q -- --sysconfdir; then
398     cabalconf+=(--sysconfdir="${EPREFIX}"/etc)
399     fi
400    
401     # appeared in Cabal-1.18+ (see '--disable-executable-stripping')
402     if ./setup configure --help | grep -q -- --disable-library-stripping; then
403     cabalconf+=(--disable-library-stripping)
404     fi
405    
406 slyfox 1.26 set -- configure \
407 slyfox 1.23 --ghc --prefix="${EPREFIX}"/usr \
408 kosmikus 1.1 --with-compiler="$(ghc-getghc)" \
409     --with-hc-pkg="$(ghc-getghcpkg)" \
410 slyfox 1.23 --prefix="${EPREFIX}"/usr \
411     --libdir="${EPREFIX}"/usr/$(get_libdir) \
412 dcoutts 1.11 --libsubdir=${P}/ghc-$(ghc-version) \
413 slyfox 1.23 --datadir="${EPREFIX}"/usr/share/ \
414 dcoutts 1.11 --datasubdir=${P}/ghc-$(ghc-version) \
415 slyfox 1.43 "${cabalconf[@]}" \
416 kosmikus 1.8 ${CABAL_CONFIGURE_FLAGS} \
417 slyfox 1.24 ${CABAL_EXTRA_CONFIGURE_FLAGS} \
418 slyfox 1.26 "$@"
419     echo ./setup "$@"
420 slyfox 1.40 ./setup "$@" || cabal-show-brokens-and-die "setup configure failed"
421 kosmikus 1.1 }
422    
423     cabal-build() {
424 slyfox 1.27 set -- build ${CABAL_EXTRA_BUILD_FLAGS} "$@"
425 slyfox 1.26 echo ./setup "$@"
426     ./setup "$@" \
427 kosmikus 1.1 || die "setup build failed"
428     }
429    
430     cabal-copy() {
431 slyfox 1.23 has "${EAPI:-0}" 0 1 2 && ! use prefix && ED=${D}
432    
433 slyfox 1.26 set -- copy --destdir="${D}" "$@"
434     echo ./setup "$@"
435     ./setup "$@" || die "setup copy failed"
436 kosmikus 1.1
437     # cabal is a bit eager about creating dirs,
438     # so remove them if they are empty
439 slyfox 1.23 rmdir "${ED}/usr/bin" 2> /dev/null
440 kosmikus 1.1 }
441    
442     cabal-pkg() {
443 kosmikus 1.9 # This does not actually register since we're using true instead
444 slyfox 1.29 # of ghc-pkg. So it just leaves the .conf file and we can
445 kosmikus 1.1 # register that ourselves (if it exists).
446 dcoutts 1.2
447 dcoutts 1.4 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
448 slyfox 1.29 # Newer cabal can generate a package conf for us:
449     ./setup register --gen-pkg-config="${T}/${P}.conf"
450 slyfox 1.47 ghc-install-pkg "${T}/${P}.conf"
451 kosmikus 1.1 fi
452     }
453    
454 kolmodin 1.13 # Some cabal libs are bundled along with some versions of ghc
455     # eg filepath-1.0 comes with ghc-6.6.1
456     # by putting CABAL_CORE_LIB_GHC_PV="6.6.1" in an ebuild we are declaring that
457     # when building with this version of ghc, the ebuild is a dummy that is it will
458     # install no files since the package is already included with ghc.
459     # However portage still records the dependency and we can upgrade the package
460     # to a later one that's not included with ghc.
461     # You can also put a space separated list, eg CABAL_CORE_LIB_GHC_PV="6.6 6.6.1".
462 slyfox 1.49 # Those versions are taken as-is from ghc `--numeric-version`.
463     # Package manager versions are also supported:
464     # CABAL_CORE_LIB_GHC_PV="7.10.* PM:7.8.4-r1".
465 kolmodin 1.13 cabal-is-dummy-lib() {
466 slyfox 1.49 local bin_ghc_version=$(ghc-version)
467     local pm_ghc_p=$(best_version dev-lang/ghc)
468     local pm_ghc_version version
469    
470     pm_ghc_version=PM:${pm_ghc_p#dev-lang/ghc-}
471    
472 kolmodin 1.13 for version in ${CABAL_CORE_LIB_GHC_PV[*]}; do
473 slyfox 1.49 [[ "${bin_ghc_version}" == ${version} ]] && return 0
474     [[ "${pm_ghc_version}" == ${version} ]] && return 0
475 kolmodin 1.13 done
476 slyfox 1.49
477 kolmodin 1.13 return 1
478     }
479    
480 kosmikus 1.1 # exported function: check if cabal is correctly installed for
481     # the currently active ghc (we cannot guarantee this with portage)
482     haskell-cabal_pkg_setup() {
483 slyfox 1.38 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
484     [[ ${RDEPEND} == *dev-lang/ghc* ]] || eqawarn "QA Notice: A library does not have runtime dependency on dev-lang/ghc."
485     fi
486 dcoutts 1.4 if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then
487 slyfox 1.29 eqawarn "QA Notice: Neither bin nor lib are in CABAL_FEATURES."
488 dcoutts 1.4 fi
489 dcoutts 1.3 if [[ -n "${CABAL_UNKNOWN}" ]]; then
490 slyfox 1.29 eqawarn "QA Notice: Unknown entry in CABAL_FEATURES: ${CABAL_UNKNOWN}"
491 dcoutts 1.3 fi
492 kolmodin 1.13 if cabal-is-dummy-lib; then
493     einfo "${P} is included in ghc-${CABAL_CORE_LIB_GHC_PV}, nothing to install."
494     fi
495 kosmikus 1.1 }
496    
497 kolmodin 1.19 haskell-cabal_src_configure() {
498 slyfox 1.29 cabal-is-dummy-lib && return
499    
500     pushd "${S}" > /dev/null
501 kolmodin 1.19
502 slyfox 1.29 cabal-bootstrap
503 slyfox 1.22
504 slyfox 1.29 cabal-configure "$@"
505 kolmodin 1.19
506 slyfox 1.29 popd > /dev/null
507 kolmodin 1.19 }
508    
509     # exported function: nice alias
510     cabal_src_configure() {
511     haskell-cabal_src_configure "$@"
512     }
513    
514 kosmikus 1.1 # exported function: cabal-style bootstrap configure and compile
515     cabal_src_compile() {
516 slyfox 1.24 # it's a common mistake when one bumps ebuild to EAPI="2" (and upper)
517     # and forgets to separate src_compile() to src_configure()/src_compile().
518     # Such error leads to default src_configure and we lose all passed flags.
519     if ! has "${EAPI:-0}" 0 1; then
520     local passed_flag
521     for passed_flag in "$@"; do
522     [[ ${passed_flag} == --flags=* ]] && \
523 slyfox 1.29 eqawarn "QA Notice: Cabal option '${passed_flag}' has effect only in src_configure()"
524 slyfox 1.24 done
525     fi
526    
527 slyfox 1.29 cabal-is-dummy-lib && return
528    
529     has src_configure ${HASKELL_CABAL_EXPF} || haskell-cabal_src_configure "$@"
530     cabal-build
531 kosmikus 1.1
532 slyfox 1.29 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
533     if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then
534 slyfox 1.47 if [[ -n "${CABAL_USE_HOOGLE}" ]] && use hoogle; then
535     # hoogle, hscolour and haddock
536     cabal-hoogle-hscolour-haddock
537     else
538     # haddock and hscolour
539     cabal-hscolour-haddock
540     fi
541 kolmodin 1.21 else
542 slyfox 1.47 if [[ -n "${CABAL_USE_HOOGLE}" ]] && use hoogle; then
543     # hoogle and haddock
544     cabal-hoogle-haddock
545     else
546     # just haddock
547     cabal-haddock
548     fi
549 slyfox 1.29 fi
550     else
551     if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then
552 slyfox 1.47 if [[ -n "${CABAL_USE_HOOGLE}" ]] && use hoogle; then
553     # hoogle and hscolour
554     cabal-hoogle-hscolour
555     else
556     # just hscolour
557     cabal-hscolour
558     fi
559     else
560     if [[ -n "${CABAL_USE_HOOGLE}" ]] && use hoogle; then
561     # just hoogle
562     cabal-hoogle
563     fi
564 kolmodin 1.13 fi
565 kosmikus 1.1 fi
566     }
567 kolmodin 1.16
568 kosmikus 1.1 haskell-cabal_src_compile() {
569 kolmodin 1.19 pushd "${S}" > /dev/null
570    
571     cabal_src_compile "$@"
572    
573     popd > /dev/null
574     }
575    
576     haskell-cabal_src_test() {
577     pushd "${S}" > /dev/null
578    
579 kolmodin 1.20 if cabal-is-dummy-lib; then
580     einfo ">>> No tests for dummy library: ${CATEGORY}/${PF}"
581     else
582     einfo ">>> Test phase [cabal test]: ${CATEGORY}/${PF}"
583 slyfox 1.26 set -- test "$@"
584     echo ./setup "$@"
585     ./setup "$@" || die "cabal test failed"
586 kolmodin 1.20 fi
587 kolmodin 1.19
588     popd > /dev/null
589 kosmikus 1.1 }
590    
591     # exported function: cabal-style copy and register
592     cabal_src_install() {
593 slyfox 1.23 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
594    
595 slyfox 1.29 if ! cabal-is-dummy-lib; then
596 kolmodin 1.13 cabal-copy
597     cabal-pkg
598 slyfox 1.29 fi
599 kosmikus 1.1
600 slyfox 1.29 # create a dummy local package conf file for haskell-updater
601     # if it does not exist (dummy libraries and binaries w/o libraries)
602     local ghc_confdir_with_prefix="$(ghc-confdir)"
603     # remove EPREFIX
604     dodir ${ghc_confdir_with_prefix#${EPREFIX}}
605 slyfox 1.47 local hint_db="${D}/$(ghc-confdir)"
606     local hint_file="${hint_db}/${PF}.conf"
607     mkdir -p "${hint_db}" || die
608     touch "${hint_file}" || die
609 kosmikus 1.1 }
610 kolmodin 1.19
611 kosmikus 1.1 haskell-cabal_src_install() {
612 kolmodin 1.19 pushd "${S}" > /dev/null
613    
614 kosmikus 1.1 cabal_src_install
615 kolmodin 1.19
616     popd > /dev/null
617 kosmikus 1.1 }
618    
619 slyfox 1.47 haskell-cabal_pkg_postinst() {
620     ghc-package_pkg_postinst
621     }
622    
623     haskell-cabal_pkg_postrm() {
624     ghc-package_pkg_postrm
625     }
626    
627 slyfox 1.38 # @FUNCTION: cabal_flag
628     # @DESCRIPTION:
629 kolmodin 1.19 # ebuild.sh:use_enable() taken as base
630     #
631     # Usage examples:
632     #
633     # CABAL_CONFIGURE_FLAGS=$(cabal_flag gui)
634     # leads to "--flags=gui" or "--flags=-gui" (useflag 'gui')
635     #
636     # CABAL_CONFIGURE_FLAGS=$(cabal_flag gtk gui)
637     # also leads to "--flags=gui" or " --flags=-gui" (useflag 'gtk')
638     #
639     cabal_flag() {
640     if [[ -z "$1" ]]; then
641     echo "!!! cabal_flag() called without a parameter." >&2
642     echo "!!! cabal_flag() <USEFLAG> [<cabal_flagname>]" >&2
643     return 1
644     fi
645    
646     local UWORD=${2:-$1}
647    
648     if use "$1"; then
649     echo "--flags=${UWORD}"
650     else
651     echo "--flags=-${UWORD}"
652     fi
653    
654     return 0
655     }
656 slyfox 1.36
657     # @FUNCTION: cabal_chdeps
658     # @DESCRIPTION:
659     # Allows easier patching of $CABAL_FILE (${S}/${PN}.cabal by default)
660     # depends
661     #
662     # Accepts argument list as pairs of substitutions: <from-string> <to-string>...
663     #
664     # Dies on error.
665     #
666     # Usage examples:
667     #
668     # src_prepare() {
669     # cabal_chdeps \
670     # 'base >= 4.2 && < 4.6' 'base >= 4.2 && < 4.7' \
671     # 'containers ==0.4.*' 'containers >= 0.4 && < 0.6'
672     #}
673     # or
674     # src_prepare() {
675     # CABAL_FILE=${S}/${MY_PN}.cabal cabal_chdeps \
676     # 'base >= 4.2 && < 4.6' 'base >= 4.2 && < 4.7'
677     # CABAL_FILE=${S}/${MY_PN}-tools.cabal cabal_chdeps \
678     # 'base == 3.*' 'base >= 4.2 && < 4.7'
679     #}
680     #
681     cabal_chdeps() {
682 slyfox 1.44 local cabal_fn=${MY_PN:-${PN}}.cabal
683     local cf=${CABAL_FILE:-${S}/${cabal_fn}}
684 slyfox 1.36 local from_ss # ss - substring
685     local to_ss
686     local orig_c # c - contents
687     local new_c
688    
689     [[ -f $cf ]] || die "cabal file '$cf' does not exist"
690    
691     orig_c=$(< "$cf")
692    
693     while :; do
694     from_pat=$1
695     to_str=$2
696    
697     [[ -n ${from_pat} ]] || break
698     [[ -n ${to_str} ]] || die "'${from_str}' does not have 'to' part"
699    
700 slyfox 1.37 einfo "CHDEP: '${from_pat}' -> '${to_str}'"
701    
702 slyfox 1.36 # escape pattern-like symbols
703     from_pat=${from_pat//\*/\\*}
704     from_pat=${from_pat//\[/\\[}
705    
706     new_c=${orig_c//${from_pat}/${to_str}}
707    
708     if [[ -n $CABAL_DEBUG_LOOSENING ]]; then
709     echo "${orig_c}" >"${T}/${cf}".pre
710     echo "${new_c}" >"${T}/${cf}".post
711     diff -u "${T}/${cf}".{pre,post}
712     fi
713    
714 slyfox 1.37 [[ "${orig_c}" == "${new_c}" ]] && die "no trigger for '${from_pat}'"
715 slyfox 1.36 orig_c=${new_c}
716     shift
717     shift
718     done
719    
720     echo "${new_c}" > "$cf" ||
721     die "failed to update"
722     }
723 slyfox 1.42
724 slyfox 1.47 # @FUNCTION: cabal-constraint
725     # @DESCRIPTION:
726     # Allowes to set contraint to the libraries that are
727     # used by specified package
728     cabal-constraint() {
729     while read p v ; do
730     echo "--constraint \"$p == $v\""
731     done < $(ghc-pkgdeps ${1})
732     }
733    
734 slyfox 1.42 # @FUNCTION: replace-hcflags
735     # @USAGE: <old> <new>
736     # @DESCRIPTION:
737     # Replace the <old> flag with <new> in HCFLAGS. Accepts shell globs for <old>.
738     # The implementation is picked from flag-o-matic.eclass:replace-flags()
739     replace-hcflags() {
740     [[ $# != 2 ]] && die "Usage: replace-hcflags <old flag> <new flag>"
741    
742     local f new=()
743     for f in ${HCFLAGS} ; do
744     # Note this should work with globs like -O*
745     if [[ ${f} == ${1} ]]; then
746     einfo "HCFLAGS: replacing '${f}' to '${2}'"
747     f=${2}
748     fi
749     new+=( "${f}" )
750     done
751     export HCFLAGS="${new[*]}"
752    
753     return 0
754     }

  ViewVC Help
Powered by ViewVC 1.1.20