#!/bin/bash

# FNT - bootstrap and configure source tree
#
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# Written by:
#	Slava Zanko <slavazanko@gmail.com>
#
#
# This file is part of the FIDO New Technology.
#
# FIDO New Technology 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.
#
# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

#*** include section (source functions, for example) *******************

#*** file scope functions **********************************************

#*** main code *********************************************************

set -e

: ${AUTOCONF=autoconf}
: ${AUTOHEADER=autoheader}
: ${AUTOMAKE=automake}
: ${ACLOCAL=aclocal}
: ${AUTOPOINT=autopoint}
: ${LIBTOOLIZE=libtoolize}
: ${XGETTEXT=xgettext}

srcdir=$(dirname $0); test -z "$srcdir" && srcdir=.

(
set -e

cd "$srcdir"

rm -rf autom4te.cache

if test ! -d config; then
  mkdir config
fi


rm -rf intl
$AUTOPOINT --force || exit 1

> po/POTFILES.in

find_POTFILES(){
    files=`find . -name "$1" `
    if test "x$2" != "x"; then
	files=`echo $files| grep -v "$2"`
    fi
    if test "x$files" = "x"; then 
	return 1
    fi
$XGETTEXT --keyword=_ --keyword=N_ --keyword=Q_ --output=- $files | \
    sed -ne \
'/^#:/{s/#://;s/:[0-9]*/\
/g;s/ //g;p;}' | \
    grep -v '^$' | \
    sort | \
    uniq >>po/POTFILES.in
}

find_POTFILES '*.[ch]'
find_POTFILES '*.pl' 'sql/make_dump.pl'
find_POTFILES '*.pl.in'

$LIBTOOLIZE

ACLOCAL_INCLUDES="-I m4"

$ACLOCAL $ACLOCAL_INCLUDES $ACLOCAL_FLAGS
test -f aclocal.m4 || \
  { echo "aclocal failed to generate aclocal.m4" >&2; exit 1; }

$AUTOHEADER || exit 1
test -f config.h.in || \
  { echo "autoheader failed to generate config.h.in" >&2; exit 1; }

$AUTOCONF || exit 1
test -f configure || \
  { echo "autoconf failed to generate configure" >&2; exit 1; }

if test "`$AUTOMAKE --version|awk '{print $NF;exit}'`" = '1.5' ; then
    $AUTOMAKE -a src/Makefile
fi
$AUTOMAKE -a
test -f Makefile.in || \
  { echo "automake failed to generate Makefile.in" >&2; exit 1; }

) || exit 1

