#!/bin/bash

# Generated with:
#     make headers_install
#     find usr/include/linux -name '*.h' | xargs egrep -l 'socket|sockaddr|ifreq|SIOC|inet' | sed 's,^usr/include/,,'
# and some manual sanity-checking.
headers='
linux/inet_diag.h
linux/netfilter_ipv4/ip_tables.h
linux/netfilter_ipv4/ipt_LOG.h
linux/nfs_mount.h
linux/if_bonding.h
linux/if_frad.h
linux/ip_vs.h
linux/pkt_cls.h
linux/x25.h
linux/netfilter/xt_conntrack.h
linux/netfilter/xt_connlimit.h
linux/netfilter/xt_iprange.h
linux/netfilter/nfnetlink_log.h
linux/netfilter/nfnetlink_compat.h
linux/if_ppp.h
linux/rose.h
linux/atmbr2684.h
linux/if_slip.h
linux/mii.h
linux/can.h
linux/atm.h
linux/caif/if_caif.h
linux/caif/caif_socket.h
linux/scc.h
linux/dccp.h
linux/ipv6.h
linux/atmlec.h
linux/netlink.h
linux/if_packet.h
linux/udp.h
linux/isdn.h
linux/if_ec.h
linux/wanrouter.h
linux/netfilter.h
linux/if_tunnel.h
linux/irda.h
linux/if_pppol2tp.h
linux/mroute6.h
linux/atmppp.h
linux/dn.h
linux/netrom.h
linux/net.h
linux/nfs4_mount.h
linux/atmclip.h
linux/if_pppox.h
linux/mroute.h
linux/wireless.h
linux/sockios.h
linux/ncp_fs.h
linux/if_plip.h
linux/if_eql.h
linux/tipc.h
linux/socket.h
linux/if.h
linux/xfrm.h
linux/atmdev.h
linux/if_cablemodem.h
linux/bpqether.h
linux/errqueue.h
linux/in6.h
linux/ncp_mount.h
linux/atalk.h
linux/netfilter_arp/arp_tables.h
linux/nfsd/syscall.h
linux/in.h
linux/if_arp.h
linux/can/bcm.h
linux/can/raw.h
linux/can/netlink.h
linux/can/error.h
linux/mqueue.h
linux/ax25.h
linux/llc.h
linux/tcp.h
linux/audit.h
linux/un.h
linux/atmarp.h
linux/phonet.h
linux/netfilter_ipv6/ip6t_LOG.h
linux/netfilter_ipv6/ip6_tables.h
linux/route.h
linux/pkt_sched.h
linux/atmsvc.h
linux/rtnetlink.h
linux/ipx.h
linux/tipc_config.h
linux/atm_tcp.h
'

CC=${CC:-cc}
CFLAGS="-D__STRICT_KERNEL_NAMES -Wall $CFLAGS"

for header in $headers; do
    echo '--------------------------------------------------------------------'
    echo "Include <$header> alone:"
    echo > test.c "#include <$header>"
    echo >>test.c "int main(void) { return 0; }"
    $CC $CFLAGS test.c && echo PASS || echo FAIL
done

for header in $headers; do
    echo '--------------------------------------------------------------------'
    echo "Include <$header> then <sys/socket.h>:"
    echo > test.c "#include <$header>"
    echo >>test.c "#include <sys/socket.h>"
    echo >>test.c "int main(void) { return 0; }"
    $CC $CFLAGS test.c && echo PASS || echo FAIL
done

for header in $headers; do
    echo '--------------------------------------------------------------------'
    echo "Include <sys/socket.h> then <$header>:"
    echo > test.c "#include <sys/socket.h>"
    echo >>test.c "#include <$header>"
    echo >>test.c "int main(void) { return 0; }"
    $CC $CFLAGS test.c && echo PASS || echo FAIL
done

for header in $headers; do
    echo '--------------------------------------------------------------------'
    echo "Include <netinet/in.h>, <net/if.h> then <$header>:"
    case $header in
        # We assume these are incompatible and redundant with the above
	linux/if.h | linux/in.h | linux/in6.h | linux/route.h)
	    echo SKIP
	    continue
	    ;;
	*)
	    ;;
    esac
    echo > test.c "#include <netinet/in.h>"
    echo >>test.c "#include <net/if.h>"
    echo >>test.c "#include <$header>"
    echo >>test.c "int main(void) { return 0; }"
    $CC $CFLAGS test.c && echo PASS || echo FAIL
done

rm -f test.c a.out
