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

Contents of /eclass/haskell-cabal.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download)
Thu Feb 16 14:10:51 2006 UTC (8 years, 2 months ago) by dcoutts
Branch: MAIN
Changes since 1.3: +14 -11 lines
Expect one of "lib"/"bin" in CABAL_FEATURES.
Only run the registration if "lib" is set.
Always expect a package file to be generated when "lib" is set.

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.3 2006/02/16 12:32:53 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
130 ./setup configure \
131 --ghc --prefix=/usr \
132 --with-compiler="$(ghc-getghc)" \
133 --with-hc-pkg="$(ghc-getghcpkg)" \
134 ${cabalconf} \
135 "$@" || die "setup configure failed"
136 }
137
138 cabal-build() {
139 ./setup build \
140 || die "setup build failed"
141 }
142
143 cabal-copy() {
144 ./setup copy \
145 --copy-prefix="${D}/usr" \
146 || die "setup copy failed"
147
148 # cabal is a bit eager about creating dirs,
149 # so remove them if they are empty
150 rmdir "${D}/usr/bin" 2> /dev/null
151
152 # GHC 6.4 has a bug in get/setPermission and Cabal 1.1.1 has
153 # no workaround.
154 # set the +x permission on executables
155 if [[ -d "${D}/usr/bin" ]] ; then
156 chmod +x "${D}/usr/bin/"*
157 fi
158 }
159
160 cabal-pkg() {
161 # This does not actually register since we're using /usr/bin/true instead
162 # of ghc-pkg. So it just leaves the .installed-pkg-config and we can
163 # register that ourselves (if it exists).
164 local result
165 local err
166
167 if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then
168 sed -i 's:ghc-pkg:/usr/bin/true:' .setup-config
169 ./setup register || die "setup register failed"
170 if [[ -f .installed-pkg-config ]]; then
171 ghc-setup-pkg .installed-pkg-config
172 ghc-install-pkg
173 else
174 die "setup register has not generated a package configuration file"
175 fi
176 fi
177 }
178
179 # exported function: check if cabal is correctly installed for
180 # the currently active ghc (we cannot guarantee this with portage)
181 haskell-cabal_pkg_setup() {
182 if [[ -z "${CABAL_BOOTSTRAP}" ]] && ! ghc-sanecabal "1.1.3"; then
183 eerror "The package dev-haskell/cabal is not correctly installed for"
184 eerror "the currently active version of ghc ($(ghc-version)). Please"
185 eerror "run ghc-updater or re-emerge dev-haskell/cabal."
186 die "cabal is not correctly installed"
187 fi
188 if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then
189 eerror "QA: Neither bin nor lib are in CABAL_FEATURES."
190 fi
191 if [[ -n "${CABAL_UNKNOWN}" ]]; then
192 ewarn "Unknown entry in CABAL_FEATURES: ${CABAL_UNKNONW}"
193 fi
194 }
195
196 # exported function: cabal-style bootstrap configure and compile
197 cabal_src_compile() {
198 cabal-bootstrap
199 cabal-configure
200 cabal-build
201
202 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
203 cabal-haddock
204 fi
205 }
206 haskell-cabal_src_compile() {
207 cabal_src_compile
208 }
209
210 # exported function: cabal-style copy and register
211 cabal_src_install() {
212 cabal-copy
213 cabal-pkg
214
215 if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
216 dohtml dist/doc/html/*
217 fi
218 }
219 haskell-cabal_src_install() {
220 cabal_src_install
221 }
222
223 EXPORT_FUNCTIONS pkg_setup src_compile src_install

  ViewVC Help
Powered by ViewVC 1.1.20