#!/bin/sh
#
# This bootstrap file has been inspired by Bootstraping chapter
# in Autobook by Vaughan, Elliston, Tromey and Taylor.
# http://sources.redhat.com/autobook/
#
# Usage: $0 [path to wxwin.m4]
#           


set -x
set -e

if [ ! -d configure.aux ]; then
  mkdir configure.aux
fi

# required by autoconf
hg log --style changelog > ChangeLog

# generate Mercurial's id
echo '#define CHANGESET "Hg revision: '`hg id -r tip -i`', branch: '`hg id -b`'."' > include/hgid.h

# generate .spec
MVER=$(cat configure.ac | awk '{if(/AC_INIT/) {gsub("[\\[\\]\\,]"," ");  print $3;}}')
awk -v v=$MVER '{ if( /^Version:/ ) print $1,v; else print; }' < munipack.spec.template > munipack.spec

# add -I for localy installed wxwin.m4 (or add its parent directory as 
#                                      the first command-line argument)

if [ "$1" ]; then
   ACLOCAL_PATH="-I $1"
fi

aclocal $ACLOCAL_PATH \
&& autoheader \
&& automake --gnu --add-missing --copy \
&& autoconf

# ./bootstrap /usr/local/share/aclocal 
# ./configure FCFLAGS="-Wall -g -p -fcheck=all -fimplicit-none -fbacktrace" CFLAGS="-Wall -g -p"  CXXFLAGS="-D__WXDEBUG__ -g -p -Wall -fbounds-check" --prefix=/tmp/opt --enable-bundle BUNDLEDIR=/tmp/opt
