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

Contents of /eclass/haskell-cabal.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Thu Feb 16 12:32:53 2006 UTC (8 years, 6 months ago) by dcoutts
Branch: MAIN
Changes since 1.2: +13 -2 lines
Add "lib" and "bin" to known CABAL_FEATURES.
Also complain less about unknown values CABAL_FEATURES.

1 kosmikus 1.1 # Copyright 1999-2005 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 dcoutts 1.3 # $Header: /var/cvsroot/gentoo-x86/eclass/haskell-cabal.eclass,v 1.2 2005/12/05 12:24:53 dcoutts 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 dcoutts 1.3 # bin -- the package installs binaries
28     # lib -- the package installs libraries
29 kosmikus 1.1 #
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 dcoutts 1.3 bin) CABAL_HAS_BINARIES=yes;;
53     lib) CABAL_HAS_LIBRARIES=yes;;
54     *) CABAL_UNKNOWN="${CABAL_UNKNOWN} ${feature}";;
55 kosmikus 1.1 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 dcoutts 1.3 # Libraries require GHC to be installed.
95     if [[ -n "${CABAL_HAS_LIBRARIES}" ]]; then
96     RDEPEND="${RDEPEND} virtual/ghc"
97     fi
98 kosmikus 1.1
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 dcoutts 1.2 cabalconf="${cabalconf} --enable-executable-profiling";
127     cabalconf="${cabalconf} --enable-library-profiling"
128 kosmikus 1.1 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 dcoutts 1.2 local result
165     local err
166    
167 kosmikus 1.1 sed -i 's:ghc-pkg:/usr/bin/true:' .setup-config
168 dcoutts 1.2 result="$(./setup register 2>&1)"
169     err="$?"
170     if ! echo ${result} | grep -q "no library to register"; then
171     $(exit "${err}") || die "setup register failed"
172     fi
173 kosmikus 1.1 if [[ -f .installed-pkg-config ]]; then
174     ghc-setup-pkg .installed-pkg-config
175     ghc-install-pkg
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 dcoutts 1.3 if [[ -n "${CABAL_UNKNOWN}" ]]; then
189     ewarn "Unknown entry in CABAL_FEATURES: ${CABAL_UNKNONW}"
190     fi
191 kosmikus 1.1 }
192    
193     # exported function: cabal-style bootstrap configure and compile
194     cabal_src_compile() {
195     cabal-bootstrap
196     cabal-configure
197     cabal-build
198    
199     if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
200     cabal-haddock
201     fi
202     }
203     haskell-cabal_src_compile() {
204     cabal_src_compile
205     }
206    
207     # exported function: cabal-style copy and register
208     cabal_src_install() {
209     cabal-copy
210     cabal-pkg
211    
212     if [[ -n "${CABAL_USE_HADDOCK}" ]] && use doc; then
213     dohtml dist/doc/html/*
214     fi
215     }
216     haskell-cabal_src_install() {
217     cabal_src_install
218     }
219    
220     EXPORT_FUNCTIONS pkg_setup src_compile src_install

  ViewVC Help
Powered by ViewVC 1.1.20