| 1 | # Copyright 1999-2011 Gentoo Foundation |
1 | # Copyright 1999-2011 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.23 2011/03/13 20:15:14 slyfox Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/haskell-cabal.eclass,v 1.24 2011/05/08 15:13:10 slyfox Exp $ |
| 4 | # |
4 | # |
| 5 | # Original authors: Andres Loeh <kosmikus@gentoo.org> |
5 | # Original authors: Andres Loeh <kosmikus@gentoo.org> |
| 6 | # Duncan Coutts <dcoutts@gentoo.org> |
6 | # Duncan Coutts <dcoutts@gentoo.org> |
| 7 | # Maintained by: Haskell herd <haskell@gentoo.org> |
7 | # Maintained by: Haskell herd <haskell@gentoo.org> |
| 8 | # |
8 | # |
| … | |
… | |
| 43 | # |
43 | # |
| 44 | # Special flags to Cabal Configure can now be set by using |
44 | # Special flags to Cabal Configure can now be set by using |
| 45 | # CABAL_CONFIGURE_FLAGS |
45 | # CABAL_CONFIGURE_FLAGS |
| 46 | |
46 | |
| 47 | inherit ghc-package multilib |
47 | inherit ghc-package multilib |
|
|
48 | |
|
|
49 | # @ECLASS-VARIABLE: CABAL_EXTRA_CONFIGURE_FLAGS |
|
|
50 | # @DESCRIPTION: |
|
|
51 | # User-specified additional parameters passed to 'setup configure'. |
|
|
52 | # example: /etc/make.conf: CABAL_EXTRA_CONFIGURE_FLAGS=--enable-shared |
|
|
53 | : ${CABAL_EXTRA_CONFIGURE_FLAGS:=} |
|
|
54 | |
|
|
55 | # @ECLASS-VARIABLE: GHC_BOOTSTRAP_FLAGS |
|
|
56 | # @DESCRIPTION: |
|
|
57 | # User-specified additional parameters for ghc when building |
|
|
58 | # _only_ 'setup' binary bootstrap. |
|
|
59 | # example: /etc/make.conf: GHC_BOOTSTRAP_FLAGS=-dynamic to make |
|
|
60 | # linking 'setup' faster. |
|
|
61 | : ${GHC_BOOTSTRAP_FLAGS:=} |
| 48 | |
62 | |
| 49 | HASKELL_CABAL_EXPF="pkg_setup src_compile src_test src_install" |
63 | HASKELL_CABAL_EXPF="pkg_setup src_compile src_test src_install" |
| 50 | |
64 | |
| 51 | case "${EAPI:-0}" in |
65 | case "${EAPI:-0}" in |
| 52 | 2|3|4) HASKELL_CABAL_EXPF+=" src_configure" ;; |
66 | 2|3|4) HASKELL_CABAL_EXPF+=" src_configure" ;; |
| … | |
… | |
| 123 | if [[ "${CABAL_BOOTSTRAP}" ]]; then |
137 | if [[ "${CABAL_BOOTSTRAP}" ]]; then |
| 124 | # We're bootstrapping cabal, so the cabal version is the version |
138 | # We're bootstrapping cabal, so the cabal version is the version |
| 125 | # of this package itself. |
139 | # of this package itself. |
| 126 | _CABAL_VERSION_CACHE="${PV}" |
140 | _CABAL_VERSION_CACHE="${PV}" |
| 127 | elif [[ "${CABAL_FROM_GHC}" ]]; then |
141 | elif [[ "${CABAL_FROM_GHC}" ]]; then |
| 128 | # We can't assume there's a version of Cabal installed by ebuild as |
142 | local cabal_package=$(echo "$(ghc-libdir)"/Cabal-*) |
| 129 | # this might be a first time install of GHC (for packages that |
143 | # /path/to/ghc/Cabal-${VER} -> ${VER} |
| 130 | # use the shipped Cabal like haskell-updater). |
144 | _CABAL_VERSION_CACHE="${cabal_package/*Cabal-/}" |
| 131 | |
|
|
| 132 | # The user is likely to only have one version of Cabal, provided |
|
|
| 133 | # by GHC. Note that dev-haskell/cabal can be a dummy package, only |
|
|
| 134 | # using the version provided by GHC. If the user has another version |
|
|
| 135 | # of Cabal too (more recent than the one GHC provides through |
|
|
| 136 | # dev-haskell/cabal, or possibly older if he used an old |
|
|
| 137 | # Cabal package) the most recent is used (expected to be the last |
|
|
| 138 | # one in the ghc-pkg output). |
|
|
| 139 | _CABAL_VERSION_CACHE="$(ghc-pkg field Cabal version | tail -n 1)" |
|
|
| 140 | |
|
|
| 141 | # Strip out the "version: " prefix |
|
|
| 142 | _CABAL_VERSION_CACHE="${_CABAL_VERSION_CACHE#"version: "}" |
|
|
| 143 | else |
145 | else |
| 144 | # We ask portage, not ghc, so that we only pick up |
146 | # We ask portage, not ghc, so that we only pick up |
| 145 | # portage-installed cabal versions. |
147 | # portage-installed cabal versions. |
| 146 | _CABAL_VERSION_CACHE="$(ghc-extractportageversion dev-haskell/cabal)" |
148 | _CABAL_VERSION_CACHE="$(ghc-extractportageversion dev-haskell/cabal)" |
| 147 | fi |
149 | fi |
| … | |
… | |
| 169 | else |
171 | else |
| 170 | # older ghc's don't support package versioning |
172 | # older ghc's don't support package versioning |
| 171 | cabalpackage=Cabal |
173 | cabalpackage=Cabal |
| 172 | fi |
174 | fi |
| 173 | einfo "Using cabal-$(cabal-version)." |
175 | einfo "Using cabal-$(cabal-version)." |
|
|
176 | |
|
|
177 | make_setup() { |
| 174 | $(ghc-getghc) -package "${cabalpackage}" --make "${setupmodule}" -o setup \ |
178 | $(ghc-getghc) -package "${cabalpackage}" --make "${setupmodule}" \ |
|
|
179 | ${GHC_BOOTSTRAP_FLAGS} \ |
|
|
180 | "$@" \ |
|
|
181 | -o setup |
|
|
182 | } |
|
|
183 | if $(ghc-supports-shared-libraries); then |
|
|
184 | # some custom build systems might use external libraries, |
|
|
185 | # for which we don't have shared libs, so keep static fallback |
|
|
186 | make_setup -dynamic "$@" || make_setup "$@" || die "compiling ${setupmodule} failed" |
|
|
187 | else |
| 175 | || die "compiling ${setupmodule} failed" |
188 | make_setup "$@" || die "compiling ${setupmodule} failed" |
|
|
189 | fi |
| 176 | } |
190 | } |
| 177 | |
191 | |
| 178 | cabal-mksetup() { |
192 | cabal-mksetup() { |
| 179 | local setupdir |
193 | local setupdir |
| 180 | |
194 | |
| … | |
… | |
| 229 | |
243 | |
| 230 | # Building GHCi libs on ppc64 causes "TOC overflow". |
244 | # Building GHCi libs on ppc64 causes "TOC overflow". |
| 231 | if use ppc64; then |
245 | if use ppc64; then |
| 232 | cabalconf="${cabalconf} --disable-library-for-ghci" |
246 | cabalconf="${cabalconf} --disable-library-for-ghci" |
| 233 | fi |
247 | fi |
|
|
248 | |
|
|
249 | # currently cabal does not respect CFLAGS and LDFLAGS on it's own (bug #333217) |
|
|
250 | # so translate LDFLAGS to ghc parameters (without filtering) |
|
|
251 | local flag |
|
|
252 | for flag in $LDFLAGS; do cabalconf="${cabalconf} --ghc-option=-optl$flag"; done |
| 234 | |
253 | |
| 235 | if version_is_at_least "1.4" "$(cabal-version)"; then |
254 | if version_is_at_least "1.4" "$(cabal-version)"; then |
| 236 | # disable executable stripping for the executables, as portage will |
255 | # disable executable stripping for the executables, as portage will |
| 237 | # strip by itself, and pre-stripping gives a QA warning. |
256 | # strip by itself, and pre-stripping gives a QA warning. |
| 238 | # cabal versions previous to 1.4 does not strip executables, and does |
257 | # cabal versions previous to 1.4 does not strip executables, and does |
| … | |
… | |
| 251 | # Note: with Cabal-1.1.6.x we do not have enough control |
270 | # Note: with Cabal-1.1.6.x we do not have enough control |
| 252 | # to put the docs into the right place. They're currently going |
271 | # to put the docs into the right place. They're currently going |
| 253 | # into /usr/share/${P}/ghc-x.y/doc/ |
272 | # into /usr/share/${P}/ghc-x.y/doc/ |
| 254 | # rather than /usr/share/doc/${PF}/ |
273 | # rather than /usr/share/doc/${PF}/ |
| 255 | # Because we can only set the datadir, not the docdir. |
274 | # Because we can only set the datadir, not the docdir. |
|
|
275 | |
|
|
276 | # 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. |
|
|
278 | [[ ${CATEGORY}/${PN} == "dev-haskell/cabal" ]] && \ |
|
|
279 | $(ghc-supports-shared-libraries) && \ |
|
|
280 | cabalconf="${cabalconf} --enable-shared" |
| 256 | |
281 | |
| 257 | ./setup configure \ |
282 | ./setup configure \ |
| 258 | --ghc --prefix="${EPREFIX}"/usr \ |
283 | --ghc --prefix="${EPREFIX}"/usr \ |
| 259 | --with-compiler="$(ghc-getghc)" \ |
284 | --with-compiler="$(ghc-getghc)" \ |
| 260 | --with-hc-pkg="$(ghc-getghcpkg)" \ |
285 | --with-hc-pkg="$(ghc-getghcpkg)" \ |
| … | |
… | |
| 263 | --libsubdir=${P}/ghc-$(ghc-version) \ |
288 | --libsubdir=${P}/ghc-$(ghc-version) \ |
| 264 | --datadir="${EPREFIX}"/usr/share/ \ |
289 | --datadir="${EPREFIX}"/usr/share/ \ |
| 265 | --datasubdir=${P}/ghc-$(ghc-version) \ |
290 | --datasubdir=${P}/ghc-$(ghc-version) \ |
| 266 | ${cabalconf} \ |
291 | ${cabalconf} \ |
| 267 | ${CABAL_CONFIGURE_FLAGS} \ |
292 | ${CABAL_CONFIGURE_FLAGS} \ |
|
|
293 | ${CABAL_EXTRA_CONFIGURE_FLAGS} \ |
| 268 | "$@" || die "setup configure failed" |
294 | "$@" || die "setup configure failed" |
| 269 | } |
295 | } |
| 270 | |
296 | |
| 271 | cabal-build() { |
297 | cabal-build() { |
| 272 | unset LANG LC_ALL LC_MESSAGES |
298 | unset LANG LC_ALL LC_MESSAGES |
| … | |
… | |
| 363 | if ! cabal-is-dummy-lib; then |
389 | if ! cabal-is-dummy-lib; then |
| 364 | pushd "${S}" > /dev/null |
390 | pushd "${S}" > /dev/null |
| 365 | |
391 | |
| 366 | cabal-bootstrap |
392 | cabal-bootstrap |
| 367 | |
393 | |
| 368 | ghc_flags="" |
|
|
| 369 | # currently cabal does not respect CFLAGS and LDFLAGS on it's own (bug #333217) |
|
|
| 370 | # so translate LDFLAGS to ghc parameters (without filtering) |
|
|
| 371 | for flag in $LDFLAGS; do ghc_flags="${ghc_flags} --ghc-option=-optl$flag"; done |
|
|
| 372 | |
|
|
| 373 | cabal-configure $ghc_flags "$@" |
394 | cabal-configure $ghc_flags "$@" |
| 374 | |
395 | |
| 375 | popd > /dev/null |
396 | popd > /dev/null |
| 376 | fi |
397 | fi |
| 377 | } |
398 | } |
| … | |
… | |
| 381 | haskell-cabal_src_configure "$@" |
402 | haskell-cabal_src_configure "$@" |
| 382 | } |
403 | } |
| 383 | |
404 | |
| 384 | # exported function: cabal-style bootstrap configure and compile |
405 | # exported function: cabal-style bootstrap configure and compile |
| 385 | cabal_src_compile() { |
406 | cabal_src_compile() { |
|
|
407 | # it's a common mistake when one bumps ebuild to EAPI="2" (and upper) |
|
|
408 | # and forgets to separate src_compile() to src_configure()/src_compile(). |
|
|
409 | # Such error leads to default src_configure and we lose all passed flags. |
|
|
410 | if ! has "${EAPI:-0}" 0 1; then |
|
|
411 | local passed_flag |
|
|
412 | for passed_flag in "$@"; do |
|
|
413 | [[ ${passed_flag} == --flags=* ]] && \ |
|
|
414 | eqawarn "Cabal option '${passed_flag}' has effect only in src_configure()" |
|
|
415 | done |
|
|
416 | fi |
|
|
417 | |
| 386 | if ! cabal-is-dummy-lib; then |
418 | if ! cabal-is-dummy-lib; then |
| 387 | has src_configure ${HASKELL_CABAL_EXPF} || haskell-cabal_src_configure "$@" |
419 | has src_configure ${HASKELL_CABAL_EXPF} || haskell-cabal_src_configure "$@" |
| 388 | cabal-build |
420 | cabal-build |
| 389 | |
421 | |
| 390 | if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then |
422 | if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then |