#!/bin/sh
#
# Pos6poison configure script
#
# Copyright (C) Meilof Veeningen, 2003
#

echo "----------------------------"
echo "pos6poision configure script"
echo "----------------------------"
echo ""

while [ $# -gt 0 ]
do
  case $1 in
    -h | --help | -?)
      echo "usage: ./configure [--help]"
      exit 0
      ;;
    *)
      echo "*** configure: unknown command line option (try '-h')" 1>&2
      exit 1
      ;;
  esac
  shift
done

echo -n "Looking for Pos6... "

if ! pos6_version=`pos6-config --version 2>&1` ; then
  echo "error"
  echo "*** Pos6 not found!"
  echo "*** The pos6-config script was not found on your system."
  echo "*** To compile this module, you will need to have the Pos6"
  echo "*** headers installed (for example, use the pos6-devel"
  echo "*** package or something like that)."
  exit 1
fi
echo "found $pos6_version"

echo -n "Determining Pos6 compile flags... "
pos6_cxxflags=`pos6-config --cflags`
echo "done"

echo -n "Determining Pos6 link flags... "
pos6_ldflags=`pos6-config --libs`
echo "done"

echo -n "Determining installation directory... "
pos6_dir=`pos6-config --libdir`
echo "done"

# write makefile

echo -n "Writing makefile... "

cat >Makefile <<EOF
all: poison.la

poison.la: poison.lo
	libtool --mode=link c++ $pos6_ldflags -o poison.la -rpath $pos6_dir -module poison.lo

poison.lo: poison.cpp Makefile
	libtool --mode=compile c++ -c $pos6_cxxflags -o poison.lo poison.cpp

install: all uninstall
	cp poison.la .libs/poison.so.0 $pos6_dir
	ln -s $pos6_dir/poison.so.0 $pos6_dir/poison.so

clean:
	-rm -f *.la *.lo
	-rm -rf .libs/

uninstall:
	-rm -f $pos6_dir/{poison.la,poison.so,poison.so.0}

dist:
	tar -czvvf poison.tgz configure poison.cpp README
EOF

echo "done"
echo ""
echo "Now, type 'make' to build the module."
