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

Contents of /eclass/ghc-package.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.41 - (show annotations) (download)
Sat Mar 28 13:32:40 2015 UTC (5 weeks, 1 day ago) by slyfox
Branch: MAIN
CVS Tags: HEAD
Changes since 1.40: +1 -8 lines
Enable building dynamic haskell executables since dev-lang/ghc-7.10.1_rc3.

1 # Copyright 1999-2015 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.40 2015/01/01 21:23:03 slyfox Exp $
4
5 # @ECLASS: ghc-package.eclass
6 # @MAINTAINER:
7 # "Gentoo's Haskell Language team" <haskell@gentoo.org>
8 # @AUTHOR:
9 # Original Author: Andres Loeh <kosmikus@gentoo.org>
10 # @BLURB: This eclass helps with the Glasgow Haskell Compiler's package configuration utility.
11 # @DESCRIPTION:
12 # Helper eclass to handle ghc installation/upgrade/deinstallation process.
13
14 inherit versionator
15
16 # @FUNCTION: ghc-getghc
17 # @DESCRIPTION:
18 # returns the name of the ghc executable
19 ghc-getghc() {
20 type -P ghc
21 }
22
23 # @FUNCTION: ghc-getghcpkg
24 # @DESCRIPTION:
25 # Internal function determines returns the name of the ghc-pkg executable
26 ghc-getghcpkg() {
27 type -P ghc-pkg
28 }
29
30 # @FUNCTION: ghc-getghcpkgbin
31 # @DESCRIPTION:
32 # returns the name of the ghc-pkg binary (ghc-pkg
33 # itself usually is a shell script, and we have to
34 # bypass the script under certain circumstances);
35 # for Cabal, we add an empty global package config file,
36 # because for some reason the global package file
37 # must be specified
38 ghc-getghcpkgbin() {
39 if version_is_at_least "7.9.20141222" "$(ghc-version)"; then
40 # ghc-7.10 stopped supporting single-file database
41 local empty_db="${T}/empty.conf.d" ghc_pkg="$(ghc-libdir)/bin/ghc-pkg"
42 if [[ ! -d ${empty_db} ]]; then
43 "${ghc_pkg}" init "${empty_db}" || die "Failed to initialize empty global db"
44 fi
45 echo "$(ghc-libdir)/bin/ghc-pkg" "--global-package-db=${empty_db}"
46
47 elif version_is_at_least "7.7.20121101" "$(ghc-version)"; then
48 # the ghc-pkg executable changed name in ghc 6.10, as it no longer needs
49 # the wrapper script with the static flags
50 # was moved to bin/ subtree by:
51 # http://www.haskell.org/pipermail/cvs-ghc/2012-September/076546.html
52 echo '[]' > "${T}/empty.conf"
53 echo "$(ghc-libdir)/bin/ghc-pkg" "--global-package-db=${T}/empty.conf"
54
55 elif version_is_at_least "7.5.20120516" "$(ghc-version)"; then
56 echo '[]' > "${T}/empty.conf"
57 echo "$(ghc-libdir)/ghc-pkg" "--global-package-db=${T}/empty.conf"
58
59 else
60 echo '[]' > "${T}/empty.conf"
61 echo "$(ghc-libdir)/ghc-pkg" "--global-conf=${T}/empty.conf"
62 fi
63 }
64
65 # @FUNCTION: ghc-version
66 # @DESCRIPTION:
67 # returns the version of ghc
68 _GHC_VERSION_CACHE=""
69 ghc-version() {
70 if [[ -z "${_GHC_VERSION_CACHE}" ]]; then
71 _GHC_VERSION_CACHE="$($(ghc-getghc) --numeric-version)"
72 fi
73 echo "${_GHC_VERSION_CACHE}"
74 }
75
76 # @FUNCTION: ghc-cabal-version
77 # @DESCRIPTION:
78 # return version of the Cabal library bundled with ghc
79 ghc-cabal-version() {
80 if version_is_at_least "7.9.20141222" "$(ghc-version)"; then
81 # outputs in format: 'version: 1.18.1.5'
82 set -- `$(ghc-getghcpkg) --package-db=$(ghc-libdir)/package.conf.d.initial field Cabal version`
83 echo "$2"
84 else
85 local cabal_package=`echo "$(ghc-libdir)"/Cabal-*`
86 # /path/to/ghc/Cabal-${VER} -> ${VER}
87 echo "${cabal_package/*Cabal-/}"
88 fi
89 }
90
91 # @FUNCTION: ghc-sanecabal
92 # @DESCRIPTION:
93 # check if a standalone Cabal version is available for the
94 # currently used ghc; takes minimal version of Cabal as
95 # an optional argument
96 ghc-sanecabal() {
97 local f
98 local version
99 if [[ -z "$1" ]]; then version="1.0.1"; else version="$1"; fi
100 for f in $(ghc-confdir)/cabal-*; do
101 [[ -f "${f}" ]] && version_is_at_least "${version}" "${f#*cabal-}" && return
102 done
103 return 1
104 }
105
106 # @FUNCTION: ghc-supports-shared-libraries
107 # @DESCRIPTION:
108 # checks if ghc is built with support for building
109 # shared libraries (aka '-dynamic' option)
110 ghc-supports-shared-libraries() {
111 $(ghc-getghc) --info | grep "RTS ways" | grep -q "dyn"
112 }
113
114 # @FUNCTION: ghc-supports-threaded-runtime
115 # @DESCRIPTION:
116 # checks if ghc is built with support for threaded
117 # runtime (aka '-threaded' option)
118 ghc-supports-threaded-runtime() {
119 $(ghc-getghc) --info | grep "RTS ways" | grep -q "thr"
120 }
121
122 # @FUNCTION: ghc-supports-smp
123 # @DESCRIPTION:
124 # checks if ghc is built with support for multiple cores runtime
125 ghc-supports-smp() {
126 $(ghc-getghc) --info | grep "Support SMP" | grep -q "YES"
127 }
128
129 # @FUNCTION: ghc-supports-interpreter
130 # @DESCRIPTION:
131 # checks if ghc has interpreter mode (aka GHCi)
132 # It usually means that ghc supports for template haskell.
133 ghc-supports-interpreter() {
134 $(ghc-getghc) --info | grep "Have interpreter" | grep -q "YES"
135 }
136
137 # @FUNCTION: ghc-supports-parallel-make
138 # @DESCRIPTION:
139 # checks if ghc has support for '--make -j' mode
140 # The option was introduced in ghc-7.8-rc1.
141 ghc-supports-parallel-make() {
142 $(ghc-getghc) --info | grep "Support parallel --make" | grep -q "YES"
143 }
144
145 # @FUNCTION: ghc-extractportageversion
146 # @DESCRIPTION:
147 # extract the version of a portage-installed package
148 ghc-extractportageversion() {
149 local pkg
150 local version
151 pkg="$(best_version $1)"
152 version="${pkg#$1-}"
153 version="${version%-r*}"
154 version="${version%_pre*}"
155 echo "${version}"
156 }
157
158 # @FUNCTION: ghc-libdir
159 # @DESCRIPTION:
160 # returns the library directory
161 _GHC_LIBDIR_CACHE=""
162 ghc-libdir() {
163 if [[ -z "${_GHC_LIBDIR_CACHE}" ]]; then
164 _GHC_LIBDIR_CACHE="$($(ghc-getghc) --print-libdir)"
165 fi
166 echo "${_GHC_LIBDIR_CACHE}"
167 }
168
169 # @FUNCTION: ghc-confdir
170 # @DESCRIPTION:
171 # returns the (Gentoo) library configuration directory, we
172 # store here a hint for 'haskell-updater' about packages
173 # installed for old ghc versions and current ones.
174 ghc-confdir() {
175 echo "$(ghc-libdir)/gentoo"
176 }
177
178 # @FUNCTION: ghc-package-db
179 # @DESCRIPTION:
180 # returns the global package database directory
181 ghc-package-db() {
182 echo "$(ghc-libdir)/package.conf.d"
183 }
184
185 # @FUNCTION: ghc-localpkgconfd
186 # @DESCRIPTION:
187 # returns the name of the local (package-specific)
188 # package configuration file
189 ghc-localpkgconfd() {
190 echo "${PF}.conf.d"
191 }
192
193 # @FUNCTION: ghc-package-exists
194 # @DESCRIPTION:
195 # tests if a ghc package exists
196 ghc-package-exists() {
197 $(ghc-getghcpkg) describe "$1" > /dev/null 2>&1
198 }
199
200 # @FUNCTION: check-for-collisions
201 # @DESCRIPTION: makes sure no packages
202 # have the same version as initial package setup
203 check-for-collisions() {
204 local localpkgconf=$1
205 local checked_pkg
206 local initial_pkg_db="$(ghc-libdir)/package.conf.d.initial"
207
208 for checked_pkg in `$(ghc-getghcpkgbin) -f "${localpkgconf}" list --simple-output`
209 do
210 # should return empty output
211 local collided=`$(ghc-getghcpkgbin) -f ${initial_pkg_db} list --simple-output "${checked_pkg}"`
212
213 if [[ -n ${collided} ]]; then
214 eerror "Package ${checked_pkg} is shipped with $(ghc-version)."
215 eerror "Ebuild author forgot CABAL_CORE_LIB_GHC_PV entry."
216 eerror "Found in ${initial_pkg_db}."
217 die
218 fi
219 done
220 }
221
222 # @FUNCTION: ghc-install-pkg
223 # @DESCRIPTION:
224 # moves the local (package-specific) package configuration
225 # file to its final destination
226 ghc-install-pkg() {
227 local pkg_config_file=$1
228 local localpkgconf="${T}/$(ghc-localpkgconfd)"
229 local pkg_path pkg pkg_db="${D}/$(ghc-package-db)" hint_db="${D}/$(ghc-confdir)"
230
231 $(ghc-getghcpkgbin) init "${localpkgconf}" || die "Failed to initialize empty local db"
232 $(ghc-getghcpkgbin) -f "${localpkgconf}" update - --force \
233 < "${pkg_config_file}" || die "failed to register ${pkg}"
234
235 check-for-collisions "${localpkgconf}"
236
237 mkdir -p "${pkg_db}" || die
238 for pkg_path in "${localpkgconf}"/*.conf; do
239 pkg=$(basename "${pkg_path}")
240 cp "${pkg_path}" "${pkg_db}/${pkg}" || die
241 done
242
243 mkdir -p "${hint_db}" || die
244 cp "${pkg_config_file}" "${hint_db}/${PF}.conf" || die
245 chmod 0644 "${hint_db}/${PF}.conf" || die
246 }
247
248 # @FUNCTION: ghc-recache-db
249 # @DESCRIPTION:
250 # updates 'package.cache' binary cacne for registered '*.conf'
251 # packages
252 ghc-recache-db() {
253 einfo "Recaching GHC package DB"
254 $(ghc-getghcpkg) recache
255 }
256
257 # @FUNCTION: ghc-register-pkg
258 # @DESCRIPTION:
259 # registers all packages in the local (package-specific)
260 # package configuration file
261 ghc-register-pkg() {
262 ghc-recache-db
263 }
264
265 # @FUNCTION: ghc-reregister
266 # @DESCRIPTION:
267 # re-adds all available .conf files to the global
268 # package conf file, to be used on a ghc reinstallation
269 ghc-reregister() {
270 ghc-recache-db
271 }
272
273 # @FUNCTION: ghc-unregister-pkg
274 # @DESCRIPTION:
275 # unregisters a package configuration file
276 ghc-unregister-pkg() {
277 ghc-recache-db
278 }
279
280 # @FUNCTION: ghc-pkgdeps
281 # @DESCRIPTION:
282 # exported function: loads a package dependency in a form
283 # cabal_package version
284 ghc-pkgdeps() {
285 echo $($(ghc-getghcpkg) describe "${1}") \
286 | sed \
287 -e '/depends/,/^.*:/ !d' \
288 -e 's/\(.*\)-\(.*\)-\(.*\)/\1 \2/' \
289 -e 's/^.*://g'
290 }
291
292 # @FUNCTION: ghc-package_pkg_postinst
293 # @DESCRIPTION:
294 # updates package.cache after package install
295 ghc-package_pkg_postinst() {
296 ghc-recache-db
297 }
298
299 # @FUNCTION: ghc-package_pkg_prerm
300 # @DESCRIPTION:
301 # updates package.cache after package deinstall
302 ghc-package_pkg_prerm() {
303 ewarn "ghc-package.eclass: 'ghc-package_pkg_prerm()' is a noop"
304 ewarn "ghc-package.eclass: consider 'haskell-cabal_pkg_postrm()' instead"
305 }
306
307 # @FUNCTION: ghc-package_pkg_postrm
308 # @DESCRIPTION:
309 # updates package.cache after package deinstall
310 ghc-package_pkg_postrm() {
311 ghc-recache-db
312 }

  ViewVC Help
Powered by ViewVC 1.1.20