/[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.2 Revision 1.15
1# Copyright 1999-2005 Gentoo Foundation 1# Copyright 1999-2006 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.2 2005/12/05 12:24:53 dcoutts Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/haskell-cabal.eclass,v 1.15 2009/07/27 19:03:20 kolmodin 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#
22# happy -- parser generator 22# happy -- parser generator
23# c2hs -- C interface generator 23# c2hs -- C interface generator
24# cpphs -- C preprocessor clone written in Haskell 24# cpphs -- C preprocessor clone written in Haskell
25# profile -- if package supports to build profiling-enabled libraries 25# profile -- if package supports to build profiling-enabled libraries
26# bootstrap -- only used for the cabal package itself 26# bootstrap -- only used for the cabal package itself
27# bin -- the package installs binaries
28# lib -- the package installs libraries
27# 29#
28# Dependencies on other cabal packages have to be specified 30# Dependencies on other cabal packages have to be specified
29# correctly. 31# correctly.
30# 32#
31# Cabal libraries should usually be SLOTted with "${PV}". 33# Cabal libraries should usually be SLOTted with "${PV}".
32# 34#
33# Many Cabal packages require S to be manually set. 35# Many Cabal packages require S to be manually set.
34# 36#
35# Conforming Cabal packages don't require any function definitions 37# Conforming Cabal packages don't require any function definitions
36# in the ebuild. 38# in the ebuild.
39#
40# Special flags to Cabal Configure can now be set by using
41# CABAL_CONFIGURE_FLAGS
37 42
38inherit ghc-package 43inherit ghc-package multilib
39 44
40 45
41for feature in ${CABAL_FEATURES}; do 46for feature in ${CABAL_FEATURES}; do
42 case ${feature} in 47 case ${feature} in
43 haddock) CABAL_USE_HADDOCK=yes;; 48 haddock) CABAL_USE_HADDOCK=yes;;
45 happy) CABAL_USE_HAPPY=yes;; 50 happy) CABAL_USE_HAPPY=yes;;
46 c2hs) CABAL_USE_C2HS=yes;; 51 c2hs) CABAL_USE_C2HS=yes;;
47 cpphs) CABAL_USE_CPPHS=yes;; 52 cpphs) CABAL_USE_CPPHS=yes;;
48 profile) CABAL_USE_PROFILE=yes;; 53 profile) CABAL_USE_PROFILE=yes;;
49 bootstrap) CABAL_BOOTSTRAP=yes;; 54 bootstrap) CABAL_BOOTSTRAP=yes;;
50 *) ewarn "Unknown entry in CABAL_FEATURES: ${feature}";; 55 bin) CABAL_HAS_BINARIES=yes;;
56 lib) CABAL_HAS_LIBRARIES=yes;;
57 *) CABAL_UNKNOWN="${CABAL_UNKNOWN} ${feature}";;
51 esac 58 esac
52done 59done
53 60
54if [[ -n "${CABAL_USE_HADDOCK}" ]]; then 61if [[ -n "${CABAL_USE_HADDOCK}" ]]; then
55 IUSE="${IUSE} doc" 62 IUSE="${IUSE} doc"
56 DEPEND="${DEPEND} doc? ( dev-haskell/haddock )" 63 DEPEND="${DEPEND} doc? ( dev-haskell/haddock )"
57 cabalconf="${cabalconf} --with-haddock=/usr/bin/haddock"
58fi 64fi
59 65
60if [[ -n "${CABAL_USE_ALEX}" ]]; then 66if [[ -n "${CABAL_USE_ALEX}" ]]; then
61 DEPEND="${DEPEND} dev-haskell/alex" 67 DEPEND="${DEPEND} dev-haskell/alex"
62 cabalconf="${cabalconf} --with-alex=/usr/bin/alex" 68 cabalconf="${cabalconf} --with-alex=/usr/bin/alex"
81 IUSE="${IUSE} profile" 87 IUSE="${IUSE} profile"
82fi 88fi
83 89
84# We always use a standalone version of Cabal, rather than the one that comes 90# We always use a standalone version of Cabal, rather than the one that comes
85# with GHC. But of course we can't depend on cabal when building cabal itself. 91# with GHC. But of course we can't depend on cabal when building cabal itself.
92if [[ -z ${CABAL_MIN_VERSION} ]]; then
93 CABAL_MIN_VERSION=1.1.4
94fi
86if [[ -z "${CABAL_BOOTSTRAP}" ]]; then 95if [[ -z "${CABAL_BOOTSTRAP}" ]]; then
87 DEPEND="${DEPEND} >=dev-haskell/cabal-1.1.3" 96 DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}"
97fi
98
99# Libraries require GHC to be installed.
100if [[ -n "${CABAL_HAS_LIBRARIES}" ]]; then
101 RDEPEND="${RDEPEND} dev-lang/ghc"
102fi
103
104# returns the version of cabal currently in use
105_CABAL_VERSION_CACHE=""
106cabal-version() {
107 if [[ -z "${_CABAL_VERSION_CACHE}" ]]; then
108 if [[ "${CABAL_BOOTSTRAP}" ]]; then
109 # We're bootstrapping cabal, so the cabal version is the version
110 # of this package itself.
111 _CABAL_VERSION_CACHE="${PV}"
112 else
113 # We ask portage, not ghc, so that we only pick up
114 # portage-installed cabal versions.
115 _CABAL_VERSION_CACHE="$(ghc-extractportageversion dev-haskell/cabal)"
116 fi
88fi 117 fi
89 118 echo "${_CABAL_VERSION_CACHE}"
119}
90 120
91cabal-bootstrap() { 121cabal-bootstrap() {
92 local setupmodule 122 local setupmodule
93 local cabalversion 123 local cabalpackage
94 if [[ -f "${S}/Setup.lhs" ]]; then 124 if [[ -f "${S}/Setup.lhs" ]]; then
95 setupmodule="${S}/Setup.lhs" 125 setupmodule="${S}/Setup.lhs"
96 else 126 else
97 if [[ -f "${S}/Setup.hs" ]]; then 127 if [[ -f "${S}/Setup.hs" ]]; then
98 setupmodule="${S}/Setup.hs" 128 setupmodule="${S}/Setup.hs"
101 fi 131 fi
102 fi 132 fi
103 133
104 # We build the setup program using the latest version of 134 # We build the setup program using the latest version of
105 # cabal that we have installed 135 # cabal that we have installed
106 cabalversion=$(ghc-bestcabalversion) 136 if version_is_at_least "6.4" "$(ghc-version)"; then
137 cabalpackage=Cabal-$(cabal-version)
138 else
139 # older ghc's don't support package versioning
140 cabalpackage=Cabal
141 fi
107 einfo "Using ${cabalversion}." 142 einfo "Using cabal-$(cabal-version)."
108 $(ghc-getghc) -package "${cabalversion}" --make "${setupmodule}" -o setup \ 143 $(ghc-getghc) -package "${cabalpackage}" --make "${setupmodule}" -o setup \
109 || die "compiling ${setupmodule} failed" 144 || die "compiling ${setupmodule} failed"
145}
146
147cabal-mksetup() {
148 local setupdir
149
150 if [[ -n $1 ]]; then
151 setupdir=$1
152 else
153 setupdir=${S}
154 fi
155
156 rm -f "${setupdir}"/Setup.{lhs,hs}
157
158 echo 'import Distribution.Simple; main = defaultMainWithHooks defaultUserHooks' \
159 > $setupdir/Setup.hs
110} 160}
111 161
112cabal-haddock() { 162cabal-haddock() {
113 ./setup haddock || die "setup haddock failed" 163 ./setup haddock || die "setup haddock failed"
114} 164}
115 165
116cabal-configure() { 166cabal-configure() {
167 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
168 cabalconf="${cabalconf} --with-haddock=/usr/bin/haddock"
169 fi
117 if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then 170 if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then
118 cabalconf="${cabalconf} --enable-executable-profiling";
119 cabalconf="${cabalconf} --enable-library-profiling" 171 cabalconf="${cabalconf} --enable-library-profiling"
120 fi 172 fi
173 # Building GHCi libs on ppc64 causes "TOC overflow".
174 if use ppc64; then
175 cabalconf="${cabalconf} --disable-library-for-ghci"
176 fi
177
178 if version_is_at_least "1.2.0" "$(cabal-version)"; then
179 cabalconf="${cabalconf} --docdir=/usr/share/doc/${PF}"
180 # As of Cabal 1.2, configure is quite quiet. For diagnostic purposes
181 # it's better if the configure chatter is in the build logs:
182 cabalconf="${cabalconf} --verbose"
183 fi
184 # Note: with Cabal-1.1.6.x we do not have enough control
185 # to put the docs into the right place. They're currently going
186 # into /usr/share/${P}/ghc-x.y/doc/
187 # rather than /usr/share/doc/${PF}/
188 # Because we can only set the datadir, not the docdir.
121 189
122 ./setup configure \ 190 ./setup configure \
123 --ghc --prefix=/usr \ 191 --ghc --prefix=/usr \
124 --with-compiler="$(ghc-getghc)" \ 192 --with-compiler="$(ghc-getghc)" \
125 --with-hc-pkg="$(ghc-getghcpkg)" \ 193 --with-hc-pkg="$(ghc-getghcpkg)" \
194 --prefix=/usr \
195 --libdir=/usr/$(get_libdir) \
196 --libsubdir=${P}/ghc-$(ghc-version) \
197 --datadir=/usr/share/ \
198 --datasubdir=${P}/ghc-$(ghc-version) \
126 ${cabalconf} \ 199 ${cabalconf} \
200 ${CABAL_CONFIGURE_FLAGS} \
127 "$@" || die "setup configure failed" 201 "$@" || die "setup configure failed"
128} 202}
129 203
130cabal-build() { 204cabal-build() {
205 unset LANG LC_ALL LC_MESSAGES
131 ./setup build \ 206 ./setup build \
132 || die "setup build failed" 207 || die "setup build failed"
133} 208}
134 209
135cabal-copy() { 210cabal-copy() {
136 ./setup copy \ 211 ./setup copy \
137 --copy-prefix="${D}/usr" \ 212 --destdir="${D}" \
138 || die "setup copy failed" 213 || die "setup copy failed"
139 214
140 # cabal is a bit eager about creating dirs, 215 # cabal is a bit eager about creating dirs,
141 # so remove them if they are empty 216 # so remove them if they are empty
142 rmdir "${D}/usr/bin" 2> /dev/null 217 rmdir "${D}/usr/bin" 2> /dev/null
145 # no workaround. 220 # no workaround.
146 # set the +x permission on executables 221 # set the +x permission on executables
147 if [[ -d "${D}/usr/bin" ]] ; then 222 if [[ -d "${D}/usr/bin" ]] ; then
148 chmod +x "${D}/usr/bin/"* 223 chmod +x "${D}/usr/bin/"*
149 fi 224 fi
225 # TODO: do we still need this?
150} 226}
151 227
152cabal-pkg() { 228cabal-pkg() {
153 # This does not actually register since we're using /usr/bin/true instead 229 # This does not actually register since we're using true instead
154 # of ghc-pkg. So it just leaves the .installed-pkg-config and we can 230 # of ghc-pkg. So it just leaves the .installed-pkg-config and we can
155 # register that ourselves (if it exists). 231 # register that ourselves (if it exists).
156 local result 232 local result
157 local err 233 local err
158 234
159 sed -i 's:ghc-pkg:/usr/bin/true:' .setup-config 235 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
160 result="$(./setup register 2>&1)" 236 if version_is_at_least "1.2.0" "$(cabal-version)"; then
161 err="$?" 237 # Newer cabal can generate a package conf for us:
162 if ! echo ${result} | grep -q "no library to register"; then 238 ./setup register --gen-pkg-config="${T}/${P}.conf"
163 $(exit "${err}") || die "setup register failed" 239 ghc-setup-pkg "${T}/${P}.conf"
164 fi 240 ghc-install-pkg
241 else
242 # With older cabal we have to hack it by replacing its ghc-pkg
243 # with true and then just picking up the .installed-pkg-config
244 # file and registering that ourselves (if it exists).
245 sed -i "s|$(ghc-getghcpkg)|$(type -P true)|" .setup-config
246 ./setup register || die "setup register failed"
165 if [[ -f .installed-pkg-config ]]; then 247 if [[ -f .installed-pkg-config ]]; then
166 ghc-setup-pkg .installed-pkg-config 248 ghc-setup-pkg .installed-pkg-config
167 ghc-install-pkg 249 ghc-install-pkg
250 else
251 die "setup register has not generated a package configuration file"
252 fi
168 fi 253 fi
254 fi
255}
256
257# Some cabal libs are bundled along with some versions of ghc
258# eg filepath-1.0 comes with ghc-6.6.1
259# by putting CABAL_CORE_LIB_GHC_PV="6.6.1" in an ebuild we are declaring that
260# when building with this version of ghc, the ebuild is a dummy that is it will
261# install no files since the package is already included with ghc.
262# However portage still records the dependency and we can upgrade the package
263# to a later one that's not included with ghc.
264# You can also put a space separated list, eg CABAL_CORE_LIB_GHC_PV="6.6 6.6.1".
265cabal-is-dummy-lib() {
266 for version in ${CABAL_CORE_LIB_GHC_PV[*]}; do
267 [[ "$(ghc-version)" == "$version" ]] && return 0
268 done
269 return 1
169} 270}
170 271
171# exported function: check if cabal is correctly installed for 272# exported function: check if cabal is correctly installed for
172# the currently active ghc (we cannot guarantee this with portage) 273# the currently active ghc (we cannot guarantee this with portage)
173haskell-cabal_pkg_setup() { 274haskell-cabal_pkg_setup() {
275 ghc-package_pkg_setup
174 if [[ -z "${CABAL_BOOTSTRAP}" ]] && ! ghc-sanecabal "1.1.3"; then 276 if [[ -z "${CABAL_BOOTSTRAP}" ]] && ! ghc-sanecabal "${CABAL_MIN_VERSION}"; then
175 eerror "The package dev-haskell/cabal is not correctly installed for" 277 eerror "The package dev-haskell/cabal is not correctly installed for"
176 eerror "the currently active version of ghc ($(ghc-version)). Please" 278 eerror "the currently active version of ghc ($(ghc-version)). Please"
177 eerror "run ghc-updater or re-emerge dev-haskell/cabal." 279 eerror "run ghc-updater or re-emerge dev-haskell/cabal."
178 die "cabal is not correctly installed" 280 die "cabal is not correctly installed"
179 fi 281 fi
282 if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then
283 eerror "QA: Neither bin nor lib are in CABAL_FEATURES."
284 fi
285 if [[ -n "${CABAL_UNKNOWN}" ]]; then
286 ewarn "Unknown entry in CABAL_FEATURES: ${CABAL_UNKNOWN}"
287 fi
288 if cabal-is-dummy-lib; then
289 einfo "${P} is included in ghc-${CABAL_CORE_LIB_GHC_PV}, nothing to install."
290 fi
180} 291}
181 292
182# exported function: cabal-style bootstrap configure and compile 293# exported function: cabal-style bootstrap configure and compile
183cabal_src_compile() { 294cabal_src_compile() {
295 if ! cabal-is-dummy-lib; then
184 cabal-bootstrap 296 cabal-bootstrap
185 cabal-configure 297 cabal-configure
186 cabal-build 298 cabal-build
187 299
188 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then 300 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
189 cabal-haddock 301 cabal-haddock
302 fi
190 fi 303 fi
191} 304}
192haskell-cabal_src_compile() { 305haskell-cabal_src_compile() {
193 cabal_src_compile 306 cabal_src_compile
194} 307}
195 308
196# exported function: cabal-style copy and register 309# exported function: cabal-style copy and register
197cabal_src_install() { 310cabal_src_install() {
311 if cabal-is-dummy-lib; then
312 # create a dummy local package conf file for the sake of ghc-updater
313 dodir "$(ghc-confdir)"
314 echo '[]' > "${D}/$(ghc-confdir)/$(ghc-localpkgconf)"
315 else
198 cabal-copy 316 cabal-copy
199 cabal-pkg 317 cabal-pkg
200 318
201 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then 319 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
320 if ! version_is_at_least "1.1.6" "$(cabal-version)"; then
202 dohtml dist/doc/html/* 321 dohtml -r dist/doc/html/*
322 fi
323 fi
203 fi 324 fi
204} 325}
205haskell-cabal_src_install() { 326haskell-cabal_src_install() {
206 cabal_src_install 327 cabal_src_install
207} 328}

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.15

  ViewVC Help
Powered by ViewVC 1.1.20