#!/bin/bash

# Copyright 2006 David Hilvert <dhilvert@auricle.dyndns.org>,
#                              <dhilvert@ugcs.caltech.edu>

#  This file is part of the Anti-Lamenessing Engine.
#
#  The Anti-Lamenessing Engine 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 3 of the License, or
#  (at your option) any later version.
#
#  The Anti-Lamenessing Engine is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with Anti-Lamenessing Engine; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

###
### 'bootstrap' generates build files for distribution.
###

#
# Check for the existence of a configure script.
#

if test -e configure && test "x$1" != "x-r"; then
	echo
	echo "To install:"
	echo "1) Run './configure'."
	echo "2) Run 'make'."
	echo "3) Run 'make install'."
	echo ""
	echo "* To regenerate configure, run '$0 -r'"
	echo
	exit
fi

if ! which gnulib-tool &> /dev/null; then
	echo "*** Cannot find 'gnulib-tool'. ***"
	exit
fi

if ! which ln &> /dev/null; then
	echo "*** Cannot find 'ln'. ***"
	exit
fi

if ! which automake &> /dev/null; then
	echo "*** Cannot find 'automake'. ***"
	exit 
fi

if ! which autoreconf &> /dev/null; then
	echo "*** Cannot find 'autoreconf'. ***"
	exit
fi

if ! test -e /usr/share/aclocal/acx_pthread.m4; then
	echo "*** Cannot find file '/usr/share/aclocal/acx_pthread.m4'. ***"
	exit
fi

#
# Add autoconf archive files.
#

mkdir -p m4
cp /usr/share/aclocal/acx_pthread.m4 m4/.

#
# Make documentation
#

chmod a+x doc/make-changelog
chmod a+x doc/make-infos
make -C doc ../TODO ../README ../ChangeLog ../NEWS
a2x -f manpage doc/man/ale.1.txt

#
# Import GNU extension strndup
#

gnulib-tool --libtool --import strndup error strtod

#
# Placeholders for automake-mandated files.
#

# touch NEWS
# touch AUTHORS

#
# Use the automake-mandated spelling for the changelog.
#

# ln -s Changelog ChangeLog

#
# Run autotools' bootstrap script, adding things that automake thinks are
# missing, among other things (--install).
#

autoreconf --install

#
# Run automake again, with the --foreign option.
#

# echo ""
# echo "Rerunning automake with --foreign flag."
# automake --foreign

#
# Make wrapper script executable
#

chmod a+x ./ale

#
# Indicate that we're done.
# 

echo ""
echo "Done."

#
# Tell the user what to do next.
#

echo
echo "To install:"
echo "1) Run './configure'."
echo "2) Run 'make'."
echo "3) Run 'make install'."

