#!/bin/bash -e
# Sets the compatibility for a Common Lisp Source
# Written by Kevin Rosenberg <kmr@debian.org>
# GPL-2 license

progname="$(basename $0)"
pversion='$Revision: 1.5 $'

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

# This is a list of all known CLC-compatible implementation
known_impl="cmucl-normal cmucl-safe cmucl-small sbcl sbcl-mt clisp acl alisp alisp8 mlisp mlisp8 lispworks openmcl scl"

usage()
{
        cat >&2 <<END
Usage: $progname package-name [implementation ...] [OPTIONS]
$progname sets compatibility for a Common Lisp source package.
This function will set the package's autobuild to "no" for
all known implementations except for the implementations supplied
on the command line.

This command also accepts these "virtual" implementation names
  cmucl    (equivalent to "cmucl-normal cmucl-safe cmucl-small")
  allegro  (equivalent to "acl alisp alisp8 mlisp mlisp8")

Options: 
  -h                  Print this short help message
END
}

clc_bin_dir=/usr/lib/common-lisp/bin

if [ $# = 0 ]; then usage; exit 1; fi

# make sure that first argument is not an option switch
if [ $(expr "$1" : "\(\-\)") ]; then
  usage
  exit 1
fi

source=$1
shift

compatible_impl=""
# Command line
while [ $# != 0 ]; do
    case "$1" in
        -h) usage; exit 0              ;;
	-*) usage; exit 1              ;;
	*)  
	    arg=$1
	    if [ "$arg" = "cmucl" ]; then
		arg="cmucl-normal cmucl-safe cmucl-small"
	    elif [ "$arg" = "allegro" ]; then
		arg="acl alisp alisp8 mlisp mlisp8"
	    fi
	    compatible_impl="$arg $compatible_impl"
	    ;;
    esac
    shift
done

for impl in $known_impl; do
    expr=$(expr "$compatible_impl" : ".*\($impl\).*") || true
    if [ ! "$expr" ]; then
	mkdir -p /etc/common-lisp/$impl/$source
	echo "no" > /etc/common-lisp/$impl/$source/autobuild
    fi
done
