#!/bin/sh
if test -f "$1"; then
  echo "using file $1"
  make -f "$1" -f install/makefile-init-step
else
  echo "using ./resources"
  make -f ./resources -f install/makefile-init-step
fi


set LIBTOOL_M4DIR "unknown"
for i in /usr/share/aclocal /usr/local/libtool/share/aclocal
do 
  if [ -r $i/libtool.m4 ]; then LIBTOOL_M4DIR=$i; fi
done;
echo "libtool macro dir: ${LIBTOOL_M4DIR}";


ACLOCAL=${ACLOCAL:-aclocal}
AUTOCONF=${AUTOCONF:-autoconf}
AUTOHEADER=${AUTOHEADER:-autoheader}
AUTOMAKE=${AUTOMAKE:-automake}

export ACLOCAL AUTOMAKE AUTOCONF AUTOHEADER

AUTOMAKE_OPTS="--add-missing --foreign"
ACDIRS="-I install/macros"

LIBTOOLIZE=libtoolize

if test ! -f ./install/ltmain.sh; then
  echo "$LIBTOOLIZE -f" && $LIBTOOLIZE -f
fi

if test -w acinclude.m4 && test -r ${LIBTOOL_M4DIR}/libtool.m4
then
  if egrep -s '^A[CU]_DEFUN\(.*A[CM]_PROG_LIBTOOL' acinclude.m4; then
    echo 'libtool.m4 already in acinclude.m4'
  else
    echo 'Appending ${LIBTOOL_M4DIR}/libtool.m4 to acinclude.m4'
    cat ${LIBTOOL_M4DIR}/libtool.m4 >> acinclude.m4
  fi
else
 if test -d "${LIBTOOL_M4DIR}"; then 
   ACDIRS="${ACDIRS} -I ${LIBTOOL_M4DIR}"
  fi;
fi

echo ${ACLOCAL} ${ACDIRS} && ${ACLOCAL} ${ACDIRS} \
&& echo ${AUTOHEADER} && ${AUTOHEADER}  && touch include/synaps/config.h.in \
&& echo ${AUTOMAKE} ${AUTOMAKE_OPTS} && ${AUTOMAKE} ${AUTOMAKE_OPTS} \
&& echo ${AUTOCONF} && ${AUTOCONF}

