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

Diff of /eclass/haskell-cabal.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.50

  ViewVC Help
Powered by ViewVC 1.1.20