#! /bin/sh
set -x

# Time-stamp:        "2007-07-04 10:23:13 bkorb"
# Last Committed:    $Date: 2007/07/04 21:36:37 $
#
##  This file is part of AutoOpts, a companion to AutoGen.
##  AutoOpts is free software.
##  AutoOpts is copyright (c) 1992-2007 by Bruce Korb - all rights reserved
##
##  AutoOpts is available under any one of two licenses.  The license
##  in use must be one of these two and the choice is under the control
##  of the user of the license.
##
##   The GNU Lesser General Public License, version 3 or later
##      See the files "COPYING.lgplv3" and "COPYING.gplv3"
##
##   The Modified Berkeley Software Distribution License
##      See the file "COPYING.mbsd"
##
##  These files have the following md5sums:
##
##  239588c55c22c60ffe159946a760a33e pkg/libopts/COPYING.gplv3
##  fa82ca978890795162346e661b47161a pkg/libopts/COPYING.lgplv3
##  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd

egrep '#undef +AUTOOPTS_ENABLED' ${top_builddir}/config.h >/dev/null && \
 exit 0

srcdir=`dirname $0`
srcdir=`cd ${srcdir} ; pwd`
rm -f ${destdir}/options.h
exec 3> ${destdir}/options.h
sed '/^#include <sys/q' ${srcdir}/autoopts/options.h >&3

if egrep 'define +HAVE_STDINT_H' ${top_builddir}/config.h >/dev/null
then echo '#include <stdint.h>' >&3
else echo '#include <inttypes.h>' >&3 ; fi

if egrep 'define +HAVE_LIMITS_H' ${top_builddir}/config.h >/dev/null
then echo '#include <limits.h>' >&3
else echo '#include <sys/limits>' >&3 ; fi

if egrep 'define +HAVE_U_INT' ${top_builddir}/config.h >/dev/null
then :
else echo 'typedef unsigned int u_int;' >&3 ; fi

if egrep 'define +HAVE_SYSEXITS_H' ${top_builddir}/config.h >/dev/null
then echo '#include <sysexits.h>' >&3 ; fi

egrep 'define +NO_OPTIONAL_OPT_ARGS' ${top_builddir}/config.h >&3

sed '1,/endif.*HAVE_SYSEXITS_H/d' ${srcdir}/autoopts/options.h >&3

exec 3>&-
