#!/bin/sh -e
# This configure script ensures that the configure.sh script exists, and
# if not, it tries to fetch rsync's generated files or build them.  We
# then transfer control to the configure.sh script to do the real work.

dir=`dirname $0`
realconfigure="$dir/configure.sh"

if [ ! -f "$realconfigure" ]; then
    if test x"$dir" != x -a x"$dir" != x.; then
	curdir=`pwd`
	cd "$dir"
    else
	curdir=''
    fi
    if make -f prepare-source.mak conf; then
	:
    elif [ -f "$HOME/build_farm/build_test.fns" ]; then
	# Allow the build farm to grab latest files via rsync.
	rsync -pvz rsync://rsync.samba.org/rsyncftp/generated-files/'c*' .
    else
	echo 'Failed to build configure.sh and/or config.h.in -- giving up.' >&2
	rm -f "$realconfigure"
	exit 1
    fi
    if test x"$curdir" != x; then
	cd "$curdir"
    fi
fi

exec "$realconfigure" "${@}"
