/[gentoo-x86]/eclass/ghc-package.eclass
Gentoo

Contents of /eclass/ghc-package.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.19 - (hide annotations) (download)
Wed Aug 2 19:52:04 2006 UTC (8 years ago) by dcoutts
Branch: MAIN
Changes since 1.18: +7 -12 lines
The change about how we pick a version of cabal to use as described in the
previous commit. (Oops, committed in two bits, never mind)

1 kosmikus 1.1 # Copyright 1999-2004 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 dcoutts 1.19 # $Header: /var/cvsroot/gentoo-x86/eclass/ghc-package.eclass,v 1.18 2006/08/02 19:49:03 dcoutts Exp $
4 kosmikus 1.1 #
5     # Author: Andres Loeh <kosmikus@gentoo.org>
6 dcoutts 1.17 # Maintained by: Haskell herd <haskell@gentoo.org>
7 kosmikus 1.1 #
8     # This eclass helps with the Glasgow Haskell Compiler's package
9     # configuration utility.
10    
11 kosmikus 1.6 inherit versionator
12    
13 kosmikus 1.7 # promote /opt/ghc/bin to a better position in the search path
14     PATH="/usr/bin:/opt/ghc/bin:${PATH}"
15 kosmikus 1.1
16     # for later configuration using environment variables/
17     # returns the name of the ghc executable
18     ghc-getghc() {
19 dcoutts 1.18 echo "$(which ghc)"
20 kosmikus 1.1 }
21    
22     # returns the name of the ghc-pkg executable
23     ghc-getghcpkg() {
24 dcoutts 1.18 echo "$(which ghc-pkg)"
25 kosmikus 1.1 }
26    
27     # returns the name of the ghc-pkg binary (ghc-pkg
28     # itself usually is a shell script, and we have to
29 kosmikus 1.6 # bypass the script under certain circumstances);
30 kosmikus 1.15 # for Cabal, we add an empty global package config file,
31     # because for some reason the global package file
32     # must be specified
33 kosmikus 1.1 ghc-getghcpkgbin() {
34 kosmikus 1.6 if ghc-cabal; then
35 kosmikus 1.15 echo '[]' > "${T}/empty.conf"
36     echo "$(ghc-libdir)/ghc-pkg.bin" "--global-conf=${T}/empty.conf"
37 kosmikus 1.6 else
38 kosmikus 1.15 echo "$(ghc-libdir)/ghc-pkg.bin"
39 kosmikus 1.6 fi
40 kosmikus 1.1 }
41    
42     # returns the version of ghc
43 kosmikus 1.6 _GHC_VERSION_CACHE=""
44 kosmikus 1.1 ghc-version() {
45 kosmikus 1.6 if [[ -z "${_GHC_VERSION_CACHE}" ]]; then
46 dcoutts 1.16 _GHC_VERSION_CACHE="$($(ghc-getghc) --numeric-version)"
47 kosmikus 1.6 fi
48     echo "${_GHC_VERSION_CACHE}"
49     }
50    
51 kosmikus 1.15 # this function can be used to determine if ghc itself
52     # uses the Cabal package format; it has nothing to do
53     # with the Cabal libraries ... ghc uses the Cabal package
54     # format since version 6.4
55 kosmikus 1.6 ghc-cabal() {
56     version_is_at_least "6.4" "$(ghc-version)"
57 kosmikus 1.1 }
58    
59 kosmikus 1.15 # return the best version of the Cabal library that is available
60     ghc-bestcabalversion() {
61     local cabalpackage
62     local cabalversion
63     if ghc-cabal; then
64 dcoutts 1.19 # We ask portage, not ghc, so that we only pick up
65     # portage-installed cabal versions.
66     cabalpackage="$(best_version cabal)"
67     cabalversion="${cabalpackage#dev-haskell/cabal-}"
68     cabalversion="${cabalversion%-r*}"
69     cabalversion="${cabalversion%_pre*}"
70 kosmikus 1.15 echo "Cabal-${cabalversion}"
71     else
72     # older ghc's don't support package versioning
73     echo Cabal
74     fi
75     }
76    
77     # check if a standalone Cabal version is available for the
78     # currently used ghc; takes minimal version of Cabal as
79     # an optional argument
80     ghc-sanecabal() {
81     local f
82     local version
83     if [[ -z "$1" ]]; then version="1.0.1"; else version="$1"; fi
84     for f in $(ghc-confdir)/cabal-*; do
85     [[ -f "${f}" ]] && version_is_at_least "${version}" "${f#*cabal-}" && return
86     done
87     return 1
88     }
89    
90 kosmikus 1.1 # returns the library directory
91 kosmikus 1.6 _GHC_LIBDIR_CACHE=""
92 kosmikus 1.1 ghc-libdir() {
93 kosmikus 1.6 if [[ -z "${_GHC_LIBDIR_CACHE}" ]]; then
94     _GHC_LIBDIR_CACHE="$($(ghc-getghc) --print-libdir)"
95     fi
96     echo "${_GHC_LIBDIR_CACHE}"
97 kosmikus 1.1 }
98    
99     # returns the (Gentoo) library configuration directory
100     ghc-confdir() {
101 kosmikus 1.15 echo "$(ghc-libdir)/gentoo"
102 kosmikus 1.1 }
103    
104     # returns the name of the local (package-specific)
105     # package configuration file
106     ghc-localpkgconf() {
107     echo "${PF}.conf"
108     }
109    
110 kosmikus 1.3 # make a ghci foo.o file from a libfoo.a file
111     ghc-makeghcilib() {
112     local outfile
113     outfile="$(dirname $1)/$(basename $1 | sed 's:^lib\?\(.*\)\.a$:\1.o:')"
114 kosmikus 1.15 ld --relocatable --discard-all --output="${outfile}" --whole-archive "$1"
115     }
116    
117     # tests if a ghc package exists
118     ghc-package-exists() {
119     $(ghc-getghcpkg) -s "$1" > /dev/null 2>&1
120 kosmikus 1.3 }
121    
122     # creates a local (package-specific) package
123     # configuration file; the arguments should be
124     # uninstalled package description files, each
125     # containing a single package description; if
126     # no arguments are given, the resulting file is
127     # empty
128 kosmikus 1.1 ghc-setup-pkg() {
129 kosmikus 1.3 local localpkgconf
130     localpkgconf="${S}/$(ghc-localpkgconf)"
131 kosmikus 1.15 echo '[]' > "${localpkgconf}"
132 dcoutts 1.10 for pkg in $*; do
133 kosmikus 1.15 $(ghc-getghcpkgbin) -f "${localpkgconf}" -u --force \
134     < "${pkg}" || die "failed to register ${pkg}"
135 kosmikus 1.3 done
136 kosmikus 1.1 }
137    
138 araujo 1.9 # fixes the library and import directories path
139     # of the package configuration file
140     ghc-fixlibpath() {
141 kosmikus 1.15 sed -i "s|$1|$(ghc-libdir)|g" "${S}/$(ghc-localpkgconf)"
142 araujo 1.9 if [[ -n "$2" ]]; then
143 kosmikus 1.15 sed -i "s|$2|$(ghc-libdir)/imports|g" "${S}/$(ghc-localpkgconf)"
144 araujo 1.9 fi
145     }
146    
147 kosmikus 1.1 # moves the local (package-specific) package configuration
148     # file to its final destination
149     ghc-install-pkg() {
150 kosmikus 1.15 mkdir -p "${D}/$(ghc-confdir)"
151     cat "${S}/$(ghc-localpkgconf)" | sed "s|${D}||g" \
152     > "${D}/$(ghc-confdir)/$(ghc-localpkgconf)"
153 kosmikus 1.1 }
154    
155     # registers all packages in the local (package-specific)
156     # package configuration file
157     ghc-register-pkg() {
158     local localpkgconf
159 kosmikus 1.3 localpkgconf="$(ghc-confdir)/$1"
160 kosmikus 1.15 if [[ -f "${localpkgconf}" ]]; then
161     for pkg in $(ghc-listpkg "${localpkgconf}"); do
162 kosmikus 1.8 ebegin "Registering ${pkg} "
163 kosmikus 1.15 $(ghc-getghcpkgbin) -f "${localpkgconf}" -s "${pkg}" \
164 kosmikus 1.8 | $(ghc-getghcpkg) -u --force > /dev/null
165     eend $?
166 kosmikus 1.7 done
167     fi
168 kosmikus 1.1 }
169    
170     # re-adds all available .conf files to the global
171     # package conf file, to be used on a ghc reinstallation
172     ghc-reregister() {
173 kosmikus 1.15 einfo "Re-adding packages (may cause several harmless warnings) ..."
174 kosmikus 1.5 if [ -d "$(ghc-confdir)" ]; then
175 kosmikus 1.15 pushd "$(ghc-confdir)" > /dev/null
176 kosmikus 1.5 for conf in *.conf; do
177 kosmikus 1.15 # einfo "Processing ${conf} ..."
178     ghc-register-pkg "${conf}"
179 kosmikus 1.5 done
180 kosmikus 1.8 popd > /dev/null
181 kosmikus 1.5 fi
182 kosmikus 1.1 }
183    
184 kosmikus 1.15 # unregisters a package configuration file
185     # protected are all packages that are still contained in
186     # another package configuration file
187 kosmikus 1.1 ghc-unregister-pkg() {
188     local localpkgconf
189 kosmikus 1.15 local i
190     local pkg
191     local protected
192 kosmikus 1.3 localpkgconf="$(ghc-confdir)/$1"
193 kosmikus 1.15
194     for i in $(ghc-confdir)/*.conf; do
195     [[ "${i}" != "${localpkgconf}" ]] && protected="${protected} $(ghc-listpkg ${i})"
196     done
197     # protected now contains the packages that cannot be unregistered yet
198    
199     if [[ -f "${localpkgconf}" ]]; then
200 kosmikus 1.7 for pkg in $(ghc-reverse "$(ghc-listpkg ${localpkgconf})"); do
201 kosmikus 1.15 if $(ghc-elem "${pkg}" "${protected}"); then
202     einfo "Package ${pkg} is protected."
203     elif ! ghc-package-exists "${pkg}"; then
204     :
205     # einfo "Package ${pkg} is not installed for ghc-$(ghc-version)."
206     else
207     ebegin "Unregistering ${pkg} "
208     $(ghc-getghcpkg) -r "${pkg}" --force > /dev/null
209     eend $?
210     fi
211 kosmikus 1.7 done
212     fi
213 kosmikus 1.1 }
214    
215     # help-function: reverse a list
216     ghc-reverse() {
217     local result
218 kosmikus 1.15 local i
219 kosmikus 1.1 for i in $1; do
220     result="${i} ${result}"
221     done
222 kosmikus 1.15 echo "${result}"
223     }
224    
225     # help-function: element-check
226     ghc-elem() {
227     local i
228     for i in $2; do
229     [[ "$1" == "${i}" ]] && return 0
230     done
231     return 1
232 kosmikus 1.1 }
233    
234     # show the packages in a package configuration file
235     ghc-listpkg() {
236 kosmikus 1.6 local ghcpkgcall
237 kosmikus 1.15 local i
238     for i in $*; do
239     if ghc-cabal; then
240     echo $($(ghc-getghcpkg) list -f "${i}") \
241     | sed \
242     -e "s|^.*${i}:\([^:]*\).*$|\1|" \
243     -e "s|/.*$||" \
244     -e "s|,| |g" -e "s|[()]||g"
245     else
246     echo $($(ghc-getghcpkgbin) -l -f "${i}") \
247     | cut -f2 -d':' \
248     | sed 's:,: :g'
249     fi
250     done
251 kosmikus 1.1 }
252    
253     # exported function: registers the package-specific package
254     # configuration file
255     ghc-package_pkg_postinst() {
256 kosmikus 1.15 ghc-register-pkg "$(ghc-localpkgconf)"
257 kosmikus 1.1 }
258    
259 kosmikus 1.15 # exported function: unregisters the package-specific package
260     # configuration file; a package contained therein is unregistered
261     # only if it the same package is not also contained in another
262     # package configuration file ...
263 kosmikus 1.1 ghc-package_pkg_prerm() {
264 kosmikus 1.15 ghc-unregister-pkg "$(ghc-localpkgconf)"
265 kosmikus 1.1 }
266    
267     EXPORT_FUNCTIONS pkg_postinst pkg_prerm

  ViewVC Help
Powered by ViewVC 1.1.20