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

Contents of /eclass/haskell-cabal.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (show annotations) (download)
Wed Oct 4 17:49:20 2006 UTC (7 years, 6 months ago) by kosmikus
Branch: MAIN
Changes since 1.7: +6 -2 lines
Install HTML docs recursively. Allow to add extra flags to package configuration.

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
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 if [[ -z "${CABAL_BOOTSTRAP}" ]]; then
94 DEPEND="${DEPEND} >=dev-haskell/cabal-1.1.3"
95 fi
96
97 # Libraries require GHC to be installed.
98 if [[ -n "${CABAL_HAS_LIBRARIES}" ]]; then
99 RDEPEND="${RDEPEND} virtual/ghc"
100 fi
101
102 cabal-bootstrap() {
103 local setupmodule
104 local cabalversion
105 if [[ -f "${S}/Setup.lhs" ]]; then
106 setupmodule="${S}/Setup.lhs"
107 else
108 if [[ -f "${S}/Setup.hs" ]]; then
109 setupmodule="${S}/Setup.hs"
110 else
111 die "No Setup.lhs or Setup.hs found"
112 fi
113 fi
114
115 # We build the setup program using the latest version of
116 # cabal that we have installed
117 cabalversion=$(ghc-bestcabalversion)
118 einfo "Using ${cabalversion}."
119 $(ghc-getghc) -package "${cabalversion}" --make "${setupmodule}" -o setup \
120 || die "compiling ${setupmodule} failed"
121 }
122
123 cabal-haddock() {
124 ./setup haddock || die "setup haddock failed"
125 }
126
127 cabal-configure() {
128 if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then
129 cabalconf="${cabalconf} --enable-executable-profiling";
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 ./setup configure \
138 --ghc --prefix=/usr \
139 --with-compiler="$(ghc-getghc)" \
140 --with-hc-pkg="$(ghc-getghcpkg)" \
141 ${cabalconf} \
142 ${CABAL_CONFIGURE_FLAGS} \
143 "$@" || die "setup configure failed"
144 }
145
146 cabal-build() {
147 ./setup build \
148 || die "setup build failed"
149 }
150
151 cabal-copy() {
152 ./setup copy \
153 --copy-prefix="${D}/usr" \
154 || die "setup copy failed"
155
156 # cabal is a bit eager about creating dirs,
157 # so remove them if they are empty
158 rmdir "${D}/usr/bin" 2> /dev/null
159
160 # GHC 6.4 has a bug in get/setPermission and Cabal 1.1.1 has
161 # no workaround.
162 # set the +x permission on executables
163 if [[ -d "${D}/usr/bin" ]] ; then
164 chmod +x "${D}/usr/bin/"*
165 fi
166 }
167
168 cabal-pkg() {
169 # This does not actually register since we're using /usr/bin/true instead
170 # of ghc-pkg. So it just leaves the .installed-pkg-config and we can
171 # register that ourselves (if it exists).
172 local result
173 local err
174
175 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
176 sed -i "s|$(ghc-getghcpkg)|/usr/bin/true|" .setup-config
177 ./setup register || die "setup register failed"
178 if [[ -f .installed-pkg-config ]]; then
179 ghc-setup-pkg .installed-pkg-config
180 ghc-install-pkg
181 else
182 die "setup register has not generated a package configuration file"
183 fi
184 fi
185 }
186
187 # exported function: check if cabal is correctly installed for
188 # the currently active ghc (we cannot guarantee this with portage)
189 haskell-cabal_pkg_setup() {
190 if [[ -z "${CABAL_BOOTSTRAP}" ]] && ! ghc-sanecabal "1.1.3"; then
191 eerror "The package dev-haskell/cabal is not correctly installed for"
192 eerror "the currently active version of ghc ($(ghc-version)). Please"
193 eerror "run ghc-updater or re-emerge dev-haskell/cabal."
194 die "cabal is not correctly installed"
195 fi
196 if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then
197 eerror "QA: Neither bin nor lib are in CABAL_FEATURES."
198 fi
199 if [[ -n "${CABAL_UNKNOWN}" ]]; then
200 ewarn "Unknown entry in CABAL_FEATURES: ${CABAL_UNKNONW}"
201 fi
202 }
203
204 # exported function: cabal-style bootstrap configure and compile
205 cabal_src_compile() {
206 cabal-bootstrap
207 cabal-configure
208 cabal-build
209
210 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
211 cabal-haddock
212 fi
213 }
214 haskell-cabal_src_compile() {
215 cabal_src_compile
216 }
217
218 # exported function: cabal-style copy and register
219 cabal_src_install() {
220 cabal-copy
221 cabal-pkg
222
223 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
224 dohtml -r dist/doc/html/*
225 fi
226 }
227 haskell-cabal_src_install() {
228 cabal_src_install
229 }
230
231 EXPORT_FUNCTIONS pkg_setup src_compile src_install

  ViewVC Help
Powered by ViewVC 1.1.20