#!/bin/sh
#
##############################################################
# This will generate automatically configure and Makefile.in #
##############################################################

#######
cat /dev/null > acconfig.h
cat `find . -type f -name "acconfig.h.incl" -print` >> acconfig.h

#######
# Autogenerate configure.in from configure.in.tmpl
#######
cat configure.in.tmpl > configure.in
cat <<EOF >>configure.in
dnl
dnl Include configure.incl from subdirs
dnl
EOF

cat `find . -type f -name "configure.incl" -print` >> configure.in

cat <<EOF >>configure.in
dnl
dnl Output configuration files
dnl
AC_OUTPUT([
EOF

# sort so parent dirs are before children
echo `find . -type f -name "Makefile.am" -print | \
	grep -v src/plugin/decode | \
	sed 's/Makefile\.am$//' | \
	sort | \
	sed 's/^\.\///' | \
	sed 's/$/Makefile/' | \
	tr '\n\r' ' '` >> configure.in
cat << EOF >>configure.in
script/oms-config
dist/redhat/pkg.spec], [chmod +x script/oms-config])
EOF

#######
if test -d m4; then
	rm -f acinclude.m4
	for m4_file in m4/*.m4; do
		cat $m4_file >> acinclude.m4
	done
fi

#######

set -x

aclocal -I m4 \
&& libtoolize --force --copy \
&& autoheader \
&& automake --gnu --add-missing --copy \
&& autoconf

rm -f config.cache
