| 1 |
kosmikus |
1.1 |
# Copyright 1999-2004 Gentoo Foundation
|
| 2 |
|
|
# Distributed under the terms of the GNU General Public License v2
|
| 3 |
kosmikus |
1.4 |
# $Header: /var/cvsroot/gentoo-x86/eclass/ghc-package.eclass,v 1.3 2004/11/04 13:13:59 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 |
|
|
ECLASS="ghc-package"
|
| 11 |
|
|
INHERITED="$INHERITED $ECLASS"
|
| 12 |
|
|
|
| 13 |
|
|
PATH="${PATH}:/opt/ghc/bin"
|
| 14 |
|
|
|
| 15 |
|
|
# for later configuration using environment variables/
|
| 16 |
|
|
# returns the name of the ghc executable
|
| 17 |
|
|
ghc-getghc() {
|
| 18 |
|
|
echo "ghc"
|
| 19 |
|
|
}
|
| 20 |
|
|
|
| 21 |
|
|
# returns the name of the ghc-pkg executable
|
| 22 |
|
|
ghc-getghcpkg() {
|
| 23 |
|
|
echo "ghc-pkg"
|
| 24 |
|
|
}
|
| 25 |
|
|
|
| 26 |
|
|
# returns the name of the ghc-pkg binary (ghc-pkg
|
| 27 |
|
|
# itself usually is a shell script, and we have to
|
| 28 |
|
|
# bypass the script under certain circumstances)
|
| 29 |
|
|
ghc-getghcpkgbin() {
|
| 30 |
|
|
echo $(ghc-libdir)/"ghc-pkg.bin"
|
| 31 |
|
|
}
|
| 32 |
|
|
|
| 33 |
|
|
# returns the version of ghc
|
| 34 |
|
|
ghc-version() {
|
| 35 |
|
|
$(ghc-getghc) --version | sed 's:^.*version ::'
|
| 36 |
|
|
}
|
| 37 |
|
|
|
| 38 |
|
|
# returns the library directory
|
| 39 |
|
|
ghc-libdir() {
|
| 40 |
|
|
$(ghc-getghc) --print-libdir
|
| 41 |
|
|
}
|
| 42 |
|
|
|
| 43 |
|
|
# returns the (Gentoo) library configuration directory
|
| 44 |
|
|
ghc-confdir() {
|
| 45 |
|
|
echo $(ghc-libdir)/gentoo
|
| 46 |
|
|
}
|
| 47 |
|
|
|
| 48 |
|
|
# returns the name of the local (package-specific)
|
| 49 |
|
|
# package configuration file
|
| 50 |
|
|
ghc-localpkgconf() {
|
| 51 |
|
|
echo "${PF}.conf"
|
| 52 |
|
|
}
|
| 53 |
|
|
|
| 54 |
kosmikus |
1.3 |
# make a ghci foo.o file from a libfoo.a file
|
| 55 |
|
|
ghc-makeghcilib() {
|
| 56 |
|
|
local outfile
|
| 57 |
|
|
outfile="$(dirname $1)/$(basename $1 | sed 's:^lib\?\(.*\)\.a$:\1.o:')"
|
| 58 |
kosmikus |
1.4 |
ld --relocatable --discard-all --output="${outfile}" --whole-archive $1
|
| 59 |
kosmikus |
1.3 |
}
|
| 60 |
|
|
|
| 61 |
|
|
# creates a local (package-specific) package
|
| 62 |
|
|
# configuration file; the arguments should be
|
| 63 |
|
|
# uninstalled package description files, each
|
| 64 |
|
|
# containing a single package description; if
|
| 65 |
|
|
# no arguments are given, the resulting file is
|
| 66 |
|
|
# empty
|
| 67 |
kosmikus |
1.1 |
ghc-setup-pkg() {
|
| 68 |
kosmikus |
1.3 |
local localpkgconf
|
| 69 |
|
|
localpkgconf="${S}/$(ghc-localpkgconf)"
|
| 70 |
|
|
echo '[' > ${localpkgconf}
|
| 71 |
|
|
while [ -n "$1" ]; do
|
| 72 |
|
|
cat "$1" >> ${localpkgconf}
|
| 73 |
|
|
shift
|
| 74 |
|
|
[ -n "$1" ] && echo ',' >> ${localpkgconf}
|
| 75 |
|
|
done
|
| 76 |
|
|
echo ']' >> ${localpkgconf}
|
| 77 |
kosmikus |
1.1 |
}
|
| 78 |
|
|
|
| 79 |
|
|
# moves the local (package-specific) package configuration
|
| 80 |
|
|
# file to its final destination
|
| 81 |
|
|
ghc-install-pkg() {
|
| 82 |
|
|
mkdir -p ${D}/$(ghc-confdir)
|
| 83 |
|
|
cat ${S}/$(ghc-localpkgconf) | sed "s:${D}::" \
|
| 84 |
|
|
> ${D}/$(ghc-confdir)/$(ghc-localpkgconf)
|
| 85 |
|
|
}
|
| 86 |
|
|
|
| 87 |
|
|
# registers all packages in the local (package-specific)
|
| 88 |
|
|
# package configuration file
|
| 89 |
|
|
ghc-register-pkg() {
|
| 90 |
|
|
local localpkgconf
|
| 91 |
kosmikus |
1.3 |
localpkgconf="$(ghc-confdir)/$1"
|
| 92 |
kosmikus |
1.1 |
for pkg in $(ghc-listpkg ${localpkgconf}); do
|
| 93 |
|
|
einfo "Registering ${pkg} ..."
|
| 94 |
|
|
$(ghc-getghcpkgbin) -f ${localpkgconf} -s ${pkg} \
|
| 95 |
kosmikus |
1.2 |
| $(ghc-getghcpkg) -u --force
|
| 96 |
kosmikus |
1.1 |
done
|
| 97 |
|
|
}
|
| 98 |
|
|
|
| 99 |
|
|
# re-adds all available .conf files to the global
|
| 100 |
|
|
# package conf file, to be used on a ghc reinstallation
|
| 101 |
|
|
ghc-reregister() {
|
| 102 |
|
|
einfo "Re-adding packages ..."
|
| 103 |
|
|
ewarn "This may cause several warnings, but they should be harmless."
|
| 104 |
|
|
pushd $(ghc-confdir)
|
| 105 |
|
|
for conf in *.conf; do
|
| 106 |
|
|
einfo "Processing ${conf} ..."
|
| 107 |
|
|
ghc-register-pkg ${conf}
|
| 108 |
|
|
done
|
| 109 |
|
|
popd
|
| 110 |
|
|
}
|
| 111 |
|
|
|
| 112 |
|
|
# unregisters ...
|
| 113 |
|
|
ghc-unregister-pkg() {
|
| 114 |
|
|
local localpkgconf
|
| 115 |
kosmikus |
1.3 |
localpkgconf="$(ghc-confdir)/$1"
|
| 116 |
kosmikus |
1.1 |
for pkg in $(ghc-reverse "$(ghc-listpkg ${localpkgconf})"); do
|
| 117 |
|
|
einfo "Unregistering ${pkg} ..."
|
| 118 |
|
|
$(ghc-getghcpkg) -r ${pkg} --force
|
| 119 |
|
|
done
|
| 120 |
|
|
}
|
| 121 |
|
|
|
| 122 |
|
|
# help-function: reverse a list
|
| 123 |
|
|
ghc-reverse() {
|
| 124 |
|
|
local result
|
| 125 |
|
|
for i in $1; do
|
| 126 |
|
|
result="${i} ${result}"
|
| 127 |
|
|
done
|
| 128 |
|
|
echo ${result}
|
| 129 |
|
|
}
|
| 130 |
|
|
|
| 131 |
|
|
# show the packages in a package configuration file
|
| 132 |
|
|
ghc-listpkg() {
|
| 133 |
|
|
[ -f $1 ] && echo $($(ghc-getghcpkgbin) -l -f $1) \
|
| 134 |
|
|
| cut -f2 -d':' \
|
| 135 |
|
|
| sed 's:,: :g'
|
| 136 |
|
|
}
|
| 137 |
|
|
|
| 138 |
|
|
# exported function: registers the package-specific package
|
| 139 |
|
|
# configuration file
|
| 140 |
|
|
ghc-package_pkg_postinst() {
|
| 141 |
|
|
ghc-register-pkg $(ghc-localpkgconf)
|
| 142 |
|
|
}
|
| 143 |
|
|
|
| 144 |
|
|
# exported function: unregisters the package-specific
|
| 145 |
|
|
# package configuration file, under the condition that
|
| 146 |
|
|
# after removal, no other instances of the package will
|
| 147 |
|
|
# be left (necessary check because ghc packages are not
|
| 148 |
|
|
# versioned)
|
| 149 |
|
|
ghc-package_pkg_prerm() {
|
| 150 |
|
|
has_version "<${CATEGORY}/${PF}" || has_version ">${CATEGORY}/${PF}" \
|
| 151 |
|
|
|| ghc-unregister-pkg $(ghc-localpkgconf)
|
| 152 |
|
|
}
|
| 153 |
|
|
|
| 154 |
|
|
EXPORT_FUNCTIONS pkg_postinst pkg_prerm
|