#!/bin/sh
####################################################
#
# newMakefile 1.94
#
# Installes the Makefile and the Makefile.def 
# in the current directory.
# 
# If Makefile.def already exists, it is not 
# copied.
#
####################################################

MYNAME=`basename $0`
echo "$MYNAME 1.94"
echo ""

##### Try to find where I'm installed

DIR=`echo $0 | sed -e s%$MYNAME\$%%`
DIR=`echo $DIR | sed -e s%/\$%%`
if [ "$DIR" = "" ]; then
  DIR="."
fi

##### First try in the directory where I'm run from
##### Then try other possibilities

echo "Finding Makefile and Makefile.def..."
echo "  Trying $DIR/Makefile..."
if [ -r $DIR/Makefile ]; then
  PRE=$DIR
else
  echo "  Trying $HOME/make/Makefile..."
  if [ -r $HOME/make/Makefile ]; then
    PRE=$HOME/make
  else 
    echo "  Trying $HOME/bin/Makefile..."
    if [ -r $HOME/bin/Makefile ]; then
      PRE=$HOME/bin
    else
      echo "  Trying /usr/local/make/Makefile..."
      if [ -r /usr/local/make/Makefile ]; then
	PRE=/usr/local/make
      else
	echo "  Trying /usr/local/bin/Makefile..."
	if [ -r /usr/local/bin/Makefile ]; then
          PRE=/usr/local/bin
        else
	  echo "I don't know where to find Makefile and Makefile.def."
	  exit
        fi
      fi
    fi
  fi
fi
        
##### Now Install the makefile

echo "Creating Makefile."
cp $PRE/Makefile .

if [ ! -r ./Makefile.def ]; then
  if [ -r $PRE/Makefile.def ]; then
    echo "Creating Makefile.def."
    cp $PRE/Makefile.def .
    echo "done."
  else
    echo "Can't find Makefile.def, faulty installation."
  fi
else
  echo "Makefile.def already there, not creating."
  echo "done."
fi

if [ ! -r ./Makefile.lsm ]; then
  if [ -r $PRE/Makefile.lsm ]; then
    echo "Creating Makefile.lsm."
    cp $PRE/Makefile.lsm .
    echo "done."
  else
    echo "Can't find Makefile.lsm, faulty installation."
  fi
else
  echo "Makefile.lsm already there, not creating."
  echo "done."
fi

