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

Contents of /eclass/haskell-cabal.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (show annotations) (download)
Wed Jul 25 18:07:02 2007 UTC (7 years, 5 months ago) by dcoutts
Branch: MAIN
Changes since 1.10: +25 -9 lines
Updates to ghc and cabal eclasses to go with ghc-6.6.x upgrade.

1 # Copyright 1999-2006 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: $
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-executable-profiling";
131 cabalconf="${cabalconf} --enable-library-profiling"
132 fi
133 # Building GHCi libs on ppc64 causes "TOC overflow".
134 if use ppc64; then
135 cabalconf="${cabalconf} --disable-library-for-ghci"
136 fi
137
138 # Note: with Cabal-1.1.6.x we still do not have enough control
139 # to put the docs into the right place. They're currently going
140 # into /usr/share/${P}/ghc-x.y/doc/
141 # rather than /usr/share/doc/${PF}/
142 # Because we can only set the datadir, not the docdir.
143
144 ./setup configure \
145 --ghc --prefix=/usr \
146 --with-compiler="$(ghc-getghc)" \
147 --with-hc-pkg="$(ghc-getghcpkg)" \
148 --prefix=/usr \
149 --libdir=/usr/$(get_libdir) \
150 --libsubdir=${P}/ghc-$(ghc-version) \
151 --datadir=/usr/share/ \
152 --datasubdir=${P}/ghc-$(ghc-version) \
153 ${cabalconf} \
154 ${CABAL_CONFIGURE_FLAGS} \
155 "$@" || die "setup configure failed"
156 }
157
158 cabal-build() {
159 ./setup build \
160 || die "setup build failed"
161 }
162
163 cabal-copy() {
164 ./setup copy \
165 --destdir="${D}" \
166 || die "setup copy failed"
167
168 # cabal is a bit eager about creating dirs,
169 # so remove them if they are empty
170 rmdir "${D}/usr/bin" 2> /dev/null
171
172 # GHC 6.4 has a bug in get/setPermission and Cabal 1.1.1 has
173 # no workaround.
174 # set the +x permission on executables
175 if [[ -d "${D}/usr/bin" ]] ; then
176 chmod +x "${D}/usr/bin/"*
177 fi
178 # TODO: do we still need this?
179 }
180
181 cabal-pkg() {
182 # This does not actually register since we're using true instead
183 # of ghc-pkg. So it just leaves the .installed-pkg-config and we can
184 # register that ourselves (if it exists).
185 local result
186 local err
187
188 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
189 sed -i "s|$(ghc-getghcpkg)|$(which true)|" .setup-config
190 ./setup register || die "setup register failed"
191 if [[ -f .installed-pkg-config ]]; then
192 ghc-setup-pkg .installed-pkg-config
193 ghc-install-pkg
194 else
195 die "setup register has not generated a package configuration file"
196 fi
197 fi
198 }
199
200 # exported function: check if cabal is correctly installed for
201 # the currently active ghc (we cannot guarantee this with portage)
202 haskell-cabal_pkg_setup() {
203 ghc-package_pkg_setup
204 if [[ -z "${CABAL_BOOTSTRAP}" ]] && ! ghc-sanecabal "${CABAL_MIN_VERSION}"; then
205 eerror "The package dev-haskell/cabal is not correctly installed for"
206 eerror "the currently active version of ghc ($(ghc-version)). Please"
207 eerror "run ghc-updater or re-emerge dev-haskell/cabal."
208 die "cabal is not correctly installed"
209 fi
210 if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then
211 eerror "QA: Neither bin nor lib are in CABAL_FEATURES."
212 fi
213 if [[ -n "${CABAL_UNKNOWN}" ]]; then
214 ewarn "Unknown entry in CABAL_FEATURES: ${CABAL_UNKNONW}"
215 fi
216 }
217
218 # exported function: cabal-style bootstrap configure and compile
219 cabal_src_compile() {
220 cabal-bootstrap
221 cabal-configure
222 cabal-build
223
224 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
225 cabal-haddock
226 fi
227 }
228 haskell-cabal_src_compile() {
229 cabal_src_compile
230 }
231
232 # exported function: cabal-style copy and register
233 cabal_src_install() {
234 cabal-copy
235 cabal-pkg
236
237 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
238 local cabalversion=$(ghc-extractportageversion dev-haskell/cabal)
239 if ! version_is_at_least "1.1.6" "${cabalversion}"; then
240 dohtml -r dist/doc/html/*
241 fi
242 fi
243 }
244 haskell-cabal_src_install() {
245 cabal_src_install
246 }
247
248 EXPORT_FUNCTIONS pkg_setup src_compile src_install

  ViewVC Help
Powered by ViewVC 1.1.20