#! /bin/sh
set -x

# Time-stamp:        "2008-04-06 12:56:45 bkorb"
# Last Committed:    $Date: 2008/04/07 00:06:32 $
#
##  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`
test -z "${pkgdatadir}" && exit 1

for tpl in $*
do
    if test -d ${pkgdatadir}
    then test -f ${pkgdatadir}/${tpl} && rm -f ${pkgdatadir}/${tpl}
    else mkdir -p ${pkgdatadir} || exit 1
    fi

    sed -e "s/@LIBOPTS_VER@/${LIBOPTS_VER}/" \
        -e '/^(setenv "SHELL" /s@.*@(setenv "SHELL" "'${conf_shell}'")@' \
        ${srcdir}/${tpl} > ${pkgdatadir}/${tpl}
done

rm -f ${destdir}/options.h
exec 3> ${destdir}/options.h
opthdrsrc=${srcdir}/autoopts/options.h

sed '/^#include <stdio/q' ${opthdrsrc} >&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' ${opthdrsrc} >&3

exec 3>&-
