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

Contents of /eclass/ghc-package.eclass

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20