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

Contents of /eclass/ghc-package.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (show annotations) (download)
Fri Mar 18 23:31:48 2005 UTC (9 years, 5 months ago) by kosmikus
Branch: MAIN
Changes since 1.5: +37 -7 lines
* ghc-package eclass is now compatible with ghc-6.4

1 # Copyright 1999-2004 Gentoo Foundation
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 $
4 #
5 # Author: Andres Loeh <kosmikus@gentoo.org>
6 #
7 # This eclass helps with the Glasgow Haskell Compiler's package
8 # configuration utility.
9
10 inherit versionator
11
12 ECLASS="ghc-package"
13 INHERITED="${INHERITED} ${ECLASS}"
14
15 PATH="${PATH}:/opt/ghc/bin"
16
17 # for later configuration using environment variables/
18 # returns the name of the ghc executable
19 ghc-getghc() {
20 echo "ghc"
21 }
22
23 # returns the name of the ghc-pkg executable
24 ghc-getghcpkg() {
25 echo "ghc-pkg"
26 }
27
28 # returns the name of the ghc-pkg binary (ghc-pkg
29 # itself usually is a shell script, and we have to
30 # bypass the script under certain circumstances);
31 # for Cabal, we add the global package config file,
32 # because for some reason that's required
33 ghc-getghcpkgbin() {
34 if ghc-cabal; then
35 echo $(ghc-libdir)/"ghc-pkg.bin" "--global-conf=$(ghc-libdir)/package.conf"
36 else
37 echo $(ghc-libdir)/"ghc-pkg.bin"
38 fi
39 }
40
41 # returns the version of ghc
42 _GHC_VERSION_CACHE=""
43 ghc-version() {
44 if [[ -z "${_GHC_VERSION_CACHE}" ]]; then
45 _GHC_VERSION_CACHE="$($(ghc-getghc) --version | sed 's:^.*version ::')"
46 fi
47 echo "${_GHC_VERSION_CACHE}"
48 }
49
50 # returns true for ghc >= 6.4
51 ghc-cabal() {
52 version_is_at_least "6.4" "$(ghc-version)"
53 }
54
55 # returns the library directory
56 _GHC_LIBDIR_CACHE=""
57 ghc-libdir() {
58 if [[ -z "${_GHC_LIBDIR_CACHE}" ]]; then
59 _GHC_LIBDIR_CACHE="$($(ghc-getghc) --print-libdir)"
60 fi
61 echo "${_GHC_LIBDIR_CACHE}"
62 }
63
64 # returns the (Gentoo) library configuration directory
65 ghc-confdir() {
66 echo $(ghc-libdir)/gentoo
67 }
68
69 # returns the name of the local (package-specific)
70 # package configuration file
71 ghc-localpkgconf() {
72 echo "${PF}.conf"
73 }
74
75 # make a ghci foo.o file from a libfoo.a file
76 ghc-makeghcilib() {
77 local outfile
78 outfile="$(dirname $1)/$(basename $1 | sed 's:^lib\?\(.*\)\.a$:\1.o:')"
79 ld --relocatable --discard-all --output="${outfile}" --whole-archive $1
80 }
81
82 # creates a local (package-specific) package
83 # configuration file; the arguments should be
84 # uninstalled package description files, each
85 # containing a single package description; if
86 # no arguments are given, the resulting file is
87 # empty
88 ghc-setup-pkg() {
89 local localpkgconf
90 localpkgconf="${S}/$(ghc-localpkgconf)"
91 echo '[' > ${localpkgconf}
92 while [ -n "$1" ]; do
93 cat "$1" >> ${localpkgconf}
94 shift
95 [ -n "$1" ] && echo ',' >> ${localpkgconf}
96 done
97 echo ']' >> ${localpkgconf}
98 }
99
100 # moves the local (package-specific) package configuration
101 # file to its final destination
102 ghc-install-pkg() {
103 mkdir -p ${D}/$(ghc-confdir)
104 cat ${S}/$(ghc-localpkgconf) | sed "s:${D}::" \
105 > ${D}/$(ghc-confdir)/$(ghc-localpkgconf)
106 }
107
108 # registers all packages in the local (package-specific)
109 # package configuration file
110 ghc-register-pkg() {
111 local localpkgconf
112 localpkgconf="$(ghc-confdir)/$1"
113 for pkg in $(ghc-listpkg ${localpkgconf}); do
114 einfo "Registering ${pkg} ..."
115 $(ghc-getghcpkgbin) -f ${localpkgconf} -s ${pkg} \
116 | $(ghc-getghcpkg) -u --force
117 done
118 }
119
120 # re-adds all available .conf files to the global
121 # package conf file, to be used on a ghc reinstallation
122 ghc-reregister() {
123 einfo "Re-adding packages ..."
124 ewarn "This may cause several warnings, but they should be harmless."
125 if [ -d "$(ghc-confdir)" ]; then
126 pushd $(ghc-confdir)
127 for conf in *.conf; do
128 einfo "Processing ${conf} ..."
129 ghc-register-pkg ${conf}
130 done
131 popd
132 fi
133 }
134
135 # unregisters ...
136 ghc-unregister-pkg() {
137 local localpkgconf
138 localpkgconf="$(ghc-confdir)/$1"
139 for pkg in $(ghc-reverse "$(ghc-listpkg ${localpkgconf})"); do
140 einfo "Unregistering ${pkg} ..."
141 $(ghc-getghcpkg) -r ${pkg} --force
142 done
143 }
144
145 # help-function: reverse a list
146 ghc-reverse() {
147 local result
148 for i in $1; do
149 result="${i} ${result}"
150 done
151 echo ${result}
152 }
153
154 # show the packages in a package configuration file
155 ghc-listpkg() {
156 local ghcpkgcall
157 if ghc-cabal; then
158 echo $($(ghc-getghcpkg) list -f $1) \
159 | sed \
160 -e "s|^.*${f}:\([^:]*\).*$|\1|" \
161 -e "s|/.*$||" \
162 -e "s|,| |g" -e "s|[()]||g"
163 else
164 echo $($(ghc-getghcpkgbin) -l -f $1) \
165 | cut -f2 -d':' \
166 | sed 's:,: :g'
167 fi
168 }
169
170 # exported function: registers the package-specific package
171 # configuration file
172 ghc-package_pkg_postinst() {
173 ghc-register-pkg $(ghc-localpkgconf)
174 }
175
176 # exported function: unregisters the package-specific
177 # package configuration file, under the condition that
178 # after removal, no other instances of the package will
179 # be left (necessary check because ghc packages are not
180 # versioned)
181 ghc-package_pkg_prerm() {
182 has_version "<${CATEGORY}/${PF}" || has_version ">${CATEGORY}/${PF}" \
183 || ghc-unregister-pkg $(ghc-localpkgconf)
184 }
185
186 EXPORT_FUNCTIONS pkg_postinst pkg_prerm

  ViewVC Help
Powered by ViewVC 1.1.20