logo

overlay

My (experimental) gentoo overlay

common-lisp-common.eclass (5513B)


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