#!/bin/sh

set -e
PATH=/bin:/usr/bin:$PATH; export PATH
trap "rm -f tmp$$a.c tmp$$b.c tmp$$a.o tmp$$b.o" 0
target=port_ipv6

cat > tmp$$a.c <<EOF
#include <sys/types.h>
#include <netinet/in.h>
struct sockaddr_in6 xx;
EOF

cat > tmp$$b.c <<EOF
#include <sys/types.h>
#include <netinet/in.h>
struct in6_addr xx;
EOF

cat > ${target}.h <<EOF

/* This file is automatically generated. Do Not Edit. */

#ifndef ${target}_h
#define ${target}_h

EOF

if gcc -c tmp$$a.c > /dev/null 2>&1
then
        echo "#define HAS_INET6_STRUCTS" >> ${target}.h
        if gcc -c tmp$$b.c > /dev/null 2>&1
        then
		:
	else
                echo "#define in6_addr in_addr6" >> ${target}.h
        fi
else
        echo "#undef HAS_INET6_STRUCTS" >> ${target}.h
fi
echo  >> ${target}.h
echo "#endif" >> ${target}.h
exit 0
