| 1 |
kosmikus |
1.1 |
# Copyright 1999-2004 Gentoo Foundation
|
| 2 |
|
|
# Distributed under the terms of the GNU General Public License v2
|
| 3 |
kosmikus |
1.8 |
# $Header: /var/cvsroot/gentoo-x86/eclass/ghc-package.eclass,v 1.7 2005/03/23 13:55:06 kosmikus Exp $
|
| 4 |
kosmikus |
1.1 |
#
|
| 5 |
|
|
# Author: Andres Loeh <kosmikus@gentoo.org>
|
| 6 |
|
|
#
|
| 7 |
|
|
# This eclass helps with the Glasgow Haskell Compiler's package
|
| 8 |
|
|
# configuration utility.
|
| 9 |
|
|
|
| 10 |
kosmikus |
1.6 |
inherit versionator
|
| 11 |
|
|
|
| 12 |
kosmikus |
1.1 |
ECLASS="ghc-package"
|
| 13 |
kosmikus |
1.6 |
INHERITED="${INHERITED} ${ECLASS}"
|
| 14 |
kosmikus |
1.1 |
|
| 15 |
kosmikus |
1.7 |
# promote /opt/ghc/bin to a better position in the search path
|
| 16 |
|
|
PATH="/usr/bin:/opt/ghc/bin:${PATH}"
|
| 17 |
kosmikus |
1.1 |
|
| 18 |
|
|
# for later configuration using environment variables/
|
| 19 |
|
|
# returns the name of the ghc executable
|
| 20 |
|
|
ghc-getghc() {
|
| 21 |
|
|
echo "ghc"
|
| 22 |
|
|
}
|
| 23 |
|
|
|
| 24 |
|
|
# returns the name of the ghc-pkg executable
|
| 25 |
|
|
ghc-getghcpkg() {
|
| 26 |
|
|
echo "ghc-pkg"
|
| 27 |
|
|
}
|
| 28 |
|
|
|
| 29 |
|
|
# returns the name of the ghc-pkg binary (ghc-pkg
|
| 30 |
|
|
# itself usually is a shell script, and we have to
|
| 31 |
kosmikus |
1.6 |
# bypass the script under certain circumstances);
|
| 32 |
|
|
# for Cabal, we add the global package config file,
|
| 33 |
|
|
# because for some reason that's required
|
| 34 |
kosmikus |
1.1 |
ghc-getghcpkgbin() {
|
| 35 |
kosmikus |
1.6 |
if ghc-cabal; then
|
| 36 |
|
|
echo $(ghc-libdir)/"ghc-pkg.bin" "--global-conf=$(ghc-libdir)/package.conf"
|
| 37 |
|
|
else
|
| 38 |
|
|
echo $(ghc-libdir)/"ghc-pkg.bin"
|
| 39 |
|
|
fi
|
| 40 |
kosmikus |
1.1 |
}
|
| 41 |
|
|
|
| 42 |
|
|
# returns the version of ghc
|
| 43 |
kosmikus |
1.6 |
_GHC_VERSION_CACHE=""
|
| 44 |
kosmikus |
1.1 |
ghc-version() {
|
| 45 |
kosmikus |
1.6 |
if [[ -z "${_GHC_VERSION_CACHE}" ]]; then
|
| 46 |
|
|
_GHC_VERSION_CACHE="$($(ghc-getghc) --version | sed 's:^.*version ::')"
|
| 47 |
|
|
fi
|
| 48 |
|
|
echo "${_GHC_VERSION_CACHE}"
|
| 49 |
|
|
}
|
| 50 |
|
|
|
| 51 |
|
|
# returns true for ghc >= 6.4
|
| 52 |
|
|
ghc-cabal() {
|
| 53 |
|
|
version_is_at_least "6.4" "$(ghc-version)"
|
| 54 |
kosmikus |
1.1 |
}
|
| 55 |
|
|
|
| 56 |
|
|
# returns the library directory
|
| 57 |
kosmikus |
1.6 |
_GHC_LIBDIR_CACHE=""
|
| 58 |
kosmikus |
1.1 |
ghc-libdir() {
|
| 59 |
kosmikus |
1.6 |
if [[ -z "${_GHC_LIBDIR_CACHE}" ]]; then
|
| 60 |
|
|
_GHC_LIBDIR_CACHE="$($(ghc-getghc) --print-libdir)"
|
| 61 |
|
|
fi
|
| 62 |
|
|
echo "${_GHC_LIBDIR_CACHE}"
|
| 63 |
kosmikus |
1.1 |
}
|
| 64 |
|
|
|
| 65 |
|
|
# returns the (Gentoo) library configuration directory
|
| 66 |
|
|
ghc-confdir() {
|
| 67 |
|
|
echo $(ghc-libdir)/gentoo
|
| 68 |
|
|
}
|
| 69 |
|
|
|
| 70 |
|
|
# returns the name of the local (package-specific)
|
| 71 |
|
|
# package configuration file
|
| 72 |
|
|
ghc-localpkgconf() {
|
| 73 |
|
|
echo "${PF}.conf"
|
| 74 |
|
|
}
|
| 75 |
|
|
|
| 76 |
kosmikus |
1.3 |
# make a ghci foo.o file from a libfoo.a file
|
| 77 |
|
|
ghc-makeghcilib() {
|
| 78 |
|
|
local outfile
|
| 79 |
|
|
outfile="$(dirname $1)/$(basename $1 | sed 's:^lib\?\(.*\)\.a$:\1.o:')"
|
| 80 |
kosmikus |
1.4 |
ld --relocatable --discard-all --output="${outfile}" --whole-archive $1
|
| 81 |
kosmikus |
1.3 |
}
|
| 82 |
|
|
|
| 83 |
|
|
# creates a local (package-specific) package
|
| 84 |
|
|
# configuration file; the arguments should be
|
| 85 |
|
|
# uninstalled package description files, each
|
| 86 |
|
|
# containing a single package description; if
|
| 87 |
|
|
# no arguments are given, the resulting file is
|
| 88 |
|
|
# empty
|
| 89 |
kosmikus |
1.1 |
ghc-setup-pkg() {
|
| 90 |
kosmikus |
1.3 |
local localpkgconf
|
| 91 |
|
|
localpkgconf="${S}/$(ghc-localpkgconf)"
|
| 92 |
|
|
echo '[' > ${localpkgconf}
|
| 93 |
|
|
while [ -n "$1" ]; do
|
| 94 |
|
|
cat "$1" >> ${localpkgconf}
|
| 95 |
|
|
shift
|
| 96 |
|
|
[ -n "$1" ] && echo ',' >> ${localpkgconf}
|
| 97 |
|
|
done
|
| 98 |
|
|
echo ']' >> ${localpkgconf}
|
| 99 |
kosmikus |
1.1 |
}
|
| 100 |
|
|
|
| 101 |
|
|
# moves the local (package-specific) package configuration
|
| 102 |
|
|
# file to its final destination
|
| 103 |
|
|
ghc-install-pkg() {
|
| 104 |
|
|
mkdir -p ${D}/$(ghc-confdir)
|
| 105 |
|
|
cat ${S}/$(ghc-localpkgconf) | sed "s:${D}::" \
|
| 106 |
|
|
> ${D}/$(ghc-confdir)/$(ghc-localpkgconf)
|
| 107 |
|
|
}
|
| 108 |
|
|
|
| 109 |
|
|
# registers all packages in the local (package-specific)
|
| 110 |
|
|
# package configuration file
|
| 111 |
|
|
ghc-register-pkg() {
|
| 112 |
|
|
local localpkgconf
|
| 113 |
kosmikus |
1.3 |
localpkgconf="$(ghc-confdir)/$1"
|
| 114 |
kosmikus |
1.7 |
if [[ -f ${localpkgconf} ]]; then
|
| 115 |
|
|
for pkg in $(ghc-listpkg ${localpkgconf}); do
|
| 116 |
kosmikus |
1.8 |
ebegin "Registering ${pkg} "
|
| 117 |
kosmikus |
1.7 |
$(ghc-getghcpkgbin) -f ${localpkgconf} -s ${pkg} \
|
| 118 |
kosmikus |
1.8 |
| $(ghc-getghcpkg) -u --force > /dev/null
|
| 119 |
|
|
eend $?
|
| 120 |
kosmikus |
1.7 |
done
|
| 121 |
|
|
fi
|
| 122 |
kosmikus |
1.1 |
}
|
| 123 |
|
|
|
| 124 |
|
|
# re-adds all available .conf files to the global
|
| 125 |
|
|
# package conf file, to be used on a ghc reinstallation
|
| 126 |
|
|
ghc-reregister() {
|
| 127 |
|
|
einfo "Re-adding packages ..."
|
| 128 |
kosmikus |
1.8 |
einfo "(This may cause several warnings, but they should be harmless.)"
|
| 129 |
kosmikus |
1.5 |
if [ -d "$(ghc-confdir)" ]; then
|
| 130 |
kosmikus |
1.8 |
pushd $(ghc-confdir) > /dev/null
|
| 131 |
kosmikus |
1.5 |
for conf in *.conf; do
|
| 132 |
|
|
einfo "Processing ${conf} ..."
|
| 133 |
|
|
ghc-register-pkg ${conf}
|
| 134 |
|
|
done
|
| 135 |
kosmikus |
1.8 |
popd > /dev/null
|
| 136 |
kosmikus |
1.5 |
fi
|
| 137 |
kosmikus |
1.1 |
}
|
| 138 |
|
|
|
| 139 |
|
|
# unregisters ...
|
| 140 |
|
|
ghc-unregister-pkg() {
|
| 141 |
|
|
local localpkgconf
|
| 142 |
kosmikus |
1.3 |
localpkgconf="$(ghc-confdir)/$1"
|
| 143 |
kosmikus |
1.7 |
if [[ -f ${localpkgconf} ]]; then
|
| 144 |
|
|
for pkg in $(ghc-reverse "$(ghc-listpkg ${localpkgconf})"); do
|
| 145 |
kosmikus |
1.8 |
ebegin "Unregistering ${pkg} "
|
| 146 |
|
|
$(ghc-getghcpkg) -r ${pkg} --force > /dev/null
|
| 147 |
|
|
eend $?
|
| 148 |
kosmikus |
1.7 |
done
|
| 149 |
|
|
fi
|
| 150 |
kosmikus |
1.1 |
}
|
| 151 |
|
|
|
| 152 |
|
|
# help-function: reverse a list
|
| 153 |
|
|
ghc-reverse() {
|
| 154 |
|
|
local result
|
| 155 |
|
|
for i in $1; do
|
| 156 |
|
|
result="${i} ${result}"
|
| 157 |
|
|
done
|
| 158 |
|
|
echo ${result}
|
| 159 |
|
|
}
|
| 160 |
|
|
|
| 161 |
|
|
# show the packages in a package configuration file
|
| 162 |
|
|
ghc-listpkg() {
|
| 163 |
kosmikus |
1.6 |
local ghcpkgcall
|
| 164 |
|
|
if ghc-cabal; then
|
| 165 |
|
|
echo $($(ghc-getghcpkg) list -f $1) \
|
| 166 |
|
|
| sed \
|
| 167 |
|
|
-e "s|^.*${f}:\([^:]*\).*$|\1|" \
|
| 168 |
|
|
-e "s|/.*$||" \
|
| 169 |
|
|
-e "s|,| |g" -e "s|[()]||g"
|
| 170 |
|
|
else
|
| 171 |
|
|
echo $($(ghc-getghcpkgbin) -l -f $1) \
|
| 172 |
kosmikus |
1.1 |
| cut -f2 -d':' \
|
| 173 |
|
|
| sed 's:,: :g'
|
| 174 |
kosmikus |
1.6 |
fi
|
| 175 |
kosmikus |
1.1 |
}
|
| 176 |
|
|
|
| 177 |
|
|
# exported function: registers the package-specific package
|
| 178 |
|
|
# configuration file
|
| 179 |
|
|
ghc-package_pkg_postinst() {
|
| 180 |
|
|
ghc-register-pkg $(ghc-localpkgconf)
|
| 181 |
|
|
}
|
| 182 |
|
|
|
| 183 |
|
|
# exported function: unregisters the package-specific
|
| 184 |
|
|
# package configuration file, under the condition that
|
| 185 |
|
|
# after removal, no other instances of the package will
|
| 186 |
|
|
# be left (necessary check because ghc packages are not
|
| 187 |
|
|
# versioned)
|
| 188 |
|
|
ghc-package_pkg_prerm() {
|
| 189 |
|
|
has_version "<${CATEGORY}/${PF}" || has_version ">${CATEGORY}/${PF}" \
|
| 190 |
|
|
|| ghc-unregister-pkg $(ghc-localpkgconf)
|
| 191 |
|
|
}
|
| 192 |
|
|
|
| 193 |
|
|
EXPORT_FUNCTIONS pkg_postinst pkg_prerm
|