#!/bin/sh
#*=====================================================================*/
#*    serrano/ml/camloo/distribution/configure ...                     */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Thu Jan 27 15:41:36 1994                          */
#*    Last change :  Thu Mar 17 13:54:18 1994 (serrano)                */
#*    -------------------------------------------------------------    */
#*    The camloo's configuration file                                  */
#*=====================================================================*/

#*---------------------------------------------------------------------*/
#*    Le site                                                          */
#*---------------------------------------------------------------------*/
site=`pwd`
version="0.2"

#*---------------------------------------------------------------------*/
#*    Checking Bigloo                                                  */
#*---------------------------------------------------------------------*/
echo ". Checking Bigloo"

bv=`bigloo -version` || exit $?

case $bv in
  Bigloo*)
    bfv=`echo $bv | sed 's/Bigloo (v//' | sed 's/)//'`
    biv=`echo $bfv | sed 's/\.//'`;;
  *)
    echo "Bigloo release 1.6 (or greater) is required for the Camloo package"
    exit 1;;
esac

if test $biv -lt 16; then
  echo "Bigloo release 1.6 (or greater) is required for the Camloo package"
  exit 1;
fi

#*---------------------------------------------------------------------*/
#*    We (sometimes) change the -copt option in the old -c option.     */
#*---------------------------------------------------------------------*/
( bigloo -copt 0 -version > /dev/null || (
    echo ". changing -copt with -c in Makefiles"
   
    mv distribution/boot distribution/boot.old   
    cat distribution/boot.old | sed -e s,"-copt","-c", > distribution/boot
    \rm distribution/boot.old 

    mv distribution/install distribution/install.old   
    cat distribution/install.old | sed -e s,"-copt","-c", > distribution/install
    \rm distribution/install.old 

    mv comptime$version/Makefile comptime$version/Makefile.old   
    cat comptime$version/Makefile.old | sed -e s,"-copt","-c", > comptime$version/Makefile
    \rm comptime$version/Makefile.old 

    mv runtime$version/Makefile runtime$version/Makefile.old   
    cat runtime$version/Makefile.old | sed -e s,"-copt","-c", > runtime$version/Makefile
    \rm runtime$version/Makefile.old

    mv contrib$version/libunix/Makefile contrib$version/libunix/Makefile.old   
    cat contrib$version/libunix/Makefile.old | sed -e s,"-copt","-c", > contrib$version/libunix/Makefile
    \rm contrib$version/libunix/Makefile.old ) )

#*---------------------------------------------------------------------*/
#*    Some global variables                                            */
#*---------------------------------------------------------------------*/
lib_dir=/usr/local/lib/bigloo/$bfv
bigloo_lib_dir="`bigloo -query | grep \"\*lib-dir[ ]*\*\" | sed 's/\*lib-dir\*[ ]*: //'`"
 
#*---------------------------------------------------------------------*/
#*    We parse the arguments                                           */
#*---------------------------------------------------------------------*/
while : ; do
  case $1 in
    "")
      break;;
    --lib=*|-lib=*)
      lib_dir="`echo $1 | sed 's/^[-a-z]*=//'`";;
    -*)
      echo "Unknown option \"$1\", ignored" >&2;;
  esac
  shift
done
 
#*---------------------------------------------------------------------*/
#*    We get the name of the C compiler                                */
#*---------------------------------------------------------------------*/
cc="`bigloo -query | grep \"\*cc[ ]*\*\" | sed 's/\*cc\*[ ]*: //'`"
 
#*---------------------------------------------------------------------*/
#*    We compile `beep' (so, we test cc)                               */
#*---------------------------------------------------------------------*/
echo ". Compiling tools"
 
tools_dir="$site/tools"
cflags="-O"
 
(cd $tools_dir
 $cc $cflags beep.c -o beep || exit $?) || exit $?
 
(cd $tools_dir
 $cc $cflags dirname.c -o dirname || exit $?) || exit $?
 
#*---------------------------------------------------------------------*/
#*    We install the temporary `caml' extension descriptor             */
#*---------------------------------------------------------------------*/
echo ". Updating distribution/install"
 
cat distribution/caml.tpl | sed -e s,"/net/cornas/icsla2/serrano/ml/camloo",$site, > lib/$version/caml
 
#*---------------------------------------------------------------------*/
#*    On patche les Makefiles des constributions                       */
#*---------------------------------------------------------------------*/
echo ". Updating contributions"
 
(cd contrib$version/libunix;
 mv Makefile Makefile.old;

 cat Makefile.old | sed -e s,"/net/cornas/icsla2/serrano/ml/camloo",$site, > Makefile;

 \rm Makefile.old)

#*---------------------------------------------------------------------*/
#*    We change the flags of the two files distribution/{boot,install} */
#*---------------------------------------------------------------------*/
echo ". changing files modes"

chmod a+rx distribution/boot
chmod a+rx distribution/install
