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

Contents of /eclass/haskell-cabal.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (hide annotations) (download)
Mon Jan 15 13:58:13 2007 UTC (7 years, 8 months ago) by kosmikus
Branch: MAIN
Changes since 1.8: +3 -2 lines
detect true rather than assume its location; should fix bug #161937

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

  ViewVC Help
Powered by ViewVC 1.1.20