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

Contents of /eclass/haskell-cabal.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (show annotations) (download)
Fri Jul 27 09:09:20 2007 UTC (7 years, 1 month ago) by kolmodin
Branch: MAIN
Changes since 1.11: +2 -3 lines
Cabal profiling should not affect executables. Fix which/type -P.

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.11 2007/07/25 18:07:02 dcoutts 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 # exported function: check if cabal is correctly installed for
200 # the currently active ghc (we cannot guarantee this with portage)
201 haskell-cabal_pkg_setup() {
202 ghc-package_pkg_setup
203 if [[ -z "${CABAL_BOOTSTRAP}" ]] && ! ghc-sanecabal "${CABAL_MIN_VERSION}"; then
204 eerror "The package dev-haskell/cabal is not correctly installed for"
205 eerror "the currently active version of ghc ($(ghc-version)). Please"
206 eerror "run ghc-updater or re-emerge dev-haskell/cabal."
207 die "cabal is not correctly installed"
208 fi
209 if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then
210 eerror "QA: Neither bin nor lib are in CABAL_FEATURES."
211 fi
212 if [[ -n "${CABAL_UNKNOWN}" ]]; then
213 ewarn "Unknown entry in CABAL_FEATURES: ${CABAL_UNKNONW}"
214 fi
215 }
216
217 # exported function: cabal-style bootstrap configure and compile
218 cabal_src_compile() {
219 cabal-bootstrap
220 cabal-configure
221 cabal-build
222
223 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
224 cabal-haddock
225 fi
226 }
227 haskell-cabal_src_compile() {
228 cabal_src_compile
229 }
230
231 # exported function: cabal-style copy and register
232 cabal_src_install() {
233 cabal-copy
234 cabal-pkg
235
236 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
237 local cabalversion=$(ghc-extractportageversion dev-haskell/cabal)
238 if ! version_is_at_least "1.1.6" "${cabalversion}"; then
239 dohtml -r dist/doc/html/*
240 fi
241 fi
242 }
243 haskell-cabal_src_install() {
244 cabal_src_install
245 }
246
247 EXPORT_FUNCTIONS pkg_setup src_compile src_install

  ViewVC Help
Powered by ViewVC 1.1.20