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

Contents of /eclass/haskell-cabal.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download)
Wed Mar 1 12:54:35 2006 UTC (8 years, 8 months ago) by dcoutts
Branch: MAIN
Changes since 1.4: +6 -1 lines
Don't build GHCi libs for arches that do not support GHCi.
Also building GHCi libs on ppc64 causes "TOC overflow".

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.4 2006/02/16 14:10:51 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 inherit ghc-package
41
42
43 for feature in ${CABAL_FEATURES}; do
44 case ${feature} in
45 haddock) CABAL_USE_HADDOCK=yes;;
46 alex) CABAL_USE_ALEX=yes;;
47 happy) CABAL_USE_HAPPY=yes;;
48 c2hs) CABAL_USE_C2HS=yes;;
49 cpphs) CABAL_USE_CPPHS=yes;;
50 profile) CABAL_USE_PROFILE=yes;;
51 bootstrap) CABAL_BOOTSTRAP=yes;;
52 bin) CABAL_HAS_BINARIES=yes;;
53 lib) CABAL_HAS_LIBRARIES=yes;;
54 *) CABAL_UNKNOWN="${CABAL_UNKNOWN} ${feature}";;
55 esac
56 done
57
58 if [[ -n "${CABAL_USE_HADDOCK}" ]]; then
59 IUSE="${IUSE} doc"
60 DEPEND="${DEPEND} doc? ( dev-haskell/haddock )"
61 cabalconf="${cabalconf} --with-haddock=/usr/bin/haddock"
62 fi
63
64 if [[ -n "${CABAL_USE_ALEX}" ]]; then
65 DEPEND="${DEPEND} dev-haskell/alex"
66 cabalconf="${cabalconf} --with-alex=/usr/bin/alex"
67 fi
68
69 if [[ -n "${CABAL_USE_HAPPY}" ]]; then
70 DEPEND="${DEPEND} dev-haskell/happy"
71 cabalconf="${cabalconf} --with-happy=/usr/bin/happy"
72 fi
73
74 if [[ -n "${CABAL_USE_C2HS}" ]]; then
75 DEPEND="${DEPEND} dev-haskell/c2hs"
76 cabalconf="${cabalconf} --with-c2hs=/usr/bin/c2hs"
77 fi
78
79 if [[ -n "${CABAL_USE_CPPHS}" ]]; then
80 DEPEND="${DEPEND} dev-haskell/cpphs"
81 cabalconf="${cabalconf} --with-cpphs=/usr/bin/cpphs"
82 fi
83
84 if [[ -n "${CABAL_USE_PROFILE}" ]]; then
85 IUSE="${IUSE} profile"
86 fi
87
88 # We always use a standalone version of Cabal, rather than the one that comes
89 # with GHC. But of course we can't depend on cabal when building cabal itself.
90 if [[ -z "${CABAL_BOOTSTRAP}" ]]; then
91 DEPEND="${DEPEND} >=dev-haskell/cabal-1.1.3"
92 fi
93
94 # Libraries require GHC to be installed.
95 if [[ -n "${CABAL_HAS_LIBRARIES}" ]]; then
96 RDEPEND="${RDEPEND} virtual/ghc"
97 fi
98
99 cabal-bootstrap() {
100 local setupmodule
101 local cabalversion
102 if [[ -f "${S}/Setup.lhs" ]]; then
103 setupmodule="${S}/Setup.lhs"
104 else
105 if [[ -f "${S}/Setup.hs" ]]; then
106 setupmodule="${S}/Setup.hs"
107 else
108 die "No Setup.lhs or Setup.hs found"
109 fi
110 fi
111
112 # We build the setup program using the latest version of
113 # cabal that we have installed
114 cabalversion=$(ghc-bestcabalversion)
115 einfo "Using ${cabalversion}."
116 $(ghc-getghc) -package "${cabalversion}" --make "${setupmodule}" -o setup \
117 || die "compiling ${setupmodule} failed"
118 }
119
120 cabal-haddock() {
121 ./setup haddock || die "setup haddock failed"
122 }
123
124 cabal-configure() {
125 if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then
126 cabalconf="${cabalconf} --enable-executable-profiling";
127 cabalconf="${cabalconf} --enable-library-profiling"
128 fi
129 # Don't build GHCi libs for arches that do not support GHCi.
130 # Also building GHCi libs on ppc64 causes "TOC overflow".
131 if use alpha || use ppc64; then
132 cabalconf="${cabalconf} --disable-library-for-ghci"
133 fi
134
135 ./setup configure \
136 --ghc --prefix=/usr \
137 --with-compiler="$(ghc-getghc)" \
138 --with-hc-pkg="$(ghc-getghcpkg)" \
139 ${cabalconf} \
140 "$@" || die "setup configure failed"
141 }
142
143 cabal-build() {
144 ./setup build \
145 || die "setup build failed"
146 }
147
148 cabal-copy() {
149 ./setup copy \
150 --copy-prefix="${D}/usr" \
151 || die "setup copy failed"
152
153 # cabal is a bit eager about creating dirs,
154 # so remove them if they are empty
155 rmdir "${D}/usr/bin" 2> /dev/null
156
157 # GHC 6.4 has a bug in get/setPermission and Cabal 1.1.1 has
158 # no workaround.
159 # set the +x permission on executables
160 if [[ -d "${D}/usr/bin" ]] ; then
161 chmod +x "${D}/usr/bin/"*
162 fi
163 }
164
165 cabal-pkg() {
166 # This does not actually register since we're using /usr/bin/true instead
167 # of ghc-pkg. So it just leaves the .installed-pkg-config and we can
168 # register that ourselves (if it exists).
169 local result
170 local err
171
172 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
173 sed -i 's:ghc-pkg:/usr/bin/true:' .setup-config
174 ./setup register || die "setup register failed"
175 if [[ -f .installed-pkg-config ]]; then
176 ghc-setup-pkg .installed-pkg-config
177 ghc-install-pkg
178 else
179 die "setup register has not generated a package configuration file"
180 fi
181 fi
182 }
183
184 # exported function: check if cabal is correctly installed for
185 # the currently active ghc (we cannot guarantee this with portage)
186 haskell-cabal_pkg_setup() {
187 if [[ -z "${CABAL_BOOTSTRAP}" ]] && ! ghc-sanecabal "1.1.3"; then
188 eerror "The package dev-haskell/cabal is not correctly installed for"
189 eerror "the currently active version of ghc ($(ghc-version)). Please"
190 eerror "run ghc-updater or re-emerge dev-haskell/cabal."
191 die "cabal is not correctly installed"
192 fi
193 if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then
194 eerror "QA: Neither bin nor lib are in CABAL_FEATURES."
195 fi
196 if [[ -n "${CABAL_UNKNOWN}" ]]; then
197 ewarn "Unknown entry in CABAL_FEATURES: ${CABAL_UNKNONW}"
198 fi
199 }
200
201 # exported function: cabal-style bootstrap configure and compile
202 cabal_src_compile() {
203 cabal-bootstrap
204 cabal-configure
205 cabal-build
206
207 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
208 cabal-haddock
209 fi
210 }
211 haskell-cabal_src_compile() {
212 cabal_src_compile
213 }
214
215 # exported function: cabal-style copy and register
216 cabal_src_install() {
217 cabal-copy
218 cabal-pkg
219
220 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
221 dohtml dist/doc/html/*
222 fi
223 }
224 haskell-cabal_src_install() {
225 cabal_src_install
226 }
227
228 EXPORT_FUNCTIONS pkg_setup src_compile src_install

  ViewVC Help
Powered by ViewVC 1.1.20