| 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.2 2004/11/03 20:38:35 kosmikus Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/ghc-package.eclass,v 1.11 2005/05/11 21:26:04 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 | # promote /opt/ghc/bin to a better position in the search path |
|
|
16 | PATH="/usr/bin:/opt/ghc/bin:${PATH}" |
| 14 | |
17 | |
| 15 | # for later configuration using environment variables/ |
18 | # for later configuration using environment variables/ |
| 16 | # returns the name of the ghc executable |
19 | # returns the name of the ghc executable |
| 17 | ghc-getghc() { |
20 | ghc-getghc() { |
| 18 | echo "ghc" |
21 | echo "ghc" |
| … | |
… | |
| 23 | echo "ghc-pkg" |
26 | echo "ghc-pkg" |
| 24 | } |
27 | } |
| 25 | |
28 | |
| 26 | # returns the name of the ghc-pkg binary (ghc-pkg |
29 | # returns the name of the ghc-pkg binary (ghc-pkg |
| 27 | # itself usually is a shell script, and we have to |
30 | # itself usually is a shell script, and we have to |
| 28 | # bypass the script under certain circumstances) |
31 | # bypass the script under certain circumstances); |
|
|
32 | # for Cabal, we add the global package config file, |
|
|
33 | # because for some reason that's required |
| 29 | ghc-getghcpkgbin() { |
34 | ghc-getghcpkgbin() { |
|
|
35 | if ghc-cabal; then |
|
|
36 | echo $(ghc-libdir)/"ghc-pkg.bin" "--global-conf=$(ghc-libdir)/package.conf" |
|
|
37 | else |
| 30 | echo $(ghc-libdir)/"ghc-pkg.bin" |
38 | echo $(ghc-libdir)/"ghc-pkg.bin" |
|
|
39 | fi |
| 31 | } |
40 | } |
| 32 | |
41 | |
| 33 | # returns the version of ghc |
42 | # returns the version of ghc |
|
|
43 | _GHC_VERSION_CACHE="" |
| 34 | ghc-version() { |
44 | ghc-version() { |
|
|
45 | if [[ -z "${_GHC_VERSION_CACHE}" ]]; then |
| 35 | $(ghc-getghc) --version | sed 's:^.*version ::' |
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)" |
| 36 | } |
54 | } |
| 37 | |
55 | |
| 38 | # returns the library directory |
56 | # returns the library directory |
|
|
57 | _GHC_LIBDIR_CACHE="" |
| 39 | ghc-libdir() { |
58 | ghc-libdir() { |
| 40 | $(ghc-getghc) --print-libdir |
59 | if [[ -z "${_GHC_LIBDIR_CACHE}" ]]; then |
|
|
60 | _GHC_LIBDIR_CACHE="$($(ghc-getghc) --print-libdir)" |
|
|
61 | fi |
|
|
62 | echo "${_GHC_LIBDIR_CACHE}" |
| 41 | } |
63 | } |
| 42 | |
64 | |
| 43 | # returns the (Gentoo) library configuration directory |
65 | # returns the (Gentoo) library configuration directory |
| 44 | ghc-confdir() { |
66 | ghc-confdir() { |
| 45 | echo $(ghc-libdir)/gentoo |
67 | echo $(ghc-libdir)/gentoo |
| … | |
… | |
| 49 | # package configuration file |
71 | # package configuration file |
| 50 | ghc-localpkgconf() { |
72 | ghc-localpkgconf() { |
| 51 | echo "${PF}.conf" |
73 | echo "${PF}.conf" |
| 52 | } |
74 | } |
| 53 | |
75 | |
|
|
76 | # 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 | ld --relocatable --discard-all --output="${outfile}" --whole-archive $1 |
|
|
81 | } |
|
|
82 | |
| 54 | # creates an empty local (package-specific) package |
83 | # creates a local (package-specific) package |
| 55 | # configuration file |
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 |
| 56 | ghc-setup-pkg() { |
89 | ghc-setup-pkg() { |
|
|
90 | local localpkgconf |
|
|
91 | localpkgconf="${S}/$(ghc-localpkgconf)" |
| 57 | echo '[]' > ${S}/$(ghc-localpkgconf) |
92 | echo '[]' > ${localpkgconf} |
|
|
93 | for pkg in $*; do |
|
|
94 | $(ghc-getghcpkgbin) -f ${localpkgconf} -u --force \ |
|
|
95 | < ${pkg} || die "failed to register ${pkg}" |
|
|
96 | done |
|
|
97 | } |
|
|
98 | |
|
|
99 | # fixes the library and import directories path |
|
|
100 | # of the package configuration file |
|
|
101 | ghc-fixlibpath() { |
|
|
102 | sed -i "s|$1|$(ghc-libdir)|g" ${S}/$(ghc-localpkgconf) |
|
|
103 | if [[ -n "$2" ]]; then |
|
|
104 | sed -i "s|$2|$(ghc-libdir)/imports|g" ${S}/$(ghc-localpkgconf) |
|
|
105 | fi |
| 58 | } |
106 | } |
| 59 | |
107 | |
| 60 | # moves the local (package-specific) package configuration |
108 | # moves the local (package-specific) package configuration |
| 61 | # file to its final destination |
109 | # file to its final destination |
| 62 | ghc-install-pkg() { |
110 | ghc-install-pkg() { |
| 63 | mkdir -p ${D}/$(ghc-confdir) |
111 | mkdir -p ${D}/$(ghc-confdir) |
| 64 | cat ${S}/$(ghc-localpkgconf) | sed "s:${D}::" \ |
112 | cat ${S}/$(ghc-localpkgconf) | sed "s|${D}||g" \ |
| 65 | > ${D}/$(ghc-confdir)/$(ghc-localpkgconf) |
113 | > ${D}/$(ghc-confdir)/$(ghc-localpkgconf) |
| 66 | } |
114 | } |
| 67 | |
115 | |
| 68 | # registers all packages in the local (package-specific) |
116 | # registers all packages in the local (package-specific) |
| 69 | # package configuration file |
117 | # package configuration file |
| 70 | ghc-register-pkg() { |
118 | ghc-register-pkg() { |
| 71 | local localpkgconf |
119 | local localpkgconf |
| 72 | localpkgconf=$(ghc-confdir)/$1 |
120 | localpkgconf="$(ghc-confdir)/$1" |
|
|
121 | if [[ -f ${localpkgconf} ]]; then |
| 73 | for pkg in $(ghc-listpkg ${localpkgconf}); do |
122 | for pkg in $(ghc-listpkg ${localpkgconf}); do |
| 74 | einfo "Registering ${pkg} ..." |
123 | ebegin "Registering ${pkg} " |
| 75 | $(ghc-getghcpkgbin) -f ${localpkgconf} -s ${pkg} \ |
124 | $(ghc-getghcpkgbin) -f ${localpkgconf} -s ${pkg} \ |
| 76 | | $(ghc-getghcpkg) -u --force |
125 | | $(ghc-getghcpkg) -u --force > /dev/null |
|
|
126 | eend $? |
| 77 | done |
127 | done |
|
|
128 | fi |
| 78 | } |
129 | } |
| 79 | |
130 | |
| 80 | # re-adds all available .conf files to the global |
131 | # re-adds all available .conf files to the global |
| 81 | # package conf file, to be used on a ghc reinstallation |
132 | # package conf file, to be used on a ghc reinstallation |
| 82 | ghc-reregister() { |
133 | ghc-reregister() { |
| 83 | einfo "Re-adding packages ..." |
134 | einfo "Re-adding packages ..." |
| 84 | ewarn "This may cause several warnings, but they should be harmless." |
135 | einfo "(This may cause several warnings, but they should be harmless.)" |
|
|
136 | if [ -d "$(ghc-confdir)" ]; then |
| 85 | pushd $(ghc-confdir) |
137 | pushd $(ghc-confdir) > /dev/null |
| 86 | for conf in *.conf; do |
138 | for conf in *.conf; do |
| 87 | einfo "Processing ${conf} ..." |
139 | einfo "Processing ${conf} ..." |
| 88 | ghc-register-pkg ${conf} |
140 | ghc-register-pkg ${conf} |
| 89 | done |
141 | done |
| 90 | popd |
142 | popd > /dev/null |
|
|
143 | fi |
| 91 | } |
144 | } |
| 92 | |
145 | |
| 93 | # unregisters ... |
146 | # unregisters ... |
| 94 | ghc-unregister-pkg() { |
147 | ghc-unregister-pkg() { |
| 95 | local localpkgconf |
148 | local localpkgconf |
| 96 | localpkgconf=$(ghc-confdir)/$1 |
149 | localpkgconf="$(ghc-confdir)/$1" |
|
|
150 | if [[ -f ${localpkgconf} ]]; then |
| 97 | for pkg in $(ghc-reverse "$(ghc-listpkg ${localpkgconf})"); do |
151 | for pkg in $(ghc-reverse "$(ghc-listpkg ${localpkgconf})"); do |
| 98 | einfo "Unregistering ${pkg} ..." |
152 | ebegin "Unregistering ${pkg} " |
| 99 | $(ghc-getghcpkg) -r ${pkg} --force |
153 | $(ghc-getghcpkg) -r ${pkg} --force > /dev/null |
|
|
154 | eend $? |
| 100 | done |
155 | done |
|
|
156 | fi |
| 101 | } |
157 | } |
| 102 | |
158 | |
| 103 | # help-function: reverse a list |
159 | # help-function: reverse a list |
| 104 | ghc-reverse() { |
160 | ghc-reverse() { |
| 105 | local result |
161 | local result |
| … | |
… | |
| 109 | echo ${result} |
165 | echo ${result} |
| 110 | } |
166 | } |
| 111 | |
167 | |
| 112 | # show the packages in a package configuration file |
168 | # show the packages in a package configuration file |
| 113 | ghc-listpkg() { |
169 | ghc-listpkg() { |
|
|
170 | local ghcpkgcall |
|
|
171 | if ghc-cabal; then |
|
|
172 | echo $($(ghc-getghcpkg) list -f $1) \ |
|
|
173 | | sed \ |
|
|
174 | -e "s|^.*${f}:\([^:]*\).*$|\1|" \ |
|
|
175 | -e "s|/.*$||" \ |
|
|
176 | -e "s|,| |g" -e "s|[()]||g" |
|
|
177 | else |
| 114 | [ -f $1 ] && echo $($(ghc-getghcpkgbin) -l -f $1) \ |
178 | echo $($(ghc-getghcpkgbin) -l -f $1) \ |
| 115 | | cut -f2 -d':' \ |
179 | | cut -f2 -d':' \ |
| 116 | | sed 's:,: :g' |
180 | | sed 's:,: :g' |
|
|
181 | fi |
| 117 | } |
182 | } |
| 118 | |
183 | |
| 119 | # exported function: registers the package-specific package |
184 | # exported function: registers the package-specific package |
| 120 | # configuration file |
185 | # configuration file |
| 121 | ghc-package_pkg_postinst() { |
186 | ghc-package_pkg_postinst() { |