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