/[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.50
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.50 2015/03/28 13:32:40 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:
45# CABAL_EXTRA_CONFIGURE_FLAGS="--enable-shared --enable-executable-dynamic"
41: ${CABAL_EXTRA_CONFIGURE_FLAGS:=} 46: ${CABAL_EXTRA_CONFIGURE_FLAGS:=}
42 47
43# @ECLASS-VARIABLE: CABAL_EXTRA_BUILD_FLAGS 48# @ECLASS-VARIABLE: CABAL_EXTRA_BUILD_FLAGS
44# @DESCRIPTION: 49# @DESCRIPTION:
45# User-specified additional parameters passed to 'setup build'. 50# User-specified additional parameters passed to 'setup build'.
46# example: /etc/make.conf: CABAL_EXTRA_BUILD_FLAGS=-v 51# example: /etc/portage/make.conf: CABAL_EXTRA_BUILD_FLAGS=-v
47: ${CABAL_EXTRA_BUILD_FLAGS:=} 52: ${CABAL_EXTRA_BUILD_FLAGS:=}
48 53
49# @ECLASS-VARIABLE: GHC_BOOTSTRAP_FLAGS 54# @ECLASS-VARIABLE: GHC_BOOTSTRAP_FLAGS
50# @DESCRIPTION: 55# @DESCRIPTION:
51# User-specified additional parameters for ghc when building 56# User-specified additional parameters for ghc when building
52# _only_ 'setup' binary bootstrap. 57# _only_ 'setup' binary bootstrap.
53# example: /etc/make.conf: GHC_BOOTSTRAP_FLAGS=-dynamic to make 58# example: /etc/portage/make.conf: GHC_BOOTSTRAP_FLAGS=-dynamic to make
54# linking 'setup' faster. 59# linking 'setup' faster.
55: ${GHC_BOOTSTRAP_FLAGS:=} 60: ${GHC_BOOTSTRAP_FLAGS:=}
56 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
57HASKELL_CABAL_EXPF="pkg_setup src_compile src_test src_install" 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"
58 74
59case "${EAPI:-0}" in 75case "${EAPI:-0}" in
60 2|3|4) HASKELL_CABAL_EXPF+=" src_configure" ;; 76 2|3|4|5) HASKELL_CABAL_EXPF+=" src_configure" ;;
61 *) ;; 77 *) ;;
62esac 78esac
63 79
64EXPORT_FUNCTIONS ${HASKELL_CABAL_EXPF} 80EXPORT_FUNCTIONS ${HASKELL_CABAL_EXPF}
65 81
75 profile) CABAL_USE_PROFILE=yes;; 91 profile) CABAL_USE_PROFILE=yes;;
76 bootstrap) CABAL_BOOTSTRAP=yes;; 92 bootstrap) CABAL_BOOTSTRAP=yes;;
77 bin) CABAL_HAS_BINARIES=yes;; 93 bin) CABAL_HAS_BINARIES=yes;;
78 lib) CABAL_HAS_LIBRARIES=yes;; 94 lib) CABAL_HAS_LIBRARIES=yes;;
79 nocabaldep) CABAL_FROM_GHC=yes;; 95 nocabaldep) CABAL_FROM_GHC=yes;;
96 ghcdeps) CABAL_GHC_CONSTRAINT=yes;;
80 test-suite) CABAL_TEST_SUITE=yes;; 97 test-suite) CABAL_TEST_SUITE=yes;;
81 *) CABAL_UNKNOWN="${CABAL_UNKNOWN} ${feature}";; 98 *) CABAL_UNKNOWN="${CABAL_UNKNOWN} ${feature}";;
82 esac 99 esac
83done 100done
84 101
92if [[ -n "${CABAL_USE_HSCOLOUR}" ]]; then 109if [[ -n "${CABAL_USE_HSCOLOUR}" ]]; then
93 IUSE="${IUSE} hscolour" 110 IUSE="${IUSE} hscolour"
94 DEPEND="${DEPEND} hscolour? ( dev-haskell/hscolour )" 111 DEPEND="${DEPEND} hscolour? ( dev-haskell/hscolour )"
95fi 112fi
96 113
114if [[ -n "${CABAL_USE_HOOGLE}" ]]; then
115 # enabled only in ::haskell
116 CABAL_USE_HOOGLE=
117fi
118
97if [[ -n "${CABAL_USE_ALEX}" ]]; then 119if [[ -n "${CABAL_USE_ALEX}" ]]; then
98 DEPEND="${DEPEND} dev-haskell/alex" 120 DEPEND="${DEPEND} dev-haskell/alex"
99fi 121fi
100 122
101if [[ -n "${CABAL_USE_HAPPY}" ]]; then 123if [[ -n "${CABAL_USE_HAPPY}" ]]; then
125fi 147fi
126if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]]; then 148if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]]; then
127 DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}" 149 DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}"
128fi 150fi
129 151
130# Libraries require GHC to be installed.
131if [[ -n "${CABAL_HAS_LIBRARIES}" ]]; then
132 RDEPEND="${RDEPEND} dev-lang/ghc"
133fi
134
135# 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.
136_CABAL_VERSION_CACHE="" 154: ${_CABAL_VERSION_CACHE:=""}
137cabal-version() { 155cabal-version() {
138 if [[ -z "${_CABAL_VERSION_CACHE}" ]]; then 156 if [[ -z "${_CABAL_VERSION_CACHE}" ]]; then
139 if [[ "${CABAL_BOOTSTRAP}" ]]; then 157 if [[ "${CABAL_BOOTSTRAP}" ]]; then
140 # We're bootstrapping cabal, so the cabal version is the version 158 # We're bootstrapping cabal, so the cabal version is the version
141 # of this package itself. 159 # of this package itself.
142 _CABAL_VERSION_CACHE="${PV}" 160 _CABAL_VERSION_CACHE="${PV}"
143 elif [[ "${CABAL_FROM_GHC}" ]]; then 161 elif [[ "${CABAL_FROM_GHC}" ]]; then
144 local cabal_package=$(echo "$(ghc-libdir)"/Cabal-*) 162 _CABAL_VERSION_CACHE="$(ghc-cabal-version)"
145 # /path/to/ghc/Cabal-${VER} -> ${VER}
146 _CABAL_VERSION_CACHE="${cabal_package/*Cabal-/}"
147 else 163 else
148 # We ask portage, not ghc, so that we only pick up 164 # We ask portage, not ghc, so that we only pick up
149 # portage-installed cabal versions. 165 # portage-installed cabal versions.
150 _CABAL_VERSION_CACHE="$(ghc-extractportageversion dev-haskell/cabal)" 166 _CABAL_VERSION_CACHE="$(ghc-extractportageversion dev-haskell/cabal)"
151 fi 167 fi
176 cabalpackage=Cabal-$(cabal-version) 192 cabalpackage=Cabal-$(cabal-version)
177 einfo "Using cabal-$(cabal-version)." 193 einfo "Using cabal-$(cabal-version)."
178 194
179 make_setup() { 195 make_setup() {
180 set -- -package "${cabalpackage}" --make "${setupmodule}" \ 196 set -- -package "${cabalpackage}" --make "${setupmodule}" \
197 ${HCFLAGS} \
181 ${GHC_BOOTSTRAP_FLAGS} \ 198 ${GHC_BOOTSTRAP_FLAGS} \
182 "$@" \ 199 "$@" \
183 -o setup 200 -o setup
184 echo $(ghc-getghc) ${HCFLAGS} "$@" 201 echo $(ghc-getghc) "$@"
185 $(ghc-getghc) "$@" 202 $(ghc-getghc) "$@"
186 } 203 }
187 if $(ghc-supports-shared-libraries); then 204 if $(ghc-supports-shared-libraries); then
188 # # some custom build systems might use external libraries, 205 # # some custom build systems might use external libraries,
189 # # for which we don't have shared libs, so keep static fallback 206 # # 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 207 # bug #411789, http://hackage.haskell.org/trac/ghc/ticket/5743#comment:3
192 # make_setup -dynamic "$@" || 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; } ||
193 make_setup "$@" || die "compiling ${setupmodule} failed" 220 make_setup "$@" || die "compiling ${setupmodule} failed"
194 else 221 else
195 make_setup "$@" || die "compiling ${setupmodule} failed" 222 make_setup "$@" || die "compiling ${setupmodule} failed"
196 fi 223 fi
197} 224}
198 225
199cabal-mksetup() { 226cabal-mksetup() {
200 local setupdir 227 local setupdir=${1:-${S}}
228 local setup_src=${setupdir}/Setup.hs
201 229
202 if [[ -n $1 ]]; then
203 setupdir=$1
204 else
205 setupdir=${S}
206 fi
207
208 rm -f "${setupdir}"/Setup.{lhs,hs} 230 rm -vf "${setupdir}"/Setup.{lhs,hs}
231 elog "Creating 'Setup.hs' for 'Simple' build type."
209 232
210 echo 'import Distribution.Simple; main = defaultMainWithHooks defaultUserHooks' \ 233 echo 'import Distribution.Simple; main = defaultMainWithHooks defaultUserHooks' \
211 > $setupdir/Setup.hs || die "failed to create default Setup.hs" 234 > "${setup_src}" || die "failed to create default Setup.hs"
212} 235}
213 236
214cabal-hscolour() { 237cabal-hscolour() {
215 set -- hscolour "$@" 238 set -- hscolour "$@"
216 echo ./setup "$@" 239 echo ./setup "$@"
219 242
220cabal-haddock() { 243cabal-haddock() {
221 set -- haddock "$@" 244 set -- haddock "$@"
222 echo ./setup "$@" 245 echo ./setup "$@"
223 ./setup "$@" || die "setup haddock failed" 246 ./setup "$@" || die "setup haddock failed"
247}
248
249cabal-hoogle() {
250 ewarn "hoogle USE flag requires doc USE flag, building without hoogle"
224} 251}
225 252
226cabal-hscolour-haddock() { 253cabal-hscolour-haddock() {
227 # --hyperlink-source implies calling 'setup hscolour' 254 # --hyperlink-source implies calling 'setup hscolour'
228 set -- haddock --hyperlink-source 255 set -- haddock --hyperlink-source
229 echo ./setup "$@" 256 echo ./setup "$@"
230 ./setup "$@" --hyperlink-source || die "setup haddock --hyperlink-source failed" 257 ./setup "$@" --hyperlink-source || die "setup haddock --hyperlink-source failed"
231} 258}
232 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 "$@"
307}
308
233cabal-configure() { 309cabal-configure() {
310 local cabalconf=()
234 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX= 311 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
235 312
236 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then 313 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
237 cabalconf="${cabalconf} --with-haddock=${EPREFIX}/usr/bin/haddock" 314 cabalconf+=(--with-haddock=${EPREFIX}/usr/bin/haddock)
238 fi 315 fi
239 if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then 316 if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then
240 cabalconf="${cabalconf} --enable-library-profiling" 317 cabalconf+=(--enable-library-profiling)
241 fi 318 fi
242 if [[ -n "${CABAL_USE_ALEX}" ]]; then 319 if [[ -n "${CABAL_USE_ALEX}" ]]; then
243 cabalconf="${cabalconf} --with-alex=${EPREFIX}/usr/bin/alex" 320 cabalconf+=(--with-alex=${EPREFIX}/usr/bin/alex)
244 fi 321 fi
245 322
246 if [[ -n "${CABAL_USE_HAPPY}" ]]; then 323 if [[ -n "${CABAL_USE_HAPPY}" ]]; then
247 cabalconf="${cabalconf} --with-happy=${EPREFIX}/usr/bin/happy" 324 cabalconf+=(--with-happy=${EPREFIX}/usr/bin/happy)
248 fi 325 fi
249 326
250 if [[ -n "${CABAL_USE_C2HS}" ]]; then 327 if [[ -n "${CABAL_USE_C2HS}" ]]; then
251 cabalconf="${cabalconf} --with-c2hs=${EPREFIX}/usr/bin/c2hs" 328 cabalconf+=(--with-c2hs=${EPREFIX}/usr/bin/c2hs)
252 fi 329 fi
253 if [[ -n "${CABAL_USE_CPPHS}" ]]; then 330 if [[ -n "${CABAL_USE_CPPHS}" ]]; then
254 cabalconf="${cabalconf} --with-cpphs=${EPREFIX}/usr/bin/cpphs" 331 cabalconf+=(--with-cpphs=${EPREFIX}/usr/bin/cpphs)
255 fi 332 fi
256 if [[ -n "${CABAL_TEST_SUITE}" ]]; then 333 if [[ -n "${CABAL_TEST_SUITE}" ]]; then
257 cabalconf="${cabalconf} $(use_enable test tests)" 334 cabalconf+=($(use_enable test tests))
335 fi
336
337 if [[ -n "${CABAL_GHC_CONSTRAINT}" ]]; then
338 cabalconf+=($(cabal-constraint "ghc"))
258 fi 339 fi
259 340
260 local option 341 local option
261 for option in ${HCFLAGS} 342 for option in ${HCFLAGS}
262 do 343 do
263 cabalconf+=" --ghc-option=$option" 344 cabalconf+=(--ghc-option="$option")
264 done 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
265 358
266 # Building GHCi libs on ppc64 causes "TOC overflow". 359 # Building GHCi libs on ppc64 causes "TOC overflow".
267 if use ppc64; then 360 if use ppc64; then
268 cabalconf="${cabalconf} --disable-library-for-ghci" 361 cabalconf+=(--disable-library-for-ghci)
269 fi 362 fi
270 363
271 # currently cabal does not respect CFLAGS and LDFLAGS on it's own (bug #333217) 364 # currently cabal does not respect CFLAGS and LDFLAGS on it's own (bug #333217)
272 # so translate LDFLAGS to ghc parameters (without filtering) 365 # so translate LDFLAGS to ghc parameters (without filtering)
273 local flag 366 local flag
367 for flag in $CFLAGS; do cabalconf+=(--ghc-option="-optc$flag"); done
274 for flag in $LDFLAGS; do cabalconf="${cabalconf} --ghc-option=-optl$flag"; done 368 for flag in $LDFLAGS; do cabalconf+=(--ghc-option="-optl$flag"); done
275 369
276 # disable executable stripping for the executables, as portage will 370 # disable executable stripping for the executables, as portage will
277 # strip by itself, and pre-stripping gives a QA warning. 371 # strip by itself, and pre-stripping gives a QA warning.
278 # cabal versions previous to 1.4 does not strip executables, and does 372 # cabal versions previous to 1.4 does not strip executables, and does
279 # not accept the flag. 373 # not accept the flag.
280 # this fixes numerous bugs, amongst them; 374 # this fixes numerous bugs, amongst them;
281 # bug #251881, bug #251882, bug #251884, bug #251886, bug #299494 375 # bug #251881, bug #251882, bug #251884, bug #251886, bug #299494
282 cabalconf="${cabalconf} --disable-executable-stripping" 376 cabalconf+=(--disable-executable-stripping)
283 377
284 cabalconf="${cabalconf} --docdir=${EPREFIX}/usr/share/doc/${PF}" 378 cabalconf+=(--docdir="${EPREFIX}"/usr/share/doc/${PF})
285 # 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
286 # 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:
287 cabalconf="${cabalconf} --verbose" 381 cabalconf+=(--verbose)
288 382
289 # We build shared version of our Cabal where ghc ships it's shared 383 # 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. 384 # version of it. We will link ./setup as dynamic binary againt Cabal later.
291 [[ ${CATEGORY}/${PN} == "dev-haskell/cabal" ]] && \ 385 [[ ${CATEGORY}/${PN} == "dev-haskell/cabal" ]] && \
292 $(ghc-supports-shared-libraries) && \ 386 $(ghc-supports-shared-libraries) && \
293 cabalconf="${cabalconf} --enable-shared" 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)
399 fi
400 fi
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
294 411
295 set -- configure \ 412 set -- configure \
296 --ghc --prefix="${EPREFIX}"/usr \ 413 --ghc --prefix="${EPREFIX}"/usr \
297 --with-compiler="$(ghc-getghc)" \ 414 --with-compiler="$(ghc-getghc)" \
298 --with-hc-pkg="$(ghc-getghcpkg)" \ 415 --with-hc-pkg="$(ghc-getghcpkg)" \
299 --prefix="${EPREFIX}"/usr \ 416 --prefix="${EPREFIX}"/usr \
300 --libdir="${EPREFIX}"/usr/$(get_libdir) \ 417 --libdir="${EPREFIX}"/usr/$(get_libdir) \
301 --libsubdir=${P}/ghc-$(ghc-version) \ 418 --libsubdir=${P}/ghc-$(ghc-version) \
302 --datadir="${EPREFIX}"/usr/share/ \ 419 --datadir="${EPREFIX}"/usr/share/ \
303 --datasubdir=${P}/ghc-$(ghc-version) \ 420 --datasubdir=${P}/ghc-$(ghc-version) \
304 ${cabalconf} \ 421 "${cabalconf[@]}" \
305 ${CABAL_CONFIGURE_FLAGS} \ 422 ${CABAL_CONFIGURE_FLAGS} \
306 ${CABAL_EXTRA_CONFIGURE_FLAGS} \ 423 ${CABAL_EXTRA_CONFIGURE_FLAGS} \
307 "$@" 424 "$@"
308 echo ./setup "$@" 425 echo ./setup "$@"
309 ./setup "$@" || die "setup configure failed" 426 ./setup "$@" || cabal-show-brokens-and-die "setup configure failed"
310} 427}
311 428
312cabal-build() { 429cabal-build() {
313 unset LANG LC_ALL LC_MESSAGES
314 set -- build ${CABAL_EXTRA_BUILD_FLAGS} "$@" 430 set -- build ${CABAL_EXTRA_BUILD_FLAGS} "$@"
315 echo ./setup "$@" 431 echo ./setup "$@"
316 ./setup "$@" \ 432 ./setup "$@" \
317 || die "setup build failed" 433 || die "setup build failed"
318} 434}
335 # register that ourselves (if it exists). 451 # register that ourselves (if it exists).
336 452
337 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then 453 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
338 # Newer cabal can generate a package conf for us: 454 # Newer cabal can generate a package conf for us:
339 ./setup register --gen-pkg-config="${T}/${P}.conf" 455 ./setup register --gen-pkg-config="${T}/${P}.conf"
340 ghc-setup-pkg "${T}/${P}.conf" 456 ghc-install-pkg "${T}/${P}.conf"
341 ghc-install-pkg
342 fi 457 fi
343} 458}
344 459
345# Some cabal libs are bundled along with some versions of ghc 460# Some cabal libs are bundled along with some versions of ghc
346# eg filepath-1.0 comes with ghc-6.6.1 461# eg filepath-1.0 comes with ghc-6.6.1
348# 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
349# install no files since the package is already included with ghc. 464# install no files since the package is already included with ghc.
350# 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
351# to a later one that's not included with ghc. 466# 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". 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".
353cabal-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
354 for version in ${CABAL_CORE_LIB_GHC_PV[*]}; do 478 for version in ${CABAL_CORE_LIB_GHC_PV[*]}; do
355 [[ "$(ghc-version)" == "$version" ]] && return 0 479 [[ "${bin_ghc_version}" == ${version} ]] && return 0
480 [[ "${pm_ghc_version}" == ${version} ]] && return 0
356 done 481 done
482
357 return 1 483 return 1
358} 484}
359 485
360# exported function: check if cabal is correctly installed for 486# exported function: check if cabal is correctly installed for
361# the currently active ghc (we cannot guarantee this with portage) 487# the currently active ghc (we cannot guarantee this with portage)
362haskell-cabal_pkg_setup() { 488haskell-cabal_pkg_setup() {
489 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
490 [[ ${RDEPEND} == *dev-lang/ghc* ]] || eqawarn "QA Notice: A library does not have runtime dependency on dev-lang/ghc."
491 fi
363 if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then 492 if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then
364 eqawarn "QA Notice: Neither bin nor lib are in CABAL_FEATURES." 493 eqawarn "QA Notice: Neither bin nor lib are in CABAL_FEATURES."
365 fi 494 fi
366 if [[ -n "${CABAL_UNKNOWN}" ]]; then 495 if [[ -n "${CABAL_UNKNOWN}" ]]; then
367 eqawarn "QA Notice: Unknown entry in CABAL_FEATURES: ${CABAL_UNKNOWN}" 496 eqawarn "QA Notice: Unknown entry in CABAL_FEATURES: ${CABAL_UNKNOWN}"
406 has src_configure ${HASKELL_CABAL_EXPF} || haskell-cabal_src_configure "$@" 535 has src_configure ${HASKELL_CABAL_EXPF} || haskell-cabal_src_configure "$@"
407 cabal-build 536 cabal-build
408 537
409 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then 538 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
410 if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then 539 if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then
540 if [[ -n "${CABAL_USE_HOOGLE}" ]] && use hoogle; then
411 # hscolour and haddock 541 # hoogle, hscolour and haddock
542 cabal-hoogle-hscolour-haddock
543 else
544 # haddock and hscolour
412 cabal-hscolour-haddock 545 cabal-hscolour-haddock
546 fi
413 else 547 else
548 if [[ -n "${CABAL_USE_HOOGLE}" ]] && use hoogle; then
549 # hoogle and haddock
550 cabal-hoogle-haddock
551 else
414 # just haddock 552 # just haddock
415 cabal-haddock 553 cabal-haddock
554 fi
416 fi 555 fi
417 else 556 else
418 if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then 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
419 # just hscolour 562 # just hscolour
420 cabal-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
421 fi 570 fi
422 fi 571 fi
423} 572}
424 573
425haskell-cabal_src_compile() { 574haskell-cabal_src_compile() {
457 # create a dummy local package conf file for haskell-updater 606 # create a dummy local package conf file for haskell-updater
458 # if it does not exist (dummy libraries and binaries w/o libraries) 607 # if it does not exist (dummy libraries and binaries w/o libraries)
459 local ghc_confdir_with_prefix="$(ghc-confdir)" 608 local ghc_confdir_with_prefix="$(ghc-confdir)"
460 # remove EPREFIX 609 # remove EPREFIX
461 dodir ${ghc_confdir_with_prefix#${EPREFIX}} 610 dodir ${ghc_confdir_with_prefix#${EPREFIX}}
462 local conf_file="${D}/$(ghc-confdir)/$(ghc-localpkgconf)" 611 local hint_db="${D}/$(ghc-confdir)"
463 [[ -e $conf_file ]] || echo '[]' > "$conf_file" || die 612 local hint_file="${hint_db}/${PF}.conf"
613 mkdir -p "${hint_db}" || die
614 touch "${hint_file}" || die
464} 615}
465 616
466haskell-cabal_src_install() { 617haskell-cabal_src_install() {
467 pushd "${S}" > /dev/null 618 pushd "${S}" > /dev/null
468 619
469 cabal_src_install 620 cabal_src_install
470 621
471 popd > /dev/null 622 popd > /dev/null
472} 623}
473 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:
474# ebuild.sh:use_enable() taken as base 635# ebuild.sh:use_enable() taken as base
475# 636#
476# Usage examples: 637# Usage examples:
477# 638#
478# CABAL_CONFIGURE_FLAGS=$(cabal_flag gui) 639# CABAL_CONFIGURE_FLAGS=$(cabal_flag gui)
496 echo "--flags=-${UWORD}" 657 echo "--flags=-${UWORD}"
497 fi 658 fi
498 659
499 return 0 660 return 0
500} 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}
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}
754 fi
755 new+=( "${f}" )
756 done
757 export HCFLAGS="${new[*]}"
758
759 return 0
760}

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

  ViewVC Help
Powered by ViewVC 1.1.20