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

Contents of /eclass/ghc-package.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (hide 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 kosmikus 1.1 # Copyright 1999-2004 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 agriffis 1.12 # $Header: /var/cvsroot/gentoo-x86/eclass/ghc-package.eclass,v 1.11 2005/05/11 21:26:04 kosmikus Exp $
4 kosmikus 1.1 #
5     # Author: Andres Loeh <kosmikus@gentoo.org>
6     #
7     # This eclass helps with the Glasgow Haskell Compiler's package
8     # configuration utility.
9    
10 kosmikus 1.6 inherit versionator
11    
12     INHERITED="${INHERITED} ${ECLASS}"
13 kosmikus 1.1
14 kosmikus 1.7 # promote /opt/ghc/bin to a better position in the search path
15     PATH="/usr/bin:/opt/ghc/bin:${PATH}"
16 kosmikus 1.1
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 kosmikus 1.6 # 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 kosmikus 1.1 ghc-getghcpkgbin() {
34 kosmikus 1.6 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 kosmikus 1.1 }
40    
41     # returns the version of ghc
42 kosmikus 1.6 _GHC_VERSION_CACHE=""
43 kosmikus 1.1 ghc-version() {
44 kosmikus 1.6 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 kosmikus 1.1 }
54    
55     # returns the library directory
56 kosmikus 1.6 _GHC_LIBDIR_CACHE=""
57 kosmikus 1.1 ghc-libdir() {
58 kosmikus 1.6 if [[ -z "${_GHC_LIBDIR_CACHE}" ]]; then
59     _GHC_LIBDIR_CACHE="$($(ghc-getghc) --print-libdir)"
60     fi
61     echo "${_GHC_LIBDIR_CACHE}"
62 kosmikus 1.1 }
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 kosmikus 1.3 # 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 kosmikus 1.4 ld --relocatable --discard-all --output="${outfile}" --whole-archive $1
80 kosmikus 1.3 }
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 kosmikus 1.1 ghc-setup-pkg() {
89 kosmikus 1.3 local localpkgconf
90     localpkgconf="${S}/$(ghc-localpkgconf)"
91 dcoutts 1.10 echo '[]' > ${localpkgconf}
92     for pkg in $*; do
93     $(ghc-getghcpkgbin) -f ${localpkgconf} -u --force \
94 kosmikus 1.11 < ${pkg} || die "failed to register ${pkg}"
95 kosmikus 1.3 done
96 kosmikus 1.1 }
97    
98 araujo 1.9 # fixes the library and import directories path
99     # of the package configuration file
100     ghc-fixlibpath() {
101 dcoutts 1.10 sed -i "s|$1|$(ghc-libdir)|g" ${S}/$(ghc-localpkgconf)
102 araujo 1.9 if [[ -n "$2" ]]; then
103 dcoutts 1.10 sed -i "s|$2|$(ghc-libdir)/imports|g" ${S}/$(ghc-localpkgconf)
104 araujo 1.9 fi
105     }
106    
107 kosmikus 1.1 # moves the local (package-specific) package configuration
108     # file to its final destination
109     ghc-install-pkg() {
110     mkdir -p ${D}/$(ghc-confdir)
111 dcoutts 1.10 cat ${S}/$(ghc-localpkgconf) | sed "s|${D}||g" \
112 kosmikus 1.1 > ${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 kosmikus 1.3 localpkgconf="$(ghc-confdir)/$1"
120 kosmikus 1.7 if [[ -f ${localpkgconf} ]]; then
121     for pkg in $(ghc-listpkg ${localpkgconf}); do
122 kosmikus 1.8 ebegin "Registering ${pkg} "
123 kosmikus 1.7 $(ghc-getghcpkgbin) -f ${localpkgconf} -s ${pkg} \
124 kosmikus 1.8 | $(ghc-getghcpkg) -u --force > /dev/null
125     eend $?
126 kosmikus 1.7 done
127     fi
128 kosmikus 1.1 }
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 kosmikus 1.8 einfo "(This may cause several warnings, but they should be harmless.)"
135 kosmikus 1.5 if [ -d "$(ghc-confdir)" ]; then
136 kosmikus 1.8 pushd $(ghc-confdir) > /dev/null
137 kosmikus 1.5 for conf in *.conf; do
138     einfo "Processing ${conf} ..."
139     ghc-register-pkg ${conf}
140     done
141 kosmikus 1.8 popd > /dev/null
142 kosmikus 1.5 fi
143 kosmikus 1.1 }
144    
145     # unregisters ...
146     ghc-unregister-pkg() {
147     local localpkgconf
148 kosmikus 1.3 localpkgconf="$(ghc-confdir)/$1"
149 kosmikus 1.7 if [[ -f ${localpkgconf} ]]; then
150     for pkg in $(ghc-reverse "$(ghc-listpkg ${localpkgconf})"); do
151 kosmikus 1.8 ebegin "Unregistering ${pkg} "
152     $(ghc-getghcpkg) -r ${pkg} --force > /dev/null
153     eend $?
154 kosmikus 1.7 done
155     fi
156 kosmikus 1.1 }
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 kosmikus 1.6 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 kosmikus 1.1 | cut -f2 -d':' \
179     | sed 's:,: :g'
180 kosmikus 1.6 fi
181 kosmikus 1.1 }
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