#!/bin/bash

PROGNAME=$(basename $0)

if [ `id -u` != 0 ] ; then
 echo $PROGNAME: you need to be root to run this program
 exit 1
fi

if [ -z "$1" ] ; then
 cat <<EOF
usage: $PROGNAME compiler-name 

un-registers a Common Lisp compiler to the 
Common-Lisp-Controller system.
EOF
    exit 1
fi

IMPL=$1
IMPL_BIN="/usr/lib/common-lisp/bin/$IMPL.sh"

if [ ! -f "$IMPL_BIN" ] ; then
  cat <<EOF
$PROGNAME: No implementation of the name $IMPL is registered 
Cannot find the file $IMPL_BIN

Maybe you already removed it?
EOF
  exit 0
fi
if [ ! -r "$IMPL_BIN" ] ; then
  cat <<EOF
$PROGNAME: No implementation of the name $IMPL is registered 
Cannot read the file $IMPL_BIN

Maybe you already removed it?
EOF
  exit 0
fi

# Uninstall the CLC
sh $IMPL_BIN remove-clc || echo "De-installation of CLC failed" >&2

clc-autobuild-impl $IMPL inherit

# Just remove the damn subtree

(cd / ; rm -rf "/usr/lib/common-lisp/$IMPL/" ; true )

echo "$PROGNAME: Common Lisp implementation $IMPL uninstalled"

