#!/bin/sh -e

# Run this script to generate all the Makefile.in's (and the
# other files generated by Automake) and the configure script.
#
# Note that this script only needs to be run when building
# Posadis from the CVS source tree.
#
# Copyright (C) 2001, Jama Poulsen <jama@debianlinux.net>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.

PROJECT=poslib

DIE=0

echo
echo "Running required buildtools check ..."
echo

(m4 --version) < /dev/null > /dev/null 2>&1 || {
  echo "You must have GNU M4  installed to build $PROJECT."
  echo "Download the appropriate package for your distribution, or get"
  echo "http://mirrors.sunsite.dk/gnu/m4/m4-1.4.tar.gz"
  echo
  DIE=1
}

(libtool --version) < /dev/null > /dev/null 2>&1 || {
  echo "You must have GNU Libtool installed to build $PROJECT."
  echo "Download the appropriate package for your distribution, or get"
  echo "http://mirrors.sunsite.dk/gnu/libtool/libtool-1.4.tar.gz"
  echo
  DIE=1
}

(automake --version) < /dev/null > /dev/null 2>&1 || {
  echo "You must have GNU Automake installed to build $PROJECT."
  echo "Download the appropriate package for your distribution, or get"
  echo "http://mirrors.sunsite.dk/gnu/automake/automake-1.4.tar.gz"
  echo
  DIE=1
}

(autoconf --version) < /dev/null > /dev/null 2>&1 || {
  echo "You must have GNU Autoconf installed to build $PROJECT."
  echo "Download the appropriate package for your distribution, or get"
  echo "http://mirrors.sunsite.dk/gnu/autoconf/autoconf-2.13.tar.gz"
  echo
  DIE=1
}

if test "$DIE" -eq 1; then
  exit 1
fi

if test ! -f ltmain.sh; then
  ln -s /usr/share/libtool/ltmain.sh
fi

echo "Running aclocal ..."
echo
aclocal $ACLOCAL_FLAGS

echo "Running automake ..."
echo
  # "--include-deps" is needed for CVS developers who want to use
  # another "Make" than GNU Make, eg. BSD Make. So (for now) GNU Make
  # is not a requirement for Posadis developers. Posadis users should
  # only use the ./configure script from the tarball release, which
  # by default already works with BSD make.
automake --add-missing --include-deps

autoheader

echo "Running autoconf ..."
echo
autoconf

echo "Running ./configure ..."
echo
if test -z "$*"; then
  echo " Note: If you wish to pass any arguments to ./configure,"
  echo " please specify them on the $0 command line."
  echo
  ./configure --silent
else
  ./configure "$@"
fi

echo
echo "Now type 'make' to start building $PROJECT."
echo

exit 0
