| 1 | # Copyright 1999-2005 Gentoo Foundation |
1 | # Copyright 1999-2006 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/haskell-cabal.eclass,v 1.1.1.1 2005/11/30 09:59:22 chriswhite Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/haskell-cabal.eclass,v 1.18 2010/01/26 20:50:40 kolmodin Exp $ |
| 4 | # |
4 | # |
| 5 | # Original authors: Andres Loeh <kosmikus@gentoo.org> |
5 | # Original authors: Andres Loeh <kosmikus@gentoo.org> |
| 6 | # Duncan Coutts <dcoutts@gentoo.org> |
6 | # Duncan Coutts <dcoutts@gentoo.org> |
| 7 | # Maintained by: Haskell herd <haskell@gentoo.org> |
7 | # Maintained by: Haskell herd <haskell@gentoo.org> |
| 8 | # |
8 | # |
| … | |
… | |
| 22 | # happy -- parser generator |
22 | # happy -- parser generator |
| 23 | # c2hs -- C interface generator |
23 | # c2hs -- C interface generator |
| 24 | # cpphs -- C preprocessor clone written in Haskell |
24 | # cpphs -- C preprocessor clone written in Haskell |
| 25 | # profile -- if package supports to build profiling-enabled libraries |
25 | # profile -- if package supports to build profiling-enabled libraries |
| 26 | # bootstrap -- only used for the cabal package itself |
26 | # bootstrap -- only used for the cabal package itself |
|
|
27 | # bin -- the package installs binaries |
|
|
28 | # lib -- the package installs libraries |
|
|
29 | # nocabaldep -- don't add dependency on cabal. |
|
|
30 | # only used for packages that _must_ not pull the dependency |
|
|
31 | # on cabal, but still use this eclass (e.g. haskell-updater). |
| 27 | # |
32 | # |
| 28 | # Dependencies on other cabal packages have to be specified |
33 | # Dependencies on other cabal packages have to be specified |
| 29 | # correctly. |
34 | # correctly. |
| 30 | # |
35 | # |
| 31 | # Cabal libraries should usually be SLOTted with "${PV}". |
36 | # Cabal libraries should usually be SLOTted with "${PV}". |
| 32 | # |
37 | # |
| 33 | # Many Cabal packages require S to be manually set. |
38 | # Many Cabal packages require S to be manually set. |
| 34 | # |
39 | # |
| 35 | # Conforming Cabal packages don't require any function definitions |
40 | # Conforming Cabal packages don't require any function definitions |
| 36 | # in the ebuild. |
41 | # in the ebuild. |
|
|
42 | # |
|
|
43 | # Special flags to Cabal Configure can now be set by using |
|
|
44 | # CABAL_CONFIGURE_FLAGS |
| 37 | |
45 | |
| 38 | inherit ghc-package |
46 | inherit ghc-package multilib |
| 39 | |
47 | |
| 40 | |
48 | |
| 41 | for feature in ${CABAL_FEATURES}; do |
49 | for feature in ${CABAL_FEATURES}; do |
| 42 | case ${feature} in |
50 | case ${feature} in |
| 43 | haddock) CABAL_USE_HADDOCK=yes;; |
51 | haddock) CABAL_USE_HADDOCK=yes;; |
| 44 | alex) CABAL_USE_ALEX=yes;; |
52 | alex) CABAL_USE_ALEX=yes;; |
| 45 | happy) CABAL_USE_HAPPY=yes;; |
53 | happy) CABAL_USE_HAPPY=yes;; |
| 46 | c2hs) CABAL_USE_C2HS=yes;; |
54 | c2hs) CABAL_USE_C2HS=yes;; |
| 47 | cpphs) CABAL_USE_CPPHS=yes;; |
55 | cpphs) CABAL_USE_CPPHS=yes;; |
| 48 | profile) CABAL_USE_PROFILE=yes;; |
56 | profile) CABAL_USE_PROFILE=yes;; |
| 49 | bootstrap) CABAL_BOOTSTRAP=yes;; |
57 | bootstrap) CABAL_BOOTSTRAP=yes;; |
| 50 | *) ewarn "Unknown entry in CABAL_FEATURES: ${feature}";; |
58 | bin) CABAL_HAS_BINARIES=yes;; |
|
|
59 | lib) CABAL_HAS_LIBRARIES=yes;; |
|
|
60 | nocabaldep) CABAL_FROM_GHC=yes;; |
|
|
61 | *) CABAL_UNKNOWN="${CABAL_UNKNOWN} ${feature}";; |
| 51 | esac |
62 | esac |
| 52 | done |
63 | done |
| 53 | |
64 | |
| 54 | if [[ -n "${CABAL_USE_HADDOCK}" ]]; then |
65 | if [[ -n "${CABAL_USE_HADDOCK}" ]]; then |
| 55 | IUSE="${IUSE} doc" |
66 | IUSE="${IUSE} doc" |
| 56 | DEPEND="${DEPEND} doc? ( dev-haskell/haddock )" |
67 | DEPEND="${DEPEND} doc? ( dev-haskell/haddock )" |
| 57 | cabalconf="${cabalconf} --with-haddock=/usr/bin/haddock" |
|
|
| 58 | fi |
68 | fi |
| 59 | |
69 | |
| 60 | if [[ -n "${CABAL_USE_ALEX}" ]]; then |
70 | if [[ -n "${CABAL_USE_ALEX}" ]]; then |
| 61 | DEPEND="${DEPEND} dev-haskell/alex" |
71 | DEPEND="${DEPEND} dev-haskell/alex" |
| 62 | cabalconf="${cabalconf} --with-alex=/usr/bin/alex" |
72 | cabalconf="${cabalconf} --with-alex=/usr/bin/alex" |
| … | |
… | |
| 81 | IUSE="${IUSE} profile" |
91 | IUSE="${IUSE} profile" |
| 82 | fi |
92 | fi |
| 83 | |
93 | |
| 84 | # We always use a standalone version of Cabal, rather than the one that comes |
94 | # We always use a standalone version of Cabal, rather than the one that comes |
| 85 | # with GHC. But of course we can't depend on cabal when building cabal itself. |
95 | # with GHC. But of course we can't depend on cabal when building cabal itself. |
|
|
96 | if [[ -z ${CABAL_MIN_VERSION} ]]; then |
|
|
97 | CABAL_MIN_VERSION=1.1.4 |
|
|
98 | fi |
|
|
99 | if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]]; then |
|
|
100 | DEPEND="${DEPEND} >=dev-haskell/cabal-${CABAL_MIN_VERSION}" |
|
|
101 | fi |
|
|
102 | |
|
|
103 | # Libraries require GHC to be installed. |
|
|
104 | if [[ -n "${CABAL_HAS_LIBRARIES}" ]]; then |
|
|
105 | RDEPEND="${RDEPEND} dev-lang/ghc" |
|
|
106 | fi |
|
|
107 | |
|
|
108 | # returns the version of cabal currently in use |
|
|
109 | _CABAL_VERSION_CACHE="" |
|
|
110 | cabal-version() { |
|
|
111 | if [[ -z "${_CABAL_VERSION_CACHE}" ]]; then |
| 86 | if [[ -z "${CABAL_BOOTSTRAP}" ]]; then |
112 | if [[ "${CABAL_BOOTSTRAP}" ]]; then |
| 87 | DEPEND="${DEPEND} >=dev-haskell/cabal-1.1.3" |
113 | # We're bootstrapping cabal, so the cabal version is the version |
|
|
114 | # of this package itself. |
|
|
115 | _CABAL_VERSION_CACHE="${PV}" |
|
|
116 | elif [[ "${CABAL_FROM_GHC}" ]]; then |
|
|
117 | # We can't assume there's a version of Cabal installed by ebuild as |
|
|
118 | # this might be a first time install of GHC (for packages that |
|
|
119 | # use the shipped Cabal like haskell-updater). |
|
|
120 | |
|
|
121 | # The user is likely to only have one version of Cabal, provided |
|
|
122 | # by GHC. Note that dev-haskell/cabal can be a dummy package, only |
|
|
123 | # using the version provided by GHC. If the user has another version |
|
|
124 | # of Cabal too (more recent than the one GHC provides through |
|
|
125 | # dev-haskell/cabal, or possibly older if he used an old |
|
|
126 | # Cabal package) the most recent is used (expected to be the last |
|
|
127 | # one in the ghc-pkg output). |
|
|
128 | _CABAL_VERSION_CACHE="$(ghc-pkg field Cabal version | tail -n 1)" |
|
|
129 | |
|
|
130 | # Strip out the "version: " prefix |
|
|
131 | _CABAL_VERSION_CACHE="${_CABAL_VERSION_CACHE#"version: "}" |
|
|
132 | else |
|
|
133 | # We ask portage, not ghc, so that we only pick up |
|
|
134 | # portage-installed cabal versions. |
|
|
135 | _CABAL_VERSION_CACHE="$(ghc-extractportageversion dev-haskell/cabal)" |
|
|
136 | fi |
| 88 | fi |
137 | fi |
| 89 | |
138 | echo "${_CABAL_VERSION_CACHE}" |
|
|
139 | } |
| 90 | |
140 | |
| 91 | cabal-bootstrap() { |
141 | cabal-bootstrap() { |
| 92 | local setupmodule |
142 | local setupmodule |
| 93 | local cabalversion |
143 | local cabalpackage |
| 94 | if [[ -f "${S}/Setup.lhs" ]]; then |
144 | if [[ -f "${S}/Setup.lhs" ]]; then |
| 95 | setupmodule="${S}/Setup.lhs" |
145 | setupmodule="${S}/Setup.lhs" |
| 96 | else |
146 | else |
| 97 | if [[ -f "${S}/Setup.hs" ]]; then |
147 | if [[ -f "${S}/Setup.hs" ]]; then |
| 98 | setupmodule="${S}/Setup.hs" |
148 | setupmodule="${S}/Setup.hs" |
| … | |
… | |
| 101 | fi |
151 | fi |
| 102 | fi |
152 | fi |
| 103 | |
153 | |
| 104 | # We build the setup program using the latest version of |
154 | # We build the setup program using the latest version of |
| 105 | # cabal that we have installed |
155 | # cabal that we have installed |
| 106 | cabalversion=$(ghc-bestcabalversion) |
156 | if version_is_at_least "6.4" "$(ghc-version)"; then |
|
|
157 | cabalpackage=Cabal-$(cabal-version) |
|
|
158 | else |
|
|
159 | # older ghc's don't support package versioning |
|
|
160 | cabalpackage=Cabal |
|
|
161 | fi |
| 107 | einfo "Using ${cabalversion}." |
162 | einfo "Using cabal-$(cabal-version)." |
| 108 | $(ghc-getghc) -package "${cabalversion}" --make "${setupmodule}" -o setup \ |
163 | $(ghc-getghc) -package "${cabalpackage}" --make "${setupmodule}" -o setup \ |
| 109 | || die "compiling ${setupmodule} failed" |
164 | || die "compiling ${setupmodule} failed" |
|
|
165 | } |
|
|
166 | |
|
|
167 | cabal-mksetup() { |
|
|
168 | local setupdir |
|
|
169 | |
|
|
170 | if [[ -n $1 ]]; then |
|
|
171 | setupdir=$1 |
|
|
172 | else |
|
|
173 | setupdir=${S} |
|
|
174 | fi |
|
|
175 | |
|
|
176 | rm -f "${setupdir}"/Setup.{lhs,hs} |
|
|
177 | |
|
|
178 | echo 'import Distribution.Simple; main = defaultMainWithHooks defaultUserHooks' \ |
|
|
179 | > $setupdir/Setup.hs |
| 110 | } |
180 | } |
| 111 | |
181 | |
| 112 | cabal-haddock() { |
182 | cabal-haddock() { |
| 113 | ./setup haddock || die "setup haddock failed" |
183 | ./setup haddock || die "setup haddock failed" |
| 114 | } |
184 | } |
| 115 | |
185 | |
| 116 | cabal-configure() { |
186 | cabal-configure() { |
|
|
187 | if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then |
|
|
188 | cabalconf="${cabalconf} --with-haddock=/usr/bin/haddock" |
|
|
189 | fi |
| 117 | if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then |
190 | if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then |
|
|
191 | cabalconf="${cabalconf} --enable-library-profiling" |
|
|
192 | fi |
|
|
193 | # Building GHCi libs on ppc64 causes "TOC overflow". |
|
|
194 | if use ppc64; then |
|
|
195 | cabalconf="${cabalconf} --disable-library-for-ghci" |
|
|
196 | fi |
|
|
197 | |
|
|
198 | if version_is_at_least "1.4" "$(cabal-version)"; then |
|
|
199 | # disable executable stripping for the executables, as portage will |
|
|
200 | # strip by itself, and pre-stripping gives a QA warning. |
|
|
201 | # cabal versions previous to 1.4 does not strip executables, and does |
|
|
202 | # not accept the flag. |
|
|
203 | # this fixes numerous bugs, amongst them; |
|
|
204 | # bug #251881, bug #251882, bug #251884, bug #251886, bug #299494 |
| 118 | cabalconf="${cabalconf} --enable-executable-profiling" |
205 | cabalconf="${cabalconf} --disable-executable-stripping" |
| 119 | fi |
206 | fi |
|
|
207 | |
|
|
208 | if version_is_at_least "1.2.0" "$(cabal-version)"; then |
|
|
209 | cabalconf="${cabalconf} --docdir=/usr/share/doc/${PF}" |
|
|
210 | # As of Cabal 1.2, configure is quite quiet. For diagnostic purposes |
|
|
211 | # it's better if the configure chatter is in the build logs: |
|
|
212 | cabalconf="${cabalconf} --verbose" |
|
|
213 | fi |
|
|
214 | # Note: with Cabal-1.1.6.x we do not have enough control |
|
|
215 | # to put the docs into the right place. They're currently going |
|
|
216 | # into /usr/share/${P}/ghc-x.y/doc/ |
|
|
217 | # rather than /usr/share/doc/${PF}/ |
|
|
218 | # Because we can only set the datadir, not the docdir. |
| 120 | |
219 | |
| 121 | ./setup configure \ |
220 | ./setup configure \ |
| 122 | --ghc --prefix=/usr \ |
221 | --ghc --prefix=/usr \ |
| 123 | --with-compiler="$(ghc-getghc)" \ |
222 | --with-compiler="$(ghc-getghc)" \ |
| 124 | --with-hc-pkg="$(ghc-getghcpkg)" \ |
223 | --with-hc-pkg="$(ghc-getghcpkg)" \ |
|
|
224 | --prefix=/usr \ |
|
|
225 | --libdir=/usr/$(get_libdir) \ |
|
|
226 | --libsubdir=${P}/ghc-$(ghc-version) \ |
|
|
227 | --datadir=/usr/share/ \ |
|
|
228 | --datasubdir=${P}/ghc-$(ghc-version) \ |
| 125 | ${cabalconf} \ |
229 | ${cabalconf} \ |
|
|
230 | ${CABAL_CONFIGURE_FLAGS} \ |
| 126 | "$@" || die "setup configure failed" |
231 | "$@" || die "setup configure failed" |
| 127 | } |
232 | } |
| 128 | |
233 | |
| 129 | cabal-build() { |
234 | cabal-build() { |
|
|
235 | unset LANG LC_ALL LC_MESSAGES |
| 130 | ./setup build \ |
236 | ./setup build \ |
| 131 | || die "setup build failed" |
237 | || die "setup build failed" |
| 132 | } |
238 | } |
| 133 | |
239 | |
| 134 | cabal-copy() { |
240 | cabal-copy() { |
| 135 | ./setup copy \ |
241 | ./setup copy \ |
| 136 | --copy-prefix="${D}/usr" \ |
242 | --destdir="${D}" \ |
| 137 | || die "setup copy failed" |
243 | || die "setup copy failed" |
| 138 | |
244 | |
| 139 | # cabal is a bit eager about creating dirs, |
245 | # cabal is a bit eager about creating dirs, |
| 140 | # so remove them if they are empty |
246 | # so remove them if they are empty |
| 141 | rmdir "${D}/usr/bin" 2> /dev/null |
247 | rmdir "${D}/usr/bin" 2> /dev/null |
| … | |
… | |
| 144 | # no workaround. |
250 | # no workaround. |
| 145 | # set the +x permission on executables |
251 | # set the +x permission on executables |
| 146 | if [[ -d "${D}/usr/bin" ]] ; then |
252 | if [[ -d "${D}/usr/bin" ]] ; then |
| 147 | chmod +x "${D}/usr/bin/"* |
253 | chmod +x "${D}/usr/bin/"* |
| 148 | fi |
254 | fi |
|
|
255 | # TODO: do we still need this? |
| 149 | } |
256 | } |
| 150 | |
257 | |
| 151 | cabal-pkg() { |
258 | cabal-pkg() { |
| 152 | # This does not actually register since we're using /usr/bin/true instead |
259 | # This does not actually register since we're using true instead |
| 153 | # of ghc-pkg. So it just leaves the .installed-pkg-config and we can |
260 | # of ghc-pkg. So it just leaves the .installed-pkg-config and we can |
| 154 | # register that ourselves (if it exists). |
261 | # register that ourselves (if it exists). |
| 155 | sed -i 's:ghc-pkg:/usr/bin/true:' .setup-config |
262 | local result |
|
|
263 | local err |
|
|
264 | |
|
|
265 | if [[ -n ${CABAL_HAS_LIBRARIES} ]]; then |
|
|
266 | if version_is_at_least "1.2.0" "$(cabal-version)"; then |
|
|
267 | # Newer cabal can generate a package conf for us: |
|
|
268 | ./setup register --gen-pkg-config="${T}/${P}.conf" |
|
|
269 | ghc-setup-pkg "${T}/${P}.conf" |
|
|
270 | ghc-install-pkg |
|
|
271 | else |
|
|
272 | # With older cabal we have to hack it by replacing its ghc-pkg |
|
|
273 | # with true and then just picking up the .installed-pkg-config |
|
|
274 | # file and registering that ourselves (if it exists). |
|
|
275 | sed -i "s|$(ghc-getghcpkg)|$(type -P true)|" .setup-config |
| 156 | ./setup register || die "setup register failed" |
276 | ./setup register || die "setup register failed" |
| 157 | if [[ -f .installed-pkg-config ]]; then |
277 | if [[ -f .installed-pkg-config ]]; then |
| 158 | ghc-setup-pkg .installed-pkg-config |
278 | ghc-setup-pkg .installed-pkg-config |
| 159 | ghc-install-pkg |
279 | ghc-install-pkg |
|
|
280 | else |
|
|
281 | die "setup register has not generated a package configuration file" |
|
|
282 | fi |
| 160 | fi |
283 | fi |
|
|
284 | fi |
|
|
285 | } |
|
|
286 | |
|
|
287 | # Some cabal libs are bundled along with some versions of ghc |
|
|
288 | # eg filepath-1.0 comes with ghc-6.6.1 |
|
|
289 | # by putting CABAL_CORE_LIB_GHC_PV="6.6.1" in an ebuild we are declaring that |
|
|
290 | # when building with this version of ghc, the ebuild is a dummy that is it will |
|
|
291 | # install no files since the package is already included with ghc. |
|
|
292 | # However portage still records the dependency and we can upgrade the package |
|
|
293 | # to a later one that's not included with ghc. |
|
|
294 | # You can also put a space separated list, eg CABAL_CORE_LIB_GHC_PV="6.6 6.6.1". |
|
|
295 | cabal-is-dummy-lib() { |
|
|
296 | for version in ${CABAL_CORE_LIB_GHC_PV[*]}; do |
|
|
297 | [[ "$(ghc-version)" == "$version" ]] && return 0 |
|
|
298 | done |
|
|
299 | return 1 |
| 161 | } |
300 | } |
| 162 | |
301 | |
| 163 | # exported function: check if cabal is correctly installed for |
302 | # exported function: check if cabal is correctly installed for |
| 164 | # the currently active ghc (we cannot guarantee this with portage) |
303 | # the currently active ghc (we cannot guarantee this with portage) |
| 165 | haskell-cabal_pkg_setup() { |
304 | haskell-cabal_pkg_setup() { |
| 166 | if [[ -z "${CABAL_BOOTSTRAP}" ]] && ! ghc-sanecabal "1.1.3"; then |
305 | ghc-package_pkg_setup |
|
|
306 | if [[ -z "${CABAL_BOOTSTRAP}" && -z "${CABAL_FROM_GHC}" ]] && ! ghc-sanecabal "${CABAL_MIN_VERSION}"; then |
| 167 | eerror "The package dev-haskell/cabal is not correctly installed for" |
307 | eerror "The package dev-haskell/cabal is not correctly installed for" |
| 168 | eerror "the currently active version of ghc ($(ghc-version)). Please" |
308 | eerror "the currently active version of ghc ($(ghc-version)). Please" |
| 169 | eerror "run ghc-updater or re-emerge dev-haskell/cabal." |
309 | eerror "run ghc-updater or haskell-updater or re-build dev-haskell/cabal." |
| 170 | die "cabal is not correctly installed" |
310 | die "cabal is not correctly installed" |
|
|
311 | fi |
|
|
312 | if [[ -z "${CABAL_HAS_BINARIES}" ]] && [[ -z "${CABAL_HAS_LIBRARIES}" ]]; then |
|
|
313 | eerror "QA: Neither bin nor lib are in CABAL_FEATURES." |
|
|
314 | fi |
|
|
315 | if [[ -n "${CABAL_UNKNOWN}" ]]; then |
|
|
316 | ewarn "Unknown entry in CABAL_FEATURES: ${CABAL_UNKNOWN}" |
|
|
317 | fi |
|
|
318 | if cabal-is-dummy-lib; then |
|
|
319 | einfo "${P} is included in ghc-${CABAL_CORE_LIB_GHC_PV}, nothing to install." |
| 171 | fi |
320 | fi |
| 172 | } |
321 | } |
| 173 | |
322 | |
| 174 | # exported function: cabal-style bootstrap configure and compile |
323 | # exported function: cabal-style bootstrap configure and compile |
| 175 | cabal_src_compile() { |
324 | cabal_src_compile() { |
|
|
325 | if ! cabal-is-dummy-lib; then |
| 176 | cabal-bootstrap |
326 | cabal-bootstrap |
| 177 | cabal-configure |
327 | cabal-configure |
| 178 | cabal-build |
328 | cabal-build |
| 179 | |
329 | |
| 180 | if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then |
330 | if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then |
| 181 | cabal-haddock |
331 | cabal-haddock |
| 182 | fi |
332 | fi |
|
|
333 | fi |
| 183 | } |
334 | } |
|
|
335 | |
| 184 | haskell-cabal_src_compile() { |
336 | haskell-cabal_src_compile() { |
| 185 | cabal_src_compile |
337 | cabal_src_compile |
| 186 | } |
338 | } |
| 187 | |
339 | |
| 188 | # exported function: cabal-style copy and register |
340 | # exported function: cabal-style copy and register |
| 189 | cabal_src_install() { |
341 | cabal_src_install() { |
|
|
342 | if cabal-is-dummy-lib; then |
|
|
343 | # create a dummy local package conf file for the sake of ghc-updater |
|
|
344 | dodir "$(ghc-confdir)" |
|
|
345 | echo '[]' > "${D}/$(ghc-confdir)/$(ghc-localpkgconf)" |
|
|
346 | else |
| 190 | cabal-copy |
347 | cabal-copy |
| 191 | cabal-pkg |
348 | cabal-pkg |
| 192 | |
349 | |
| 193 | if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then |
350 | if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then |
|
|
351 | if ! version_is_at_least "1.1.6" "$(cabal-version)"; then |
| 194 | dohtml dist/doc/html/* |
352 | dohtml -r dist/doc/html/* |
|
|
353 | fi |
|
|
354 | fi |
| 195 | fi |
355 | fi |
| 196 | } |
356 | } |
| 197 | haskell-cabal_src_install() { |
357 | haskell-cabal_src_install() { |
| 198 | cabal_src_install |
358 | cabal_src_install |
| 199 | } |
359 | } |