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

Contents of /eclass/ghc-package.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (show annotations) (download)
Wed Jul 6 20:20:03 2005 UTC (9 years, 5 months ago) by agriffis
Branch: MAIN
Changes since 1.11: +1 -2 lines
Remove ECLASS= and INHERITED= which haven't been necessary for a long time now

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.11 2005/05/11 21:26:04 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 INHERITED="${INHERITED} ${ECLASS}"
13
14 # promote /opt/ghc/bin to a better position in the search path
15 PATH="/usr/bin:/opt/ghc/bin:${PATH}"
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 for pkg in $*; do
93 $(ghc-getghcpkgbin) -f ${localpkgconf} -u --force \
94 < ${pkg} || die "failed to register ${pkg}"
95 done
96 }
97
98 # fixes the library and import directories path
99 # of the package configuration file
100 ghc-fixlibpath() {
101 sed -i "s|$1|$(ghc-libdir)|g" ${S}/$(ghc-localpkgconf)
102 if [[ -n "$2" ]]; then
103 sed -i "s|$2|$(ghc-libdir)/imports|g" ${S}/$(ghc-localpkgconf)
104 fi
105 }
106
107 # moves the local (package-specific) package configuration
108 # file to its final destination
109 ghc-install-pkg() {
110 mkdir -p ${D}/$(ghc-confdir)
111 cat ${S}/$(ghc-localpkgconf) | sed "s|${D}||g" \
112 > ${D}/$(ghc-confdir)/$(ghc-localpkgconf)
113 }
114
115 # registers all packages in the local (package-specific)
116 # package configuration file
117 ghc-register-pkg() {
118 local localpkgconf
119 localpkgconf="$(ghc-confdir)/$1"
120 if [[ -f ${localpkgconf} ]]; then
121 for pkg in $(ghc-listpkg ${localpkgconf}); do
122 ebegin "Registering ${pkg} "
123 $(ghc-getghcpkgbin) -f ${localpkgconf} -s ${pkg} \
124 | $(ghc-getghcpkg) -u --force > /dev/null
125 eend $?
126 done
127 fi
128 }
129
130 # re-adds all available .conf files to the global
131 # package conf file, to be used on a ghc reinstallation
132 ghc-reregister() {
133 einfo "Re-adding packages ..."
134 einfo "(This may cause several warnings, but they should be harmless.)"
135 if [ -d "$(ghc-confdir)" ]; then
136 pushd $(ghc-confdir) > /dev/null
137 for conf in *.conf; do
138 einfo "Processing ${conf} ..."
139 ghc-register-pkg ${conf}
140 done
141 popd > /dev/null
142 fi
143 }
144
145 # unregisters ...
146 ghc-unregister-pkg() {
147 local localpkgconf
148 localpkgconf="$(ghc-confdir)/$1"
149 if [[ -f ${localpkgconf} ]]; then
150 for pkg in $(ghc-reverse "$(ghc-listpkg ${localpkgconf})"); do
151 ebegin "Unregistering ${pkg} "
152 $(ghc-getghcpkg) -r ${pkg} --force > /dev/null
153 eend $?
154 done
155 fi
156 }
157
158 # help-function: reverse a list
159 ghc-reverse() {
160 local result
161 for i in $1; do
162 result="${i} ${result}"
163 done
164 echo ${result}
165 }
166
167 # show the packages in a package configuration file
168 ghc-listpkg() {
169 local ghcpkgcall
170 if ghc-cabal; then
171 echo $($(ghc-getghcpkg) list -f $1) \
172 | sed \
173 -e "s|^.*${f}:\([^:]*\).*$|\1|" \
174 -e "s|/.*$||" \
175 -e "s|,| |g" -e "s|[()]||g"
176 else
177 echo $($(ghc-getghcpkgbin) -l -f $1) \
178 | cut -f2 -d':' \
179 | sed 's:,: :g'
180 fi
181 }
182
183 # exported function: registers the package-specific package
184 # configuration file
185 ghc-package_pkg_postinst() {
186 ghc-register-pkg $(ghc-localpkgconf)
187 }
188
189 # exported function: unregisters the package-specific
190 # package configuration file, under the condition that
191 # after removal, no other instances of the package will
192 # be left (necessary check because ghc packages are not
193 # versioned)
194 ghc-package_pkg_prerm() {
195 has_version "<${CATEGORY}/${PF}" || has_version ">${CATEGORY}/${PF}" \
196 || ghc-unregister-pkg $(ghc-localpkgconf)
197 }
198
199 EXPORT_FUNCTIONS pkg_postinst pkg_prerm

  ViewVC Help
Powered by ViewVC 1.1.20