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