#! /bin/sh

# Time-stamp:        "2010-12-10 15:25:12 bkorb"
#
##  This file is part of AutoOpts, a companion to AutoGen.
##  AutoOpts is free software.
##  AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved
##
##  AutoOpts is available under either 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:
##
##  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
##  06a1a2e4760c90ea5e1dad8dfaac4d39 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 "${CONFIG_SHELL}" && CONFIG_SHELL=/bin/sh

rm -f ${DESTdestdir}/options.h
exec 3> ${DESTdestdir}/options.h
opthdrsrc=${srcdir}/autoopts/options.h
cfgf=${top_builddir}/config.h

sed '/^#include <stdio/q' ${opthdrsrc} >&3

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

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

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

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

egrep 'define +NO_OPTIONAL_OPT_ARGS' ${cfgf} >&3

if egrep 'define +HAVE_INTPTR_T' ${cfgf} >/dev/null
then :
else
    sizeof_charp=`egrep 'define +SIZEOF_CHARP ' ${cfgf} | \
        sed 's/.*SIZEOF_CHARP *//'`
    sizeof_long=` egrep 'define +SIZEOF_LONG '  ${cfgf} | \
        sed 's/.*SIZEOF_LONG *//'`
    echo "#ifndef HAVE_UINTPTR_T"
    echo "#define HAVE_UINTPTR_T 1"
    echo "#define HAVE_INTPTR_T  1"
    if test "X${sizeof_charp}" = "X${sizeof_long}"
    then echo "typedef long intptr_t;"
         echo "typedef unsigned long uintptr_t;"
    else echo "typedef int intptr_t;"
         echo "typedef unsigned int uintptr_t;"
    fi
    echo "#endif /* HAVE_UINTPTR_T */"
fi >&3

sed '1,/endif.*HAVE_SYSEXITS_H/d' ${opthdrsrc} >&3

exec 3>&-

test -d "${DESTpkgdatadir}" && {
    sedcmd='/^#!\//s@.*@#!'${CONFIG_SHELL}'@
s%(setenv "SHELL" .*%(setenv "SHELL" "'${CONFIG_SHELL}'")%
/ test_exe ".*\/columns"/s%"[^"]*"%"'${bindir}'/columns"%'

    cd ${DESTpkgdatadir}
    for f in ag*.tpl options.tpl
    do  sed "${sedcmd}" $f > $f.tmp
        # touch -r $f $f.tmp
        mv -f $f.tmp $f
    done
}

## Local Variables:
## mode: shell-script
## indent-tabs-mode: nil
## sh-indentation: 2
## sh-basic-offset: 2
## End:

# end of install-options-h
