/[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.32 Revision 1.48
1# Copyright 1999-2012 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.32 2012/04/19 17:33:19 slyfox Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/haskell-cabal.eclass,v 1.48 2015/01/02 09:35:02 slyfox Exp $
4 4
5# @ECLASS: haskell-cabal.eclass 5# @ECLASS: haskell-cabal.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Haskell herd <haskell@gentoo.org> 7# Haskell herd <haskell@gentoo.org>
8# @AUTHOR: 8# @AUTHOR:
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 21# hscolour -- generation of colourised sources
22# hoogle -- generation of documentation search index
22# alex -- lexer/scanner generator 23# alex -- lexer/scanner generator
23# happy -- parser generator 24# happy -- parser generator
24# c2hs -- C interface generator 25# c2hs -- C interface generator
25# cpphs -- C preprocessor clone written in Haskell 26# cpphs -- C preprocessor clone written in Haskell
26# profile -- if package supports to build profiling-enabled libraries 27# profile -- if package supports to build profiling-enabled libraries
28# bin -- the package installs binaries 29# bin -- the package installs binaries
29# lib -- the package installs libraries 30# lib -- the package installs libraries
30# nocabaldep -- don't add dependency on cabal. 31# nocabaldep -- don't add dependency on cabal.
31# only used for packages that _must_ not pull the dependency 32# only used for packages that _must_ not pull the dependency
32# on cabal, but still use this eclass (e.g. haskell-updater). 33# on cabal, but still use this eclass (e.g. haskell-updater).
34# ghcdeps -- constraint dependency on package to ghc onces
35# only used for packages that use libghc internally and _must_
36# not pull upper versions
33# test-suite -- add support for cabal test-suites (introduced in Cabal-1.8) 37# test-suite -- add support for cabal test-suites (introduced in Cabal-1.8)
34 38
35inherit ghc-package multilib 39inherit eutils ghc-package multilib multiprocessing
36 40
37# @ECLASS-VARIABLE: CABAL_EXTRA_CONFIGURE_FLAGS 41# @ECLASS-VARIABLE: CABAL_EXTRA_CONFIGURE_FLAGS
38# @DESCRIPTION: 42# @DESCRIPTION:
39# User-specified additional parameters passed to 'setup configure'. 43# User-specified additional parameters passed to 'setup configure'.
40# example: /etc/make.conf: CABAL_EXTRA_CONFIGURE_FLAGS=--enable-shared 44# example: /etc/portage/make.conf: CABAL_EXTRA_CONFIGURE_FLAGS=--enable-shared
41: ${CABAL_EXTRA_CONFIGURE_FLAGS:=} 45: ${CABAL_EXTRA_CONFIGURE_FLAGS:=}
42 46
43# @ECLASS-VARIABLE: CABAL_EXTRA_BUILD_FLAGS 47# @ECLASS-VARIABLE: CABAL_EXTRA_BUILD_FLAGS
44# @DESCRIPTION: 48# @DESCRIPTION:
45# User-specified additional parameters passed to 'setup build'. 49# User-specified additional parameters passed to 'setup build'.
46# example: /etc/make.conf: CABAL_EXTRA_BUILD_FLAGS=-v 50# example: /etc/portage/make.conf: CABAL_EXTRA_BUILD_FLAGS=-v
47: ${CABAL_EXTRA_BUILD_FLAGS:=} 51: ${CABAL_EXTRA_BUILD_FLAGS:=}
48 52
49# @ECLASS-VARIABLE: GHC_BOOTSTRAP_FLAGS 53# @ECLASS-VARIABLE: GHC_BOOTSTRAP_FLAGS
50# @DESCRIPTION: 54# @DESCRIPTION:
51# User-specified additional parameters for ghc when building 55# User-specified additional parameters for ghc when building
52# _only_ 'setup' binary bootstrap. 56# _only_ 'setup' binary bootstrap.
53# example: /etc/make.conf: GHC_BOOTSTRAP_FLAGS=-dynamic to make 57# example: /etc/portage/make.conf: GHC_BOOTSTRAP_FLAGS=-dynamic to make
54# linking 'setup' faster. 58# linking 'setup' faster.
55: ${GHC_BOOTSTRAP_FLAGS:=} 59: ${GHC_BOOTSTRAP_FLAGS:=}
56 60
61# @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
57HASKELL_CABAL_EXPF="pkg_setup src_compile src_test src_install" 67HASKELL_CABAL_EXPF="pkg_setup src_compile src_test src_install pkg_postinst pkg_postrm"
68
69# 'dev-haskell/cabal' passes those options with ./configure-based
70# configuration, but most packages don't need/don't accept it:
71# #515362, #515362
72QA_CONFIGURE_OPTIONS+=" --with-compiler --with-hc --with-hc-pkg --with-gcc"
58 73
59case "${EAPI:-0}" in 74case "${EAPI:-0}" in
60 2|3|4) HASKELL_CABAL_EXPF+=" src_configure" ;; 75 2|3|4|5) HASKELL_CABAL_EXPF+=" src_configure" ;;
61 *) ;; 76 *) ;;
62esac 77esac
63 78
64EXPORT_FUNCTIONS ${HASKELL_CABAL_EXPF} 79EXPORT_FUNCTIONS ${HASKELL_CABAL_EXPF}
65 80
75 profile) CABAL_USE_PROFILE=yes;; 90 profile) CABAL_USE_PROFILE=yes;;
76 bootstrap) CABAL_BOOTSTRAP=yes;; 91 bootstrap) CABAL_BOOTSTRAP=yes;;
77 bin) CABAL_HAS_BINARIES=yes;; 92 bin) CABAL_HAS_BINARIES=yes;;
78 lib) CABAL_HAS_LIBRARIES=yes;; 93 lib) CABAL_HAS_LIBRARIES=yes;;
79 nocabaldep) CABAL_FROM_GHC=yes;; 94 nocabaldep) CABAL_FROM_GHC=yes;;
95 ghcdeps) CABAL_GHC_CONSTRAINT=yes;;
80 test-suite) CABAL_TEST_SUITE=yes;; 96 test-suite) CABAL_TEST_SUITE=yes;;
81 *) CABAL_UNKNOWN="${CABAL_UNKNOWN} ${feature}";; 97 *) CABAL_UNKNOWN="${CABAL_UNKNOWN} ${feature}";;
82 esac 98 esac
83done 99done
84 100
92if [[ -n "${CABAL_USE_HSCOLOUR}" ]]; then 108if [[ -n "${CABAL_USE_HSCOLOUR}" ]]; then
93 IUSE="${IUSE} hscolour" 109 IUSE="${IUSE} hscolour"
94 DEPEND="${DEPEND} hscolour? ( dev-haskell/hscolour )" 110 DEPEND="${DEPEND} hscolour? ( dev-haskell/hscolour )"
95fi 111fi
96 112
113if [[ -n "${CABAL_USE_HOOGLE}" ]]; then
114 # enabled only in ::gentoo-haskell
115 CABAL_USE_HOOGLE=
116fi
117
97if [[ -n "${CABAL_USE_ALEX}" ]]; then 118if [[ -n "${CABAL_USE_ALEX}" ]]; then
98 DEPEND="${DEPEND} dev-haskell/alex" 119 DEPEND="${DEPEND} dev-haskell/alex"
99fi 120fi
100 121
101if [[ -n "${CABAL_USE_HAPPY}" ]]; then 122if [[ -n "${CABAL_USE_HAPPY}" ]]; then
123if [[ -z ${CABAL_MIN_VERSION} ]]; then 144if [[ -z ${CABAL_MIN_VERSION} ]]; then
124 CABAL_MIN_VERSION=1.1.4 145 CABAL_MIN_VERSION=1.1.4
125fi 146fi
126if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]]; then 147if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]]; then
127 DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}" 148 DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}"
128fi
129
130# Libraries require GHC to be installed.
131if [[ -n "${CABAL_HAS_LIBRARIES}" ]]; then
132 RDEPEND="${RDEPEND} dev-lang/ghc"
133fi 149fi
134 150
135# returns the version of cabal currently in use 151# returns the version of cabal currently in use
136_CABAL_VERSION_CACHE="" 152_CABAL_VERSION_CACHE=""
137cabal-version() { 153cabal-version() {
139 if [[ "${CABAL_BOOTSTRAP}" ]]; then 155 if [[ "${CABAL_BOOTSTRAP}" ]]; then
140 # We're bootstrapping cabal, so the cabal version is the version 156 # We're bootstrapping cabal, so the cabal version is the version
141 # of this package itself. 157 # of this package itself.
142 _CABAL_VERSION_CACHE="${PV}" 158 _CABAL_VERSION_CACHE="${PV}"
143 elif [[ "${CABAL_FROM_GHC}" ]]; then 159 elif [[ "${CABAL_FROM_GHC}" ]]; then
144 local cabal_package=$(echo "$(ghc-libdir)"/Cabal-*) 160 _CABAL_VERSION_CACHE="$(ghc-cabal-version)"
145 # /path/to/ghc/Cabal-${VER} -> ${VER}
146 _CABAL_VERSION_CACHE="${cabal_package/*Cabal-/}"
147 else 161 else
148 # We ask portage, not ghc, so that we only pick up 162 # We ask portage, not ghc, so that we only pick up
149 # portage-installed cabal versions. 163 # portage-installed cabal versions.
150 _CABAL_VERSION_CACHE="$(ghc-extractportageversion dev-haskell/cabal)" 164 _CABAL_VERSION_CACHE="$(ghc-extractportageversion dev-haskell/cabal)"
151 fi 165 fi
176 cabalpackage=Cabal-$(cabal-version) 190 cabalpackage=Cabal-$(cabal-version)
177 einfo "Using cabal-$(cabal-version)." 191 einfo "Using cabal-$(cabal-version)."
178 192
179 make_setup() { 193 make_setup() {
180 set -- -package "${cabalpackage}" --make "${setupmodule}" \ 194 set -- -package "${cabalpackage}" --make "${setupmodule}" \
195 ${HCFLAGS} \
181 ${GHC_BOOTSTRAP_FLAGS} \ 196 ${GHC_BOOTSTRAP_FLAGS} \
182 "$@" \ 197 "$@" \
183 -o setup 198 -o setup
184 echo $(ghc-getghc) ${HCFLAGS} "$@" 199 echo $(ghc-getghc) "$@"
185 $(ghc-getghc) "$@" 200 $(ghc-getghc) "$@"
186 } 201 }
187 if $(ghc-supports-shared-libraries); then 202 if $(ghc-supports-shared-libraries); then
188 # # some custom build systems might use external libraries, 203 # # some custom build systems might use external libraries,
189 # # for which we don't have shared libs, so keep static fallback 204 # # for which we don't have shared libs, so keep static fallback
190 # Disabled '-dynamic' as ghc does not embed RPATH to used extra-libraries:
191 # bug #411789, http://hackage.haskell.org/trac/ghc/ticket/5743#comment:3 205 # bug #411789, http://hackage.haskell.org/trac/ghc/ticket/5743#comment:3
192 # make_setup -dynamic "$@" || 206 # 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; } ||
193 make_setup "$@" || die "compiling ${setupmodule} failed" 218 make_setup "$@" || die "compiling ${setupmodule} failed"
194 else 219 else
195 make_setup "$@" || die "compiling ${setupmodule} failed" 220 make_setup "$@" || die "compiling ${setupmodule} failed"
196 fi 221 fi
197} 222}
198 223
199cabal-mksetup() { 224cabal-mksetup() {
200 local setupdir 225 local setupdir=${1:-${S}}
226 local setup_src=${setupdir}/Setup.hs
201 227
202 if [[ -n $1 ]]; then
203 setupdir=$1
204 else
205 setupdir=${S}
206 fi
207
208 rm -f "${setupdir}"/Setup.{lhs,hs} 228 rm -vf "${setupdir}"/Setup.{lhs,hs}
229 elog "Creating 'Setup.hs' for 'Simple' build type."
209 230
210 echo 'import Distribution.Simple; main = defaultMainWithHooks defaultUserHooks' \ 231 echo 'import Distribution.Simple; main = defaultMainWithHooks defaultUserHooks' \
211 > $setupdir/Setup.hs || die "failed to create default Setup.hs" 232 > "${setup_src}" || die "failed to create default Setup.hs"
212} 233}
213 234
214cabal-hscolour() { 235cabal-hscolour() {
215 set -- hscolour "$@" 236 set -- hscolour "$@"
216 echo ./setup "$@" 237 echo ./setup "$@"
219 240
220cabal-haddock() { 241cabal-haddock() {
221 set -- haddock "$@" 242 set -- haddock "$@"
222 echo ./setup "$@" 243 echo ./setup "$@"
223 ./setup "$@" || die "setup haddock failed" 244 ./setup "$@" || die "setup haddock failed"
245}
246
247cabal-hoogle() {
248 ewarn "hoogle USE flag requires doc USE flag, building without hoogle"
224} 249}
225 250
226cabal-hscolour-haddock() { 251cabal-hscolour-haddock() {
227 # --hyperlink-source implies calling 'setup hscolour' 252 # --hyperlink-source implies calling 'setup hscolour'
228 set -- haddock --hyperlink-source 253 set -- haddock --hyperlink-source
229 echo ./setup "$@" 254 echo ./setup "$@"
230 ./setup "$@" --hyperlink-source || die "setup haddock --hyperlink-source failed" 255 ./setup "$@" --hyperlink-source || die "setup haddock --hyperlink-source failed"
231} 256}
232 257
258cabal-hoogle-haddock() {
259 set -- haddock --hoogle
260 echo ./setup "$@"
261 ./setup "$@" || die "setup haddock --hoogle failed"
262}
263
264cabal-hoogle-hscolour-haddock() {
265 cabal-hscolour-haddock
266 cabal-hoogle-haddock
267}
268
269cabal-hoogle-hscolour() {
270 ewarn "hoogle USE flag requires doc USE flag, building without hoogle"
271 cabal-hscolour
272}
273
274cabal-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
283cabal-show-brokens() {
284 elog "ghc-pkg check: 'checking for other broken packages:'"
285 # pretty-printer
286 $(ghc-getghcpkg) check 2>&1 \
287 | egrep -v '^Warning: haddock-(html|interfaces): ' \
288 | egrep -v '^Warning: include-dirs: ' \
289 | head -n 20
290
291 cabal-die-if-nonempty 'broken' \
292 $($(ghc-getghcpkg) check --simple-output)
293}
294
295cabal-show-old() {
296 cabal-die-if-nonempty 'outdated' \
297 $("${EPREFIX}"/usr/sbin/haskell-updater --quiet --upgrade --list-only)
298}
299
300cabal-show-brokens-and-die() {
301 cabal-show-brokens
302 cabal-show-old
303
304 die "$@"
305}
306
233cabal-configure() { 307cabal-configure() {
308 local cabalconf=()
234 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX= 309 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
235 310
236 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then 311 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
237 cabalconf="${cabalconf} --with-haddock=${EPREFIX}/usr/bin/haddock" 312 cabalconf+=(--with-haddock=${EPREFIX}/usr/bin/haddock)
238 fi 313 fi
239 if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then 314 if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then
240 cabalconf="${cabalconf} --enable-library-profiling" 315 cabalconf+=(--enable-library-profiling)
241 fi 316 fi
242 if [[ -n "${CABAL_USE_ALEX}" ]]; then 317 if [[ -n "${CABAL_USE_ALEX}" ]]; then
243 cabalconf="${cabalconf} --with-alex=${EPREFIX}/usr/bin/alex" 318 cabalconf+=(--with-alex=${EPREFIX}/usr/bin/alex)
244 fi 319 fi
245 320
246 if [[ -n "${CABAL_USE_HAPPY}" ]]; then 321 if [[ -n "${CABAL_USE_HAPPY}" ]]; then
247 cabalconf="${cabalconf} --with-happy=${EPREFIX}/usr/bin/happy" 322 cabalconf+=(--with-happy=${EPREFIX}/usr/bin/happy)
248 fi 323 fi
249 324
250 if [[ -n "${CABAL_USE_C2HS}" ]]; then 325 if [[ -n "${CABAL_USE_C2HS}" ]]; then
251 cabalconf="${cabalconf} --with-c2hs=${EPREFIX}/usr/bin/c2hs" 326 cabalconf+=(--with-c2hs=${EPREFIX}/usr/bin/c2hs)
252 fi 327 fi
253 if [[ -n "${CABAL_USE_CPPHS}" ]]; then 328 if [[ -n "${CABAL_USE_CPPHS}" ]]; then
254 cabalconf="${cabalconf} --with-cpphs=${EPREFIX}/usr/bin/cpphs" 329 cabalconf+=(--with-cpphs=${EPREFIX}/usr/bin/cpphs)
255 fi 330 fi
256 if [[ -n "${CABAL_TEST_SUITE}" ]]; then 331 if [[ -n "${CABAL_TEST_SUITE}" ]]; then
257 cabalconf="${cabalconf} $(use_enable test tests)" 332 cabalconf+=($(use_enable test tests))
333 fi
334
335 if [[ -n "${CABAL_GHC_CONSTRAINT}" ]]; then
336 cabalconf+=($(cabal-constraint "ghc"))
258 fi 337 fi
259 338
260 local option 339 local option
261 for option in ${HCFLAGS} 340 for option in ${HCFLAGS}
262 do 341 do
263 cabalconf+=" --ghc-option=$option" 342 cabalconf+=(--ghc-option="$option")
264 done 343 done
344
345 # parallel on all available cores
346 if ghc-supports-parallel-make; then
347 local max_jobs=$(makeopts_jobs)
348
349 # 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
354 cabalconf+=(--ghc-option=-j"$max_jobs")
355 fi
265 356
266 # Building GHCi libs on ppc64 causes "TOC overflow". 357 # Building GHCi libs on ppc64 causes "TOC overflow".
267 if use ppc64; then 358 if use ppc64; then
268 cabalconf="${cabalconf} --disable-library-for-ghci" 359 cabalconf+=(--disable-library-for-ghci)
269 fi 360 fi
270 361
271 # currently cabal does not respect CFLAGS and LDFLAGS on it's own (bug #333217) 362 # currently cabal does not respect CFLAGS and LDFLAGS on it's own (bug #333217)
272 # so translate LDFLAGS to ghc parameters (without filtering) 363 # so translate LDFLAGS to ghc parameters (without filtering)
273 local flag 364 local flag
274 for flag in $LDFLAGS; do cabalconf="${cabalconf} --ghc-option=-optl$flag"; done 365 for flag in $LDFLAGS; do cabalconf+=(--ghc-option="-optl$flag"); done
275 366
276 # disable executable stripping for the executables, as portage will 367 # disable executable stripping for the executables, as portage will
277 # strip by itself, and pre-stripping gives a QA warning. 368 # strip by itself, and pre-stripping gives a QA warning.
278 # cabal versions previous to 1.4 does not strip executables, and does 369 # cabal versions previous to 1.4 does not strip executables, and does
279 # not accept the flag. 370 # not accept the flag.
280 # this fixes numerous bugs, amongst them; 371 # this fixes numerous bugs, amongst them;
281 # bug #251881, bug #251882, bug #251884, bug #251886, bug #299494 372 # bug #251881, bug #251882, bug #251884, bug #251886, bug #299494
282 cabalconf="${cabalconf} --disable-executable-stripping" 373 cabalconf+=(--disable-executable-stripping)
283 374
284 cabalconf="${cabalconf} --docdir=${EPREFIX}/usr/share/doc/${PF}" 375 cabalconf+=(--docdir="${EPREFIX}"/usr/share/doc/${PF})
285 # As of Cabal 1.2, configure is quite quiet. For diagnostic purposes 376 # As of Cabal 1.2, configure is quite quiet. For diagnostic purposes
286 # it's better if the configure chatter is in the build logs: 377 # it's better if the configure chatter is in the build logs:
287 cabalconf="${cabalconf} --verbose" 378 cabalconf+=(--verbose)
288 379
289 # We build shared version of our Cabal where ghc ships it's shared 380 # We build shared version of our Cabal where ghc ships it's shared
290 # version of it. We will link ./setup as dynamic binary againt Cabal later. 381 # version of it. We will link ./setup as dynamic binary againt Cabal later.
291 [[ ${CATEGORY}/${PN} == "dev-haskell/cabal" ]] && \ 382 [[ ${CATEGORY}/${PN} == "dev-haskell/cabal" ]] && \
292 $(ghc-supports-shared-libraries) && \ 383 $(ghc-supports-shared-libraries) && \
293 cabalconf="${cabalconf} --enable-shared" 384 cabalconf+=(--enable-shared)
385
386 if $(ghc-supports-shared-libraries); then
387 # maybe a bit lower
388 if $(ghc-supports-dynamic-by-default); then
389 cabalconf+=(--enable-shared)
390 fi
391 fi
392
393 # --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
294 402
295 set -- configure \ 403 set -- configure \
296 --ghc --prefix="${EPREFIX}"/usr \ 404 --ghc --prefix="${EPREFIX}"/usr \
297 --with-compiler="$(ghc-getghc)" \ 405 --with-compiler="$(ghc-getghc)" \
298 --with-hc-pkg="$(ghc-getghcpkg)" \ 406 --with-hc-pkg="$(ghc-getghcpkg)" \
299 --prefix="${EPREFIX}"/usr \ 407 --prefix="${EPREFIX}"/usr \
300 --libdir="${EPREFIX}"/usr/$(get_libdir) \ 408 --libdir="${EPREFIX}"/usr/$(get_libdir) \
301 --libsubdir=${P}/ghc-$(ghc-version) \ 409 --libsubdir=${P}/ghc-$(ghc-version) \
302 --datadir="${EPREFIX}"/usr/share/ \ 410 --datadir="${EPREFIX}"/usr/share/ \
303 --datasubdir=${P}/ghc-$(ghc-version) \ 411 --datasubdir=${P}/ghc-$(ghc-version) \
304 ${cabalconf} \ 412 "${cabalconf[@]}" \
305 ${CABAL_CONFIGURE_FLAGS} \ 413 ${CABAL_CONFIGURE_FLAGS} \
306 ${CABAL_EXTRA_CONFIGURE_FLAGS} \ 414 ${CABAL_EXTRA_CONFIGURE_FLAGS} \
307 "$@" 415 "$@"
308 echo ./setup "$@" 416 echo ./setup "$@"
309 ./setup "$@" || die "setup configure failed" 417 ./setup "$@" || cabal-show-brokens-and-die "setup configure failed"
310} 418}
311 419
312cabal-build() { 420cabal-build() {
313 unset LANG LC_ALL LC_MESSAGES
314 set -- build ${CABAL_EXTRA_BUILD_FLAGS} "$@" 421 set -- build ${CABAL_EXTRA_BUILD_FLAGS} "$@"
315 echo ./setup "$@" 422 echo ./setup "$@"
316 ./setup "$@" \ 423 ./setup "$@" \
317 || die "setup build failed" 424 || die "setup build failed"
318} 425}
335 # register that ourselves (if it exists). 442 # register that ourselves (if it exists).
336 443
337 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then 444 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
338 # Newer cabal can generate a package conf for us: 445 # Newer cabal can generate a package conf for us:
339 ./setup register --gen-pkg-config="${T}/${P}.conf" 446 ./setup register --gen-pkg-config="${T}/${P}.conf"
340 ghc-setup-pkg "${T}/${P}.conf" 447 ghc-install-pkg "${T}/${P}.conf"
341 ghc-install-pkg
342 fi 448 fi
343} 449}
344 450
345# Some cabal libs are bundled along with some versions of ghc 451# Some cabal libs are bundled along with some versions of ghc
346# eg filepath-1.0 comes with ghc-6.6.1 452# eg filepath-1.0 comes with ghc-6.6.1
350# However portage still records the dependency and we can upgrade the package 456# However portage still records the dependency and we can upgrade the package
351# to a later one that's not included with ghc. 457# to a later one that's not included with ghc.
352# You can also put a space separated list, eg CABAL_CORE_LIB_GHC_PV="6.6 6.6.1". 458# You can also put a space separated list, eg CABAL_CORE_LIB_GHC_PV="6.6 6.6.1".
353cabal-is-dummy-lib() { 459cabal-is-dummy-lib() {
354 for version in ${CABAL_CORE_LIB_GHC_PV[*]}; do 460 for version in ${CABAL_CORE_LIB_GHC_PV[*]}; do
355 [[ "$(ghc-version)" == "$version" ]] && return 0 461 [[ "$(ghc-version)" == ${version} ]] && return 0
356 done 462 done
357 return 1 463 return 1
358} 464}
359 465
360# exported function: check if cabal is correctly installed for 466# exported function: check if cabal is correctly installed for
361# the currently active ghc (we cannot guarantee this with portage) 467# the currently active ghc (we cannot guarantee this with portage)
362haskell-cabal_pkg_setup() { 468haskell-cabal_pkg_setup() {
469 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
363 if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then 472 if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then
364 eqawarn "QA Notice: Neither bin nor lib are in CABAL_FEATURES." 473 eqawarn "QA Notice: Neither bin nor lib are in CABAL_FEATURES."
365 fi 474 fi
366 if [[ -n "${CABAL_UNKNOWN}" ]]; then 475 if [[ -n "${CABAL_UNKNOWN}" ]]; then
367 eqawarn "QA Notice: Unknown entry in CABAL_FEATURES: ${CABAL_UNKNOWN}" 476 eqawarn "QA Notice: Unknown entry in CABAL_FEATURES: ${CABAL_UNKNOWN}"
406 has src_configure ${HASKELL_CABAL_EXPF} || haskell-cabal_src_configure "$@" 515 has src_configure ${HASKELL_CABAL_EXPF} || haskell-cabal_src_configure "$@"
407 cabal-build 516 cabal-build
408 517
409 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then 518 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
410 if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then 519 if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then
520 if [[ -n "${CABAL_USE_HOOGLE}" ]] && use hoogle; then
411 # hscolour and haddock 521 # hoogle, hscolour and haddock
522 cabal-hoogle-hscolour-haddock
523 else
524 # haddock and hscolour
412 cabal-hscolour-haddock 525 cabal-hscolour-haddock
526 fi
413 else 527 else
528 if [[ -n "${CABAL_USE_HOOGLE}" ]] && use hoogle; then
529 # hoogle and haddock
530 cabal-hoogle-haddock
531 else
414 # just haddock 532 # just haddock
415 cabal-haddock 533 cabal-haddock
534 fi
416 fi 535 fi
417 else 536 else
418 if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then 537 if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then
538 if [[ -n "${CABAL_USE_HOOGLE}" ]] && use hoogle; then
539 # hoogle and hscolour
540 cabal-hoogle-hscolour
541 else
419 # just hscolour 542 # just hscolour
420 cabal-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
421 fi 550 fi
422 fi 551 fi
423} 552}
424 553
425haskell-cabal_src_compile() { 554haskell-cabal_src_compile() {
457 # create a dummy local package conf file for haskell-updater 586 # create a dummy local package conf file for haskell-updater
458 # if it does not exist (dummy libraries and binaries w/o libraries) 587 # if it does not exist (dummy libraries and binaries w/o libraries)
459 local ghc_confdir_with_prefix="$(ghc-confdir)" 588 local ghc_confdir_with_prefix="$(ghc-confdir)"
460 # remove EPREFIX 589 # remove EPREFIX
461 dodir ${ghc_confdir_with_prefix#${EPREFIX}} 590 dodir ${ghc_confdir_with_prefix#${EPREFIX}}
462 local conf_file="${D}/$(ghc-confdir)/$(ghc-localpkgconf)" 591 local hint_db="${D}/$(ghc-confdir)"
463 [[ -e $conf_file ]] || echo '[]' > "$conf_file" || die 592 local hint_file="${hint_db}/${PF}.conf"
593 mkdir -p "${hint_db}" || die
594 touch "${hint_file}" || die
464} 595}
465 596
466haskell-cabal_src_install() { 597haskell-cabal_src_install() {
467 pushd "${S}" > /dev/null 598 pushd "${S}" > /dev/null
468 599
469 cabal_src_install 600 cabal_src_install
470 601
471 popd > /dev/null 602 popd > /dev/null
472} 603}
473 604
605haskell-cabal_pkg_postinst() {
606 ghc-package_pkg_postinst
607}
608
609haskell-cabal_pkg_postrm() {
610 ghc-package_pkg_postrm
611}
612
613# @FUNCTION: cabal_flag
614# @DESCRIPTION:
474# ebuild.sh:use_enable() taken as base 615# ebuild.sh:use_enable() taken as base
475# 616#
476# Usage examples: 617# Usage examples:
477# 618#
478# CABAL_CONFIGURE_FLAGS=$(cabal_flag gui) 619# CABAL_CONFIGURE_FLAGS=$(cabal_flag gui)
496 echo "--flags=-${UWORD}" 637 echo "--flags=-${UWORD}"
497 fi 638 fi
498 639
499 return 0 640 return 0
500} 641}
642
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#
667cabal_chdeps() {
668 local cabal_fn=${MY_PN:-${PN}}.cabal
669 local cf=${CABAL_FILE:-${S}/${cabal_fn}}
670 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 einfo "CHDEP: '${from_pat}' -> '${to_str}'"
687
688 # 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 [[ "${orig_c}" == "${new_c}" ]] && die "no trigger for '${from_pat}'"
701 orig_c=${new_c}
702 shift
703 shift
704 done
705
706 echo "${new_c}" > "$cf" ||
707 die "failed to update"
708}
709
710# @FUNCTION: cabal-constraint
711# @DESCRIPTION:
712# Allowes to set contraint to the libraries that are
713# used by specified package
714cabal-constraint() {
715 while read p v ; do
716 echo "--constraint \"$p == $v\""
717 done < $(ghc-pkgdeps ${1})
718}
719
720# @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()
725replace-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}

Legend:
Removed from v.1.32  
changed lines
  Added in v.1.48

  ViewVC Help
Powered by ViewVC 1.1.20