| 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.21 2007/03/11 15:53:31 kolmodin Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/ghc-package.eclass,v 1.27 2009/03/23 20:06:19 kolmodin Exp $ |
| 4 | # |
4 | # |
| 5 | # Author: Andres Loeh <kosmikus@gentoo.org> |
5 | # Author: Andres Loeh <kosmikus@gentoo.org> |
| 6 | # Maintained by: Haskell herd <haskell@gentoo.org> |
6 | # Maintained by: Haskell herd <haskell@gentoo.org> |
| 7 | # |
7 | # |
| 8 | # This eclass helps with the Glasgow Haskell Compiler's package |
8 | # This eclass helps with the Glasgow Haskell Compiler's package |
| … | |
… | |
| 14 | PATH="/usr/bin:/opt/ghc/bin:${PATH}" |
14 | PATH="/usr/bin:/opt/ghc/bin:${PATH}" |
| 15 | |
15 | |
| 16 | # for later configuration using environment variables/ |
16 | # for later configuration using environment variables/ |
| 17 | # returns the name of the ghc executable |
17 | # returns the name of the ghc executable |
| 18 | ghc-getghc() { |
18 | ghc-getghc() { |
| 19 | echo "$(which ghc)" |
19 | type -P ghc |
| 20 | } |
20 | } |
| 21 | |
21 | |
| 22 | # returns the name of the ghc-pkg executable |
22 | # returns the name of the ghc-pkg executable |
| 23 | ghc-getghcpkg() { |
23 | ghc-getghcpkg() { |
| 24 | echo "$(which ghc-pkg)" |
24 | type -P ghc-pkg |
| 25 | } |
25 | } |
| 26 | |
26 | |
| 27 | # returns the name of the ghc-pkg binary (ghc-pkg |
27 | # returns the name of the ghc-pkg binary (ghc-pkg |
| 28 | # itself usually is a shell script, and we have to |
28 | # itself usually is a shell script, and we have to |
| 29 | # bypass the script under certain circumstances); |
29 | # bypass the script under certain circumstances); |
| 30 | # for Cabal, we add an empty global package config file, |
30 | # for Cabal, we add an empty global package config file, |
| 31 | # because for some reason the global package file |
31 | # because for some reason the global package file |
| 32 | # must be specified |
32 | # must be specified |
| 33 | ghc-getghcpkgbin() { |
33 | ghc-getghcpkgbin() { |
|
|
34 | if version_is_at_least "6.10" "$(ghc-version)"; then |
|
|
35 | # the ghc-pkg executable changed name in ghc 6.10, as it no longer needs |
|
|
36 | # the wrapper script with the static flags |
|
|
37 | echo '[]' > "${T}/empty.conf" |
|
|
38 | echo "$(ghc-libdir)/ghc-pkg" "--global-conf=${T}/empty.conf" |
| 34 | if ghc-cabal; then |
39 | elif ghc-cabal; then |
| 35 | echo '[]' > "${T}/empty.conf" |
40 | echo '[]' > "${T}/empty.conf" |
| 36 | echo "$(ghc-libdir)/ghc-pkg.bin" "--global-conf=${T}/empty.conf" |
41 | echo "$(ghc-libdir)/ghc-pkg.bin" "--global-conf=${T}/empty.conf" |
| 37 | else |
42 | else |
| 38 | echo "$(ghc-libdir)/ghc-pkg.bin" |
43 | echo "$(ghc-libdir)/ghc-pkg.bin" |
| 39 | fi |
44 | fi |
| … | |
… | |
| 56 | version_is_at_least "6.4" "$(ghc-version)" |
61 | version_is_at_least "6.4" "$(ghc-version)" |
| 57 | } |
62 | } |
| 58 | |
63 | |
| 59 | # return the best version of the Cabal library that is available |
64 | # return the best version of the Cabal library that is available |
| 60 | ghc-bestcabalversion() { |
65 | ghc-bestcabalversion() { |
| 61 | local cabalpackage |
|
|
| 62 | local cabalversion |
66 | local cabalversion |
| 63 | if ghc-cabal; then |
67 | if ghc-cabal; then |
| 64 | # We ask portage, not ghc, so that we only pick up |
68 | # We ask portage, not ghc, so that we only pick up |
| 65 | # portage-installed cabal versions. |
69 | # portage-installed cabal versions. |
| 66 | cabalpackage="$(best_version dev-haskell/cabal)" |
70 | cabalversion="$(ghc-extractportageversion dev-haskell/cabal)" |
| 67 | cabalversion="${cabalpackage#dev-haskell/cabal-}" |
|
|
| 68 | cabalversion="${cabalversion%-r*}" |
|
|
| 69 | cabalversion="${cabalversion%_pre*}" |
|
|
| 70 | echo "Cabal-${cabalversion}" |
71 | echo "Cabal-${cabalversion}" |
| 71 | else |
72 | else |
| 72 | # older ghc's don't support package versioning |
73 | # older ghc's don't support package versioning |
| 73 | echo Cabal |
74 | echo Cabal |
| 74 | fi |
75 | fi |
| … | |
… | |
| 85 | [[ -f "${f}" ]] && version_is_at_least "${version}" "${f#*cabal-}" && return |
86 | [[ -f "${f}" ]] && version_is_at_least "${version}" "${f#*cabal-}" && return |
| 86 | done |
87 | done |
| 87 | return 1 |
88 | return 1 |
| 88 | } |
89 | } |
| 89 | |
90 | |
|
|
91 | # checks if ghc and ghc-bin are installed in the same version |
|
|
92 | # (if they're both installed); if this is not the case, we |
|
|
93 | # unfortunately cannot trust portage's dependency resolution |
|
|
94 | ghc-saneghc() { |
|
|
95 | local ghcversion |
|
|
96 | local ghcbinversion |
|
|
97 | if [[ "${PN}" == "ghc" || "${PN}" == "ghc-bin" ]]; then |
|
|
98 | return |
|
|
99 | fi |
|
|
100 | if has_version dev-lang/ghc && has_version dev-lang/ghc-bin; then |
|
|
101 | ghcversion="$(ghc-extractportageversion dev-lang/ghc)" |
|
|
102 | ghcbinversion="$(ghc-extractportageversion dev-lang/ghc-bin)" |
|
|
103 | if [[ "${ghcversion}" != "${ghcbinversion}" ]]; then |
|
|
104 | return 1 |
|
|
105 | fi |
|
|
106 | fi |
|
|
107 | return |
|
|
108 | } |
|
|
109 | |
|
|
110 | # extract the version of a portage-installed package |
|
|
111 | ghc-extractportageversion() { |
|
|
112 | local pkg |
|
|
113 | local version |
|
|
114 | pkg="$(best_version $1)" |
|
|
115 | version="${pkg#$1-}" |
|
|
116 | version="${version%-r*}" |
|
|
117 | version="${version%_pre*}" |
|
|
118 | echo "${version}" |
|
|
119 | } |
|
|
120 | |
| 90 | # returns the library directory |
121 | # returns the library directory |
| 91 | _GHC_LIBDIR_CACHE="" |
122 | _GHC_LIBDIR_CACHE="" |
| 92 | ghc-libdir() { |
123 | ghc-libdir() { |
| 93 | if [[ -z "${_GHC_LIBDIR_CACHE}" ]]; then |
124 | if [[ -z "${_GHC_LIBDIR_CACHE}" ]]; then |
| 94 | _GHC_LIBDIR_CACHE="$($(ghc-getghc) --print-libdir)" |
125 | _GHC_LIBDIR_CACHE="$($(ghc-getghc) --print-libdir)" |
| … | |
… | |
| 114 | ld --relocatable --discard-all --output="${outfile}" --whole-archive "$1" |
145 | ld --relocatable --discard-all --output="${outfile}" --whole-archive "$1" |
| 115 | } |
146 | } |
| 116 | |
147 | |
| 117 | # tests if a ghc package exists |
148 | # tests if a ghc package exists |
| 118 | ghc-package-exists() { |
149 | ghc-package-exists() { |
|
|
150 | local describe_flag |
|
|
151 | if version_is_at_least "6.4" "$(ghc-version)"; then |
|
|
152 | describe_flag="describe" |
|
|
153 | else |
|
|
154 | describe_flag="--show-package" |
|
|
155 | fi |
|
|
156 | |
| 119 | $(ghc-getghcpkg) -s "$1" > /dev/null 2>&1 |
157 | $(ghc-getghcpkg) "${describe_flag}" "$1" > /dev/null 2>&1 |
| 120 | } |
158 | } |
| 121 | |
159 | |
| 122 | # creates a local (package-specific) package |
160 | # creates a local (package-specific) package |
| 123 | # configuration file; the arguments should be |
161 | # configuration file; the arguments should be |
| 124 | # uninstalled package description files, each |
162 | # uninstalled package description files, each |
| … | |
… | |
| 127 | # empty |
165 | # empty |
| 128 | ghc-setup-pkg() { |
166 | ghc-setup-pkg() { |
| 129 | local localpkgconf |
167 | local localpkgconf |
| 130 | localpkgconf="${S}/$(ghc-localpkgconf)" |
168 | localpkgconf="${S}/$(ghc-localpkgconf)" |
| 131 | echo '[]' > "${localpkgconf}" |
169 | echo '[]' > "${localpkgconf}" |
|
|
170 | local update_flag |
|
|
171 | if version_is_at_least "6.4" "$(ghc-version)"; then |
|
|
172 | update_flag="update -" |
|
|
173 | else |
|
|
174 | update_flag="--update-package" |
|
|
175 | fi |
| 132 | for pkg in $*; do |
176 | for pkg in $*; do |
| 133 | $(ghc-getghcpkgbin) -f "${localpkgconf}" -u --force \ |
177 | $(ghc-getghcpkgbin) -f "${localpkgconf}" ${update_flag} --force \ |
| 134 | < "${pkg}" || die "failed to register ${pkg}" |
178 | < "${pkg}" || die "failed to register ${pkg}" |
| 135 | done |
179 | done |
| 136 | } |
180 | } |
| 137 | |
181 | |
| 138 | # fixes the library and import directories path |
182 | # fixes the library and import directories path |
| … | |
… | |
| 155 | # registers all packages in the local (package-specific) |
199 | # registers all packages in the local (package-specific) |
| 156 | # package configuration file |
200 | # package configuration file |
| 157 | ghc-register-pkg() { |
201 | ghc-register-pkg() { |
| 158 | local localpkgconf |
202 | local localpkgconf |
| 159 | localpkgconf="$(ghc-confdir)/$1" |
203 | localpkgconf="$(ghc-confdir)/$1" |
|
|
204 | local update_flag |
|
|
205 | local describe_flag |
|
|
206 | if version_is_at_least "6.4" "$(ghc-version)"; then |
|
|
207 | update_flag="update -" |
|
|
208 | describe_flag="describe" |
|
|
209 | else |
|
|
210 | update_flag="--update-package" |
|
|
211 | describe_flag="--show-package" |
|
|
212 | fi |
| 160 | if [[ -f "${localpkgconf}" ]]; then |
213 | if [[ -f "${localpkgconf}" ]]; then |
| 161 | for pkg in $(ghc-listpkg "${localpkgconf}"); do |
214 | for pkg in $(ghc-listpkg "${localpkgconf}"); do |
| 162 | ebegin "Registering ${pkg} " |
215 | ebegin "Registering ${pkg} " |
| 163 | $(ghc-getghcpkgbin) -f "${localpkgconf}" -s "${pkg}" \ |
216 | $(ghc-getghcpkgbin) -f "${localpkgconf}" "${describe_flag}" "${pkg}" \ |
| 164 | | $(ghc-getghcpkg) -u --force > /dev/null |
217 | | $(ghc-getghcpkg) ${update_flag} --force > /dev/null |
| 165 | eend $? |
218 | eend $? |
| 166 | done |
219 | done |
| 167 | fi |
220 | fi |
| 168 | } |
221 | } |
| 169 | |
222 | |
| 170 | # re-adds all available .conf files to the global |
223 | # re-adds all available .conf files to the global |
| 171 | # package conf file, to be used on a ghc reinstallation |
224 | # package conf file, to be used on a ghc reinstallation |
| 172 | ghc-reregister() { |
225 | ghc-reregister() { |
| 173 | einfo "Re-adding packages (may cause several harmless warnings) ..." |
226 | einfo "Re-adding packages (may cause several harmless warnings) ..." |
| 174 | if [ -d "$(ghc-confdir)" ]; then |
227 | PATH="/usr/bin:${PATH}" CONFDIR="$(ghc-confdir)" |
| 175 | pushd "$(ghc-confdir)" > /dev/null |
228 | if [ -d "${CONFDIR}" ]; then |
|
|
229 | pushd "${CONFDIR}" > /dev/null |
| 176 | for conf in *.conf; do |
230 | for conf in *.conf; do |
| 177 | # einfo "Processing ${conf} ..." |
231 | PATH="/usr/bin:${PATH}" ghc-register-pkg "${conf}" |
| 178 | ghc-register-pkg "${conf}" |
|
|
| 179 | done |
232 | done |
| 180 | popd > /dev/null |
233 | popd > /dev/null |
| 181 | fi |
234 | fi |
| 182 | } |
235 | } |
| 183 | |
236 | |
| … | |
… | |
| 187 | ghc-unregister-pkg() { |
240 | ghc-unregister-pkg() { |
| 188 | local localpkgconf |
241 | local localpkgconf |
| 189 | local i |
242 | local i |
| 190 | local pkg |
243 | local pkg |
| 191 | local protected |
244 | local protected |
|
|
245 | local unregister_flag |
| 192 | localpkgconf="$(ghc-confdir)/$1" |
246 | localpkgconf="$(ghc-confdir)/$1" |
|
|
247 | |
|
|
248 | if version_is_at_least "6.4" "$(ghc-version)"; then |
|
|
249 | unregister_flag="unregister" |
|
|
250 | else |
|
|
251 | unregister_flag="--remove-package" |
|
|
252 | fi |
| 193 | |
253 | |
| 194 | for i in $(ghc-confdir)/*.conf; do |
254 | for i in $(ghc-confdir)/*.conf; do |
| 195 | [[ "${i}" != "${localpkgconf}" ]] && protected="${protected} $(ghc-listpkg ${i})" |
255 | [[ "${i}" != "${localpkgconf}" ]] && protected="${protected} $(ghc-listpkg ${i})" |
| 196 | done |
256 | done |
| 197 | # protected now contains the packages that cannot be unregistered yet |
257 | # protected now contains the packages that cannot be unregistered yet |
| … | |
… | |
| 203 | elif ! ghc-package-exists "${pkg}"; then |
263 | elif ! ghc-package-exists "${pkg}"; then |
| 204 | : |
264 | : |
| 205 | # einfo "Package ${pkg} is not installed for ghc-$(ghc-version)." |
265 | # einfo "Package ${pkg} is not installed for ghc-$(ghc-version)." |
| 206 | else |
266 | else |
| 207 | ebegin "Unregistering ${pkg} " |
267 | ebegin "Unregistering ${pkg} " |
| 208 | $(ghc-getghcpkg) -r "${pkg}" --force > /dev/null |
268 | $(ghc-getghcpkg) "${unregister_flag}" "${pkg}" --force > /dev/null |
| 209 | eend $? |
269 | eend $? |
| 210 | fi |
270 | fi |
| 211 | done |
271 | done |
| 212 | fi |
272 | fi |
| 213 | } |
273 | } |
| … | |
… | |
| 239 | if ghc-cabal; then |
299 | if ghc-cabal; then |
| 240 | echo $($(ghc-getghcpkg) list -f "${i}") \ |
300 | echo $($(ghc-getghcpkg) list -f "${i}") \ |
| 241 | | sed \ |
301 | | sed \ |
| 242 | -e "s|^.*${i}:\([^:]*\).*$|\1|" \ |
302 | -e "s|^.*${i}:\([^:]*\).*$|\1|" \ |
| 243 | -e "s|/.*$||" \ |
303 | -e "s|/.*$||" \ |
| 244 | -e "s|,| |g" -e "s|[()]||g" |
304 | -e "s|,| |g" -e "s|[(){}]||g" |
| 245 | else |
305 | else |
| 246 | echo $($(ghc-getghcpkgbin) -l -f "${i}") \ |
306 | echo $($(ghc-getghcpkgbin) -l -f "${i}") \ |
| 247 | | cut -f2 -d':' \ |
307 | | cut -f2 -d':' \ |
| 248 | | sed 's:,: :g' |
308 | | sed 's:,: :g' |
| 249 | fi |
309 | fi |
| 250 | done |
310 | done |
| 251 | } |
311 | } |
| 252 | |
312 | |
| 253 | # exported function: check if we have a consistent ghc installation |
313 | # exported function: check if we have a consistent ghc installation |
| 254 | ghc-package_pkg_setup() { |
314 | ghc-package_pkg_setup() { |
| 255 | #place holder for sanity check of ghc vs ghc-bin version issues |
315 | if ! ghc-saneghc; then |
| 256 | return |
316 | eerror "You have inconsistent versions of dev-lang/ghc and dev-lang/ghc-bin" |
|
|
317 | eerror "installed. Portage currently cannot work correctly with this setup." |
|
|
318 | eerror "There are several possibilities to work around this problem:" |
|
|
319 | eerror "(1) Up/downgrade ghc-bin to the same version as ghc." |
|
|
320 | eerror "(2) Unmerge ghc-bin." |
|
|
321 | eerror "(3) Unmerge ghc." |
|
|
322 | eerror "You probably want option 1 or 2." |
|
|
323 | die "Inconsistent versions of ghc and ghc-bin." |
|
|
324 | fi |
| 257 | } |
325 | } |
| 258 | |
326 | |
| 259 | # exported function: registers the package-specific package |
327 | # exported function: registers the package-specific package |
| 260 | # configuration file |
328 | # configuration file |
| 261 | ghc-package_pkg_postinst() { |
329 | ghc-package_pkg_postinst() { |