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

Contents of /eclass/haskell-cabal.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.48 - (hide annotations) (download)
Fri Jan 2 09:35:02 2015 UTC (2 years, 10 months ago) by slyfox
Branch: MAIN
Changes since 1.47: +2 -2 lines
Properly disable USE=hoogle.

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

  ViewVC Help
Powered by ViewVC 1.1.20