| 1 | # Copyright 1999-2004 Gentoo Foundation |
1 | # Copyright 1999-2004 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/ghc-package.eclass,v 1.3 2004/11/04 13:13:59 kosmikus Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/ghc-package.eclass,v 1.6 2005/03/18 23:31:48 kosmikus Exp $ |
| 4 | # |
4 | # |
| 5 | # Author: Andres Loeh <kosmikus@gentoo.org> |
5 | # Author: Andres Loeh <kosmikus@gentoo.org> |
| 6 | # |
6 | # |
| 7 | # This eclass helps with the Glasgow Haskell Compiler's package |
7 | # This eclass helps with the Glasgow Haskell Compiler's package |
| 8 | # configuration utility. |
8 | # configuration utility. |
| 9 | |
9 | |
|
|
10 | inherit versionator |
|
|
11 | |
| 10 | ECLASS="ghc-package" |
12 | ECLASS="ghc-package" |
| 11 | INHERITED="$INHERITED $ECLASS" |
13 | INHERITED="${INHERITED} ${ECLASS}" |
| 12 | |
14 | |
| 13 | PATH="${PATH}:/opt/ghc/bin" |
15 | PATH="${PATH}:/opt/ghc/bin" |
| 14 | |
16 | |
| 15 | # for later configuration using environment variables/ |
17 | # for later configuration using environment variables/ |
| 16 | # returns the name of the ghc executable |
18 | # returns the name of the ghc executable |
| … | |
… | |
| 23 | echo "ghc-pkg" |
25 | echo "ghc-pkg" |
| 24 | } |
26 | } |
| 25 | |
27 | |
| 26 | # returns the name of the ghc-pkg binary (ghc-pkg |
28 | # returns the name of the ghc-pkg binary (ghc-pkg |
| 27 | # itself usually is a shell script, and we have to |
29 | # itself usually is a shell script, and we have to |
| 28 | # bypass the script under certain circumstances) |
30 | # bypass the script under certain circumstances); |
|
|
31 | # for Cabal, we add the global package config file, |
|
|
32 | # because for some reason that's required |
| 29 | ghc-getghcpkgbin() { |
33 | ghc-getghcpkgbin() { |
|
|
34 | if ghc-cabal; then |
|
|
35 | echo $(ghc-libdir)/"ghc-pkg.bin" "--global-conf=$(ghc-libdir)/package.conf" |
|
|
36 | else |
| 30 | echo $(ghc-libdir)/"ghc-pkg.bin" |
37 | echo $(ghc-libdir)/"ghc-pkg.bin" |
|
|
38 | fi |
| 31 | } |
39 | } |
| 32 | |
40 | |
| 33 | # returns the version of ghc |
41 | # returns the version of ghc |
|
|
42 | _GHC_VERSION_CACHE="" |
| 34 | ghc-version() { |
43 | ghc-version() { |
|
|
44 | if [[ -z "${_GHC_VERSION_CACHE}" ]]; then |
| 35 | $(ghc-getghc) --version | sed 's:^.*version ::' |
45 | _GHC_VERSION_CACHE="$($(ghc-getghc) --version | sed 's:^.*version ::')" |
|
|
46 | fi |
|
|
47 | echo "${_GHC_VERSION_CACHE}" |
|
|
48 | } |
|
|
49 | |
|
|
50 | # returns true for ghc >= 6.4 |
|
|
51 | ghc-cabal() { |
|
|
52 | version_is_at_least "6.4" "$(ghc-version)" |
| 36 | } |
53 | } |
| 37 | |
54 | |
| 38 | # returns the library directory |
55 | # returns the library directory |
|
|
56 | _GHC_LIBDIR_CACHE="" |
| 39 | ghc-libdir() { |
57 | ghc-libdir() { |
| 40 | $(ghc-getghc) --print-libdir |
58 | if [[ -z "${_GHC_LIBDIR_CACHE}" ]]; then |
|
|
59 | _GHC_LIBDIR_CACHE="$($(ghc-getghc) --print-libdir)" |
|
|
60 | fi |
|
|
61 | echo "${_GHC_LIBDIR_CACHE}" |
| 41 | } |
62 | } |
| 42 | |
63 | |
| 43 | # returns the (Gentoo) library configuration directory |
64 | # returns the (Gentoo) library configuration directory |
| 44 | ghc-confdir() { |
65 | ghc-confdir() { |
| 45 | echo $(ghc-libdir)/gentoo |
66 | echo $(ghc-libdir)/gentoo |
| … | |
… | |
| 53 | |
74 | |
| 54 | # make a ghci foo.o file from a libfoo.a file |
75 | # make a ghci foo.o file from a libfoo.a file |
| 55 | ghc-makeghcilib() { |
76 | ghc-makeghcilib() { |
| 56 | local outfile |
77 | local outfile |
| 57 | outfile="$(dirname $1)/$(basename $1 | sed 's:^lib\?\(.*\)\.a$:\1.o:')" |
78 | outfile="$(dirname $1)/$(basename $1 | sed 's:^lib\?\(.*\)\.a$:\1.o:')" |
| 58 | ld --relocatable --discard-all --output="${outfile}" $1 |
79 | ld --relocatable --discard-all --output="${outfile}" --whole-archive $1 |
| 59 | } |
80 | } |
| 60 | |
81 | |
| 61 | # creates a local (package-specific) package |
82 | # creates a local (package-specific) package |
| 62 | # configuration file; the arguments should be |
83 | # configuration file; the arguments should be |
| 63 | # uninstalled package description files, each |
84 | # uninstalled package description files, each |
| … | |
… | |
| 99 | # re-adds all available .conf files to the global |
120 | # re-adds all available .conf files to the global |
| 100 | # package conf file, to be used on a ghc reinstallation |
121 | # package conf file, to be used on a ghc reinstallation |
| 101 | ghc-reregister() { |
122 | ghc-reregister() { |
| 102 | einfo "Re-adding packages ..." |
123 | einfo "Re-adding packages ..." |
| 103 | ewarn "This may cause several warnings, but they should be harmless." |
124 | ewarn "This may cause several warnings, but they should be harmless." |
|
|
125 | if [ -d "$(ghc-confdir)" ]; then |
| 104 | pushd $(ghc-confdir) |
126 | pushd $(ghc-confdir) |
| 105 | for conf in *.conf; do |
127 | for conf in *.conf; do |
| 106 | einfo "Processing ${conf} ..." |
128 | einfo "Processing ${conf} ..." |
| 107 | ghc-register-pkg ${conf} |
129 | ghc-register-pkg ${conf} |
| 108 | done |
130 | done |
| 109 | popd |
131 | popd |
|
|
132 | fi |
| 110 | } |
133 | } |
| 111 | |
134 | |
| 112 | # unregisters ... |
135 | # unregisters ... |
| 113 | ghc-unregister-pkg() { |
136 | ghc-unregister-pkg() { |
| 114 | local localpkgconf |
137 | local localpkgconf |
| … | |
… | |
| 128 | echo ${result} |
151 | echo ${result} |
| 129 | } |
152 | } |
| 130 | |
153 | |
| 131 | # show the packages in a package configuration file |
154 | # show the packages in a package configuration file |
| 132 | ghc-listpkg() { |
155 | ghc-listpkg() { |
|
|
156 | local ghcpkgcall |
|
|
157 | if ghc-cabal; then |
|
|
158 | echo $($(ghc-getghcpkg) list -f $1) \ |
|
|
159 | | sed \ |
|
|
160 | -e "s|^.*${f}:\([^:]*\).*$|\1|" \ |
|
|
161 | -e "s|/.*$||" \ |
|
|
162 | -e "s|,| |g" -e "s|[()]||g" |
|
|
163 | else |
| 133 | [ -f $1 ] && echo $($(ghc-getghcpkgbin) -l -f $1) \ |
164 | echo $($(ghc-getghcpkgbin) -l -f $1) \ |
| 134 | | cut -f2 -d':' \ |
165 | | cut -f2 -d':' \ |
| 135 | | sed 's:,: :g' |
166 | | sed 's:,: :g' |
|
|
167 | fi |
| 136 | } |
168 | } |
| 137 | |
169 | |
| 138 | # exported function: registers the package-specific package |
170 | # exported function: registers the package-specific package |
| 139 | # configuration file |
171 | # configuration file |
| 140 | ghc-package_pkg_postinst() { |
172 | ghc-package_pkg_postinst() { |