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

Contents of /eclass/haskell-cabal.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (show annotations) (download)
Sun Aug 5 18:49:58 2007 UTC (7 years, 4 months ago) by kolmodin
Branch: MAIN
Changes since 1.12: +38 -12 lines
Make the haskell-cabal eclass aware of updateable core ghc libs.

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.12 2007/07/27 09:09:20 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 # 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 # bin -- the package installs binaries
28 # lib -- the package installs libraries
29 #
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 #
40 # Special flags to Cabal Configure can now be set by using
41 # CABAL_CONFIGURE_FLAGS
42
43 inherit ghc-package multilib
44
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 bin) CABAL_HAS_BINARIES=yes;;
56 lib) CABAL_HAS_LIBRARIES=yes;;
57 *) CABAL_UNKNOWN="${CABAL_UNKNOWN} ${feature}";;
58 esac
59 done
60
61 if [[ -n "${CABAL_USE_HADDOCK}" ]]; then
62 IUSE="${IUSE} doc"
63 DEPEND="${DEPEND} doc? ( dev-haskell/haddock )"
64 cabalconf="${cabalconf} --with-haddock=/usr/bin/haddock"
65 fi
66
67 if [[ -n "${CABAL_USE_ALEX}" ]]; then
68 DEPEND="${DEPEND} dev-haskell/alex"
69 cabalconf="${cabalconf} --with-alex=/usr/bin/alex"
70 fi
71
72 if [[ -n "${CABAL_USE_HAPPY}" ]]; then
73 DEPEND="${DEPEND} dev-haskell/happy"
74 cabalconf="${cabalconf} --with-happy=/usr/bin/happy"
75 fi
76
77 if [[ -n "${CABAL_USE_C2HS}" ]]; then
78 DEPEND="${DEPEND} dev-haskell/c2hs"
79 cabalconf="${cabalconf} --with-c2hs=/usr/bin/c2hs"
80 fi
81
82 if [[ -n "${CABAL_USE_CPPHS}" ]]; then
83 DEPEND="${DEPEND} dev-haskell/cpphs"
84 cabalconf="${cabalconf} --with-cpphs=/usr/bin/cpphs"
85 fi
86
87 if [[ -n "${CABAL_USE_PROFILE}" ]]; then
88 IUSE="${IUSE} profile"
89 fi
90
91 # We always use a standalone version of Cabal, rather than the one that comes
92 # with GHC. But of course we can't depend on cabal when building cabal itself.
93 CABAL_MIN_VERSION=1.1.4
94 if [[ -z "${CABAL_BOOTSTRAP}" ]]; then
95 DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}"
96 fi
97
98 # Libraries require GHC to be installed.
99 if [[ -n "${CABAL_HAS_LIBRARIES}" ]]; then
100 RDEPEND="${RDEPEND} dev-lang/ghc"
101 fi
102
103 cabal-bootstrap() {
104 local setupmodule
105 local cabalversion
106 if [[ -f "${S}/Setup.lhs" ]]; then
107 setupmodule="${S}/Setup.lhs"
108 else
109 if [[ -f "${S}/Setup.hs" ]]; then
110 setupmodule="${S}/Setup.hs"
111 else
112 die "No Setup.lhs or Setup.hs found"
113 fi
114 fi
115
116 # We build the setup program using the latest version of
117 # cabal that we have installed
118 cabalversion=$(ghc-bestcabalversion)
119 einfo "Using ${cabalversion}."
120 $(ghc-getghc) -package "${cabalversion}" --make "${setupmodule}" -o setup \
121 || die "compiling ${setupmodule} failed"
122 }
123
124 cabal-haddock() {
125 ./setup haddock || die "setup haddock failed"
126 }
127
128 cabal-configure() {
129 if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then
130 cabalconf="${cabalconf} --enable-library-profiling"
131 fi
132 # Building GHCi libs on ppc64 causes "TOC overflow".
133 if use ppc64; then
134 cabalconf="${cabalconf} --disable-library-for-ghci"
135 fi
136
137 # Note: with Cabal-1.1.6.x we still do not have enough control
138 # to put the docs into the right place. They're currently going
139 # into /usr/share/${P}/ghc-x.y/doc/
140 # rather than /usr/share/doc/${PF}/
141 # Because we can only set the datadir, not the docdir.
142
143 ./setup configure \
144 --ghc --prefix=/usr \
145 --with-compiler="$(ghc-getghc)" \
146 --with-hc-pkg="$(ghc-getghcpkg)" \
147 --prefix=/usr \
148 --libdir=/usr/$(get_libdir) \
149 --libsubdir=${P}/ghc-$(ghc-version) \
150 --datadir=/usr/share/ \
151 --datasubdir=${P}/ghc-$(ghc-version) \
152 ${cabalconf} \
153 ${CABAL_CONFIGURE_FLAGS} \
154 "$@" || die "setup configure failed"
155 }
156
157 cabal-build() {
158 ./setup build \
159 || die "setup build failed"
160 }
161
162 cabal-copy() {
163 ./setup copy \
164 --destdir="${D}" \
165 || die "setup copy failed"
166
167 # cabal is a bit eager about creating dirs,
168 # so remove them if they are empty
169 rmdir "${D}/usr/bin" 2> /dev/null
170
171 # GHC 6.4 has a bug in get/setPermission and Cabal 1.1.1 has
172 # no workaround.
173 # set the +x permission on executables
174 if [[ -d "${D}/usr/bin" ]] ; then
175 chmod +x "${D}/usr/bin/"*
176 fi
177 # TODO: do we still need this?
178 }
179
180 cabal-pkg() {
181 # This does not actually register since we're using true instead
182 # of ghc-pkg. So it just leaves the .installed-pkg-config and we can
183 # register that ourselves (if it exists).
184 local result
185 local err
186
187 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
188 sed -i "s|$(ghc-getghcpkg)|$(type -P true)|" .setup-config
189 ./setup register || die "setup register failed"
190 if [[ -f .installed-pkg-config ]]; then
191 ghc-setup-pkg .installed-pkg-config
192 ghc-install-pkg
193 else
194 die "setup register has not generated a package configuration file"
195 fi
196 fi
197 }
198
199 # Some cabal libs are bundled along with some versions of ghc
200 # eg filepath-1.0 comes with ghc-6.6.1
201 # by putting CABAL_CORE_LIB_GHC_PV="6.6.1" in an ebuild we are declaring that
202 # when building with this version of ghc, the ebuild is a dummy that is it will
203 # install no files since the package is already included with ghc.
204 # However portage still records the dependency and we can upgrade the package
205 # to a later one that's not included with ghc.
206 # You can also put a space separated list, eg CABAL_CORE_LIB_GHC_PV="6.6 6.6.1".
207 cabal-is-dummy-lib() {
208 for version in ${CABAL_CORE_LIB_GHC_PV[*]}; do
209 [[ "$(ghc-version)" == "$version" ]] && return 0
210 done
211 return 1
212 }
213
214 # exported function: check if cabal is correctly installed for
215 # the currently active ghc (we cannot guarantee this with portage)
216 haskell-cabal_pkg_setup() {
217 ghc-package_pkg_setup
218 if [[ -z "${CABAL_BOOTSTRAP}" ]] && ! ghc-sanecabal "${CABAL_MIN_VERSION}"; then
219 eerror "The package dev-haskell/cabal is not correctly installed for"
220 eerror "the currently active version of ghc ($(ghc-version)). Please"
221 eerror "run ghc-updater or re-emerge dev-haskell/cabal."
222 die "cabal is not correctly installed"
223 fi
224 if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then
225 eerror "QA: Neither bin nor lib are in CABAL_FEATURES."
226 fi
227 if [[ -n "${CABAL_UNKNOWN}" ]]; then
228 ewarn "Unknown entry in CABAL_FEATURES: ${CABAL_UNKNONW}"
229 fi
230 if cabal-is-dummy-lib; then
231 einfo "${P} is included in ghc-${CABAL_CORE_LIB_GHC_PV}, nothing to install."
232 fi
233 }
234
235 # exported function: cabal-style bootstrap configure and compile
236 cabal_src_compile() {
237 if ! cabal-is-dummy-lib; then
238 cabal-bootstrap
239 cabal-configure
240 cabal-build
241
242 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
243 cabal-haddock
244 fi
245 fi
246 }
247 haskell-cabal_src_compile() {
248 cabal_src_compile
249 }
250
251 # exported function: cabal-style copy and register
252 cabal_src_install() {
253 if cabal-is-dummy-lib; then
254 # create a dummy local package conf file for the sake of ghc-updater
255 dodir "$(ghc-confdir)"
256 echo '[]' > "${D}/$(ghc-confdir)/$(ghc-localpkgconf)"
257 else
258 cabal-copy
259 cabal-pkg
260
261 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
262 local cabalversion=$(ghc-extractportageversion dev-haskell/cabal)
263 if ! version_is_at_least "1.1.6" "${cabalversion}"; then
264 dohtml -r dist/doc/html/*
265 fi
266 fi
267 fi
268 }
269 haskell-cabal_src_install() {
270 cabal_src_install
271 }
272
273 EXPORT_FUNCTIONS pkg_setup src_compile src_install

  ViewVC Help
Powered by ViewVC 1.1.20