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

Contents of /eclass/ghc-package.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations) (download)
Fri Apr 8 01:13:39 2005 UTC (9 years, 3 months ago) by araujo
Branch: MAIN
Changes since 1.8: +10 -1 lines
Added new ghc-fixlibpath eclass

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

  ViewVC Help
Powered by ViewVC 1.1.20