#!/bin/sh
###############################################################################
#                    Internetting Cooperating Programmers
# -----------------------------------------------------------------------------
#
#  ____    PROJECT
# |  _ \  __ _ _ __   ___ ___ _ __ 
# | | | |/ _` | '_ \ / __/ _ \ '__|
# | |_| | (_| | | | | (_|  __/ |   
# |____/ \__,_|_| |_|\___\___|_|   the IRC bot
#
# All files in this archive are subject to the GNU General Public License.
#
# DESCRIPTION
#
# This script first checks if the libfpl was not found by the src/configure
# script.
# If not, it scans the system for the libfpl file. If not found, it asks the
# user to enter a path in which it may find it, or the user can abort the
# search. If the library is found it modifies the config.h and src/Makefile
# to fully take advantage of fpl.
#
# $Source: /cvsroot/dancer/dancer/fplcheck,v $
# $Revision: 1.1.1.1 $
# $Date: 2000/11/13 02:42:36 $
# $Author: holsta $
# $State: Exp $
# $Locker:  $
#
# -----------------------------------------------------------------------------
###############################################################################

if egrep ac_cv_lib_fpl=\'no\' ./src/config.cache >/dev/null 2>&1; then
  echo FPL was not found by configure...
else
  echo FPL was found by configure, exiting...
  exit
fi

if egrep lfpl ./src/Makefile >/dev/null 2>&1; then
  echo ...but is included in the makefile. This might have been done manually
  echo or by this script in an earlier run!
  exit
fi

echo Due to some problems in the configure script, it does not find 3rd
echo "party libs in systems where the libs don't reside in the standard"
echo directories.
echo An extra system search for the lib is now taking place...

path="$LD_LIBRARY_PATH:/usr/local/lib:/lib:/usr/lib:$HOME:$HOME/lib:`pwd`:`pwd`/lib"
find="libfpl*"

searchpath=`echo $path | sed "s?:? ?g"`

for ITEM in $searchpath ; do
  for FILE in $ITEM/$find; do
    if [ -f $FILE ]; then
      found=$ITEM
#      echo "... found one in $ITEM!"
    fi
  done
done

echo
if test -n "$found"; then
  echo ...found one in $found!
else
  echo The extra thorough search did not find any FPL library.
  echo
  echo "Enter a directory name (or path, each dir separated with ':') to"
  echo search for libfpl in, or press enter to ignore:
  read inp

  if test -n "$inp"; then
    searchpath=`echo $inp | sed "s?:? ?g"`

    for ITEM in $searchpath ; do
      echo checks $ITEM
      for FILE in $ITEM/$find; do
        if [ -f $FILE ]; then
          found=$ITEM
          echo "... found it!"
        fi
      done
    done
  else
    echo "bye"
    exit
  fi
  if test -n "$found"; then
    echo "Your manually entered path did the job!"
  else
    echo "The lib still wasn't found. Now digging deeper."
    echo "This check may take a few minutes. Please wait..."

    searchpath=`find / -type d -name lib -print 2>/dev/null`

    for ITEM in $searchpath ; do
      for FILE in $ITEM/$find; do
        if [ -f $FILE ]; then
          found=$ITEM
        fi
      done
    done

    if test -z "$found"; then
      echo "Still no luck. Exiting."
      exit
    else
      echo "Finally found one in $found!"
    fi
  fi
fi

echo Modifies the Makefile and config.h to make use of this!

########################################################################
# We want to know if this is a Solaris machine, since we want the -R
# switch in that case. We store the string to add in the variable
# LDADDTHIS.
#
# uname -a for a Solaris can look like:
# SunOS esbjerg.dit.ou.dk 5.5 Generic sun4m
#
# A regular 4.1.4 can look like:
# SunOS ebcw242 4.1.4 2 sun4c
#
########################################################################
info=`uname -a`

os=`echo $info | cut "-d " -f1`
ver=`echo $info | cut "-d " -f3 | cut -c1`
if test "$os" = "SunOS"; then
  if test "$ver" -ge "5"; then
    LDADDTHIS=" -R$found"
    echo This seems to be a Solaris machine. Setting -R in the Makefile.
  else
    echo This seems to be a SunOS 4 machine.
  fi
#else
#  echo just a $os machine
fi


################# End of Solaris #####################

make=/tmp/make.$$
conf=/tmp/conf.$$
sed -e "s!^LDFLAGS =!LDFLAGS = -L$found$LDADDTHIS!g" -e "s!^LIBS =!LIBS = -lfpl!g" < ./src/Makefile >$make
sed -e "s!/\* #undef HAVE_LIBFPL \*/!#define HAVE_LIBFPL 1!g" <./src/config.h >$conf
cp $make ./src/Makefile
cp $conf ./src/config.h
rm $make
rm $conf

echo "Now (re-)compile Dancer."


syntax highlighted by Code2HTML, v. 0.9.1