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

Contents of /eclass/haskell-cabal.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Mon Dec 5 12:24:53 2005 UTC (8 years, 8 months ago) by dcoutts
Branch: MAIN
Changes since 1.1: +11 -3 lines
When doing profiling, enable profiling for libs as well as executables.
Cope with packages that do not register any libs, eg cabalised ebuilds that are
just straight programs (like c2hs).

1 kosmikus 1.1 # Copyright 1999-2005 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 dcoutts 1.2 # $Header: /var/cvsroot/gentoo-x86/eclass/haskell-cabal.eclass,v 1.1 2005/09/13 12:53:34 kosmikus Exp $
4 kosmikus 1.1 #
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     #
28     # Dependencies on other cabal packages have to be specified
29     # correctly.
30     #
31     # Cabal libraries should usually be SLOTted with "${PV}".
32     #
33     # Many Cabal packages require S to be manually set.
34     #
35     # Conforming Cabal packages don't require any function definitions
36     # in the ebuild.
37    
38     inherit ghc-package
39    
40    
41     for feature in ${CABAL_FEATURES}; do
42     case ${feature} in
43     haddock) CABAL_USE_HADDOCK=yes;;
44     alex) CABAL_USE_ALEX=yes;;
45     happy) CABAL_USE_HAPPY=yes;;
46     c2hs) CABAL_USE_C2HS=yes;;
47     cpphs) CABAL_USE_CPPHS=yes;;
48     profile) CABAL_USE_PROFILE=yes;;
49     bootstrap) CABAL_BOOTSTRAP=yes;;
50     *) ewarn "Unknown entry in CABAL_FEATURES: ${feature}";;
51     esac
52     done
53    
54     if [[ -n "${CABAL_USE_HADDOCK}" ]]; then
55     IUSE="${IUSE} doc"
56     DEPEND="${DEPEND} doc? ( dev-haskell/haddock )"
57     cabalconf="${cabalconf} --with-haddock=/usr/bin/haddock"
58     fi
59    
60     if [[ -n "${CABAL_USE_ALEX}" ]]; then
61     DEPEND="${DEPEND} dev-haskell/alex"
62     cabalconf="${cabalconf} --with-alex=/usr/bin/alex"
63     fi
64    
65     if [[ -n "${CABAL_USE_HAPPY}" ]]; then
66     DEPEND="${DEPEND} dev-haskell/happy"
67     cabalconf="${cabalconf} --with-happy=/usr/bin/happy"
68     fi
69    
70     if [[ -n "${CABAL_USE_C2HS}" ]]; then
71     DEPEND="${DEPEND} dev-haskell/c2hs"
72     cabalconf="${cabalconf} --with-c2hs=/usr/bin/c2hs"
73     fi
74    
75     if [[ -n "${CABAL_USE_CPPHS}" ]]; then
76     DEPEND="${DEPEND} dev-haskell/cpphs"
77     cabalconf="${cabalconf} --with-cpphs=/usr/bin/cpphs"
78     fi
79    
80     if [[ -n "${CABAL_USE_PROFILE}" ]]; then
81     IUSE="${IUSE} profile"
82     fi
83    
84     # 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.
86     if [[ -z "${CABAL_BOOTSTRAP}" ]]; then
87     DEPEND="${DEPEND} >=dev-haskell/cabal-1.1.3"
88     fi
89    
90    
91     cabal-bootstrap() {
92     local setupmodule
93     local cabalversion
94     if [[ -f "${S}/Setup.lhs" ]]; then
95     setupmodule="${S}/Setup.lhs"
96     else
97     if [[ -f "${S}/Setup.hs" ]]; then
98     setupmodule="${S}/Setup.hs"
99     else
100     die "No Setup.lhs or Setup.hs found"
101     fi
102     fi
103    
104     # We build the setup program using the latest version of
105     # cabal that we have installed
106     cabalversion=$(ghc-bestcabalversion)
107     einfo "Using ${cabalversion}."
108     $(ghc-getghc) -package "${cabalversion}" --make "${setupmodule}" -o setup \
109     || die "compiling ${setupmodule} failed"
110     }
111    
112     cabal-haddock() {
113     ./setup haddock || die "setup haddock failed"
114     }
115    
116     cabal-configure() {
117     if [[ -n "${CABAL_USE_PROFILE}" ]] && use profile; then
118 dcoutts 1.2 cabalconf="${cabalconf} --enable-executable-profiling";
119     cabalconf="${cabalconf} --enable-library-profiling"
120 kosmikus 1.1 fi
121    
122     ./setup configure \
123     --ghc --prefix=/usr \
124     --with-compiler="$(ghc-getghc)" \
125     --with-hc-pkg="$(ghc-getghcpkg)" \
126     ${cabalconf} \
127     "$@" || die "setup configure failed"
128     }
129    
130     cabal-build() {
131     ./setup build \
132     || die "setup build failed"
133     }
134    
135     cabal-copy() {
136     ./setup copy \
137     --copy-prefix="${D}/usr" \
138     || die "setup copy failed"
139    
140     # cabal is a bit eager about creating dirs,
141     # so remove them if they are empty
142     rmdir "${D}/usr/bin" 2> /dev/null
143    
144     # GHC 6.4 has a bug in get/setPermission and Cabal 1.1.1 has
145     # no workaround.
146     # set the +x permission on executables
147     if [[ -d "${D}/usr/bin" ]] ; then
148     chmod +x "${D}/usr/bin/"*
149     fi
150     }
151    
152     cabal-pkg() {
153     # This does not actually register since we're using /usr/bin/true instead
154     # of ghc-pkg. So it just leaves the .installed-pkg-config and we can
155     # register that ourselves (if it exists).
156 dcoutts 1.2 local result
157     local err
158    
159 kosmikus 1.1 sed -i 's:ghc-pkg:/usr/bin/true:' .setup-config
160 dcoutts 1.2 result="$(./setup register 2>&1)"
161     err="$?"
162     if ! echo ${result} | grep -q "no library to register"; then
163     $(exit "${err}") || die "setup register failed"
164     fi
165 kosmikus 1.1 if [[ -f .installed-pkg-config ]]; then
166     ghc-setup-pkg .installed-pkg-config
167     ghc-install-pkg
168     fi
169     }
170    
171     # exported function: check if cabal is correctly installed for
172     # the currently active ghc (we cannot guarantee this with portage)
173     haskell-cabal_pkg_setup() {
174     if [[ -z "${CABAL_BOOTSTRAP}" ]] && ! ghc-sanecabal "1.1.3"; then
175     eerror "The package dev-haskell/cabal is not correctly installed for"
176     eerror "the currently active version of ghc ($(ghc-version)). Please"
177     eerror "run ghc-updater or re-emerge dev-haskell/cabal."
178     die "cabal is not correctly installed"
179     fi
180     }
181    
182     # exported function: cabal-style bootstrap configure and compile
183     cabal_src_compile() {
184     cabal-bootstrap
185     cabal-configure
186     cabal-build
187    
188     if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
189     cabal-haddock
190     fi
191     }
192     haskell-cabal_src_compile() {
193     cabal_src_compile
194     }
195    
196     # exported function: cabal-style copy and register
197     cabal_src_install() {
198     cabal-copy
199     cabal-pkg
200    
201     if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
202     dohtml dist/doc/html/*
203     fi
204     }
205     haskell-cabal_src_install() {
206     cabal_src_install
207     }
208    
209     EXPORT_FUNCTIONS pkg_setup src_compile src_install

  ViewVC Help
Powered by ViewVC 1.1.20