+# The mount flags
+grep '^const _MNT_' gen-sysinfo.go |
+ sed -e 's/^\(const \)_\(MNT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+grep '^const _MS_' gen-sysinfo.go |
+ sed -e 's/^\(const \)_\(MS_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The fallocate flags.
+grep '^const _FALLOC_' gen-sysinfo.go |
+ sed -e 's/^\(const \)_\(FALLOC_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The statfs struct.
+# Prefer largefile variant if available.
+statfs=`grep '^type _statfs64 ' gen-sysinfo.go || true`
+if test "$statfs" != ""; then
+ grep '^type _statfs64 ' gen-sysinfo.go
+else
+ grep '^type _statfs ' gen-sysinfo.go
+fi | sed -e 's/type _statfs64/type Statfs_t/' \
+ -e 's/type _statfs/type Statfs_t/' \
+ -e 's/f_type/Type/' \
+ -e 's/f_bsize/Bsize/' \
+ -e 's/f_blocks/Blocks/' \
+ -e 's/f_bfree/Bfree/' \
+ -e 's/f_bavail/Bavail/' \
+ -e 's/f_files/Files/' \
+ -e 's/f_ffree/Ffree/' \
+ -e 's/f_fsid/Fsid/' \
+ -e 's/f_namelen/Namelen/' \
+ -e 's/f_frsize/Frsize/' \
+ -e 's/f_flags/Flags/' \
+ -e 's/f_spare/Spare/' \
+ >> ${OUT}
+
+# The timex struct.
+timex=`grep '^type _timex ' gen-sysinfo.go || true`
+if test "$timex" = ""; then
+ timex=`grep '^// type _timex ' gen-sysinfo.go || true`
+ if test "$timex" != ""; then
+ timex=`echo $timex | sed -e 's|// ||' -e 's/INVALID-bit-field/int32/g'`
+ fi
+fi
+if test "$timex" != ""; then
+ echo "$timex" | \
+ sed -e 's/_timex/Timex/' \
+ -e 's/modes/Modes/' \
+ -e 's/offset/Offset/' \
+ -e 's/freq/Freq/' \
+ -e 's/maxerror/Maxerror/' \
+ -e 's/esterror/Esterror/' \
+ -e 's/status/Status/' \
+ -e 's/constant/Constant/' \
+ -e 's/precision/Precision/' \
+ -e 's/tolerance/Tolerance/' \
+ -e 's/ time / Time /' \
+ -e 's/tick/Tick/' \
+ -e 's/ppsfreq/Ppsfreq/' \
+ -e 's/jitter/Jitter/' \
+ -e 's/shift/Shift/' \
+ -e 's/stabil/Stabil/' \
+ -e 's/jitcnt/Jitcnt/' \
+ -e 's/calcnt/Calcnt/' \
+ -e 's/errcnt/Errcnt/' \
+ -e 's/stbcnt/Stbcnt/' \
+ -e 's/tai/Tai/' \
+ -e 's/_timeval/Timeval/' \
+ >> ${OUT}
+fi
+
+# The rlimit struct.
+grep '^type _rlimit ' gen-sysinfo.go | \
+ sed -e 's/_rlimit/Rlimit/' \
+ -e 's/rlim_cur/Cur/' \
+ -e 's/rlim_max/Max/' \
+ >> ${OUT}
+
+# The RLIMIT constants.
+grep '^const _RLIMIT_' gen-sysinfo.go |
+ sed -e 's/^\(const \)_\(RLIMIT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+grep '^const _RLIM_' gen-sysinfo.go |
+ sed -e 's/^\(const \)_\(RLIM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The sysinfo struct.
+grep '^type _sysinfo ' gen-sysinfo.go | \
+ sed -e 's/_sysinfo/Sysinfo_t/' \
+ -e 's/uptime/Uptime/' \
+ -e 's/loads/Loads/' \
+ -e 's/totalram/Totalram/' \
+ -e 's/freeram/Freeram/' \
+ -e 's/sharedram/Sharedram/' \
+ -e 's/bufferram/Bufferram/' \
+ -e 's/totalswap/Totalswap/' \
+ -e 's/freeswap/Freeswap/' \
+ -e 's/procs/Procs/' \
+ -e 's/totalhigh/Totalhigh/' \
+ -e 's/freehigh/Freehigh/' \
+ -e 's/mem_unit/Unit/' \
+ >> ${OUT}
+
+# The ustat struct.
+grep '^type _ustat ' gen-sysinfo.go | \
+ sed -e 's/_ustat/Ustat_t/' \
+ -e 's/f_tfree/Tfree/' \
+ -e 's/f_tinode/Tinoe/' \
+ -e 's/f_fname/Fname/' \
+ -e 's/f_fpack/Fpack/' \
+ >> ${OUT}
+# Force it to be defined, as on some older GNU/Linux systems the
+# header file fails when using with <linux/filter.h>.
+if ! grep 'type _ustat ' gen-sysinfo.go >/dev/null 2>&1; then
+ echo 'type Ustat_t struct { Tfree int32; Tinoe uint64; Fname [5+1]int8; Fpack [5+1]int8; }' >> ${OUT}
+fi
+
+# The utimbuf struct.
+grep '^type _utimbuf ' gen-sysinfo.go | \
+ sed -e 's/_utimbuf/Utimbuf/' \
+ -e 's/actime/Actime/' \
+ -e 's/modtime/Modtime/' \
+ >> ${OUT}
+
+# The LOCK flags for flock.
+grep '^const _LOCK_' gen-sysinfo.go |
+ sed -e 's/^\(const \)_\(LOCK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The GNU/Linux LINUX_REBOOT flags.
+grep '^const _LINUX_REBOOT_' gen-sysinfo.go |
+ sed -e 's/^\(const \)_\(LINUX_REBOOT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The GNU/Linux sock_filter struct.
+grep '^type _sock_filter ' gen-sysinfo.go | \
+ sed -e 's/_sock_filter/SockFilter/' \
+ -e 's/code/Code/' \
+ -e 's/jt/Jt/' \
+ -e 's/jf/Jf/' \
+ -e 's/k /K /' \
+ >> ${OUT}
+
+# The GNU/Linux sock_fprog struct.
+grep '^type _sock_fprog ' gen-sysinfo.go | \
+ sed -e 's/_sock_fprog/SockFprog/' \
+ -e 's/len/Len/' \
+ -e 's/filter/Filter/' \
+ -e 's/_sock_filter/SockFilter/' \
+ >> ${OUT}
+
+# The GNU/Linux filter flags.
+grep '^const _BPF_' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(BPF_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The GNU/Linux nlattr struct.
+grep '^type _nlattr ' gen-sysinfo.go | \
+ sed -e 's/_nlattr/NlAttr/' \
+ -e 's/nla_len/Len/' \
+ -e 's/nla_type/Type/' \
+ >> ${OUT}
+
+# The GNU/Linux nlmsgerr struct.
+grep '^type _nlmsgerr ' gen-sysinfo.go | \
+ sed -e 's/_nlmsgerr/NlMsgerr/' \
+ -e 's/error/Error/' \
+ -e 's/msg/Msg/' \
+ -e 's/_nlmsghdr/NlMsghdr/' \
+ >> ${OUT}
+
+# The GNU/Linux rtnexthop struct.
+grep '^type _rtnexthop ' gen-sysinfo.go | \
+ sed -e 's/_rtnexthop/RtNexthop/' \
+ -e 's/rtnh_len/Len/' \
+ -e 's/rtnh_flags/Flags/' \
+ -e 's/rtnh_hops/Hops/' \
+ -e 's/rtnh_ifindex/Ifindex/' \
+ >> ${OUT}
+
+# The GNU/Linux netlink flags.
+grep '^const _NETLINK_' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(NETLINK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+grep '^const _NLA_' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(NLA_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The GNU/Linux packet socket flags.
+grep '^const _PACKET_' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(PACKET_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The GNU/Linux inotify_event struct.
+grep '^type _inotify_event ' gen-sysinfo.go | \
+ sed -e 's/_inotify_event/InotifyEvent/' \
+ -e 's/wd/Wd/' \
+ -e 's/mask/Mask/' \
+ -e 's/cookie/Cookie/' \
+ -e 's/len/Len/' \
+ -e 's/name/Name/' \
+ -e 's/\[\]/[0]/' \
+ -e 's/\[0\]byte/[0]int8/' \
+ >> ${OUT}
+
+# The Solaris 11 Update 1 _zone_net_addr_t struct.
+grep '^type _zone_net_addr_t ' gen-sysinfo.go | \
+ sed -e 's/_in6_addr/[16]byte/' \
+ >> ${OUT}
+
+# Struct sizes.
+set cmsghdr Cmsghdr ip_mreq IPMreq ip_mreqn IPMreqn ipv6_mreq IPv6Mreq \
+ ifaddrmsg IfAddrmsg ifinfomsg IfInfomsg in_pktinfo Inet4Pktinfo \
+ in6_pktinfo Inet6Pktinfo inotify_event InotifyEvent linger Linger \
+ msghdr Msghdr nlattr NlAttr nlmsgerr NlMsgerr nlmsghdr NlMsghdr \
+ rtattr RtAttr rtgenmsg RtGenmsg rtmsg RtMsg rtnexthop RtNexthop \
+ sock_filter SockFilter sock_fprog SockFprog ucred Ucred
+while test $# != 0; do
+ nc=$1
+ ngo=$2
+ shift
+ shift
+ if grep "^const _sizeof_$nc =" gen-sysinfo.go >/dev/null 2>&1; then
+ echo "const Sizeof$ngo = _sizeof_$nc" >> ${OUT}
+ fi
+done
+
+# In order to compile the net package, we need some sizes to exist
+# even if the types do not.
+if ! grep 'const SizeofIPMreq ' ${OUT} >/dev/null 2>&1; then
+ echo 'const SizeofIPMreq = 8' >> ${OUT}
+fi
+if ! grep 'const SizeofIPv6Mreq ' ${OUT} >/dev/null 2>&1; then
+ echo 'const SizeofIPv6Mreq = 20' >> ${OUT}
+fi
+if ! grep 'const SizeofIPMreqn ' ${OUT} >/dev/null 2>&1; then
+ echo 'const SizeofIPMreqn = 12' >> ${OUT}
+fi
+