/[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.6 Revision 1.16
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.6 2006/03/13 09:57:10 dcoutts Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/haskell-cabal.eclass,v 1.16 2009/09/09 18:40:11 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 else
117 # We ask portage, not ghc, so that we only pick up
118 # portage-installed cabal versions.
119 _CABAL_VERSION_CACHE="$(ghc-extractportageversion dev-haskell/cabal)"
120 fi
97fi 121 fi
122 echo "${_CABAL_VERSION_CACHE}"
123}
98 124
99cabal-bootstrap() { 125cabal-bootstrap() {
100 local setupmodule 126 local setupmodule
101 local cabalversion 127 local cabalpackage
102 if [[ -f "${S}/Setup.lhs" ]]; then 128 if [[ -f "${S}/Setup.lhs" ]]; then
103 setupmodule="${S}/Setup.lhs" 129 setupmodule="${S}/Setup.lhs"
104 else 130 else
105 if [[ -f "${S}/Setup.hs" ]]; then 131 if [[ -f "${S}/Setup.hs" ]]; then
106 setupmodule="${S}/Setup.hs" 132 setupmodule="${S}/Setup.hs"
109 fi 135 fi
110 fi 136 fi
111 137
112 # We build the setup program using the latest version of 138 # We build the setup program using the latest version of
113 # cabal that we have installed 139 # cabal that we have installed
114 cabalversion=$(ghc-bestcabalversion) 140 if version_is_at_least "6.4" "$(ghc-version)"; then
141 cabalpackage=Cabal-$(cabal-version)
142 else
143 # older ghc's don't support package versioning
144 cabalpackage=Cabal
145 fi
115 einfo "Using ${cabalversion}." 146 einfo "Using cabal-$(cabal-version)."
116 $(ghc-getghc) -package "${cabalversion}" --make "${setupmodule}" -o setup \ 147 $(ghc-getghc) -package "${cabalpackage}" --make "${setupmodule}" -o setup \
117 || die "compiling ${setupmodule} failed" 148 || die "compiling ${setupmodule} failed"
149}
150
151cabal-mksetup() {
152 local setupdir
153
154 if [[ -n $1 ]]; then
155 setupdir=$1
156 else
157 setupdir=${S}
158 fi
159
160 rm -f "${setupdir}"/Setup.{lhs,hs}
161
162 echo 'import Distribution.Simple; main = defaultMainWithHooks defaultUserHooks' \
163 > $setupdir/Setup.hs
118} 164}
119 165
120cabal-haddock() { 166cabal-haddock() {
121 ./setup haddock || die "setup haddock failed" 167 ./setup haddock || die "setup haddock failed"
122} 168}
123 169
124cabal-configure() { 170cabal-configure() {
171 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
172 cabalconf="${cabalconf} --with-haddock=/usr/bin/haddock"
173 fi
125 if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then 174 if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then
126 cabalconf="${cabalconf} --enable-executable-profiling";
127 cabalconf="${cabalconf} --enable-library-profiling" 175 cabalconf="${cabalconf} --enable-library-profiling"
128 fi 176 fi
129 # Building GHCi libs on ppc64 causes "TOC overflow". 177 # Building GHCi libs on ppc64 causes "TOC overflow".
130 if use ppc64; then 178 if use ppc64; then
131 cabalconf="${cabalconf} --disable-library-for-ghci" 179 cabalconf="${cabalconf} --disable-library-for-ghci"
132 fi 180 fi
181
182 if version_is_at_least "1.2.0" "$(cabal-version)"; then
183 cabalconf="${cabalconf} --docdir=/usr/share/doc/${PF}"
184 # As of Cabal 1.2, configure is quite quiet. For diagnostic purposes
185 # it's better if the configure chatter is in the build logs:
186 cabalconf="${cabalconf} --verbose"
187 fi
188 # Note: with Cabal-1.1.6.x we do not have enough control
189 # to put the docs into the right place. They're currently going
190 # into /usr/share/${P}/ghc-x.y/doc/
191 # rather than /usr/share/doc/${PF}/
192 # Because we can only set the datadir, not the docdir.
133 193
134 ./setup configure \ 194 ./setup configure \
135 --ghc --prefix=/usr \ 195 --ghc --prefix=/usr \
136 --with-compiler="$(ghc-getghc)" \ 196 --with-compiler="$(ghc-getghc)" \
137 --with-hc-pkg="$(ghc-getghcpkg)" \ 197 --with-hc-pkg="$(ghc-getghcpkg)" \
198 --prefix=/usr \
199 --libdir=/usr/$(get_libdir) \
200 --libsubdir=${P}/ghc-$(ghc-version) \
201 --datadir=/usr/share/ \
202 --datasubdir=${P}/ghc-$(ghc-version) \
138 ${cabalconf} \ 203 ${cabalconf} \
204 ${CABAL_CONFIGURE_FLAGS} \
139 "$@" || die "setup configure failed" 205 "$@" || die "setup configure failed"
140} 206}
141 207
142cabal-build() { 208cabal-build() {
209 unset LANG LC_ALL LC_MESSAGES
143 ./setup build \ 210 ./setup build \
144 || die "setup build failed" 211 || die "setup build failed"
145} 212}
146 213
147cabal-copy() { 214cabal-copy() {
148 ./setup copy \ 215 ./setup copy \
149 --copy-prefix="${D}/usr" \ 216 --destdir="${D}" \
150 || die "setup copy failed" 217 || die "setup copy failed"
151 218
152 # cabal is a bit eager about creating dirs, 219 # cabal is a bit eager about creating dirs,
153 # so remove them if they are empty 220 # so remove them if they are empty
154 rmdir "${D}/usr/bin" 2> /dev/null 221 rmdir "${D}/usr/bin" 2> /dev/null
157 # no workaround. 224 # no workaround.
158 # set the +x permission on executables 225 # set the +x permission on executables
159 if [[ -d "${D}/usr/bin" ]] ; then 226 if [[ -d "${D}/usr/bin" ]] ; then
160 chmod +x "${D}/usr/bin/"* 227 chmod +x "${D}/usr/bin/"*
161 fi 228 fi
229 # TODO: do we still need this?
162} 230}
163 231
164cabal-pkg() { 232cabal-pkg() {
165 # This does not actually register since we're using /usr/bin/true instead 233 # This does not actually register since we're using true instead
166 # of ghc-pkg. So it just leaves the .installed-pkg-config and we can 234 # of ghc-pkg. So it just leaves the .installed-pkg-config and we can
167 # register that ourselves (if it exists). 235 # register that ourselves (if it exists).
168 local result 236 local result
169 local err 237 local err
170 238
171 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then 239 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
172 sed -i 's:ghc-pkg:/usr/bin/true:' .setup-config 240 if version_is_at_least "1.2.0" "$(cabal-version)"; then
173 ./setup register || die "setup register failed" 241 # Newer cabal can generate a package conf for us:
174 if [[ -f .installed-pkg-config ]]; then 242 ./setup register --gen-pkg-config="${T}/${P}.conf"
175 ghc-setup-pkg .installed-pkg-config 243 ghc-setup-pkg "${T}/${P}.conf"
176 ghc-install-pkg 244 ghc-install-pkg
177 else 245 else
246 # With older cabal we have to hack it by replacing its ghc-pkg
247 # with true and then just picking up the .installed-pkg-config
248 # file and registering that ourselves (if it exists).
249 sed -i "s|$(ghc-getghcpkg)|$(type -P true)|" .setup-config
250 ./setup register || die "setup register failed"
251 if [[ -f .installed-pkg-config ]]; then
252 ghc-setup-pkg .installed-pkg-config
253 ghc-install-pkg
254 else
178 die "setup register has not generated a package configuration file" 255 die "setup register has not generated a package configuration file"
179 fi 256 fi
180 fi 257 fi
258 fi
259}
260
261# Some cabal libs are bundled along with some versions of ghc
262# eg filepath-1.0 comes with ghc-6.6.1
263# by putting CABAL_CORE_LIB_GHC_PV="6.6.1" in an ebuild we are declaring that
264# when building with this version of ghc, the ebuild is a dummy that is it will
265# install no files since the package is already included with ghc.
266# However portage still records the dependency and we can upgrade the package
267# to a later one that's not included with ghc.
268# You can also put a space separated list, eg CABAL_CORE_LIB_GHC_PV="6.6 6.6.1".
269cabal-is-dummy-lib() {
270 for version in ${CABAL_CORE_LIB_GHC_PV[*]}; do
271 [[ "$(ghc-version)" == "$version" ]] && return 0
272 done
273 return 1
181} 274}
182 275
183# exported function: check if cabal is correctly installed for 276# exported function: check if cabal is correctly installed for
184# the currently active ghc (we cannot guarantee this with portage) 277# the currently active ghc (we cannot guarantee this with portage)
185haskell-cabal_pkg_setup() { 278haskell-cabal_pkg_setup() {
186 if [[ -z "${CABAL_BOOTSTRAP}" ]] && ! ghc-sanecabal "1.1.3"; then 279 ghc-package_pkg_setup
280 if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]] && ! ghc-sanecabal "${CABAL_MIN_VERSION}"; then
187 eerror "The package dev-haskell/cabal is not correctly installed for" 281 eerror "The package dev-haskell/cabal is not correctly installed for"
188 eerror "the currently active version of ghc ($(ghc-version)). Please" 282 eerror "the currently active version of ghc ($(ghc-version)). Please"
189 eerror "run ghc-updater or re-emerge dev-haskell/cabal." 283 eerror "run ghc-updater or haskell-updater or re-build dev-haskell/cabal."
190 die "cabal is not correctly installed" 284 die "cabal is not correctly installed"
191 fi 285 fi
192 if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then 286 if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then
193 eerror "QA: Neither bin nor lib are in CABAL_FEATURES." 287 eerror "QA: Neither bin nor lib are in CABAL_FEATURES."
194 fi 288 fi
195 if [[ -n "${CABAL_UNKNOWN}" ]]; then 289 if [[ -n "${CABAL_UNKNOWN}" ]]; then
196 ewarn "Unknown entry in CABAL_FEATURES: ${CABAL_UNKNONW}" 290 ewarn "Unknown entry in CABAL_FEATURES: ${CABAL_UNKNOWN}"
291 fi
292 if cabal-is-dummy-lib; then
293 einfo "${P} is included in ghc-${CABAL_CORE_LIB_GHC_PV}, nothing to install."
197 fi 294 fi
198} 295}
199 296
200# exported function: cabal-style bootstrap configure and compile 297# exported function: cabal-style bootstrap configure and compile
201cabal_src_compile() { 298cabal_src_compile() {
299 if ! cabal-is-dummy-lib; then
202 cabal-bootstrap 300 cabal-bootstrap
203 cabal-configure 301 cabal-configure
204 cabal-build 302 cabal-build
205 303
206 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then 304 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
207 cabal-haddock 305 cabal-haddock
208 fi 306 fi
307 fi
209} 308}
309
210haskell-cabal_src_compile() { 310haskell-cabal_src_compile() {
211 cabal_src_compile 311 cabal_src_compile
212} 312}
213 313
214# exported function: cabal-style copy and register 314# exported function: cabal-style copy and register
215cabal_src_install() { 315cabal_src_install() {
316 if cabal-is-dummy-lib; then
317 # create a dummy local package conf file for the sake of ghc-updater
318 dodir "$(ghc-confdir)"
319 echo '[]' > "${D}/$(ghc-confdir)/$(ghc-localpkgconf)"
320 else
216 cabal-copy 321 cabal-copy
217 cabal-pkg 322 cabal-pkg
218 323
219 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then 324 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
325 if ! version_is_at_least "1.1.6" "$(cabal-version)"; then
220 dohtml dist/doc/html/* 326 dohtml -r dist/doc/html/*
327 fi
328 fi
221 fi 329 fi
222} 330}
223haskell-cabal_src_install() { 331haskell-cabal_src_install() {
224 cabal_src_install 332 cabal_src_install
225} 333}

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.16

  ViewVC Help
Powered by ViewVC 1.1.20