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

Contents of /eclass/haskell-cabal.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.45 - (hide annotations) (download)
Fri Jun 27 07:16:47 2014 UTC (4 years, 7 months ago) by slyfox
Branch: MAIN
Changes since 1.44: +5 -2 lines
Disable QA warning on '--with-hc --with-hc-pkg --with-gcc' flags passed by 'dev-haskell/cabal' to every configure-based haskell package. Don't unset LANG/LC_ALL/LC_MESSAGES anymore.

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

  ViewVC Help
Powered by ViewVC 1.1.20