#!/usr/bin/env bash
#                                               -*- Shell-script -*-
#
#  Copyright (C) 2005-2013 EDF-EADS-Phimeca
#
#  This library is free software: you can redistribute it and/or modify
#  it under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This library 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 Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public
#  along with this library.  If not, see <http://www.gnu.org/licenses/>.
#
#  @author conty
#  @date   2007-12-03 01:27:43 +0100 (Mon, 03 Dec 2007)
#  Id      bootstrap
#
#  This file initializes the building process of the project.
#  Call it before trying to use configure script (that normally should not
#  even exists at first).
#
set -e
trap 'echo ERROR' ERR
for ac_signal in 1 2 13 15; do
  trap 'ac_signal='$ac_signal'; echo Trap $ac_signal; { (exit 1); exit 1; }' $ac_signal
done
ac_signal=0

configdir="./config"
#otconfigdir="./include/openturns"

for file in NEWS README AUTHORS ChangeLog
do
  test ! -f $file && touch $file && echo "Creating empty file '$file'"
done

if [[ ! -d "$configdir" ]]; then
  mkdir "$configdir" && echo "Creating directory '$configdir'"
fi

#if [[ ! -d "$otconfigdir" ]]; then
#  mkdir "$otconfigdir" && echo "Creating directory '$otconfigdir'"
#fi

echo -n "Running libtoolize... "
#libtoolize --force --copy --ltdl --ltdl-tar
#libtoolize --force --copy
libtoolize --automake --copy 1>libtoolize.log 2>&1
echo "OK"

echo -n "Running aclocal... "
aclocal -I m4 1>aclocal.log 2>&1
echo "OK"

#echo -n "Running autoheader... "
#autoheader 1>autoheader.log 2>&1
#echo "OK"

echo -n "Running automake... "
automake --add-missing --copy 1>automake.log 2>&1
echo "OK"

echo -n "Running autoconf... "
autoconf 1>autoconf.log 2>&1
echo "OK"

rm -f aclocal.log libtoolize.log autoheader.log automake.log autoconf.log
