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

Contents of /eclass/haskell-cabal.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.22 - (show annotations) (download)
Sun Sep 12 07:37:09 2010 UTC (3 years, 11 months ago) by slyfox
Branch: MAIN
Changes since 1.21: +8 -2 lines
Make .cabal built haskell packages respect LDFLAGS envvar. Fixes bug #333217 (and inferior bug #335591)

1 # Copyright 1999-2006 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/haskell-cabal.eclass,v 1.21 2010/08/07 12:06:27 kolmodin Exp $
4 #
5 # Original authors: Andres Loeh <kosmikus@gentoo.org>
6 # Duncan Coutts <dcoutts@gentoo.org>
7 # Maintained by: Haskell herd <haskell@gentoo.org>
8 #
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:
14 #
15 # Before inheriting the eclass, set CABAL_FEATURES to
16 # reflect the tools and features that the package makes
17 # use of.
18 #
19 # Currently supported features:
20 # haddock -- for documentation generation
21 # hscolour -- generation of colourised sources
22 # alex -- lexer/scanner generator
23 # happy -- parser generator
24 # c2hs -- C interface generator
25 # cpphs -- C preprocessor clone written in Haskell
26 # profile -- if package supports to build profiling-enabled libraries
27 # bootstrap -- only used for the cabal package itself
28 # bin -- the package installs binaries
29 # lib -- the package installs libraries
30 # nocabaldep -- don't add dependency on cabal.
31 # only used for packages that _must_ not pull the dependency
32 # on cabal, but still use this eclass (e.g. haskell-updater).
33 #
34 # Dependencies on other cabal packages have to be specified
35 # correctly.
36 #
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
47 inherit ghc-package multilib
48
49 HASKELL_CABAL_EXPF="pkg_setup src_compile src_test src_install"
50
51 case "${EAPI:-0}" in
52 2|3|4) HASKELL_CABAL_EXPF+=" src_configure" ;;
53 *) ;;
54 esac
55
56 EXPORT_FUNCTIONS ${HASKELL_CABAL_EXPF}
57
58 for feature in ${CABAL_FEATURES}; do
59 case ${feature} in
60 haddock) CABAL_USE_HADDOCK=yes;;
61 hscolour) CABAL_USE_HSCOLOUR=yes;;
62 alex) CABAL_USE_ALEX=yes;;
63 happy) CABAL_USE_HAPPY=yes;;
64 c2hs) CABAL_USE_C2HS=yes;;
65 cpphs) CABAL_USE_CPPHS=yes;;
66 profile) CABAL_USE_PROFILE=yes;;
67 bootstrap) CABAL_BOOTSTRAP=yes;;
68 bin) CABAL_HAS_BINARIES=yes;;
69 lib) CABAL_HAS_LIBRARIES=yes;;
70 nocabaldep) CABAL_FROM_GHC=yes;;
71 *) CABAL_UNKNOWN="${CABAL_UNKNOWN} ${feature}";;
72 esac
73 done
74
75 if [[ -n "${CABAL_USE_HADDOCK}" ]]; then
76 IUSE="${IUSE} doc"
77 DEPEND="${DEPEND} doc? ( dev-haskell/haddock )"
78 fi
79
80 if [[ -n "${CABAL_USE_HSCOLOUR}" ]]; then
81 IUSE="${IUSE} hscolour"
82 DEPEND="${DEPEND} hscolour? ( dev-haskell/hscolour )"
83 fi
84
85 if [[ -n "${CABAL_USE_ALEX}" ]]; then
86 DEPEND="${DEPEND} dev-haskell/alex"
87 cabalconf="${cabalconf} --with-alex=/usr/bin/alex"
88 fi
89
90 if [[ -n "${CABAL_USE_HAPPY}" ]]; then
91 DEPEND="${DEPEND} dev-haskell/happy"
92 cabalconf="${cabalconf} --with-happy=/usr/bin/happy"
93 fi
94
95 if [[ -n "${CABAL_USE_C2HS}" ]]; then
96 DEPEND="${DEPEND} dev-haskell/c2hs"
97 cabalconf="${cabalconf} --with-c2hs=/usr/bin/c2hs"
98 fi
99
100 if [[ -n "${CABAL_USE_CPPHS}" ]]; then
101 DEPEND="${DEPEND} dev-haskell/cpphs"
102 cabalconf="${cabalconf} --with-cpphs=/usr/bin/cpphs"
103 fi
104
105 if [[ -n "${CABAL_USE_PROFILE}" ]]; then
106 IUSE="${IUSE} profile"
107 fi
108
109 # We always use a standalone version of Cabal, rather than the one that comes
110 # with GHC. But of course we can't depend on cabal when building cabal itself.
111 if [[ -z ${CABAL_MIN_VERSION} ]]; then
112 CABAL_MIN_VERSION=1.1.4
113 fi
114 if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]]; then
115 DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}"
116 fi
117
118 # Libraries require GHC to be installed.
119 if [[ -n "${CABAL_HAS_LIBRARIES}" ]]; then
120 RDEPEND="${RDEPEND} dev-lang/ghc"
121 fi
122
123 # returns the version of cabal currently in use
124 _CABAL_VERSION_CACHE=""
125 cabal-version() {
126 if [[ -z "${_CABAL_VERSION_CACHE}" ]]; then
127 if [[ "${CABAL_BOOTSTRAP}" ]]; then
128 # We're bootstrapping cabal, so the cabal version is the version
129 # of this package itself.
130 _CABAL_VERSION_CACHE="${PV}"
131 elif [[ "${CABAL_FROM_GHC}" ]]; then
132 # We can't assume there's a version of Cabal installed by ebuild as
133 # this might be a first time install of GHC (for packages that
134 # use the shipped Cabal like haskell-updater).
135
136 # The user is likely to only have one version of Cabal, provided
137 # by GHC. Note that dev-haskell/cabal can be a dummy package, only
138 # using the version provided by GHC. If the user has another version
139 # of Cabal too (more recent than the one GHC provides through
140 # dev-haskell/cabal, or possibly older if he used an old
141 # Cabal package) the most recent is used (expected to be the last
142 # one in the ghc-pkg output).
143 _CABAL_VERSION_CACHE="$(ghc-pkg field Cabal version | tail -n 1)"
144
145 # Strip out the "version: " prefix
146 _CABAL_VERSION_CACHE="${_CABAL_VERSION_CACHE#"version: "}"
147 else
148 # We ask portage, not ghc, so that we only pick up
149 # portage-installed cabal versions.
150 _CABAL_VERSION_CACHE="$(ghc-extractportageversion dev-haskell/cabal)"
151 fi
152 fi
153 echo "${_CABAL_VERSION_CACHE}"
154 }
155
156 cabal-bootstrap() {
157 local setupmodule
158 local cabalpackage
159 if [[ -f "${S}/Setup.lhs" ]]; then
160 setupmodule="${S}/Setup.lhs"
161 else
162 if [[ -f "${S}/Setup.hs" ]]; then
163 setupmodule="${S}/Setup.hs"
164 else
165 die "No Setup.lhs or Setup.hs found"
166 fi
167 fi
168
169 # We build the setup program using the latest version of
170 # cabal that we have installed
171 if version_is_at_least "6.4" "$(ghc-version)"; then
172 cabalpackage=Cabal-$(cabal-version)
173 else
174 # older ghc's don't support package versioning
175 cabalpackage=Cabal
176 fi
177 einfo "Using cabal-$(cabal-version)."
178 $(ghc-getghc) -package "${cabalpackage}" --make "${setupmodule}" -o setup \
179 || die "compiling ${setupmodule} failed"
180 }
181
182 cabal-mksetup() {
183 local setupdir
184
185 if [[ -n $1 ]]; then
186 setupdir=$1
187 else
188 setupdir=${S}
189 fi
190
191 rm -f "${setupdir}"/Setup.{lhs,hs}
192
193 echo 'import Distribution.Simple; main = defaultMainWithHooks defaultUserHooks' \
194 > $setupdir/Setup.hs
195 }
196
197 cabal-hscolour() {
198 ./setup hscolour || die "setup hscolour failed"
199 }
200
201 cabal-haddock() {
202 ./setup haddock || die "setup haddock failed"
203 }
204
205 cabal-hscolour-haddock() {
206 # --hyperlink-source implies calling 'setup hscolour'
207 ./setup haddock --hyperlink-source || die "setup haddock failed"
208 }
209
210 cabal-configure() {
211 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
212 cabalconf="${cabalconf} --with-haddock=/usr/bin/haddock"
213 fi
214 if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then
215 cabalconf="${cabalconf} --enable-library-profiling"
216 fi
217 # Building GHCi libs on ppc64 causes "TOC overflow".
218 if use ppc64; then
219 cabalconf="${cabalconf} --disable-library-for-ghci"
220 fi
221
222 if version_is_at_least "1.4" "$(cabal-version)"; then
223 # disable executable stripping for the executables, as portage will
224 # strip by itself, and pre-stripping gives a QA warning.
225 # cabal versions previous to 1.4 does not strip executables, and does
226 # not accept the flag.
227 # this fixes numerous bugs, amongst them;
228 # bug #251881, bug #251882, bug #251884, bug #251886, bug #299494
229 cabalconf="${cabalconf} --disable-executable-stripping"
230 fi
231
232 if version_is_at_least "1.2.0" "$(cabal-version)"; then
233 cabalconf="${cabalconf} --docdir=/usr/share/doc/${PF}"
234 # As of Cabal 1.2, configure is quite quiet. For diagnostic purposes
235 # it's better if the configure chatter is in the build logs:
236 cabalconf="${cabalconf} --verbose"
237 fi
238 # Note: with Cabal-1.1.6.x we do not have enough control
239 # to put the docs into the right place. They're currently going
240 # into /usr/share/${P}/ghc-x.y/doc/
241 # rather than /usr/share/doc/${PF}/
242 # Because we can only set the datadir, not the docdir.
243
244 ./setup configure \
245 --ghc --prefix=/usr \
246 --with-compiler="$(ghc-getghc)" \
247 --with-hc-pkg="$(ghc-getghcpkg)" \
248 --prefix=/usr \
249 --libdir=/usr/$(get_libdir) \
250 --libsubdir=${P}/ghc-$(ghc-version) \
251 --datadir=/usr/share/ \
252 --datasubdir=${P}/ghc-$(ghc-version) \
253 ${cabalconf} \
254 ${CABAL_CONFIGURE_FLAGS} \
255 "$@" || die "setup configure failed"
256 }
257
258 cabal-build() {
259 unset LANG LC_ALL LC_MESSAGES
260 ./setup build \
261 || die "setup build failed"
262 }
263
264 cabal-copy() {
265 ./setup copy \
266 --destdir="${D}" \
267 || die "setup copy failed"
268
269 # cabal is a bit eager about creating dirs,
270 # so remove them if they are empty
271 rmdir "${D}/usr/bin" 2> /dev/null
272
273 # GHC 6.4 has a bug in get/setPermission and Cabal 1.1.1 has
274 # no workaround.
275 # set the +x permission on executables
276 if [[ -d "${D}/usr/bin" ]] ; then
277 chmod +x "${D}/usr/bin/"*
278 fi
279 # TODO: do we still need this?
280 }
281
282 cabal-pkg() {
283 # This does not actually register since we're using true instead
284 # of ghc-pkg. So it just leaves the .installed-pkg-config and we can
285 # register that ourselves (if it exists).
286 local result
287 local err
288
289 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
290 if version_is_at_least "1.2.0" "$(cabal-version)"; then
291 # Newer cabal can generate a package conf for us:
292 ./setup register --gen-pkg-config="${T}/${P}.conf"
293 ghc-setup-pkg "${T}/${P}.conf"
294 ghc-install-pkg
295 else
296 # With older cabal we have to hack it by replacing its ghc-pkg
297 # with true and then just picking up the .installed-pkg-config
298 # file and registering that ourselves (if it exists).
299 sed -i "s|$(ghc-getghcpkg)|$(type -P true)|" .setup-config
300 ./setup register || die "setup register failed"
301 if [[ -f .installed-pkg-config ]]; then
302 ghc-setup-pkg .installed-pkg-config
303 ghc-install-pkg
304 else
305 die "setup register has not generated a package configuration file"
306 fi
307 fi
308 fi
309 }
310
311 # Some cabal libs are bundled along with some versions of ghc
312 # eg filepath-1.0 comes with ghc-6.6.1
313 # by putting CABAL_CORE_LIB_GHC_PV="6.6.1" in an ebuild we are declaring that
314 # when building with this version of ghc, the ebuild is a dummy that is it will
315 # install no files since the package is already included with ghc.
316 # However portage still records the dependency and we can upgrade the package
317 # to a later one that's not included with ghc.
318 # You can also put a space separated list, eg CABAL_CORE_LIB_GHC_PV="6.6 6.6.1".
319 cabal-is-dummy-lib() {
320 for version in ${CABAL_CORE_LIB_GHC_PV[*]}; do
321 [[ "$(ghc-version)" == "$version" ]] && return 0
322 done
323 return 1
324 }
325
326 # exported function: check if cabal is correctly installed for
327 # the currently active ghc (we cannot guarantee this with portage)
328 haskell-cabal_pkg_setup() {
329 ghc-package_pkg_setup
330 if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]] && ! ghc-sanecabal "${CABAL_MIN_VERSION}"; then
331 eerror "The package dev-haskell/cabal is not correctly installed for"
332 eerror "the currently active version of ghc ($(ghc-version)). Please"
333 eerror "run ghc-updater or haskell-updater or re-build dev-haskell/cabal."
334 die "cabal is not correctly installed"
335 fi
336 if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then
337 eerror "QA: Neither bin nor lib are in CABAL_FEATURES."
338 fi
339 if [[ -n "${CABAL_UNKNOWN}" ]]; then
340 ewarn "Unknown entry in CABAL_FEATURES: ${CABAL_UNKNOWN}"
341 fi
342 if cabal-is-dummy-lib; then
343 einfo "${P} is included in ghc-${CABAL_CORE_LIB_GHC_PV}, nothing to install."
344 fi
345 }
346
347 haskell-cabal_src_configure() {
348 pushd "${S}" > /dev/null
349
350 cabal-bootstrap
351
352 ghc_flags=""
353 # currently cabal does not respect CFLAGS and LDFLAGS on it's own (bug #333217)
354 # so translate LDFLAGS to ghc parameters (without filtering)
355 for flag in $LDFLAGS; do ghc_flags="${ghc_flags} --ghc-option=-optl$flag"; done
356
357 cabal-configure $ghc_flags "$@"
358
359 popd > /dev/null
360 }
361
362 # exported function: nice alias
363 cabal_src_configure() {
364 haskell-cabal_src_configure "$@"
365 }
366
367 # exported function: cabal-style bootstrap configure and compile
368 cabal_src_compile() {
369 if ! cabal-is-dummy-lib; then
370 has src_configure ${HASKELL_CABAL_EXPF} || haskell-cabal_src_configure "$@"
371 cabal-build
372
373 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
374 if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then
375 # hscolour and haddock
376 cabal-hscolour-haddock
377 else
378 # just haddock
379 cabal-haddock
380 fi
381 else
382 if [[ -n "${CABAL_USE_HSCOLOUR}" ]] && use hscolour; then
383 # just hscolour
384 cabal-hscolour
385 fi
386 fi
387 fi
388 }
389
390 haskell-cabal_src_compile() {
391 pushd "${S}" > /dev/null
392
393 cabal_src_compile "$@"
394
395 popd > /dev/null
396 }
397
398 haskell-cabal_src_test() {
399 pushd "${S}" > /dev/null
400
401 if cabal-is-dummy-lib; then
402 einfo ">>> No tests for dummy library: ${CATEGORY}/${PF}"
403 else
404 einfo ">>> Test phase [cabal test]: ${CATEGORY}/${PF}"
405 ./setup test || die "cabal test failed"
406 fi
407
408 popd > /dev/null
409 }
410
411 # exported function: cabal-style copy and register
412 cabal_src_install() {
413 if cabal-is-dummy-lib; then
414 # create a dummy local package conf file for the sake of ghc-updater
415 dodir "$(ghc-confdir)"
416 echo '[]' > "${D}/$(ghc-confdir)/$(ghc-localpkgconf)"
417 else
418 cabal-copy
419 cabal-pkg
420
421 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
422 if ! version_is_at_least "1.1.6" "$(cabal-version)"; then
423 dohtml -r dist/doc/html/*
424 fi
425 fi
426 fi
427 }
428
429 haskell-cabal_src_install() {
430 pushd "${S}" > /dev/null
431
432 cabal_src_install
433
434 popd > /dev/null
435 }
436
437 # ebuild.sh:use_enable() taken as base
438 #
439 # Usage examples:
440 #
441 # CABAL_CONFIGURE_FLAGS=$(cabal_flag gui)
442 # leads to "--flags=gui" or "--flags=-gui" (useflag 'gui')
443 #
444 # CABAL_CONFIGURE_FLAGS=$(cabal_flag gtk gui)
445 # also leads to "--flags=gui" or " --flags=-gui" (useflag 'gtk')
446 #
447 cabal_flag() {
448 if [[ -z "$1" ]]; then
449 echo "!!! cabal_flag() called without a parameter." >&2
450 echo "!!! cabal_flag() <USEFLAG> [<cabal_flagname>]" >&2
451 return 1
452 fi
453
454 local UWORD=${2:-$1}
455
456 if use "$1"; then
457 echo "--flags=${UWORD}"
458 else
459 echo "--flags=-${UWORD}"
460 fi
461
462 return 0
463 }

  ViewVC Help
Powered by ViewVC 1.1.20