| 1 | # Copyright 1999-2004 Gentoo Foundation |
1 | # Copyright 1999-2012 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.13 2005/07/06 20:23:20 agriffis Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/ghc-package.eclass,v 1.35 2012/11/16 15:47:17 slyfox Exp $ |
| 4 | # |
4 | |
|
|
5 | # @ECLASS: ghc-package.eclass |
|
|
6 | # @MAINTAINER: |
|
|
7 | # "Gentoo's Haskell Language team" <haskell@gentoo.org> |
|
|
8 | # @AUTHOR: |
| 5 | # Author: Andres Loeh <kosmikus@gentoo.org> |
9 | # Original Author: Andres Loeh <kosmikus@gentoo.org> |
| 6 | # |
|
|
| 7 | # This eclass helps with the Glasgow Haskell Compiler's package |
10 | # @BLURB: This eclass helps with the Glasgow Haskell Compiler's package configuration utility. |
| 8 | # configuration utility. |
11 | # @DESCRIPTION: |
|
|
12 | # Helper eclass to handle ghc installation/upgrade/deinstallation process. |
| 9 | |
13 | |
| 10 | inherit versionator |
14 | inherit versionator |
| 11 | |
15 | |
| 12 | |
16 | # @FUNCTION: ghc-getghc |
| 13 | # promote /opt/ghc/bin to a better position in the search path |
17 | # @DESCRIPTION: |
| 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 | # returns the name of the ghc executable |
| 18 | ghc-getghc() { |
19 | ghc-getghc() { |
| 19 | echo "ghc" |
20 | type -P ghc |
| 20 | } |
21 | } |
| 21 | |
22 | |
|
|
23 | # @FUNCTION: ghc-getghcpkg |
|
|
24 | # @DESCRIPTION: |
| 22 | # returns the name of the ghc-pkg executable |
25 | # Internal function determines returns the name of the ghc-pkg executable |
| 23 | ghc-getghcpkg() { |
26 | ghc-getghcpkg() { |
| 24 | echo "ghc-pkg" |
27 | type -P ghc-pkg |
| 25 | } |
28 | } |
| 26 | |
29 | |
|
|
30 | # @FUNCTION: ghc-getghcpkgbin |
|
|
31 | # @DESCRIPTION: |
| 27 | # returns the name of the ghc-pkg binary (ghc-pkg |
32 | # returns the name of the ghc-pkg binary (ghc-pkg |
| 28 | # itself usually is a shell script, and we have to |
33 | # itself usually is a shell script, and we have to |
| 29 | # bypass the script under certain circumstances); |
34 | # bypass the script under certain circumstances); |
| 30 | # for Cabal, we add the global package config file, |
35 | # for Cabal, we add an empty global package config file, |
| 31 | # because for some reason that's required |
36 | # because for some reason the global package file |
|
|
37 | # must be specified |
| 32 | ghc-getghcpkgbin() { |
38 | ghc-getghcpkgbin() { |
| 33 | if ghc-cabal; then |
39 | # the ghc-pkg executable changed name in ghc 6.10, as it no longer needs |
| 34 | echo $(ghc-libdir)/"ghc-pkg.bin" "--global-conf=$(ghc-libdir)/package.conf" |
40 | # the wrapper script with the static flags |
|
|
41 | echo '[]' > "${T}/empty.conf" |
|
|
42 | if version_is_at_least "7.7.20121101" "$(ghc-version)"; then |
|
|
43 | # was moved to bin/ subtree by: |
|
|
44 | # http://www.haskell.org/pipermail/cvs-ghc/2012-September/076546.html |
|
|
45 | echo "$(ghc-libdir)/bin/ghc-pkg" "--global-package-db=${T}/empty.conf" |
|
|
46 | elif version_is_at_least "7.5.20120516" "$(ghc-version)"; then |
|
|
47 | echo "$(ghc-libdir)/ghc-pkg" "--global-package-db=${T}/empty.conf" |
| 35 | else |
48 | else |
| 36 | echo $(ghc-libdir)/"ghc-pkg.bin" |
49 | echo "$(ghc-libdir)/ghc-pkg" "--global-conf=${T}/empty.conf" |
| 37 | fi |
50 | fi |
| 38 | } |
51 | } |
| 39 | |
52 | |
|
|
53 | # @FUNCTION: ghc-version |
|
|
54 | # @DESCRIPTION: |
| 40 | # returns the version of ghc |
55 | # returns the version of ghc |
| 41 | _GHC_VERSION_CACHE="" |
56 | _GHC_VERSION_CACHE="" |
| 42 | ghc-version() { |
57 | ghc-version() { |
| 43 | if [[ -z "${_GHC_VERSION_CACHE}" ]]; then |
58 | if [[ -z "${_GHC_VERSION_CACHE}" ]]; then |
| 44 | _GHC_VERSION_CACHE="$($(ghc-getghc) --version | sed 's:^.*version ::')" |
59 | _GHC_VERSION_CACHE="$($(ghc-getghc) --numeric-version)" |
| 45 | fi |
60 | fi |
| 46 | echo "${_GHC_VERSION_CACHE}" |
61 | echo "${_GHC_VERSION_CACHE}" |
| 47 | } |
62 | } |
| 48 | |
63 | |
| 49 | # returns true for ghc >= 6.4 |
64 | # @FUNCTION: ghc-bestcabalversion |
|
|
65 | # @DESCRIPTION: |
|
|
66 | # return the best version of the Cabal library that is available |
|
|
67 | ghc-bestcabalversion() { |
|
|
68 | # We ask portage, not ghc, so that we only pick up |
|
|
69 | # portage-installed cabal versions. |
|
|
70 | local cabalversion="$(ghc-extractportageversion dev-haskell/cabal)" |
|
|
71 | echo "Cabal-${cabalversion}" |
|
|
72 | } |
|
|
73 | |
|
|
74 | # @FUNCTION: ghc-sanecabal |
|
|
75 | # @DESCRIPTION: |
|
|
76 | # check if a standalone Cabal version is available for the |
|
|
77 | # currently used ghc; takes minimal version of Cabal as |
|
|
78 | # an optional argument |
| 50 | ghc-cabal() { |
79 | ghc-sanecabal() { |
| 51 | version_is_at_least "6.4" "$(ghc-version)" |
80 | local f |
|
|
81 | local version |
|
|
82 | if [[ -z "$1" ]]; then version="1.0.1"; else version="$1"; fi |
|
|
83 | for f in $(ghc-confdir)/cabal-*; do |
|
|
84 | [[ -f "${f}" ]] && version_is_at_least "${version}" "${f#*cabal-}" && return |
|
|
85 | done |
|
|
86 | return 1 |
| 52 | } |
87 | } |
| 53 | |
88 | |
|
|
89 | # @FUNCTION: ghc-supports-shared-libraries |
|
|
90 | # @DESCRIPTION: |
|
|
91 | # checks if ghc is built with support for building |
|
|
92 | # shared libraries (aka '-dynamic' option) |
|
|
93 | ghc-supports-shared-libraries() { |
|
|
94 | $(ghc-getghc) --info | grep "RTS ways" | grep -q "dyn" |
|
|
95 | } |
|
|
96 | |
|
|
97 | # @FUNCTION: ghc-extractportageversion |
|
|
98 | # @DESCRIPTION: |
|
|
99 | # extract the version of a portage-installed package |
|
|
100 | ghc-extractportageversion() { |
|
|
101 | local pkg |
|
|
102 | local version |
|
|
103 | pkg="$(best_version $1)" |
|
|
104 | version="${pkg#$1-}" |
|
|
105 | version="${version%-r*}" |
|
|
106 | version="${version%_pre*}" |
|
|
107 | echo "${version}" |
|
|
108 | } |
|
|
109 | |
|
|
110 | # @FUNCTION: ghc-libdir |
|
|
111 | # @DESCRIPTION: |
| 54 | # returns the library directory |
112 | # returns the library directory |
| 55 | _GHC_LIBDIR_CACHE="" |
113 | _GHC_LIBDIR_CACHE="" |
| 56 | ghc-libdir() { |
114 | ghc-libdir() { |
| 57 | if [[ -z "${_GHC_LIBDIR_CACHE}" ]]; then |
115 | if [[ -z "${_GHC_LIBDIR_CACHE}" ]]; then |
| 58 | _GHC_LIBDIR_CACHE="$($(ghc-getghc) --print-libdir)" |
116 | _GHC_LIBDIR_CACHE="$($(ghc-getghc) --print-libdir)" |
| 59 | fi |
117 | fi |
| 60 | echo "${_GHC_LIBDIR_CACHE}" |
118 | echo "${_GHC_LIBDIR_CACHE}" |
| 61 | } |
119 | } |
| 62 | |
120 | |
|
|
121 | # @FUNCTION: ghc-confdir |
|
|
122 | # @DESCRIPTION: |
| 63 | # returns the (Gentoo) library configuration directory |
123 | # returns the (Gentoo) library configuration directory |
| 64 | ghc-confdir() { |
124 | ghc-confdir() { |
| 65 | echo $(ghc-libdir)/gentoo |
125 | echo "$(ghc-libdir)/gentoo" |
| 66 | } |
126 | } |
| 67 | |
127 | |
|
|
128 | # @FUNCTION: ghc-localpkgconf |
|
|
129 | # @DESCRIPTION: |
| 68 | # returns the name of the local (package-specific) |
130 | # returns the name of the local (package-specific) |
| 69 | # package configuration file |
131 | # package configuration file |
| 70 | ghc-localpkgconf() { |
132 | ghc-localpkgconf() { |
| 71 | echo "${PF}.conf" |
133 | echo "${PF}.conf" |
| 72 | } |
134 | } |
| 73 | |
135 | |
|
|
136 | # @FUNCTION: ghc-makeghcilib |
|
|
137 | # @DESCRIPTION: |
| 74 | # make a ghci foo.o file from a libfoo.a file |
138 | # make a ghci foo.o file from a libfoo.a file |
| 75 | ghc-makeghcilib() { |
139 | ghc-makeghcilib() { |
| 76 | local outfile |
140 | local outfile |
| 77 | outfile="$(dirname $1)/$(basename $1 | sed 's:^lib\?\(.*\)\.a$:\1.o:')" |
141 | outfile="$(dirname $1)/$(basename $1 | sed 's:^lib\?\(.*\)\.a$:\1.o:')" |
| 78 | ld --relocatable --discard-all --output="${outfile}" --whole-archive $1 |
142 | ld --relocatable --discard-all --output="${outfile}" --whole-archive "$1" |
| 79 | } |
143 | } |
| 80 | |
144 | |
|
|
145 | # @FUNCTION: ghc-package-exists |
|
|
146 | # @DESCRIPTION: |
|
|
147 | # tests if a ghc package exists |
|
|
148 | ghc-package-exists() { |
|
|
149 | $(ghc-getghcpkg) describe "$1" > /dev/null 2>&1 |
|
|
150 | } |
|
|
151 | |
|
|
152 | # @FUNCTION: ghc-setup-pkg |
|
|
153 | # @DESCRIPTION: |
| 81 | # creates a local (package-specific) package |
154 | # creates a local (package-specific) package |
| 82 | # configuration file; the arguments should be |
155 | # configuration file; the arguments should be |
| 83 | # uninstalled package description files, each |
156 | # uninstalled package description files, each |
| 84 | # containing a single package description; if |
157 | # containing a single package description; if |
| 85 | # no arguments are given, the resulting file is |
158 | # no arguments are given, the resulting file is |
| 86 | # empty |
159 | # empty |
| 87 | ghc-setup-pkg() { |
160 | ghc-setup-pkg() { |
| 88 | local localpkgconf |
|
|
| 89 | localpkgconf="${S}/$(ghc-localpkgconf)" |
161 | local localpkgconf="${S}/$(ghc-localpkgconf)" |
| 90 | echo '[]' > ${localpkgconf} |
162 | echo '[]' > "${localpkgconf}" |
|
|
163 | |
| 91 | for pkg in $*; do |
164 | for pkg in $*; do |
| 92 | $(ghc-getghcpkgbin) -f ${localpkgconf} -u --force \ |
165 | $(ghc-getghcpkgbin) -f "${localpkgconf}" update - --force \ |
| 93 | < ${pkg} || die "failed to register ${pkg}" |
166 | < "${pkg}" || die "failed to register ${pkg}" |
| 94 | done |
167 | done |
| 95 | } |
168 | } |
| 96 | |
169 | |
|
|
170 | # @FUNCTION: ghc-fixlibpath |
|
|
171 | # @DESCRIPTION: |
| 97 | # fixes the library and import directories path |
172 | # fixes the library and import directories path |
| 98 | # of the package configuration file |
173 | # of the package configuration file |
| 99 | ghc-fixlibpath() { |
174 | ghc-fixlibpath() { |
| 100 | sed -i "s|$1|$(ghc-libdir)|g" ${S}/$(ghc-localpkgconf) |
175 | sed -i "s|$1|$(ghc-libdir)|g" "${S}/$(ghc-localpkgconf)" |
| 101 | if [[ -n "$2" ]]; then |
176 | if [[ -n "$2" ]]; then |
| 102 | sed -i "s|$2|$(ghc-libdir)/imports|g" ${S}/$(ghc-localpkgconf) |
177 | sed -i "s|$2|$(ghc-libdir)/imports|g" "${S}/$(ghc-localpkgconf)" |
| 103 | fi |
178 | fi |
| 104 | } |
179 | } |
| 105 | |
180 | |
|
|
181 | # @FUNCTION: ghc-install-pkg |
|
|
182 | # @DESCRIPTION: |
| 106 | # moves the local (package-specific) package configuration |
183 | # moves the local (package-specific) package configuration |
| 107 | # file to its final destination |
184 | # file to its final destination |
| 108 | ghc-install-pkg() { |
185 | ghc-install-pkg() { |
| 109 | mkdir -p ${D}/$(ghc-confdir) |
186 | mkdir -p "${D}/$(ghc-confdir)" |
| 110 | cat ${S}/$(ghc-localpkgconf) | sed "s|${D}||g" \ |
187 | cat "${S}/$(ghc-localpkgconf)" | sed "s|${D}||g" \ |
| 111 | > ${D}/$(ghc-confdir)/$(ghc-localpkgconf) |
188 | > "${D}/$(ghc-confdir)/$(ghc-localpkgconf)" |
| 112 | } |
189 | } |
| 113 | |
190 | |
|
|
191 | # @FUNCTION: ghc-register-pkg |
|
|
192 | # @DESCRIPTION: |
| 114 | # registers all packages in the local (package-specific) |
193 | # registers all packages in the local (package-specific) |
| 115 | # package configuration file |
194 | # package configuration file |
| 116 | ghc-register-pkg() { |
195 | ghc-register-pkg() { |
| 117 | local localpkgconf |
|
|
| 118 | localpkgconf="$(ghc-confdir)/$1" |
196 | local localpkgconf="$(ghc-confdir)/$1" |
|
|
197 | |
| 119 | if [[ -f ${localpkgconf} ]]; then |
198 | if [[ -f "${localpkgconf}" ]]; then |
| 120 | for pkg in $(ghc-listpkg ${localpkgconf}); do |
199 | for pkg in $(ghc-listpkg "${localpkgconf}"); do |
| 121 | ebegin "Registering ${pkg} " |
200 | ebegin "Registering ${pkg} " |
| 122 | $(ghc-getghcpkgbin) -f ${localpkgconf} -s ${pkg} \ |
201 | $(ghc-getghcpkgbin) -f "${localpkgconf}" describe "${pkg}" \ |
| 123 | | $(ghc-getghcpkg) -u --force > /dev/null |
202 | | $(ghc-getghcpkg) update - --force > /dev/null |
| 124 | eend $? |
203 | eend $? |
| 125 | done |
204 | done |
| 126 | fi |
205 | fi |
| 127 | } |
206 | } |
| 128 | |
207 | |
|
|
208 | # @FUNCTION: ghc-reregister |
|
|
209 | # @DESCRIPTION: |
| 129 | # re-adds all available .conf files to the global |
210 | # re-adds all available .conf files to the global |
| 130 | # package conf file, to be used on a ghc reinstallation |
211 | # package conf file, to be used on a ghc reinstallation |
| 131 | ghc-reregister() { |
212 | ghc-reregister() { |
| 132 | einfo "Re-adding packages ..." |
213 | has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX= |
| 133 | einfo "(This may cause several warnings, but they should be harmless.)" |
214 | einfo "Re-adding packages (may cause several harmless warnings) ..." |
| 134 | if [ -d "$(ghc-confdir)" ]; then |
215 | PATH="${EPREFIX}/usr/bin:${PATH}" CONFDIR="$(ghc-confdir)" |
| 135 | pushd $(ghc-confdir) > /dev/null |
216 | if [ -d "${CONFDIR}" ]; then |
|
|
217 | pushd "${CONFDIR}" > /dev/null |
| 136 | for conf in *.conf; do |
218 | for conf in *.conf; do |
| 137 | einfo "Processing ${conf} ..." |
219 | PATH="${EPREFIX}/usr/bin:${PATH}" ghc-register-pkg "${conf}" |
| 138 | ghc-register-pkg ${conf} |
|
|
| 139 | done |
220 | done |
| 140 | popd > /dev/null |
221 | popd > /dev/null |
| 141 | fi |
222 | fi |
| 142 | } |
223 | } |
| 143 | |
224 | |
| 144 | # unregisters ... |
225 | # @FUNCTION: ghc-unregister-pkg |
|
|
226 | # @DESCRIPTION: |
|
|
227 | # unregisters a package configuration file |
|
|
228 | # protected are all packages that are still contained in |
|
|
229 | # another package configuration file |
| 145 | ghc-unregister-pkg() { |
230 | ghc-unregister-pkg() { |
| 146 | local localpkgconf |
|
|
| 147 | localpkgconf="$(ghc-confdir)/$1" |
231 | local localpkgconf="$(ghc-confdir)/$1" |
|
|
232 | local i |
|
|
233 | local pkg |
|
|
234 | |
| 148 | if [[ -f ${localpkgconf} ]]; then |
235 | if [[ -f "${localpkgconf}" ]]; then |
| 149 | for pkg in $(ghc-reverse "$(ghc-listpkg ${localpkgconf})"); do |
236 | for pkg in $(ghc-reverse "$(ghc-listpkg ${localpkgconf})"); do |
|
|
237 | if ! ghc-package-exists "${pkg}"; then |
|
|
238 | einfo "Package ${pkg} is not installed for ghc-$(ghc-version)." |
|
|
239 | else |
| 150 | ebegin "Unregistering ${pkg} " |
240 | ebegin "Unregistering ${pkg} " |
| 151 | $(ghc-getghcpkg) -r ${pkg} --force > /dev/null |
241 | $(ghc-getghcpkg) unregister "${pkg}" --force > /dev/null |
| 152 | eend $? |
242 | eend $? |
|
|
243 | fi |
| 153 | done |
244 | done |
| 154 | fi |
245 | fi |
| 155 | } |
246 | } |
| 156 | |
247 | |
|
|
248 | # @FUNCTION: ghc-reverse |
|
|
249 | # @DESCRIPTION: |
| 157 | # help-function: reverse a list |
250 | # help-function: reverse a list |
| 158 | ghc-reverse() { |
251 | ghc-reverse() { |
| 159 | local result |
252 | local result |
|
|
253 | local i |
| 160 | for i in $1; do |
254 | for i in $1; do |
| 161 | result="${i} ${result}" |
255 | result="${i} ${result}" |
| 162 | done |
256 | done |
| 163 | echo ${result} |
257 | echo "${result}" |
| 164 | } |
258 | } |
| 165 | |
259 | |
|
|
260 | # @FUNCTION: ghc-elem |
|
|
261 | # @DESCRIPTION: |
|
|
262 | # help-function: element-check |
|
|
263 | ghc-elem() { |
|
|
264 | local i |
|
|
265 | for i in $2; do |
|
|
266 | [[ "$1" == "${i}" ]] && return 0 |
|
|
267 | done |
|
|
268 | return 1 |
|
|
269 | } |
|
|
270 | |
|
|
271 | # @FUNCTION: ghc-listpkg |
|
|
272 | # @DESCRIPTION: |
| 166 | # show the packages in a package configuration file |
273 | # show the packages in a package configuration file |
| 167 | ghc-listpkg() { |
274 | ghc-listpkg() { |
| 168 | local ghcpkgcall |
275 | local ghcpkgcall |
| 169 | if ghc-cabal; then |
276 | local i |
|
|
277 | local extra_flags |
|
|
278 | if version_is_at_least '6.12.3' "$(ghc-version)"; then |
|
|
279 | extra_flags="${extra_flags} -v0" |
|
|
280 | fi |
|
|
281 | for i in $*; do |
| 170 | echo $($(ghc-getghcpkg) list -f $1) \ |
282 | echo $($(ghc-getghcpkg) list ${extra_flags} -f "${i}") \ |
| 171 | | sed \ |
283 | | sed \ |
| 172 | -e "s|^.*${f}:\([^:]*\).*$|\1|" \ |
284 | -e "s|^.*${i}:\([^:]*\).*$|\1|" \ |
| 173 | -e "s|/.*$||" \ |
285 | -e "s|/.*$||" \ |
| 174 | -e "s|,| |g" -e "s|[()]||g" |
286 | -e "s|,| |g" -e "s|[(){}]||g" |
| 175 | else |
287 | done |
| 176 | echo $($(ghc-getghcpkgbin) -l -f $1) \ |
|
|
| 177 | | cut -f2 -d':' \ |
|
|
| 178 | | sed 's:,: :g' |
|
|
| 179 | fi |
|
|
| 180 | } |
288 | } |
| 181 | |
289 | |
|
|
290 | # @FUNCTION: ghc-package_pkg_postinst |
|
|
291 | # @DESCRIPTION: |
| 182 | # exported function: registers the package-specific package |
292 | # exported function: registers the package-specific package |
| 183 | # configuration file |
293 | # configuration file |
| 184 | ghc-package_pkg_postinst() { |
294 | ghc-package_pkg_postinst() { |
| 185 | ghc-register-pkg $(ghc-localpkgconf) |
295 | ghc-register-pkg "$(ghc-localpkgconf)" |
| 186 | } |
296 | } |
| 187 | |
297 | |
|
|
298 | # @FUNCTION: ghc-package_pkg_prerm |
|
|
299 | # @DESCRIPTION: |
| 188 | # exported function: unregisters the package-specific |
300 | # exported function: unregisters the package-specific package |
| 189 | # package configuration file, under the condition that |
301 | # configuration file; a package contained therein is unregistered |
| 190 | # after removal, no other instances of the package will |
302 | # only if it the same package is not also contained in another |
| 191 | # be left (necessary check because ghc packages are not |
303 | # package configuration file ... |
| 192 | # versioned) |
|
|
| 193 | ghc-package_pkg_prerm() { |
304 | ghc-package_pkg_prerm() { |
| 194 | has_version "<${CATEGORY}/${PF}" || has_version ">${CATEGORY}/${PF}" \ |
|
|
| 195 | || ghc-unregister-pkg $(ghc-localpkgconf) |
305 | ghc-unregister-pkg "$(ghc-localpkgconf)" |
| 196 | } |
306 | } |
| 197 | |
307 | |
| 198 | EXPORT_FUNCTIONS pkg_postinst pkg_prerm |
308 | EXPORT_FUNCTIONS pkg_postinst pkg_prerm |