kde5.eclass: Cleanup obsolete blocker
[gentoo.git] / eclass / common-lisp-common.eclass
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: common-lisp-common.eclass
5 # @MAINTAINER:
6 # Common Lisp project <common-lisp@gentoo.org>
7 # @AUTHOR: Matthew Kennedy <mkennedy@gentoo.org>
8 # @BLURB: eclass for installing Common Lisp packages.
9 # @DESCRIPTION:
10 # Sundry code common to many Common Lisp related ebuilds.
11
12 inherit eutils multilib
13
14 # Some handy constants
15 CLFASLROOT=/usr/$(get_libdir)/common-lisp/
16 CLSOURCEROOT=/usr/share/common-lisp/source/
17 CLSYSTEMROOT=/usr/share/common-lisp/systems/
18
19 # Many of our Common Lisp ebuilds are either inspired by, or actually
20 # use packages and files from the Debian project's archives.
21
22 do-debian-credits() {
23         docinto debian
24         for i in copyright README.Debian changelog; do
25                 # be silent, since all files are not always present
26                 dodoc "${S}"/debian/${i} &>/dev/null || true
27         done
28         docinto .
29 }
30
31 # Most of the code below is from Debian's Common Lisp Controller
32 # package
33
34 register-common-lisp-implementation() {
35         PROGNAME=$(basename $0)
36         # first check if there is at least a compiler-name:
37         if [ -z "$1"  ] ; then
38                 cat <<EOF
39 usage: $PROGNAME compiler-name
40
41 registers a Common Lisp compiler to the
42 Common-Lisp-Controller system.
43 EOF
44                 exit 1
45         fi
46         IMPL=$1
47         FILE="/usr/$(get_libdir)/common-lisp/bin/$IMPL.sh"
48         if [ ! -f "$FILE" ] ; then
49                 cat <<EOF
50 $PROGNAME: I cannot find the script $FILE for the implementation $IMPL
51 EOF
52                 exit 2
53         fi
54         if [ ! -r "$FILE" ] ; then
55                 cat <<EOF
56 $PROGNAME: I cannot read the script $FILE for the implementation $IMPL
57 EOF
58                 exit 2
59         fi
60         # install CLC into the lisp
61         sh "$FILE" install-clc || (echo "Installation of CLC failed" >&2 ; exit 3)
62         mkdir /usr/$(get_libdir)/common-lisp/$IMPL &>/dev/null || true
63         chown cl-builder:cl-builder /usr/$(get_libdir)/common-lisp/$IMPL
64
65         # now recompile the stuff
66         for i  in /usr/share/common-lisp/systems/*.asd  ; do
67                 if [ -f $i -a -r $i ] ; then
68                         i=${i%.asd}
69                         package=${i##*/}
70                         clc-autobuild-check $IMPL $package
71                         if [ $? = 0 ]; then
72                                 echo recompiling package $package for implementation $IMPL
73                                 /usr/bin/clc-send-command --quiet recompile $package $IMPL
74                         fi
75                 fi
76         done
77         for i  in /usr/share/common-lisp/systems/*.system  ; do
78                 if [ -f $i -a -r $i ] ; then
79                         i=${i%.system}
80                         package=${i##*/}
81                         clc-autobuild-check $IMPL $package
82                         if [ $? = 0 ]; then
83                                 echo recompiling package $package for implementation $IMPL
84                                 /usr/bin/clc-send-command --quiet recompile $package $IMPL
85                         fi
86                 fi
87         done
88         echo "$PROGNAME: Compiler $IMPL installed"
89 }
90
91 unregister-common-lisp-implementation() {
92         PROGNAME=$(basename $0)
93         if [ `id -u` != 0 ] ; then
94                 echo $PROGNAME: you need to be root to run this program
95                 exit 1
96         fi
97         if [ -z "$1" ] ; then
98                 cat <<EOF
99 usage: $PROGNAME compiler-name
100
101 un-registers a Common Lisp compiler to the
102 Common-Lisp-Controller system.
103 EOF
104                 exit 1
105         fi
106         IMPL=$1
107         IMPL_BIN="/usr/$(get_libdir)/common-lisp/bin/$IMPL.sh"
108         if [ ! -f "$IMPL_BIN" ] ; then
109                 cat <<EOF
110 $PROGNAME: No implementation of the name $IMPL is registered
111 Cannot find the file $IMPL_BIN
112
113 Maybe you already removed it?
114 EOF
115                 exit 0
116         fi
117         if [ ! -r "$IMPL_BIN" ] ; then
118                 cat <<EOF
119 $PROGNAME: No implementation of the name $IMPL is registered
120 Cannot read the file $IMPL_BIN
121
122 Maybe you already removed it?
123 EOF
124                 exit 0
125         fi
126         # Uninstall the CLC
127         sh $IMPL_BIN remove-clc || echo "De-installation of CLC failed" >&2
128         clc-autobuild-impl $IMPL inherit
129         # Just remove the damn subtree
130         (cd / ; rm -rf "/usr/$(get_libdir)/common-lisp/$IMPL/" ; true )
131         echo "$PROGNAME: Common Lisp implementation $IMPL uninstalled"
132 }
133
134 reregister-all-common-lisp-implementations() {
135         # Rebuilds all common lisp implementations
136         # Written by Kevin Rosenberg <kmr@debian.org>
137         # GPL-2 license
138         local clc_bin_dir=/usr/$(get_libdir)/common-lisp/bin
139         local opt=$(shopt nullglob); shopt -s nullglob
140         cd $clc_bin_dir
141         for impl_bin in *.sh; do
142                 impl=$(echo $impl_bin | sed 's/\(.*\).sh/\1/')
143                 unregister-common-lisp-implementation $impl
144                 register-common-lisp-implementation $impl
145         done
146         cd - >/dev/null
147         [[ $opt = *off ]] && shopt -u nullglob
148 }
149
150 # BIG FAT HACK: Since the Portage emerge step kills file timestamp
151 # information, we need to compensate by ensuring all FASL files are
152 # more recent than their source files.
153
154 # The following `impl-*-timestamp-hack' functions SHOULD NOT be used
155 # outside of this eclass.
156
157 impl-save-timestamp-hack() {
158         local impl=$1
159         dodir /usr/share/${impl}
160         tar cpjf "${D}"/usr/share/${impl}/portage-timestamp-compensate -C "${D}"/usr/$(get_libdir)/${impl} .
161 }
162
163 impl-restore-timestamp-hack() {
164         local impl=$1
165         tar xjpfo /usr/share/${impl}/portage-timestamp-compensate -C /usr/$(get_libdir)/${impl}
166 }
167
168 impl-remove-timestamp-hack() {
169         local impl=$1
170         rm -rf /usr/$(get_libdir)/${impl} &>/dev/null || true
171 }
172
173 test-in() {
174         local symbol=$1
175         shift
176         for i in $@; do
177                 if [ $i == ${symbol} ]; then
178                         return 0                        # true
179                 fi
180         done
181         false
182 }
183
184 standard-impl-postinst() {
185         local impl=$1
186         rm -rf /usr/$(get_libdir)/common-lisp/${impl}/* &>/dev/null || true
187         chown cl-builder:cl-builder /usr/$(get_libdir)/common-lisp/${impl}
188         if test-in ${impl} cmucl sbcl; then
189                 impl-restore-timestamp-hack ${impl}
190         fi
191         chown -R root:0 /usr/$(get_libdir)/${impl}
192         /usr/bin/clc-autobuild-impl ${impl} yes
193         register-common-lisp-implementation ${impl}
194 }
195
196 standard-impl-postrm() {
197         local impl=$1 impl_binary=$2
198         # Since we keep our own time stamps we must manually remove them
199         # here.
200         if [ ! -x ${impl_binary} ]; then
201                 if test-in ${impl} cmucl sbcl; then
202                         impl-remove-timestamp-hack ${impl}
203                 fi
204                 rm -rf /usr/$(get_libdir)/common-lisp/${impl}/*
205         fi
206 }
207
208 # Local Variables: ***
209 # mode: shell-script ***
210 # tab-width: 4 ***
211 # End: ***