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

Contents of /eclass/haskell-cabal.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.14 - (hide annotations) (download)
Thu Dec 13 04:44:39 2007 UTC (7 years ago) by dcoutts
Branch: MAIN
Changes since 1.13: +72 -15 lines
Update cabal eclass for new cabal-1.2 series

1 dcoutts 1.4 # Copyright 1999-2006 Gentoo Foundation
2 kosmikus 1.1 # Distributed under the terms of the GNU General Public License v2
3 dcoutts 1.14 # $Header: $
4 kosmikus 1.1 #
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     # alex -- lexer/scanner generator
22     # happy -- parser generator
23     # c2hs -- C interface generator
24     # cpphs -- C preprocessor clone written in Haskell
25     # profile -- if package supports to build profiling-enabled libraries
26     # bootstrap -- only used for the cabal package itself
27 dcoutts 1.3 # bin -- the package installs binaries
28     # lib -- the package installs libraries
29 kosmikus 1.1 #
30     # Dependencies on other cabal packages have to be specified
31     # correctly.
32     #
33     # Cabal libraries should usually be SLOTted with "${PV}".
34     #
35     # Many Cabal packages require S to be manually set.
36     #
37     # Conforming Cabal packages don't require any function definitions
38     # in the ebuild.
39 kosmikus 1.8 #
40     # Special flags to Cabal Configure can now be set by using
41     # CABAL_CONFIGURE_FLAGS
42 kosmikus 1.1
43 dcoutts 1.11 inherit ghc-package multilib
44 kosmikus 1.1
45    
46     for feature in ${CABAL_FEATURES}; do
47     case ${feature} in
48     haddock) CABAL_USE_HADDOCK=yes;;
49     alex) CABAL_USE_ALEX=yes;;
50     happy) CABAL_USE_HAPPY=yes;;
51     c2hs) CABAL_USE_C2HS=yes;;
52     cpphs) CABAL_USE_CPPHS=yes;;
53     profile) CABAL_USE_PROFILE=yes;;
54     bootstrap) CABAL_BOOTSTRAP=yes;;
55 dcoutts 1.3 bin) CABAL_HAS_BINARIES=yes;;
56     lib) CABAL_HAS_LIBRARIES=yes;;
57     *) CABAL_UNKNOWN="${CABAL_UNKNOWN} ${feature}";;
58 kosmikus 1.1 esac
59     done
60    
61     if [[ -n "${CABAL_USE_HADDOCK}" ]]; then
62     IUSE="${IUSE} doc"
63     DEPEND="${DEPEND} doc? ( dev-haskell/haddock )"
64     fi
65    
66     if [[ -n "${CABAL_USE_ALEX}" ]]; then
67     DEPEND="${DEPEND} dev-haskell/alex"
68     cabalconf="${cabalconf} --with-alex=/usr/bin/alex"
69     fi
70    
71     if [[ -n "${CABAL_USE_HAPPY}" ]]; then
72     DEPEND="${DEPEND} dev-haskell/happy"
73     cabalconf="${cabalconf} --with-happy=/usr/bin/happy"
74     fi
75    
76     if [[ -n "${CABAL_USE_C2HS}" ]]; then
77     DEPEND="${DEPEND} dev-haskell/c2hs"
78     cabalconf="${cabalconf} --with-c2hs=/usr/bin/c2hs"
79     fi
80    
81     if [[ -n "${CABAL_USE_CPPHS}" ]]; then
82     DEPEND="${DEPEND} dev-haskell/cpphs"
83     cabalconf="${cabalconf} --with-cpphs=/usr/bin/cpphs"
84     fi
85    
86     if [[ -n "${CABAL_USE_PROFILE}" ]]; then
87     IUSE="${IUSE} profile"
88     fi
89    
90     # We always use a standalone version of Cabal, rather than the one that comes
91     # with GHC. But of course we can't depend on cabal when building cabal itself.
92 dcoutts 1.14 if [[ -z ${CABAL_MIN_VERSION} ]]; then
93     CABAL_MIN_VERSION=1.1.4
94     fi
95 kosmikus 1.1 if [[ -z "${CABAL_BOOTSTRAP}" ]]; then
96 dcoutts 1.11 DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}"
97 kosmikus 1.1 fi
98    
99 dcoutts 1.3 # Libraries require GHC to be installed.
100     if [[ -n "${CABAL_HAS_LIBRARIES}" ]]; then
101 dcoutts 1.11 RDEPEND="${RDEPEND} dev-lang/ghc"
102 dcoutts 1.3 fi
103 kosmikus 1.1
104 dcoutts 1.14 # returns the version of cabal currently in use
105     _CABAL_VERSION_CACHE=""
106     cabal-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
117     fi
118     echo "${_CABAL_VERSION_CACHE}"
119     }
120    
121 kosmikus 1.1 cabal-bootstrap() {
122     local setupmodule
123 dcoutts 1.14 local cabalpackage
124 kosmikus 1.1 if [[ -f "${S}/Setup.lhs" ]]; then
125     setupmodule="${S}/Setup.lhs"
126     else
127     if [[ -f "${S}/Setup.hs" ]]; then
128     setupmodule="${S}/Setup.hs"
129     else
130     die "No Setup.lhs or Setup.hs found"
131     fi
132     fi
133    
134     # We build the setup program using the latest version of
135     # cabal that we have installed
136 dcoutts 1.14 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
142     einfo "Using cabal-$(cabal-version)."
143     $(ghc-getghc) -package "${cabalpackage}" --make "${setupmodule}" -o setup \
144 kosmikus 1.1 || die "compiling ${setupmodule} failed"
145     }
146    
147 dcoutts 1.14 cabal-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
160     }
161    
162 kosmikus 1.1 cabal-haddock() {
163     ./setup haddock || die "setup haddock failed"
164     }
165    
166     cabal-configure() {
167 dcoutts 1.14 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
168     cabalconf="${cabalconf} --with-haddock=/usr/bin/haddock"
169     fi
170 kosmikus 1.1 if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then
171 dcoutts 1.2 cabalconf="${cabalconf} --enable-library-profiling"
172 kosmikus 1.1 fi
173 dcoutts 1.6 # Building GHCi libs on ppc64 causes "TOC overflow".
174     if use ppc64; then
175 dcoutts 1.5 cabalconf="${cabalconf} --disable-library-for-ghci"
176     fi
177 kosmikus 1.1
178 dcoutts 1.14 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 dcoutts 1.11 # 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.
189    
190 kosmikus 1.1 ./setup configure \
191     --ghc --prefix=/usr \
192     --with-compiler="$(ghc-getghc)" \
193     --with-hc-pkg="$(ghc-getghcpkg)" \
194 dcoutts 1.11 --prefix=/usr \
195     --libdir=/usr/$(get_libdir) \
196     --libsubdir=${P}/ghc-$(ghc-version) \
197     --datadir=/usr/share/ \
198     --datasubdir=${P}/ghc-$(ghc-version) \
199 kosmikus 1.1 ${cabalconf} \
200 kosmikus 1.8 ${CABAL_CONFIGURE_FLAGS} \
201 kosmikus 1.1 "$@" || die "setup configure failed"
202     }
203    
204     cabal-build() {
205 dcoutts 1.14 unset LANG LC_ALL LC_MESSAGES
206 kosmikus 1.1 ./setup build \
207     || die "setup build failed"
208     }
209    
210     cabal-copy() {
211     ./setup copy \
212 dcoutts 1.11 --destdir="${D}" \
213 kosmikus 1.1 || die "setup copy failed"
214    
215     # cabal is a bit eager about creating dirs,
216     # so remove them if they are empty
217     rmdir "${D}/usr/bin" 2> /dev/null
218    
219     # GHC 6.4 has a bug in get/setPermission and Cabal 1.1.1 has
220     # no workaround.
221     # set the +x permission on executables
222     if [[ -d "${D}/usr/bin" ]] ; then
223     chmod +x "${D}/usr/bin/"*
224     fi
225 dcoutts 1.11 # TODO: do we still need this?
226 kosmikus 1.1 }
227    
228     cabal-pkg() {
229 kosmikus 1.9 # This does not actually register since we're using true instead
230 kosmikus 1.1 # of ghc-pkg. So it just leaves the .installed-pkg-config and we can
231     # register that ourselves (if it exists).
232 dcoutts 1.2 local result
233     local err
234    
235 dcoutts 1.4 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
236 dcoutts 1.14 if version_is_at_least "1.2.0" "$(cabal-version)"; then
237     # Newer cabal can generate a package conf for us:
238     ./setup register --gen-pkg-config="${T}/${P}.conf"
239     ghc-setup-pkg "${T}/${P}.conf"
240 dcoutts 1.4 ghc-install-pkg
241     else
242 dcoutts 1.14 # 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"
247     if [[ -f .installed-pkg-config ]]; then
248     ghc-setup-pkg .installed-pkg-config
249     ghc-install-pkg
250     else
251     die "setup register has not generated a package configuration file"
252     fi
253 dcoutts 1.4 fi
254 kosmikus 1.1 fi
255     }
256    
257 kolmodin 1.13 # 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".
265     cabal-is-dummy-lib() {
266     for version in ${CABAL_CORE_LIB_GHC_PV[*]}; do
267     [[ "$(ghc-version)" == "$version" ]] && return 0
268     done
269     return 1
270     }
271    
272 kosmikus 1.1 # exported function: check if cabal is correctly installed for
273     # the currently active ghc (we cannot guarantee this with portage)
274     haskell-cabal_pkg_setup() {
275 dcoutts 1.11 ghc-package_pkg_setup
276     if [[ -z "${CABAL_BOOTSTRAP}" ]] && ! ghc-sanecabal "${CABAL_MIN_VERSION}"; then
277 kosmikus 1.1 eerror "The package dev-haskell/cabal is not correctly installed for"
278     eerror "the currently active version of ghc ($(ghc-version)). Please"
279     eerror "run ghc-updater or re-emerge dev-haskell/cabal."
280     die "cabal is not correctly installed"
281     fi
282 dcoutts 1.4 if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then
283     eerror "QA: Neither bin nor lib are in CABAL_FEATURES."
284     fi
285 dcoutts 1.3 if [[ -n "${CABAL_UNKNOWN}" ]]; then
286     ewarn "Unknown entry in CABAL_FEATURES: ${CABAL_UNKNONW}"
287     fi
288 kolmodin 1.13 if cabal-is-dummy-lib; then
289     einfo "${P} is included in ghc-${CABAL_CORE_LIB_GHC_PV}, nothing to install."
290     fi
291 kosmikus 1.1 }
292    
293     # exported function: cabal-style bootstrap configure and compile
294     cabal_src_compile() {
295 kolmodin 1.13 if ! cabal-is-dummy-lib; then
296     cabal-bootstrap
297     cabal-configure
298     cabal-build
299 kosmikus 1.1
300 kolmodin 1.13 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
301     cabal-haddock
302     fi
303 kosmikus 1.1 fi
304     }
305     haskell-cabal_src_compile() {
306     cabal_src_compile
307     }
308    
309     # exported function: cabal-style copy and register
310     cabal_src_install() {
311 kolmodin 1.13 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
316     cabal-copy
317     cabal-pkg
318 kosmikus 1.1
319 kolmodin 1.13 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
320 dcoutts 1.14 if ! version_is_at_least "1.1.6" "$(cabal-version)"; then
321 kolmodin 1.13 dohtml -r dist/doc/html/*
322     fi
323 dcoutts 1.11 fi
324 kosmikus 1.1 fi
325     }
326     haskell-cabal_src_install() {
327     cabal_src_install
328     }
329    
330     EXPORT_FUNCTIONS pkg_setup src_compile src_install

  ViewVC Help
Powered by ViewVC 1.1.20