#!/bin/sh

#  Picasso Installation
#  To be run before attempting to compile picasso

#  Asks installer for Picasso HOME directory
#                     Lisp library directory
#                     Sub directories for pcl-clx
#                     Lisp location

PICHOME=$HOME
LISPLIB=/usr/local/lib/cl/code
CLING=n
SLING=n
LIBPQ=n
CLLOC=/usr/local/cl
FINI=n


echo "Picasso Installation"
echo
echo "You may re-install picasso as needed when your system configuration"
echo "changes.  Please be sure that this is being run from the account picasso"
echo "and that the picasso account has write permission on the lisp library"
echo "directory."

echo
echo

while [ $FINI != y ]
do

	echo -n "Is $PICHOME the picasso home directory? (y/n)"
	read ans
	while [ ${ans:-x} != y -a ${ans:-x} != n ] 
	do
	echo "Please answer y or n"
	echo -n "Is $PICHOME the picasso home directory? (y/n)"
	read ans
	done

	if [ ${ans:-x} = n ] 
	then
	echo -n "Please enter the full pathname of the picasso home directory:"
	read PICHOME
	fi


	echo
	echo

	echo -n "Is $LISPLIB the loaction of the Allegro CL library? (y/n)"
	read ans
	while [ ${ans:-x} != y -a ${ans:-x} != n ]
	do
	echo "Please answer y or n"
	echo -n "Is $LISPLIB the loaction of the Allegro CL library? (y/n)"
	read ans
	done

	if [ ${ans:-x} = n ]
	then
	echo -n "Please enter the full pathname of the Allegro CL library:"
	read LISPLIB
	fi

	echo
	echo

	echo "Picasso must be built into a common lisp image that does not contain"
	echo "PCL, clx, or Allegro Composer."

	echo -n "Is $CLLOC the common lisp image to be used for building Picasso? (y/n)"
	read ans
	while [ ${ans:-x} != y -a ${ans:-x} != n ]
	do
	echo "Please answer y or n"
	echo -n "Is $CLLOC the common lisp image to be used for building Picasso? (y/n)"
	read ans
	done

	if [ ${ans:-x} = n ]
	then
	echo -n "Please enter the full pathname of the common lisp image to be used:"
	read CLLOC
	fi

	echo 
	echo

	echo "In addition to CLX and PCL, Picasso can be compiled to include:"
	echo "    libpq:      a function library to interface to Postgres"
	echo "    cling:      a Common Lisp interface to Ingres QUEL"
	echo "    cling-sql:  a Common Lisp interface to Ingres SQL"
	echo 
	echo -n "Do you wish to include LIBPQ in your Picasso image? (y/n)"
	read ans
	while [ ${ans:-x} != y -a ${ans:-x} != n ]
	do
	echo "Please answer y or n"
	echo -n "Do you wish to include LIBPQ in your Picasso image? (y/n)"
	read ans
	done
	LIBPQ=$ans

	echo 

	echo -n "Do you wish to include CLING in your Picasso image? (y/n)"
	read ans
	while [ ${ans:-x} != y -a ${ans:-x} != n ]
	do
	echo "Please answer y or n"
	echo -n "Do you wish to include CLING in your Picasso image? (y/n)"
	read ans
	done
	CLING=$ans

	echo

	echo -n "Do you wish to include CLING-SQL in your Picasso image? (y/n)"
	read ans
	while [ ${ans:-x} != y -a ${ans:-x} != n ]
	do
	echo "Please answer y or n"
	echo -n "Do you wish to include CLING-SQL in your Picasso image? (y/n)"
	read ans
	done
	SLING=$ans

	echo
	echo
	echo
	echo
	echo

	echo "You have provided the following information:"
	echo
	echo "     Picasso home directory:  $PICHOME"
	echo "     Common Lisp Library:     $LISPLIB"
	echo "     Common Lisp Image:       $CLLOC"
	echo
	echo "     Install LIBPQ?           $LIBPQ"
	echo "     Install CLING?           $CLING"
	echo "     Install CLING-SQL?       $SLING"
	echo
	echo -n "Is this correct? (y/n)"
	read ans
	while [ ${ans:-x} != y -a ${ans:-x} != n ]
	do
	echo "Please answer y or n"
	echo -n "Is this correct? (y/n)"
	read ans
	done
	FINI=${ans:-x}
done

SUBD="clx pcl pds libpq"
if [ $CLING = y ]
then
SUBD="$SUBD cling"
fi
if [ $SLING = y ]
then
SUBD="$SUBD sling"
fi

echo installing...

sed -e "s^PICASSO-HOME-DIRECTORY^$PICHOME^" \
    -e "s^PICASSO-LISP-LIBRARY^$LISPLIB^" \
    < $PICHOME/lib/makefiles/src.mf \
    > $PICHOME/release/src/Makefile

sed -e "s^PICASSO-HOME-DIRECTORY^$PICHOME^" \
    -e "s^PICASSO-LISP-LIBRARY^$LISPLIB^" \
    -e "s^PICASSO-BASE-CL^$CLLOC^" \
    -e "s^PICASSO-SUBDIRS^$SUBD^" \
    < $PICHOME/lib/makefiles/src.sys.mf \
    > $PICHOME/release/src/sys/Makefile
 
echo Picasso installed.  You may proceed with compilation.
