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

Contents of /eclass/haskell-cabal.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.46 - (hide annotations) (download)
Fri Jun 27 07:26:18 2014 UTC (3 months, 3 weeks ago) by slyfox
Branch: MAIN
CVS Tags: HEAD
Changes since 1.45: +4 -3 lines
Disable QA warning on '--with-compiler' passed by 'dev-haskell/cabal' (bug #515360 by Patrick Lauer).

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

  ViewVC Help
Powered by ViewVC 1.1.20