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

Diff of /eclass/ghc-package.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.2 Revision 1.12
1# Copyright 1999-2004 Gentoo Foundation 1# Copyright 1999-2004 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/ghc-package.eclass,v 1.2 2004/11/03 20:38:35 kosmikus Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/ghc-package.eclass,v 1.12 2005/07/06 20:20:03 agriffis Exp $
4# 4#
5# Author: Andres Loeh <kosmikus@gentoo.org> 5# Author: Andres Loeh <kosmikus@gentoo.org>
6# 6#
7# This eclass helps with the Glasgow Haskell Compiler's package 7# This eclass helps with the Glasgow Haskell Compiler's package
8# configuration utility. 8# configuration utility.
9 9
10ECLASS="ghc-package" 10inherit versionator
11INHERITED="$INHERITED $ECLASS"
12 11
13PATH="${PATH}:/opt/ghc/bin" 12INHERITED="${INHERITED} ${ECLASS}"
13
14# promote /opt/ghc/bin to a better position in the search path
15PATH="/usr/bin:/opt/ghc/bin:${PATH}"
14 16
15# for later configuration using environment variables/ 17# for later configuration using environment variables/
16# returns the name of the ghc executable 18# returns the name of the ghc executable
17ghc-getghc() { 19ghc-getghc() {
18 echo "ghc" 20 echo "ghc"
23 echo "ghc-pkg" 25 echo "ghc-pkg"
24} 26}
25 27
26# returns the name of the ghc-pkg binary (ghc-pkg 28# returns the name of the ghc-pkg binary (ghc-pkg
27# itself usually is a shell script, and we have to 29# itself usually is a shell script, and we have to
28# bypass the script under certain circumstances) 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
29ghc-getghcpkgbin() { 33ghc-getghcpkgbin() {
34 if ghc-cabal; then
35 echo $(ghc-libdir)/"ghc-pkg.bin" "--global-conf=$(ghc-libdir)/package.conf"
36 else
30 echo $(ghc-libdir)/"ghc-pkg.bin" 37 echo $(ghc-libdir)/"ghc-pkg.bin"
38 fi
31} 39}
32 40
33# returns the version of ghc 41# returns the version of ghc
42_GHC_VERSION_CACHE=""
34ghc-version() { 43ghc-version() {
44 if [[ -z "${_GHC_VERSION_CACHE}" ]]; then
35 $(ghc-getghc) --version | sed 's:^.*version ::' 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
51ghc-cabal() {
52 version_is_at_least "6.4" "$(ghc-version)"
36} 53}
37 54
38# returns the library directory 55# returns the library directory
56_GHC_LIBDIR_CACHE=""
39ghc-libdir() { 57ghc-libdir() {
40 $(ghc-getghc) --print-libdir 58 if [[ -z "${_GHC_LIBDIR_CACHE}" ]]; then
59 _GHC_LIBDIR_CACHE="$($(ghc-getghc) --print-libdir)"
60 fi
61 echo "${_GHC_LIBDIR_CACHE}"
41} 62}
42 63
43# returns the (Gentoo) library configuration directory 64# returns the (Gentoo) library configuration directory
44ghc-confdir() { 65ghc-confdir() {
45 echo $(ghc-libdir)/gentoo 66 echo $(ghc-libdir)/gentoo
49# package configuration file 70# package configuration file
50ghc-localpkgconf() { 71ghc-localpkgconf() {
51 echo "${PF}.conf" 72 echo "${PF}.conf"
52} 73}
53 74
75# make a ghci foo.o file from a libfoo.a file
76ghc-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
54# creates an empty local (package-specific) package 82# creates a local (package-specific) package
55# configuration file 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
56ghc-setup-pkg() { 88ghc-setup-pkg() {
89 local localpkgconf
90 localpkgconf="${S}/$(ghc-localpkgconf)"
57 echo '[]' > ${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
100ghc-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
58} 105}
59 106
60# moves the local (package-specific) package configuration 107# moves the local (package-specific) package configuration
61# file to its final destination 108# file to its final destination
62ghc-install-pkg() { 109ghc-install-pkg() {
63 mkdir -p ${D}/$(ghc-confdir) 110 mkdir -p ${D}/$(ghc-confdir)
64 cat ${S}/$(ghc-localpkgconf) | sed "s:${D}::" \ 111 cat ${S}/$(ghc-localpkgconf) | sed "s|${D}||g" \
65 > ${D}/$(ghc-confdir)/$(ghc-localpkgconf) 112 > ${D}/$(ghc-confdir)/$(ghc-localpkgconf)
66} 113}
67 114
68# registers all packages in the local (package-specific) 115# registers all packages in the local (package-specific)
69# package configuration file 116# package configuration file
70ghc-register-pkg() { 117ghc-register-pkg() {
71 local localpkgconf 118 local localpkgconf
72 localpkgconf=$(ghc-confdir)/$1 119 localpkgconf="$(ghc-confdir)/$1"
120 if [[ -f ${localpkgconf} ]]; then
73 for pkg in $(ghc-listpkg ${localpkgconf}); do 121 for pkg in $(ghc-listpkg ${localpkgconf}); do
74 einfo "Registering ${pkg} ..." 122 ebegin "Registering ${pkg} "
75 $(ghc-getghcpkgbin) -f ${localpkgconf} -s ${pkg} \ 123 $(ghc-getghcpkgbin) -f ${localpkgconf} -s ${pkg} \
76 | $(ghc-getghcpkg) -u --force 124 | $(ghc-getghcpkg) -u --force > /dev/null
125 eend $?
77 done 126 done
127 fi
78} 128}
79 129
80# re-adds all available .conf files to the global 130# re-adds all available .conf files to the global
81# package conf file, to be used on a ghc reinstallation 131# package conf file, to be used on a ghc reinstallation
82ghc-reregister() { 132ghc-reregister() {
83 einfo "Re-adding packages ..." 133 einfo "Re-adding packages ..."
84 ewarn "This may cause several warnings, but they should be harmless." 134 einfo "(This may cause several warnings, but they should be harmless.)"
135 if [ -d "$(ghc-confdir)" ]; then
85 pushd $(ghc-confdir) 136 pushd $(ghc-confdir) > /dev/null
86 for conf in *.conf; do 137 for conf in *.conf; do
87 einfo "Processing ${conf} ..." 138 einfo "Processing ${conf} ..."
88 ghc-register-pkg ${conf} 139 ghc-register-pkg ${conf}
89 done 140 done
90 popd 141 popd > /dev/null
142 fi
91} 143}
92 144
93# unregisters ... 145# unregisters ...
94ghc-unregister-pkg() { 146ghc-unregister-pkg() {
95 local localpkgconf 147 local localpkgconf
96 localpkgconf=$(ghc-confdir)/$1 148 localpkgconf="$(ghc-confdir)/$1"
149 if [[ -f ${localpkgconf} ]]; then
97 for pkg in $(ghc-reverse "$(ghc-listpkg ${localpkgconf})"); do 150 for pkg in $(ghc-reverse "$(ghc-listpkg ${localpkgconf})"); do
98 einfo "Unregistering ${pkg} ..." 151 ebegin "Unregistering ${pkg} "
99 $(ghc-getghcpkg) -r ${pkg} --force 152 $(ghc-getghcpkg) -r ${pkg} --force > /dev/null
153 eend $?
100 done 154 done
155 fi
101} 156}
102 157
103# help-function: reverse a list 158# help-function: reverse a list
104ghc-reverse() { 159ghc-reverse() {
105 local result 160 local result
109 echo ${result} 164 echo ${result}
110} 165}
111 166
112# show the packages in a package configuration file 167# show the packages in a package configuration file
113ghc-listpkg() { 168ghc-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
114 [ -f $1 ] && echo $($(ghc-getghcpkgbin) -l -f $1) \ 177 echo $($(ghc-getghcpkgbin) -l -f $1) \
115 | cut -f2 -d':' \ 178 | cut -f2 -d':' \
116 | sed 's:,: :g' 179 | sed 's:,: :g'
180 fi
117} 181}
118 182
119# exported function: registers the package-specific package 183# exported function: registers the package-specific package
120# configuration file 184# configuration file
121ghc-package_pkg_postinst() { 185ghc-package_pkg_postinst() {

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.12

  ViewVC Help
Powered by ViewVC 1.1.20