| 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.6 2005/03/18 23:31:48 kosmikus Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/ghc-package.eclass,v 1.10 2005/05/08 14:49:25 dcoutts 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. |
| … | |
… | |
| 10 | inherit versionator |
10 | inherit versionator |
| 11 | |
11 | |
| 12 | ECLASS="ghc-package" |
12 | ECLASS="ghc-package" |
| 13 | INHERITED="${INHERITED} ${ECLASS}" |
13 | INHERITED="${INHERITED} ${ECLASS}" |
| 14 | |
14 | |
| 15 | PATH="${PATH}:/opt/ghc/bin" |
15 | # promote /opt/ghc/bin to a better position in the search path |
|
|
16 | PATH="/usr/bin:/opt/ghc/bin:${PATH}" |
| 16 | |
17 | |
| 17 | # for later configuration using environment variables/ |
18 | # for later configuration using environment variables/ |
| 18 | # returns the name of the ghc executable |
19 | # returns the name of the ghc executable |
| 19 | ghc-getghc() { |
20 | ghc-getghc() { |
| 20 | echo "ghc" |
21 | echo "ghc" |
| … | |
… | |
| 86 | # no arguments are given, the resulting file is |
87 | # no arguments are given, the resulting file is |
| 87 | # empty |
88 | # empty |
| 88 | ghc-setup-pkg() { |
89 | ghc-setup-pkg() { |
| 89 | local localpkgconf |
90 | local localpkgconf |
| 90 | localpkgconf="${S}/$(ghc-localpkgconf)" |
91 | localpkgconf="${S}/$(ghc-localpkgconf)" |
| 91 | echo '[' > ${localpkgconf} |
92 | echo '[]' > ${localpkgconf} |
| 92 | while [ -n "$1" ]; do |
93 | for pkg in $*; do |
| 93 | cat "$1" >> ${localpkgconf} |
94 | $(ghc-getghcpkgbin) -f ${localpkgconf} -u --force \ |
| 94 | shift |
95 | < ${pkg} |
| 95 | [ -n "$1" ] && echo ',' >> ${localpkgconf} |
|
|
| 96 | done |
96 | done |
| 97 | echo ']' >> ${localpkgconf} |
97 | } |
|
|
98 | |
|
|
99 | # fixes the library and import directories path |
|
|
100 | # of the package configuration file |
|
|
101 | ghc-fixlibpath() { |
|
|
102 | sed -i "s|$1|$(ghc-libdir)|g" ${S}/$(ghc-localpkgconf) |
|
|
103 | if [[ -n "$2" ]]; then |
|
|
104 | sed -i "s|$2|$(ghc-libdir)/imports|g" ${S}/$(ghc-localpkgconf) |
|
|
105 | fi |
| 98 | } |
106 | } |
| 99 | |
107 | |
| 100 | # moves the local (package-specific) package configuration |
108 | # moves the local (package-specific) package configuration |
| 101 | # file to its final destination |
109 | # file to its final destination |
| 102 | ghc-install-pkg() { |
110 | ghc-install-pkg() { |
| 103 | mkdir -p ${D}/$(ghc-confdir) |
111 | mkdir -p ${D}/$(ghc-confdir) |
| 104 | cat ${S}/$(ghc-localpkgconf) | sed "s:${D}::" \ |
112 | cat ${S}/$(ghc-localpkgconf) | sed "s|${D}||g" \ |
| 105 | > ${D}/$(ghc-confdir)/$(ghc-localpkgconf) |
113 | > ${D}/$(ghc-confdir)/$(ghc-localpkgconf) |
| 106 | } |
114 | } |
| 107 | |
115 | |
| 108 | # registers all packages in the local (package-specific) |
116 | # registers all packages in the local (package-specific) |
| 109 | # package configuration file |
117 | # package configuration file |
| 110 | ghc-register-pkg() { |
118 | ghc-register-pkg() { |
| 111 | local localpkgconf |
119 | local localpkgconf |
| 112 | localpkgconf="$(ghc-confdir)/$1" |
120 | localpkgconf="$(ghc-confdir)/$1" |
|
|
121 | if [[ -f ${localpkgconf} ]]; then |
| 113 | for pkg in $(ghc-listpkg ${localpkgconf}); do |
122 | for pkg in $(ghc-listpkg ${localpkgconf}); do |
| 114 | einfo "Registering ${pkg} ..." |
123 | ebegin "Registering ${pkg} " |
| 115 | $(ghc-getghcpkgbin) -f ${localpkgconf} -s ${pkg} \ |
124 | $(ghc-getghcpkgbin) -f ${localpkgconf} -s ${pkg} \ |
| 116 | | $(ghc-getghcpkg) -u --force |
125 | | $(ghc-getghcpkg) -u --force > /dev/null |
|
|
126 | eend $? |
| 117 | done |
127 | done |
|
|
128 | fi |
| 118 | } |
129 | } |
| 119 | |
130 | |
| 120 | # re-adds all available .conf files to the global |
131 | # re-adds all available .conf files to the global |
| 121 | # package conf file, to be used on a ghc reinstallation |
132 | # package conf file, to be used on a ghc reinstallation |
| 122 | ghc-reregister() { |
133 | ghc-reregister() { |
| 123 | einfo "Re-adding packages ..." |
134 | einfo "Re-adding packages ..." |
| 124 | ewarn "This may cause several warnings, but they should be harmless." |
135 | einfo "(This may cause several warnings, but they should be harmless.)" |
| 125 | if [ -d "$(ghc-confdir)" ]; then |
136 | if [ -d "$(ghc-confdir)" ]; then |
| 126 | pushd $(ghc-confdir) |
137 | pushd $(ghc-confdir) > /dev/null |
| 127 | for conf in *.conf; do |
138 | for conf in *.conf; do |
| 128 | einfo "Processing ${conf} ..." |
139 | einfo "Processing ${conf} ..." |
| 129 | ghc-register-pkg ${conf} |
140 | ghc-register-pkg ${conf} |
| 130 | done |
141 | done |
| 131 | popd |
142 | popd > /dev/null |
| 132 | fi |
143 | fi |
| 133 | } |
144 | } |
| 134 | |
145 | |
| 135 | # unregisters ... |
146 | # unregisters ... |
| 136 | ghc-unregister-pkg() { |
147 | ghc-unregister-pkg() { |
| 137 | local localpkgconf |
148 | local localpkgconf |
| 138 | localpkgconf="$(ghc-confdir)/$1" |
149 | localpkgconf="$(ghc-confdir)/$1" |
|
|
150 | if [[ -f ${localpkgconf} ]]; then |
| 139 | for pkg in $(ghc-reverse "$(ghc-listpkg ${localpkgconf})"); do |
151 | for pkg in $(ghc-reverse "$(ghc-listpkg ${localpkgconf})"); do |
| 140 | einfo "Unregistering ${pkg} ..." |
152 | ebegin "Unregistering ${pkg} " |
| 141 | $(ghc-getghcpkg) -r ${pkg} --force |
153 | $(ghc-getghcpkg) -r ${pkg} --force > /dev/null |
|
|
154 | eend $? |
| 142 | done |
155 | done |
|
|
156 | fi |
| 143 | } |
157 | } |
| 144 | |
158 | |
| 145 | # help-function: reverse a list |
159 | # help-function: reverse a list |
| 146 | ghc-reverse() { |
160 | ghc-reverse() { |
| 147 | local result |
161 | local result |