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