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

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.17

  ViewVC Help
Powered by ViewVC 1.1.20