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

Legend:
Removed from v.1.24  
changed lines
  Added in v.1.53

  ViewVC Help
Powered by ViewVC 1.1.20