| 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.20 2006/10/04 17:45:35 kosmikus Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/ghc-package.eclass,v 1.26 2008/01/06 19:30:24 swegener 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); |
| … | |
… | |
| 56 | version_is_at_least "6.4" "$(ghc-version)" |
56 | version_is_at_least "6.4" "$(ghc-version)" |
| 57 | } |
57 | } |
| 58 | |
58 | |
| 59 | # return the best version of the Cabal library that is available |
59 | # return the best version of the Cabal library that is available |
| 60 | ghc-bestcabalversion() { |
60 | ghc-bestcabalversion() { |
| 61 | local cabalpackage |
|
|
| 62 | local cabalversion |
61 | local cabalversion |
| 63 | if ghc-cabal; then |
62 | if ghc-cabal; then |
| 64 | # We ask portage, not ghc, so that we only pick up |
63 | # We ask portage, not ghc, so that we only pick up |
| 65 | # portage-installed cabal versions. |
64 | # portage-installed cabal versions. |
| 66 | cabalpackage="$(best_version dev-haskell/cabal)" |
65 | cabalversion="$(ghc-extractportageversion dev-haskell/cabal)" |
| 67 | cabalversion="${cabalpackage#dev-haskell/cabal-}" |
|
|
| 68 | cabalversion="${cabalversion%-r*}" |
|
|
| 69 | cabalversion="${cabalversion%_pre*}" |
|
|
| 70 | echo "Cabal-${cabalversion}" |
66 | echo "Cabal-${cabalversion}" |
| 71 | else |
67 | else |
| 72 | # older ghc's don't support package versioning |
68 | # older ghc's don't support package versioning |
| 73 | echo Cabal |
69 | echo Cabal |
| 74 | fi |
70 | fi |
| … | |
… | |
| 83 | if [[ -z "$1" ]]; then version="1.0.1"; else version="$1"; fi |
79 | if [[ -z "$1" ]]; then version="1.0.1"; else version="$1"; fi |
| 84 | for f in $(ghc-confdir)/cabal-*; do |
80 | for f in $(ghc-confdir)/cabal-*; do |
| 85 | [[ -f "${f}" ]] && version_is_at_least "${version}" "${f#*cabal-}" && return |
81 | [[ -f "${f}" ]] && version_is_at_least "${version}" "${f#*cabal-}" && return |
| 86 | done |
82 | done |
| 87 | return 1 |
83 | return 1 |
|
|
84 | } |
|
|
85 | |
|
|
86 | # checks if ghc and ghc-bin are installed in the same version |
|
|
87 | # (if they're both installed); if this is not the case, we |
|
|
88 | # unfortunately cannot trust portage's dependency resolution |
|
|
89 | ghc-saneghc() { |
|
|
90 | local ghcversion |
|
|
91 | local ghcbinversion |
|
|
92 | if [[ "${PN}" == "ghc" || "${PN}" == "ghc-bin" ]]; then |
|
|
93 | return |
|
|
94 | fi |
|
|
95 | if has_version dev-lang/ghc && has_version dev-lang/ghc-bin; then |
|
|
96 | ghcversion="$(ghc-extractportageversion dev-lang/ghc)" |
|
|
97 | ghcbinversion="$(ghc-extractportageversion dev-lang/ghc-bin)" |
|
|
98 | if [[ "${ghcversion}" != "${ghcbinversion}" ]]; then |
|
|
99 | return 1 |
|
|
100 | fi |
|
|
101 | fi |
|
|
102 | return |
|
|
103 | } |
|
|
104 | |
|
|
105 | # extract the version of a portage-installed package |
|
|
106 | ghc-extractportageversion() { |
|
|
107 | local pkg |
|
|
108 | local version |
|
|
109 | pkg="$(best_version $1)" |
|
|
110 | version="${pkg#$1-}" |
|
|
111 | version="${version%-r*}" |
|
|
112 | version="${version%_pre*}" |
|
|
113 | echo "${version}" |
| 88 | } |
114 | } |
| 89 | |
115 | |
| 90 | # returns the library directory |
116 | # returns the library directory |
| 91 | _GHC_LIBDIR_CACHE="" |
117 | _GHC_LIBDIR_CACHE="" |
| 92 | ghc-libdir() { |
118 | ghc-libdir() { |
| … | |
… | |
| 239 | if ghc-cabal; then |
265 | if ghc-cabal; then |
| 240 | echo $($(ghc-getghcpkg) list -f "${i}") \ |
266 | echo $($(ghc-getghcpkg) list -f "${i}") \ |
| 241 | | sed \ |
267 | | sed \ |
| 242 | -e "s|^.*${i}:\([^:]*\).*$|\1|" \ |
268 | -e "s|^.*${i}:\([^:]*\).*$|\1|" \ |
| 243 | -e "s|/.*$||" \ |
269 | -e "s|/.*$||" \ |
| 244 | -e "s|,| |g" -e "s|[()]||g" |
270 | -e "s|,| |g" -e "s|[(){}]||g" |
| 245 | else |
271 | else |
| 246 | echo $($(ghc-getghcpkgbin) -l -f "${i}") \ |
272 | echo $($(ghc-getghcpkgbin) -l -f "${i}") \ |
| 247 | | cut -f2 -d':' \ |
273 | | cut -f2 -d':' \ |
| 248 | | sed 's:,: :g' |
274 | | sed 's:,: :g' |
| 249 | fi |
275 | fi |
| 250 | done |
276 | done |
|
|
277 | } |
|
|
278 | |
|
|
279 | # exported function: check if we have a consistent ghc installation |
|
|
280 | ghc-package_pkg_setup() { |
|
|
281 | if ! ghc-saneghc; then |
|
|
282 | eerror "You have inconsistent versions of dev-lang/ghc and dev-lang/ghc-bin" |
|
|
283 | eerror "installed. Portage currently cannot work correctly with this setup." |
|
|
284 | eerror "There are several possibilities to work around this problem:" |
|
|
285 | eerror "(1) Up/downgrade ghc-bin to the same version as ghc." |
|
|
286 | eerror "(2) Unmerge ghc-bin." |
|
|
287 | eerror "(3) Unmerge ghc." |
|
|
288 | eerror "You probably want option 1 or 2." |
|
|
289 | die "Inconsistent versions of ghc and ghc-bin." |
|
|
290 | fi |
| 251 | } |
291 | } |
| 252 | |
292 | |
| 253 | # exported function: registers the package-specific package |
293 | # exported function: registers the package-specific package |
| 254 | # configuration file |
294 | # configuration file |
| 255 | ghc-package_pkg_postinst() { |
295 | ghc-package_pkg_postinst() { |
| … | |
… | |
| 262 | # package configuration file ... |
302 | # package configuration file ... |
| 263 | ghc-package_pkg_prerm() { |
303 | ghc-package_pkg_prerm() { |
| 264 | ghc-unregister-pkg "$(ghc-localpkgconf)" |
304 | ghc-unregister-pkg "$(ghc-localpkgconf)" |
| 265 | } |
305 | } |
| 266 | |
306 | |
| 267 | EXPORT_FUNCTIONS pkg_postinst pkg_prerm |
307 | EXPORT_FUNCTIONS pkg_setup pkg_postinst pkg_prerm |