#! /bin/sh

PATH=..:$PATH

if test -d tmp
then
    if test -d tmp/modules
    then rm -f tmp/modules/* >/dev/null 2>&1
    else mkdir tmp/modules
    fi
else
    mkdir tmp tmp/modules
fi

posix_list=`
{   echo alloca
    posix-modules | sed '/^error$/d'
} | tr -d ' \t' | sed '/^$/d' | sort -u`

cat > tmp/modules/libposix <<- _EOF_
	Description:
	Wrap up all the posix modules into an installable libposix.la.

	Files:

	Depends-on:
	${posix_list}

	configure.ac:

	Makefile.am:
	lib_LTLIBRARIES = libposix.la

	Include:

	License:
	LGPL

	Maintainer:
	Bruce Korb
	Gary V. Vaughan
	_EOF_

opts='--local-dir=tmp
	--import
	--lib=libposix
	--makefile-name=gnulib.mk
	--macro-prefix=LIBPOSIX
	--libtool
	--no-changelog
	--symlink
	--with-tests
	--with-c++-tests
	--with-longrunning-tests'

# We cannot tell which modules will get pulled in via dependencies
# when gnulib-tool gets run.  Therefore, strip out "error" from all
# modules that mention it.  Either we won't use the module, or the
# module will have to be tweaked to remove the dependency for libposix.
# "GNULIB_LIBPOSIX" is a CPP symbol for libposix.  Also, avoid testing
# any module that has had its error dependency removed.
#
for mod in `egrep -l '^error$' ../modules/[a-z]*`
do
    test "X$mod" = Xerror && continue
    d=`basename $mod`
    opts="${opts} --avoid=${d}-tests"
    sed '/^error$/d' ${mod} > tmp/modules/$d
done >&2

# Bootstrap for autotools.
#
echo gnulib-tool ${opts} git-version-gen libposix
gnulib-tool ${opts} git-version-gen libposix

# No need to maintain a Makefile.am just to include gnulib.mk.
#
mv tests/gnulib.mk tests/Makefile.am

# Run autotools.
#
autoreconf --force --install --verbose --symlink
