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

Contents of /eclass/ghc-package.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download)
Wed Nov 24 15:05:49 2004 UTC (9 years, 7 months ago) by kosmikus
Branch: MAIN
Changes since 1.4: +9 -7 lines
* check for existence of configuration directory prior to doing
  anything in ghc-reregister function

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.4 2004/11/04 14:16:14 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 ECLASS="ghc-package"
11 INHERITED="$INHERITED $ECLASS"
12
13 PATH="${PATH}:/opt/ghc/bin"
14
15 # for later configuration using environment variables/
16 # returns the name of the ghc executable
17 ghc-getghc() {
18 echo "ghc"
19 }
20
21 # returns the name of the ghc-pkg executable
22 ghc-getghcpkg() {
23 echo "ghc-pkg"
24 }
25
26 # returns the name of the ghc-pkg binary (ghc-pkg
27 # itself usually is a shell script, and we have to
28 # bypass the script under certain circumstances)
29 ghc-getghcpkgbin() {
30 echo $(ghc-libdir)/"ghc-pkg.bin"
31 }
32
33 # returns the version of ghc
34 ghc-version() {
35 $(ghc-getghc) --version | sed 's:^.*version ::'
36 }
37
38 # returns the library directory
39 ghc-libdir() {
40 $(ghc-getghc) --print-libdir
41 }
42
43 # returns the (Gentoo) library configuration directory
44 ghc-confdir() {
45 echo $(ghc-libdir)/gentoo
46 }
47
48 # returns the name of the local (package-specific)
49 # package configuration file
50 ghc-localpkgconf() {
51 echo "${PF}.conf"
52 }
53
54 # make a ghci foo.o file from a libfoo.a file
55 ghc-makeghcilib() {
56 local outfile
57 outfile="$(dirname $1)/$(basename $1 | sed 's:^lib\?\(.*\)\.a$:\1.o:')"
58 ld --relocatable --discard-all --output="${outfile}" --whole-archive $1
59 }
60
61 # creates a local (package-specific) package
62 # configuration file; the arguments should be
63 # uninstalled package description files, each
64 # containing a single package description; if
65 # no arguments are given, the resulting file is
66 # empty
67 ghc-setup-pkg() {
68 local localpkgconf
69 localpkgconf="${S}/$(ghc-localpkgconf)"
70 echo '[' > ${localpkgconf}
71 while [ -n "$1" ]; do
72 cat "$1" >> ${localpkgconf}
73 shift
74 [ -n "$1" ] && echo ',' >> ${localpkgconf}
75 done
76 echo ']' >> ${localpkgconf}
77 }
78
79 # moves the local (package-specific) package configuration
80 # file to its final destination
81 ghc-install-pkg() {
82 mkdir -p ${D}/$(ghc-confdir)
83 cat ${S}/$(ghc-localpkgconf) | sed "s:${D}::" \
84 > ${D}/$(ghc-confdir)/$(ghc-localpkgconf)
85 }
86
87 # registers all packages in the local (package-specific)
88 # package configuration file
89 ghc-register-pkg() {
90 local localpkgconf
91 localpkgconf="$(ghc-confdir)/$1"
92 for pkg in $(ghc-listpkg ${localpkgconf}); do
93 einfo "Registering ${pkg} ..."
94 $(ghc-getghcpkgbin) -f ${localpkgconf} -s ${pkg} \
95 | $(ghc-getghcpkg) -u --force
96 done
97 }
98
99 # re-adds all available .conf files to the global
100 # package conf file, to be used on a ghc reinstallation
101 ghc-reregister() {
102 einfo "Re-adding packages ..."
103 ewarn "This may cause several warnings, but they should be harmless."
104 if [ -d "$(ghc-confdir)" ]; then
105 pushd $(ghc-confdir)
106 for conf in *.conf; do
107 einfo "Processing ${conf} ..."
108 ghc-register-pkg ${conf}
109 done
110 popd
111 fi
112 }
113
114 # unregisters ...
115 ghc-unregister-pkg() {
116 local localpkgconf
117 localpkgconf="$(ghc-confdir)/$1"
118 for pkg in $(ghc-reverse "$(ghc-listpkg ${localpkgconf})"); do
119 einfo "Unregistering ${pkg} ..."
120 $(ghc-getghcpkg) -r ${pkg} --force
121 done
122 }
123
124 # help-function: reverse a list
125 ghc-reverse() {
126 local result
127 for i in $1; do
128 result="${i} ${result}"
129 done
130 echo ${result}
131 }
132
133 # show the packages in a package configuration file
134 ghc-listpkg() {
135 [ -f $1 ] && echo $($(ghc-getghcpkgbin) -l -f $1) \
136 | cut -f2 -d':' \
137 | sed 's:,: :g'
138 }
139
140 # exported function: registers the package-specific package
141 # configuration file
142 ghc-package_pkg_postinst() {
143 ghc-register-pkg $(ghc-localpkgconf)
144 }
145
146 # exported function: unregisters the package-specific
147 # package configuration file, under the condition that
148 # after removal, no other instances of the package will
149 # be left (necessary check because ghc packages are not
150 # versioned)
151 ghc-package_pkg_prerm() {
152 has_version "<${CATEGORY}/${PF}" || has_version ">${CATEGORY}/${PF}" \
153 || ghc-unregister-pkg $(ghc-localpkgconf)
154 }
155
156 EXPORT_FUNCTIONS pkg_postinst pkg_prerm

  ViewVC Help
Powered by ViewVC 1.1.20