#! /bin/sh

##  Create include/inn/system.h from include/config.h.
##
##  include/config.h is generated by autoconf and contains all of the test
##  results for a platform.  Most of these are only used when building INN,
##  but some of them are needed for various definitions in the header files
##  for INN's libraries.  We want to be able to install those header files
##  and their prerequisites, but we don't want to define the normal symbols
##  defined by autoconf since they're too likely to conflict with other
##  packages.
##
##  This script takes the path to awk as its first argument and the path to
##  include/config.h as its second argument and generates a file suitable
##  for being included as <inn/system.h>.  It contains only the autoconf
##  results needed for INN's API, and the symbols that might conflict with
##  autoconf results in other packages have INN_ prepended.

cat <<EOF
/* Automatically generated by mksystem from config.h; do not edit. */

/* This header contains information obtained by INN at configure time that
   is needed by INN headers.  Autoconf results that may conflict with the
   autoconf results of another package have INN_ prepended to the
   preprocessor symbols. */

#ifndef INN_SYSTEM_H
#define INN_SYSTEM_H 1

EOF

$1 '

/^#define HAVE_BROKEN_IN6_ARE_ADDR_EQUAL/  { print $1 " INN_" $2 " " $3 }
/^#define HAVE_C99_VAMACROS/               { print $1 " INN_" $2 " " $3 }
/^#define HAVE_DECL_INET_ATON/             { print $1 " INN_" $2 " " $3 }
/^#define HAVE_DECL_INET_NTOA/             { print $1 " INN_" $2 " " $3 }
/^#define HAVE_GETADDRINFO/                { print $1 " INN_" $2 " " $3 }
/^#define HAVE_GETNAMEINFO/                { print $1 " INN_" $2 " " $3 }
/^#define HAVE_GNU_VAMACROS/               { print $1 " INN_" $2 " " $3 }
/^#define HAVE_INET6/                      { print $1 " INN_" $2 " " $3 }
/^#define HAVE_INET_ATON/                  { print $1 " INN_" $2 " " $3 }
/^#define HAVE_INET_NTOA/                  { print $1 " INN_" $2 " " $3 }
/^#define HAVE_INET_NTOP/                  { print $1 " INN_" $2 " " $3 }
/^#define HAVE_INTTYPES_H/                 { print $1 " INN_" $2 " " $3 }
/^#define HAVE_LONG_LONG_INT/              { print $1 " INN_" $2 " " $3 }
/^#define HAVE_MSYNC_3_ARG/                { print $1 " INN_" $2 " " $3 }
/^#define HAVE_SOCKLEN_T/                  { print $1 " INN_" $2 " " $3 }
/^#define HAVE_STDBOOL_H/                  { print $1 " INN_" $2 " " $3 }
/^#define HAVE_STRUCT_SOCKADDR_SA_LEN/     { print $1 " INN_" $2 " " $3 }
/^#define HAVE_STRUCT_SOCKADDR_STORAGE/    { print $1 " INN_" $2 " " $3 }
/^#define HAVE_SYS_BITYPES_H/              { print $1 " INN_" $2 " " $3 }
/^#define HAVE_UNIX_DOMAIN_SOCKETS/        { print $1 " INN_" $2 " " $3 }
/^#define HAVE__BOOL/                      { print $1 " INN_" $2 " " $3 }

' $2

cat <<EOF

#endif /* INN_SYSTEM_H */
EOF
