/[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.3 Revision 1.9
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.3 2004/11/04 13:13:59 kosmikus Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/ghc-package.eclass,v 1.9 2005/04/08 01:13:39 araujo 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
10inherit versionator
11
10ECLASS="ghc-package" 12ECLASS="ghc-package"
11INHERITED="$INHERITED $ECLASS" 13INHERITED="${INHERITED} ${ECLASS}"
12 14
13PATH="${PATH}:/opt/ghc/bin" 15# promote /opt/ghc/bin to a better position in the search path
16PATH="/usr/bin:/opt/ghc/bin:${PATH}"
14 17
15# for later configuration using environment variables/ 18# for later configuration using environment variables/
16# returns the name of the ghc executable 19# returns the name of the ghc executable
17ghc-getghc() { 20ghc-getghc() {
18 echo "ghc" 21 echo "ghc"
23 echo "ghc-pkg" 26 echo "ghc-pkg"
24} 27}
25 28
26# returns the name of the ghc-pkg binary (ghc-pkg 29# returns the name of the ghc-pkg binary (ghc-pkg
27# itself usually is a shell script, and we have to 30# itself usually is a shell script, and we have to
28# bypass the script under certain circumstances) 31# bypass the script under certain circumstances);
32# for Cabal, we add the global package config file,
33# because for some reason that's required
29ghc-getghcpkgbin() { 34ghc-getghcpkgbin() {
35 if ghc-cabal; then
36 echo $(ghc-libdir)/"ghc-pkg.bin" "--global-conf=$(ghc-libdir)/package.conf"
37 else
30 echo $(ghc-libdir)/"ghc-pkg.bin" 38 echo $(ghc-libdir)/"ghc-pkg.bin"
39 fi
31} 40}
32 41
33# returns the version of ghc 42# returns the version of ghc
43_GHC_VERSION_CACHE=""
34ghc-version() { 44ghc-version() {
45 if [[ -z "${_GHC_VERSION_CACHE}" ]]; then
35 $(ghc-getghc) --version | sed 's:^.*version ::' 46 _GHC_VERSION_CACHE="$($(ghc-getghc) --version | sed 's:^.*version ::')"
47 fi
48 echo "${_GHC_VERSION_CACHE}"
49}
50
51# returns true for ghc >= 6.4
52ghc-cabal() {
53 version_is_at_least "6.4" "$(ghc-version)"
36} 54}
37 55
38# returns the library directory 56# returns the library directory
57_GHC_LIBDIR_CACHE=""
39ghc-libdir() { 58ghc-libdir() {
40 $(ghc-getghc) --print-libdir 59 if [[ -z "${_GHC_LIBDIR_CACHE}" ]]; then
60 _GHC_LIBDIR_CACHE="$($(ghc-getghc) --print-libdir)"
61 fi
62 echo "${_GHC_LIBDIR_CACHE}"
41} 63}
42 64
43# returns the (Gentoo) library configuration directory 65# returns the (Gentoo) library configuration directory
44ghc-confdir() { 66ghc-confdir() {
45 echo $(ghc-libdir)/gentoo 67 echo $(ghc-libdir)/gentoo
53 75
54# make a ghci foo.o file from a libfoo.a file 76# make a ghci foo.o file from a libfoo.a file
55ghc-makeghcilib() { 77ghc-makeghcilib() {
56 local outfile 78 local outfile
57 outfile="$(dirname $1)/$(basename $1 | sed 's:^lib\?\(.*\)\.a$:\1.o:')" 79 outfile="$(dirname $1)/$(basename $1 | sed 's:^lib\?\(.*\)\.a$:\1.o:')"
58 ld --relocatable --discard-all --output="${outfile}" $1 80 ld --relocatable --discard-all --output="${outfile}" --whole-archive $1
59} 81}
60 82
61# creates a local (package-specific) package 83# creates a local (package-specific) package
62# configuration file; the arguments should be 84# configuration file; the arguments should be
63# uninstalled package description files, each 85# uninstalled package description files, each
74 [ -n "$1" ] && echo ',' >> ${localpkgconf} 96 [ -n "$1" ] && echo ',' >> ${localpkgconf}
75 done 97 done
76 echo ']' >> ${localpkgconf} 98 echo ']' >> ${localpkgconf}
77} 99}
78 100
101# fixes the library and import directories path
102# of the package configuration file
103ghc-fixlibpath() {
104 sed -i "s|$1|$(ghc-libdir)|" ${S}/$(ghc-localpkgconf)
105 if [[ -n "$2" ]]; then
106 sed -i "s|$2|$(ghc-libdir)/imports|" ${S}/$(ghc-localpkgconf)
107 fi
108}
109
79# moves the local (package-specific) package configuration 110# moves the local (package-specific) package configuration
80# file to its final destination 111# file to its final destination
81ghc-install-pkg() { 112ghc-install-pkg() {
82 mkdir -p ${D}/$(ghc-confdir) 113 mkdir -p ${D}/$(ghc-confdir)
83 cat ${S}/$(ghc-localpkgconf) | sed "s:${D}::" \ 114 cat ${S}/$(ghc-localpkgconf) | sed "s:${D}::" \
87# registers all packages in the local (package-specific) 118# registers all packages in the local (package-specific)
88# package configuration file 119# package configuration file
89ghc-register-pkg() { 120ghc-register-pkg() {
90 local localpkgconf 121 local localpkgconf
91 localpkgconf="$(ghc-confdir)/$1" 122 localpkgconf="$(ghc-confdir)/$1"
123 if [[ -f ${localpkgconf} ]]; then
92 for pkg in $(ghc-listpkg ${localpkgconf}); do 124 for pkg in $(ghc-listpkg ${localpkgconf}); do
93 einfo "Registering ${pkg} ..." 125 ebegin "Registering ${pkg} "
94 $(ghc-getghcpkgbin) -f ${localpkgconf} -s ${pkg} \ 126 $(ghc-getghcpkgbin) -f ${localpkgconf} -s ${pkg} \
95 | $(ghc-getghcpkg) -u --force 127 | $(ghc-getghcpkg) -u --force > /dev/null
128 eend $?
96 done 129 done
130 fi
97} 131}
98 132
99# re-adds all available .conf files to the global 133# re-adds all available .conf files to the global
100# package conf file, to be used on a ghc reinstallation 134# package conf file, to be used on a ghc reinstallation
101ghc-reregister() { 135ghc-reregister() {
102 einfo "Re-adding packages ..." 136 einfo "Re-adding packages ..."
103 ewarn "This may cause several warnings, but they should be harmless." 137 einfo "(This may cause several warnings, but they should be harmless.)"
138 if [ -d "$(ghc-confdir)" ]; then
104 pushd $(ghc-confdir) 139 pushd $(ghc-confdir) > /dev/null
105 for conf in *.conf; do 140 for conf in *.conf; do
106 einfo "Processing ${conf} ..." 141 einfo "Processing ${conf} ..."
107 ghc-register-pkg ${conf} 142 ghc-register-pkg ${conf}
108 done 143 done
109 popd 144 popd > /dev/null
145 fi
110} 146}
111 147
112# unregisters ... 148# unregisters ...
113ghc-unregister-pkg() { 149ghc-unregister-pkg() {
114 local localpkgconf 150 local localpkgconf
115 localpkgconf="$(ghc-confdir)/$1" 151 localpkgconf="$(ghc-confdir)/$1"
152 if [[ -f ${localpkgconf} ]]; then
116 for pkg in $(ghc-reverse "$(ghc-listpkg ${localpkgconf})"); do 153 for pkg in $(ghc-reverse "$(ghc-listpkg ${localpkgconf})"); do
117 einfo "Unregistering ${pkg} ..." 154 ebegin "Unregistering ${pkg} "
118 $(ghc-getghcpkg) -r ${pkg} --force 155 $(ghc-getghcpkg) -r ${pkg} --force > /dev/null
156 eend $?
119 done 157 done
158 fi
120} 159}
121 160
122# help-function: reverse a list 161# help-function: reverse a list
123ghc-reverse() { 162ghc-reverse() {
124 local result 163 local result
128 echo ${result} 167 echo ${result}
129} 168}
130 169
131# show the packages in a package configuration file 170# show the packages in a package configuration file
132ghc-listpkg() { 171ghc-listpkg() {
172 local ghcpkgcall
173 if ghc-cabal; then
174 echo $($(ghc-getghcpkg) list -f $1) \
175 | sed \
176 -e "s|^.*${f}:\([^:]*\).*$|\1|" \
177 -e "s|/.*$||" \
178 -e "s|,| |g" -e "s|[()]||g"
179 else
133 [ -f $1 ] && echo $($(ghc-getghcpkgbin) -l -f $1) \ 180 echo $($(ghc-getghcpkgbin) -l -f $1) \
134 | cut -f2 -d':' \ 181 | cut -f2 -d':' \
135 | sed 's:,: :g' 182 | sed 's:,: :g'
183 fi
136} 184}
137 185
138# exported function: registers the package-specific package 186# exported function: registers the package-specific package
139# configuration file 187# configuration file
140ghc-package_pkg_postinst() { 188ghc-package_pkg_postinst() {

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.9

  ViewVC Help
Powered by ViewVC 1.1.20