* lib/gcc-dg.exp (process-message): Support relative line number
[official-gcc.git] / libgo / mksysinfo.sh
blob10e38036c60ba1030e8cd62749e60f299c33106f
1 #!/bin/sh
3 # Copyright 2009 The Go Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style
5 # license that can be found in the LICENSE file.
7 # Create sysinfo.go.
9 # This shell script creates the sysinfo.go file which holds types and
10 # constants extracted from the system header files. This relies on a
11 # hook in gcc: the -fdump-go-spec option will generate debugging
12 # information in Go syntax.
14 # We currently #include all the files at once, which works, but leads
15 # to exposing some names which ideally should not be exposed, as they
16 # match grep patterns. E.g., WCHAR_MIN gets exposed because it starts
17 # with W, like the wait flags.
19 CC=${CC:-gcc}
20 OUT=tmp-sysinfo.go
22 set -e
24 rm -f sysinfo.c
25 cat > sysinfo.c <<EOF
26 #include "config.h"
28 #include <sys/types.h>
29 #include <dirent.h>
30 #include <errno.h>
31 #include <fcntl.h>
32 #include <ucontext.h>
33 #include <netinet/in.h>
34 /* <netinet/tcp.h> needs u_char/u_short, but <sys/bsd_types> is only
35 included by <netinet/in.h> if _SGIAPI (i.e. _SGI_SOURCE
36 && !_XOPEN_SOURCE.
37 <sys/termios.h> only defines TIOCNOTTY if !_XOPEN_SOURCE, while
38 <sys/ttold.h> does so unconditionally. */
39 #ifdef __sgi__
40 #include <sys/bsd_types.h>
41 #include <sys/ttold.h>
42 #endif
43 #include <netinet/tcp.h>
44 #if defined(HAVE_NETINET_IN_SYSTM_H)
45 #include <netinet/in_systm.h>
46 #endif
47 #if defined(HAVE_NETINET_IP_H)
48 #include <netinet/ip.h>
49 #endif
50 #if defined(HAVE_NETINET_IP_MROUTE_H)
51 #include <netinet/ip_mroute.h>
52 #endif
53 #if defined(HAVE_NETINET_IF_ETHER_H)
54 #include <netinet/if_ether.h>
55 #endif
56 #include <signal.h>
57 #include <sys/ioctl.h>
58 #include <termios.h>
59 #if defined(HAVE_SYSCALL_H)
60 #include <syscall.h>
61 #endif
62 #if defined(HAVE_SYS_SYSCALL_H)
63 #include <sys/syscall.h>
64 #endif
65 #if defined(HAVE_SYS_EPOLL_H)
66 #include <sys/epoll.h>
67 #endif
68 #if defined(HAVE_SYS_FILE_H)
69 #include <sys/file.h>
70 #endif
71 #if defined(HAVE_SYS_MMAN_H)
72 #include <sys/mman.h>
73 #endif
74 #if defined(HAVE_SYS_PRCTL_H)
75 #include <sys/prctl.h>
76 #endif
77 #if defined(HAVE_SYS_PTRACE_H)
78 #include <sys/ptrace.h>
79 #endif
80 #include <sys/resource.h>
81 #include <sys/uio.h>
82 #include <sys/socket.h>
83 #include <sys/stat.h>
84 #include <sys/time.h>
85 #include <sys/times.h>
86 #include <sys/wait.h>
87 #include <sys/un.h>
88 #if defined(HAVE_SYS_USER_H)
89 #include <sys/user.h>
90 #endif
91 #if defined(HAVE_SYS_UTSNAME_H)
92 #include <sys/utsname.h>
93 #endif
94 #if defined(HAVE_SYS_SELECT_H)
95 #include <sys/select.h>
96 #endif
97 #include <time.h>
98 #include <unistd.h>
99 #include <netdb.h>
100 #include <pwd.h>
101 #include <grp.h>
102 #if defined(HAVE_LINUX_FILTER_H)
103 #include <linux/filter.h>
104 #endif
105 #if defined(HAVE_LINUX_IF_ADDR_H)
106 #include <linux/if_addr.h>
107 #endif
108 #if defined(HAVE_LINUX_IF_ETHER_H)
109 #include <linux/if_ether.h>
110 #endif
111 #if defined(HAVE_LINUX_IF_TUN_H)
112 #include <linux/if_tun.h>
113 #endif
114 #if defined(HAVE_LINUX_NETLINK_H)
115 #include <linux/netlink.h>
116 #endif
117 #if defined(HAVE_LINUX_RTNETLINK_H)
118 #include <linux/rtnetlink.h>
119 #endif
120 #if defined(HAVE_NET_IF_H)
121 #include <net/if.h>
122 #endif
123 #if defined(HAVE_NET_IF_ARP_H)
124 #include <net/if_arp.h>
125 #endif
126 #if defined(HAVE_NET_ROUTE_H)
127 #include <net/route.h>
128 #endif
129 #if defined (HAVE_NETPACKET_PACKET_H)
130 #include <netpacket/packet.h>
131 #endif
132 #if defined(HAVE_SYS_MOUNT_H)
133 #include <sys/mount.h>
134 #endif
135 #if defined(HAVE_SYS_VFS_H)
136 #include <sys/vfs.h>
137 #endif
138 #if defined(HAVE_STATFS_H)
139 #include <sys/statfs.h>
140 #endif
141 #if defined(HAVE_SYS_TIMEX_H)
142 #include <sys/timex.h>
143 #endif
144 #if defined(HAVE_SYS_SYSINFO_H)
145 #include <sys/sysinfo.h>
146 #endif
147 #if defined(HAVE_USTAT_H)
148 #include <ustat.h>
149 #endif
150 #if defined(HAVE_UTIME_H)
151 #include <utime.h>
152 #endif
153 #if defined(HAVE_LINUX_ETHER_H)
154 #include <linux/ether.h>
155 #endif
156 #if defined(HAVE_LINUX_FS_H)
157 #include <linux/fs.h>
158 #endif
159 #if defined(HAVE_LINUX_REBOOT_H)
160 #include <linux/reboot.h>
161 #endif
162 #if defined(HAVE_SYS_INOTIFY_H)
163 #include <sys/inotify.h>
164 #endif
165 #if defined(HAVE_NETINET_ICMP6_H)
166 #include <netinet/icmp6.h>
167 #endif
168 #if defined(HAVE_SCHED_H)
169 #include <sched.h>
170 #endif
172 /* Constants that may only be defined as expressions on some systems,
173 expressions too complex for -fdump-go-spec to handle. These are
174 handled specially below. */
175 enum {
176 #ifdef TIOCGWINSZ
177 TIOCGWINSZ_val = TIOCGWINSZ,
178 #endif
179 #ifdef TIOCSWINSZ
180 TIOCSWINSZ_val = TIOCSWINSZ,
181 #endif
182 #ifdef TIOCNOTTY
183 TIOCNOTTY_val = TIOCNOTTY,
184 #endif
185 #ifdef TIOCSCTTY
186 TIOCSCTTY_val = TIOCSCTTY,
187 #endif
188 #ifdef TIOCGPGRP
189 TIOCGPGRP_val = TIOCGPGRP,
190 #endif
191 #ifdef TIOCSPGRP
192 TIOCSPGRP_val = TIOCSPGRP,
193 #endif
194 #ifdef TIOCGPTN
195 TIOCGPTN_val = TIOCGPTN,
196 #endif
197 #ifdef TIOCSPTLCK
198 TIOCSPTLCK_val = TIOCSPTLCK,
199 #endif
200 #ifdef TIOCGDEV
201 TIOCGDEV_val = TIOCGDEV,
202 #endif
203 #ifdef TIOCSIG
204 TIOCSIG_val = TIOCSIG,
205 #endif
206 #ifdef TCGETS
207 TCGETS_val = TCGETS,
208 #endif
209 #ifdef TCSETS
210 TCSETS_val = TCSETS,
211 #endif
212 #ifdef TUNSETIFF
213 TUNSETIFF_val = TUNSETIFF,
214 #endif
215 #ifdef TUNSETNOCSUM
216 TUNSETNOCSUM_val = TUNSETNOCSUM,
217 #endif
218 #ifdef TUNSETDEBUG
219 TUNSETDEBUG_val = TUNSETDEBUG,
220 #endif
221 #ifdef TUNSETPERSIST
222 TUNSETPERSIST_val = TUNSETPERSIST,
223 #endif
224 #ifdef TUNSETOWNER
225 TUNSETOWNER_val = TUNSETOWNER,
226 #endif
227 #ifdef TUNSETLINK
228 TUNSETLINK_val = TUNSETLINK,
229 #endif
230 #ifdef TUNSETGROUP
231 TUNSETGROUP_val = TUNSETGROUP,
232 #endif
233 #ifdef TUNGETFEATURES
234 TUNGETFEATURES_val = TUNGETFEATURES,
235 #endif
236 #ifdef TUNSETOFFLOAD
237 TUNSETOFFLOAD_val = TUNSETOFFLOAD,
238 #endif
239 #ifdef TUNSETTXFILTER
240 TUNSETTXFILTER_val = TUNSETTXFILTER,
241 #endif
242 #ifdef TUNGETIFF
243 TUNGETIFF_val = TUNGETIFF,
244 #endif
245 #ifdef TUNGETSNDBUF
246 TUNGETSNDBUF_val = TUNGETSNDBUF,
247 #endif
248 #ifdef TUNSETSNDBUF
249 TUNSETSNDBUF_val = TUNSETSNDBUF,
250 #endif
251 #ifdef TUNATTACHFILTER
252 TUNATTACHFILTER_val = TUNATTACHFILTER,
253 #endif
254 #ifdef TUNDETACHFILTER
255 TUNDETACHFILTER_val = TUNDETACHFILTER,
256 #endif
257 #ifdef TUNGETVNETHDRSZ
258 TUNGETVNETHDRSZ_val = TUNGETVNETHDRSZ,
259 #endif
260 #ifdef TUNSETVNETHDRSZ
261 TUNSETVNETHDRSZ_val = TUNSETVNETHDRSZ,
262 #endif
263 #ifdef TUNSETQUEUE
264 TUNSETQUEUE_val = TUNSETQUEUE,
265 #endif
266 #ifdef TUNSETIFINDEX
267 TUNSETIFINDEX_val = TUNSETIFINDEX,
268 #endif
269 #ifdef TUNGETFILTER
270 TUNGETFILTER_val = TUNGETFILTER,
271 #endif
272 #ifdef NLA_HDRLEN
273 NLA_HDRLEN_val = NLA_HDRLEN,
274 #endif
279 ${CC} -fdump-go-spec=gen-sysinfo.go -std=gnu99 -S -o sysinfo.s sysinfo.c
281 echo 'package syscall' > ${OUT}
282 echo 'import "unsafe"' >> ${OUT}
283 echo 'type _ unsafe.Pointer' >> ${OUT}
285 # Get all the consts and types, skipping ones which could not be
286 # represented in Go and ones which we need to rewrite. We also skip
287 # function declarations, as we don't need them here. All the symbols
288 # will all have a leading underscore.
289 grep -v '^// ' gen-sysinfo.go | \
290 grep -v '^func' | \
291 grep -v '^type _timeval ' | \
292 grep -v '^type _timespec_t ' | \
293 grep -v '^type _timespec ' | \
294 grep -v '^type _timestruc_t ' | \
295 grep -v '^type _epoll_' | \
296 grep -v 'in6_addr' | \
297 grep -v 'sockaddr_in6' | \
298 sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
299 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
300 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
301 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
302 >> ${OUT}
304 # The errno constants. These get type Errno.
305 echo '#include <errno.h>' | ${CC} -x c - -E -dM | \
306 egrep '#define E[A-Z0-9_]+ ' | \
307 sed -e 's/^#define \(E[A-Z0-9_]*\) .*$/const \1 = Errno(_\1)/' >> ${OUT}
309 # The O_xxx flags.
310 egrep '^const _(O|F|FD)_' gen-sysinfo.go | \
311 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
312 if ! grep '^const O_ASYNC' ${OUT} >/dev/null 2>&1; then
313 echo "const O_ASYNC = 0" >> ${OUT}
315 if ! grep '^const O_CLOEXEC' ${OUT} >/dev/null 2>&1; then
316 echo "const O_CLOEXEC = 0" >> ${OUT}
319 # The os package requires F_DUPFD_CLOEXEC to be defined.
320 if ! grep '^const F_DUPFD_CLOEXEC' ${OUT} >/dev/null 2>&1; then
321 echo "const F_DUPFD_CLOEXEC = 0" >> ${OUT}
324 # These flags can be lost on i386 GNU/Linux when using
325 # -D_FILE_OFFSET_BITS=64, because we see "#define F_SETLK F_SETLK64"
326 # before we see the definition of F_SETLK64.
327 for flag in F_GETLK F_SETLK F_SETLKW; do
328 if ! grep "^const ${flag} " ${OUT} >/dev/null 2>&1 \
329 && grep "^const ${flag}64 " ${OUT} >/dev/null 2>&1; then
330 echo "const ${flag} = ${flag}64" >> ${OUT}
332 done
334 # The Flock_t struct for fcntl.
335 grep '^type _flock ' gen-sysinfo.go | \
336 sed -e 's/type _flock/type Flock_t/' \
337 -e 's/l_type/Type/' \
338 -e 's/l_whence/Whence/' \
339 -e 's/l_start/Start/' \
340 -e 's/l_len/Len/' \
341 -e 's/l_pid/Pid/' \
342 >> ${OUT}
344 # The signal numbers.
345 grep '^const _SIG[^_]' gen-sysinfo.go | \
346 grep -v '^const _SIGEV_' | \
347 sed -e 's/^\(const \)_\(SIG[^= ]*\)\(.*\)$/\1\2 = Signal(_\2)/' >> ${OUT}
348 if ! grep '^const SIGPOLL ' ${OUT} >/dev/null 2>&1; then
349 if grep '^const SIGIO ' ${OUT} > /dev/null 2>&1; then
350 echo "const SIGPOLL = SIGIO" >> ${OUT}
353 if ! grep '^const SIGCLD ' ${OUT} >/dev/null 2>&1; then
354 if grep '^const SIGCHLD ' ${OUT} >/dev/null 2>&1; then
355 echo "const SIGCLD = SIGCHLD" >> ${OUT}
359 # The syscall numbers. We force the names to upper case.
360 grep '^const _SYS_' gen-sysinfo.go | \
361 sed -e 's/const _\(SYS_[^= ]*\).*$/\1/' | \
362 while read sys; do
363 sup=`echo $sys | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
364 echo "const $sup = _$sys" >> ${OUT}
365 done
367 # The GNU/Linux support wants to use SYS_GETDENTS64 if available.
368 if ! grep '^const SYS_GETDENTS ' ${OUT} >/dev/null 2>&1; then
369 echo "const SYS_GETDENTS = 0" >> ${OUT}
371 if ! grep '^const SYS_GETDENTS64 ' ${OUT} >/dev/null 2>&1; then
372 echo "const SYS_GETDENTS64 = 0" >> ${OUT}
375 # Stat constants.
376 grep '^const _S_' gen-sysinfo.go | \
377 sed -e 's/^\(const \)_\(S_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
379 # Mmap constants.
380 grep '^const _PROT_' gen-sysinfo.go | \
381 sed -e 's/^\(const \)_\(PROT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
382 grep '^const _MAP_' gen-sysinfo.go | \
383 sed -e 's/^\(const \)_\(MAP_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
384 grep '^const _MADV_' gen-sysinfo.go | \
385 sed -e 's/^\(const \)_\(MADV_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
386 grep '^const _MCL_' gen-sysinfo.go | \
387 sed -e 's/^\(const \)_\(MCL_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
389 # Process status constants.
390 grep '^const _W' gen-sysinfo.go |
391 sed -e 's/^\(const \)_\(W[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
392 # WSTOPPED was introduced in glibc 2.3.4.
393 if ! grep '^const _WSTOPPED = ' gen-sysinfo.go >/dev/null 2>&1; then
394 if grep '^const _WUNTRACED = ' gen-sysinfo.go > /dev/null 2>&1; then
395 echo 'const WSTOPPED = _WUNTRACED' >> ${OUT}
396 else
397 echo 'const WSTOPPED = 2' >> ${OUT}
400 if grep '^const ___WALL = ' gen-sysinfo.go >/dev/null 2>&1 \
401 && ! grep '^const _WALL = ' gen-sysinfo.go >/dev/null 2>&1; then
402 echo 'const WALL = ___WALL' >> ${OUT}
405 # Networking constants.
406 egrep '^const _(AF|ARPHRD|ETH|IN|SOCK|SOL|SO|IPPROTO|TCP|IP|IPV6)_' gen-sysinfo.go |
407 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
408 grep '^const _SOMAXCONN' gen-sysinfo.go |
409 sed -e 's/^\(const \)_\(SOMAXCONN[^= ]*\)\(.*\)$/\1\2 = _\2/' \
410 >> ${OUT}
411 grep '^const _SHUT_' gen-sysinfo.go |
412 sed -e 's/^\(const \)_\(SHUT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
414 # The net package requires some const definitions.
415 for m in IP_PKTINFO IPV6_V6ONLY IPPROTO_IPV6 IPV6_JOIN_GROUP IPV6_LEAVE_GROUP IPV6_TCLASS SO_REUSEPORT; do
416 if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
417 echo "const $m = 0" >> ${OUT}
419 done
420 for m in SOCK_CLOEXEC SOCK_NONBLOCK; do
421 if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
422 echo "const $m = -1" >> ${OUT}
424 done
426 # The syscall package requires AF_LOCAL.
427 if ! grep '^const AF_LOCAL ' ${OUT} >/dev/null 2>&1; then
428 if grep '^const AF_UNIX ' ${OUT} >/dev/null 2>&1; then
429 echo "const AF_LOCAL = AF_UNIX" >> ${OUT}
433 # sysconf constants.
434 grep '^const __SC' gen-sysinfo.go |
435 sed -e 's/^\(const \)__\(SC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
437 # pathconf constants.
438 grep '^const __PC' gen-sysinfo.go |
439 sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
441 # The PATH_MAX constant.
442 if grep '^const _PATH_MAX ' gen-sysinfo.go >/dev/null 2>&1; then
443 echo 'const PathMax = _PATH_MAX' >> ${OUT}
446 # epoll constants.
447 grep '^const _EPOLL' gen-sysinfo.go |
448 sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
449 # Make sure EPOLLRDHUP and EPOLL_CLOEXEC are defined.
450 if ! grep '^const EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
451 echo "const EPOLLRDHUP = 0x2000" >> ${OUT}
453 if ! grep '^const EPOLL_CLOEXEC' ${OUT} >/dev/null 2>&1; then
454 echo "const EPOLL_CLOEXEC = 02000000" >> ${OUT}
457 # Prctl constants.
458 grep '^const _PR_' gen-sysinfo.go |
459 sed -e 's/^\(const \)_\(PR_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
461 # Ptrace constants.
462 grep '^const _PTRACE' gen-sysinfo.go |
463 sed -e 's/^\(const \)_\(PTRACE[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
464 # We need some ptrace options that are not defined in older versions
465 # of glibc.
466 if ! grep '^const PTRACE_SETOPTIONS' ${OUT} > /dev/null 2>&1; then
467 echo "const PTRACE_SETOPTIONS = 0x4200" >> ${OUT}
469 if ! grep '^const PTRACE_O_TRACESYSGOOD' ${OUT} > /dev/null 2>&1; then
470 echo "const PTRACE_O_TRACESYSGOOD = 0x1" >> ${OUT}
472 if ! grep '^const PTRACE_O_TRACEFORK' ${OUT} > /dev/null 2>&1; then
473 echo "const PTRACE_O_TRACEFORK = 0x2" >> ${OUT}
475 if ! grep '^const PTRACE_O_TRACEVFORK' ${OUT} > /dev/null 2>&1; then
476 echo "const PTRACE_O_TRACEVFORK = 0x4" >> ${OUT}
478 if ! grep '^const PTRACE_O_TRACECLONE' ${OUT} > /dev/null 2>&1; then
479 echo "const PTRACE_O_TRACECLONE = 0x8" >> ${OUT}
481 if ! grep '^const PTRACE_O_TRACEEXEC' ${OUT} > /dev/null 2>&1; then
482 echo "const PTRACE_O_TRACEEXEC = 0x10" >> ${OUT}
484 if ! grep '^const PTRACE_O_TRACEVFORKDONE' ${OUT} > /dev/null 2>&1; then
485 echo "const PTRACE_O_TRACEVFORKDONE = 0x20" >> ${OUT}
487 if ! grep '^const PTRACE_O_TRACEEXIT' ${OUT} > /dev/null 2>&1; then
488 echo "const PTRACE_O_TRACEEXIT = 0x40" >> ${OUT}
490 if ! grep '^const PTRACE_O_MASK' ${OUT} > /dev/null 2>&1; then
491 echo "const PTRACE_O_MASK = 0x7f" >> ${OUT}
493 if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev/null 2>&1; then
494 echo "const PTRACE_GETEVENTMSG = 0x4201" >> ${OUT}
496 if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev/null 2>&1; then
497 echo "const PTRACE_EVENT_FORK = 1" >> ${OUT}
499 if ! grep '^const PTRACE_EVENT_VFORK' ${OUT} > /dev/null 2>&1; then
500 echo "const PTRACE_EVENT_VFORK = 2" >> ${OUT}
502 if ! grep '^const PTRACE_EVENT_CLONE' ${OUT} > /dev/null 2>&1; then
503 echo "const PTRACE_EVENT_CLONE = 3" >> ${OUT}
505 if ! grep '^const PTRACE_EVENT_EXEC' ${OUT} > /dev/null 2>&1; then
506 echo "const PTRACE_EVENT_EXEC = 4" >> ${OUT}
508 if ! grep '^const PTRACE_EVENT_VFORK_DONE' ${OUT} > /dev/null 2>&1; then
509 echo "const PTRACE_EVENT_VFORK_DONE = 5" >> ${OUT}
511 if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev/null 2>&1; then
512 echo "const PTRACE_EVENT_EXIT = 6" >> ${OUT}
514 if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev/null 2>&1; then
515 echo "const _PTRACE_TRACEME = 0" >> ${OUT}
518 # A helper function that prints a structure from gen-sysinfo.go with the first
519 # letter of the field names in upper case. $1 is the name of structure. If $2
520 # is not empty, the structure or type is renamed to $2.
521 upcase_fields () {
522 name="$1"
523 def=`grep "^type $name" gen-sysinfo.go`
524 fields=`echo $def | sed -e 's/^[^{]*{\(.*\)}$/\1/'`
525 prefix=`echo $def | sed -e 's/{.*//'`
526 if test "$2" != ""; then
527 prefix=`echo $prefix | sed -e "s/$1/$2/"`
529 if test "$fields" != ""; then
530 nfields=
531 while test -n "$fields"; do
532 field=`echo $fields | sed -e 's/^\([^;]*\);.*$/\1/'`
533 fields=`echo $fields | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
534 # capitalize the next character.
535 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
536 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
537 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
538 field="$f$r"
539 nfields="$nfields $field;"
540 done
541 echo "${prefix} {$nfields }"
545 # The registers returned by PTRACE_GETREGS. This is probably
546 # GNU/Linux specific; it should do no harm if there is no
547 # _user_regs_struct.
548 regs=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true`
549 if test "$regs" = ""; then
550 # s390
551 regs=`grep '^type __user_regs_struct struct' gen-sysinfo.go || true`
552 if test "$regs" != ""; then
553 # Substructures of __user_regs_struct on s390
554 upcase_fields "__user_psw_struct" "PtracePsw" >> ${OUT} || true
555 upcase_fields "__user_fpregs_struct" "PtraceFpregs" >> ${OUT} || true
556 upcase_fields "__user_per_struct" "PtracePer" >> ${OUT} || true
559 if test "$regs" != ""; then
560 regs=`echo $regs |
561 sed -e 's/type __*user_regs_struct struct //' -e 's/[{}]//g'`
562 regs=`echo $regs | sed -e s'/^ *//'`
563 nregs=
564 while test -n "$regs"; do
565 field=`echo $regs | sed -e 's/^\([^;]*\);.*$/\1/'`
566 regs=`echo $regs | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
567 # Capitalize the first character of the field.
568 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
569 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
570 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
571 field="$f$r"
572 field=`echo "$field" | sed \
573 -e 's/__user_psw_struct/PtracePsw/' \
574 -e 's/__user_fpregs_struct/PtraceFpregs/' \
575 -e 's/__user_per_struct/PtracePer/'`
576 nregs="$nregs $field;"
577 done
578 echo "type PtraceRegs struct {$nregs }" >> ${OUT}
581 # Some basic types.
582 echo 'type Size_t _size_t' >> ${OUT}
583 echo "type Ssize_t _ssize_t" >> ${OUT}
584 if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go > /dev/null 2>&1; then
585 echo "type Offset_t _off64_t" >> ${OUT}
586 else
587 echo "type Offset_t _off_t" >> ${OUT}
589 echo "type Mode_t _mode_t" >> ${OUT}
590 echo "type Pid_t _pid_t" >> ${OUT}
591 echo "type Uid_t _uid_t" >> ${OUT}
592 echo "type Gid_t _gid_t" >> ${OUT}
593 echo "type Socklen_t _socklen_t" >> ${OUT}
595 # The C int type.
596 sizeof_int=`grep '^const ___SIZEOF_INT__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
597 if test "$sizeof_int" = "4"; then
598 echo "type _C_int int32" >> ${OUT}
599 echo "type _C_uint uint32" >> ${OUT}
600 elif test "$sizeof_int" = "8"; then
601 echo "type _C_int int64" >> ${OUT}
602 echo "type _C_uint uint64" >> ${OUT}
603 else
604 echo 1>&2 "mksysinfo.sh: could not determine size of int (got $sizeof_int)"
605 exit 1
608 # The C long type, needed because that is the type that ptrace returns.
609 sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
610 if test "$sizeof_long" = "4"; then
611 echo "type _C_long int32" >> ${OUT}
612 elif test "$sizeof_long" = "8"; then
613 echo "type _C_long int64" >> ${OUT}
614 else
615 echo 1>&2 "mksysinfo.sh: could not determine size of long (got $sizeof_long)"
616 exit 1
619 # Solaris 2 needs _u?pad128_t, but its default definition in terms of long
620 # double is commented by -fdump-go-spec.
621 if grep "^// type _pad128_t" gen-sysinfo.go > /dev/null 2>&1; then
622 echo "type _pad128_t struct { _l [4]int32; }" >> ${OUT}
624 if grep "^// type _upad128_t" gen-sysinfo.go > /dev/null 2>&1; then
625 echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
628 # The time_t type.
629 if grep '^type _time_t ' gen-sysinfo.go > /dev/null 2>&1; then
630 echo 'type Time_t _time_t' >> ${OUT}
633 # The time structures need special handling: we need to name the
634 # types, so that we can cast integers to the right types when
635 # assigning to the structures.
636 timeval=`grep '^type _timeval ' gen-sysinfo.go`
637 timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
638 timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
639 echo "type Timeval_sec_t $timeval_sec" >> ${OUT}
640 echo "type Timeval_usec_t $timeval_usec" >> ${OUT}
641 echo $timeval | \
642 sed -e 's/type _timeval /type Timeval /' \
643 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timeval_sec_t/' \
644 -e 's/tv_usec *[a-zA-Z0-9_]*/Usec Timeval_usec_t/' >> ${OUT}
645 timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
646 if test "$timespec" = ""; then
647 # IRIX 6.5 has __timespec instead.
648 timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
650 timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
651 timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
652 echo "type Timespec_sec_t $timespec_sec" >> ${OUT}
653 echo "type Timespec_nsec_t $timespec_nsec" >> ${OUT}
654 echo $timespec | \
655 sed -e 's/^type ___timespec /type Timespec /' \
656 -e 's/^type _timespec /type Timespec /' \
657 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timespec_sec_t/' \
658 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timespec_nsec_t/' >> ${OUT}
660 timestruc=`grep '^type _timestruc_t ' gen-sysinfo.go || true`
661 if test "$timestruc" != ""; then
662 timestruc_sec=`echo $timestruc | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
663 timestruc_nsec=`echo $timestruc | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
664 echo "type Timestruc_sec_t $timestruc_sec" >> ${OUT}
665 echo "type Timestruc_nsec_t $timestruc_nsec" >> ${OUT}
666 echo $timestruc | \
667 sed -e 's/^type _timestruc_t /type Timestruc /' \
668 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timestruc_sec_t/' \
669 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timestruc_nsec_t/' >> ${OUT}
672 # The tms struct.
673 grep '^type _tms ' gen-sysinfo.go | \
674 sed -e 's/type _tms/type Tms/' \
675 -e 's/tms_utime/Utime/' \
676 -e 's/tms_stime/Stime/' \
677 -e 's/tms_cutime/Cutime/' \
678 -e 's/tms_cstime/Cstime/' \
679 >> ${OUT}
681 # The stat type.
682 # Prefer largefile variant if available.
683 stat=`grep '^type _stat64 ' gen-sysinfo.go || true`
684 if test "$stat" != ""; then
685 grep '^type _stat64 ' gen-sysinfo.go
686 else
687 grep '^type _stat ' gen-sysinfo.go
688 fi | sed -e 's/type _stat64/type Stat_t/' \
689 -e 's/type _stat/type Stat_t/' \
690 -e 's/st_dev/Dev/' \
691 -e 's/st_ino/Ino/g' \
692 -e 's/st_nlink/Nlink/' \
693 -e 's/st_mode/Mode/' \
694 -e 's/st_uid/Uid/' \
695 -e 's/st_gid/Gid/' \
696 -e 's/st_rdev/Rdev/' \
697 -e 's/st_size/Size/' \
698 -e 's/st_blksize/Blksize/' \
699 -e 's/st_blocks/Blocks/' \
700 -e 's/st_atim/Atim/' \
701 -e 's/st_mtim/Mtim/' \
702 -e 's/st_ctim/Ctim/' \
703 -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
704 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
705 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
706 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
707 -e 's/Godump_[0-9] struct { \([^;]*;\) };/\1/g' \
708 >> ${OUT}
710 # The directory searching types.
711 # Prefer largefile variant if available.
712 dirent=`grep '^type _dirent64 ' gen-sysinfo.go || true`
713 if test "$dirent" != ""; then
714 grep '^type _dirent64 ' gen-sysinfo.go
715 else
716 grep '^type _dirent ' gen-sysinfo.go
717 fi | sed -e 's/type _dirent64/type Dirent/' \
718 -e 's/type _dirent/type Dirent/' \
719 -e 's/d_name \[0+1\]/d_name [0+256]/' \
720 -e 's/d_name/Name/' \
721 -e 's/]int8/]byte/' \
722 -e 's/d_ino/Ino/' \
723 -e 's/d_off/Off/' \
724 -e 's/d_reclen/Reclen/' \
725 -e 's/d_type/Type/' \
726 >> ${OUT}
727 echo "type DIR _DIR" >> ${OUT}
729 # Values for d_type field in dirent.
730 grep '^const _DT_' gen-sysinfo.go |
731 sed -e 's/^\(const \)_\(DT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
733 # The rusage struct.
734 rusage=`grep '^type _rusage struct' gen-sysinfo.go`
735 if test "$rusage" != ""; then
736 # Remove anonymous unions from GNU/Linux <bits/resource.h>.
737 rusage=`echo $rusage | sed -e 's/Godump_[0-9][0-9]* struct {\([^}]*\)};/\1/g'`
738 rusage=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'`
739 rusage=`echo $rusage | sed -e 's/^ *//'`
740 nrusage=
741 while test -n "$rusage"; do
742 field=`echo $rusage | sed -e 's/^\([^;]*\);.*$/\1/'`
743 rusage=`echo $rusage | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
744 # Drop the leading ru_, capitalize the next character.
745 field=`echo $field | sed -e 's/^ru_//'`
746 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
747 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
748 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
749 # Fix _timeval _timespec, and _timestruc_t.
750 r=`echo $r | sed -e s'/ _timeval$/ Timeval/'`
751 r=`echo $r | sed -e s'/ _timespec$/ Timespec/'`
752 r=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'`
753 field="$f$r"
754 nrusage="$nrusage $field;"
755 done
756 echo "type Rusage struct {$nrusage }" >> ${OUT}
757 else
758 echo "type Rusage struct {}" >> ${OUT}
761 # The RUSAGE constants.
762 grep '^const _RUSAGE_' gen-sysinfo.go | \
763 sed -e 's/^\(const \)_\(RUSAGE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
765 # The utsname struct.
766 grep '^type _utsname ' gen-sysinfo.go | \
767 sed -e 's/_utsname/Utsname/' \
768 -e 's/sysname/Sysname/' \
769 -e 's/nodename/Nodename/' \
770 -e 's/release/Release/' \
771 -e 's/version/Version/' \
772 -e 's/machine/Machine/' \
773 -e 's/domainname/Domainname/' \
774 >> ${OUT}
776 # The iovec struct.
777 iovec=`grep '^type _iovec ' gen-sysinfo.go`
778 iovec_len=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
779 echo "type Iovec_len_t $iovec_len" >> ${OUT}
780 echo $iovec | \
781 sed -e 's/_iovec/Iovec/' \
782 -e 's/iov_base/Base/' \
783 -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
784 >> ${OUT}
786 # The msghdr struct.
787 msghdr=`grep '^type _msghdr ' gen-sysinfo.go`
788 msghdr_controllen=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
789 echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT}
790 echo $msghdr | \
791 sed -e 's/_msghdr/Msghdr/' \
792 -e 's/msg_name/Name/' \
793 -e 's/msg_namelen/Namelen/' \
794 -e 's/msg_iov/Iov/' \
795 -e 's/msg_iovlen/Iovlen/' \
796 -e 's/_iovec/Iovec/' \
797 -e 's/msg_control/Control/' \
798 -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
799 -e 's/msg_flags/Flags/' \
800 >> ${OUT}
802 # The MSG_ flags for Msghdr.
803 grep '^const _MSG_' gen-sysinfo.go | \
804 sed -e 's/^\(const \)_\(MSG_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
806 # The cmsghdr struct.
807 cmsghdr=`grep '^type _cmsghdr ' gen-sysinfo.go`
808 if test -n "$cmsghdr"; then
809 cmsghdr_len=`echo $cmsghdr | sed -n -e 's/^.*cmsg_len \([^ ]*\);.*$/\1/p'`
810 echo "type Cmsghdr_len_t $cmsghdr_len" >> ${OUT}
811 echo "$cmsghdr" | \
812 sed -e 's/_cmsghdr/Cmsghdr/' \
813 -e 's/cmsg_len *[a-zA-Z0-9_]*/Len Cmsghdr_len_t/' \
814 -e 's/cmsg_level/Level/' \
815 -e 's/cmsg_type/Type/' \
816 -e 's/\[\]/[0]/' \
817 >> ${OUT}
820 # The SCM_ flags for Cmsghdr.
821 grep '^const _SCM_' gen-sysinfo.go | \
822 sed -e 's/^\(const \)_\(SCM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
824 # The ucred struct.
825 upcase_fields "_ucred" "Ucred" >> ${OUT} || true
827 # The ip_mreq struct.
828 grep '^type _ip_mreq ' gen-sysinfo.go | \
829 sed -e 's/_ip_mreq/IPMreq/' \
830 -e 's/imr_multiaddr/Multiaddr/' \
831 -e 's/imr_interface/Interface/' \
832 -e 's/_in_addr/[4]byte/g' \
833 >> ${OUT}
835 # We need IPMreq to compile the net package.
836 if ! grep 'type IPMreq ' ${OUT} >/dev/null 2>&1; then
837 echo 'type IPMreq struct { Multiaddr [4]byte; Interface [4]byte; }' >> ${OUT}
840 # The ipv6_mreq struct.
841 grep '^type _ipv6_mreq ' gen-sysinfo.go | \
842 sed -e 's/_ipv6_mreq/IPv6Mreq/' \
843 -e 's/ipv6mr_multiaddr/Multiaddr/' \
844 -e 's/ipv6mr_interface/Interface/' \
845 -e 's/_in6_addr/[16]byte/' \
846 >> ${OUT}
848 # We need IPv6Mreq to compile the net package.
849 if ! grep 'type IPv6Mreq ' ${OUT} >/dev/null 2>&1; then
850 echo 'type IPv6Mreq struct { Multiaddr [16]byte; Interface uint32; }' >> ${OUT}
853 # The ip_mreqn struct.
854 grep '^type _ip_mreqn ' gen-sysinfo.go | \
855 sed -e 's/_ip_mreqn/IPMreqn/' \
856 -e 's/imr_multiaddr/Multiaddr/' \
857 -e 's/imr_address/Address/' \
858 -e 's/imr_ifindex/Ifindex/' \
859 -e 's/_in_addr/[4]byte/g' \
860 >> ${OUT}
862 # We need IPMreq to compile the net package.
863 if ! grep 'type IPMreqn ' ${OUT} >/dev/null 2>&1; then
864 echo 'type IPMreqn struct { Multiaddr [4]byte; Interface [4]byte; Ifindex int32 }' >> ${OUT}
867 # The icmp6_filter struct.
868 grep '^type _icmp6_filter ' gen-sysinfo.go | \
869 sed -e 's/_icmp6_filter/ICMPv6Filter/' \
870 -e 's/data/Data/' \
871 -e 's/filt/Filt/' \
872 >> ${OUT}
874 # We need ICMPv6Filter to compile the syscall package.
875 if ! grep 'type ICMPv6Filter ' ${OUT} > /dev/null 2>&1; then
876 echo 'type ICMPv6Filter struct { Data [8]uint32 }' >> ${OUT}
879 # The ip6_mtuinfo struct.
880 grep '^type _ip6_mtuinfo ' gen-sysinfo.go | \
881 sed -e 's/_ip6_mtuinfo/IPv6MTUInfo/' \
882 -e 's/ip6m_addr/Addr/' \
883 -e 's/_sockaddr_in6/RawSockaddrInet6/' \
884 -e 's/ip6m_mtu/Mtu/' \
885 >> ${OUT}
887 # Try to guess the type to use for fd_set.
888 fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
889 fds_bits_type="_C_long"
890 if test "$fd_set" != ""; then
891 fds_bits_type=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
893 echo "type fds_bits_type $fds_bits_type" >> ${OUT}
895 # The addrinfo struct.
896 grep '^type _addrinfo ' gen-sysinfo.go | \
897 sed -e 's/_addrinfo/Addrinfo/g' \
898 -e 's/ ai_/ Ai_/g' \
899 >> ${OUT}
901 # The addrinfo and nameinfo flags and errors.
902 grep '^const _AI_' gen-sysinfo.go | \
903 sed -e 's/^\(const \)_\(AI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
904 grep '^const _EAI_' gen-sysinfo.go | \
905 sed -e 's/^\(const \)_\(EAI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
906 grep '^const _NI_' gen-sysinfo.go | \
907 sed -e 's/^\(const \)_\(NI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
909 # The passwd struct.
910 grep '^type _passwd ' gen-sysinfo.go | \
911 sed -e 's/_passwd/Passwd/' \
912 -e 's/ pw_/ Pw_/g' \
913 >> ${OUT}
915 # The group struct.
916 grep '^type _group ' gen-sysinfo.go | \
917 sed -e 's/_group/Group/' \
918 -e 's/ gr_/ Gr_/g' \
919 >> ${OUT}
921 # The ioctl flags for the controlling TTY.
922 grep '^const _TIOC' gen-sysinfo.go | \
923 grep -v '_val =' | \
924 sed -e 's/^\(const \)_\(TIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
925 grep '^const _TUNSET' gen-sysinfo.go | \
926 grep -v '_val =' | \
927 sed -e 's/^\(const \)_\(TUNSET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
928 # We need TIOCGWINSZ.
929 if ! grep '^const TIOCGWINSZ' ${OUT} >/dev/null 2>&1; then
930 if grep '^const _TIOCGWINSZ_val' ${OUT} >/dev/null 2>&1; then
931 echo 'const TIOCGWINSZ = _TIOCGWINSZ_val' >> ${OUT}
934 if ! grep '^const TIOCSWINSZ' ${OUT} >/dev/null 2>&1; then
935 if grep '^const _TIOCSWINSZ_val' ${OUT} >/dev/null 2>&1; then
936 echo 'const TIOCSWINSZ = _TIOCSWINSZ_val' >> ${OUT}
939 if ! grep '^const TIOCNOTTY' ${OUT} >/dev/null 2>&1; then
940 if grep '^const _TIOCNOTTY_val' ${OUT} >/dev/null 2>&1; then
941 echo 'const TIOCNOTTY = _TIOCNOTTY_val' >> ${OUT}
944 if ! grep '^const TIOCSCTTY' ${OUT} >/dev/null 2>&1; then
945 if grep '^const _TIOCSCTTY_val' ${OUT} >/dev/null 2>&1; then
946 echo 'const TIOCSCTTY = _TIOCSCTTY_val' >> ${OUT}
949 if ! grep '^const TIOCGPGRP' ${OUT} >/dev/null 2>&1; then
950 if grep '^const _TIOCGPGRP_val' ${OUT} >/dev/null 2>&1; then
951 echo 'const TIOCGPGRP = _TIOCGPGRP_val' >> ${OUT}
954 if ! grep '^const TIOCSPGRP' ${OUT} >/dev/null 2>&1; then
955 if grep '^const _TIOCSPGRP_val' ${OUT} >/dev/null 2>&1; then
956 echo 'const TIOCSPGRP = _TIOCSPGRP_val' >> ${OUT}
959 if ! grep '^const TIOCGPTN' ${OUT} >/dev/null 2>&1; then
960 if grep '^const _TIOCGPTN_val' ${OUT} >/dev/null 2>&1; then
961 echo 'const TIOCGPTN = _TIOCGPTN_val' >> ${OUT}
964 if ! grep '^const TIOCSPTLCK' ${OUT} >/dev/null 2>&1; then
965 if grep '^const _TIOCSPTLCK_val' ${OUT} >/dev/null 2>&1; then
966 echo 'const TIOCSPTLCK = _TIOCSPTLCK_val' >> ${OUT}
969 if ! grep '^const TIOCGDEV' ${OUT} >/dev/null 2>&1; then
970 if grep '^const _TIOCGDEV_val' ${OUT} >/dev/null 2>&1; then
971 echo 'const TIOCGDEV = _TIOCGDEV_val' >> ${OUT}
974 if ! grep '^const TIOCSIG' ${OUT} >/dev/null 2>&1; then
975 if grep '^const _TIOCSIG_val' ${OUT} >/dev/null 2>&1; then
976 echo 'const TIOCSIG = _TIOCSIG_val' >> ${OUT}
980 if ! grep '^const TUNSETNOCSUM' ${OUT} >/dev/null 2>&1; then
981 if grep '^const _TUNSETNOCSUM_val' ${OUT} >/dev/null 2>&1; then
982 echo 'const TUNSETNOCSUM = _TUNSETNOCSUM_val' >> ${OUT}
986 if ! grep '^const TUNSETDEBUG' ${OUT} >/dev/null 2>&1; then
987 if grep '^const _TUNSETDEBUG_val' ${OUT} >/dev/null 2>&1; then
988 echo 'const TUNSETDEBUG = _TUNSETDEBUG_val' >> ${OUT}
992 if ! grep '^const TUNSETIFF' ${OUT} >/dev/null 2>&1; then
993 if grep '^const _TUNSETIFF_val' ${OUT} >/dev/null 2>&1; then
994 echo 'const TUNSETIFF = _TUNSETIFF_val' >> ${OUT}
998 if ! grep '^const TUNSETPERSIST' ${OUT} >/dev/null 2>&1; then
999 if grep '^const _TUNSETPERSIST_val' ${OUT} >/dev/null 2>&1; then
1000 echo 'const TUNSETPERSIST = _TUNSETPERSIST_val' >> ${OUT}
1004 if ! grep '^const TUNSETOWNER' ${OUT} >/dev/null 2>&1; then
1005 if grep '^const _TUNSETOWNER_val' ${OUT} >/dev/null 2>&1; then
1006 echo 'const TUNSETOWNER = _TUNSETOWNER_val' >> ${OUT}
1010 if ! grep '^const TUNSETLINK' ${OUT} >/dev/null 2>&1; then
1011 if grep '^const _TUNSETLINK_val' ${OUT} >/dev/null 2>&1; then
1012 echo 'const TUNSETLINK = _TUNSETLINK_val' >> ${OUT}
1016 if ! grep '^const TUNSETGROUP' ${OUT} >/dev/null 2>&1; then
1017 if grep '^const _TUNSETGROUP_val' ${OUT} >/dev/null 2>&1; then
1018 echo 'const TUNSETGROUP = _TUNSETGROUP_val' >> ${OUT}
1022 if ! grep '^const TUNGETFEATURES' ${OUT} >/dev/null 2>&1; then
1023 if grep '^const _TUNGETFEATURES_val' ${OUT} >/dev/null 2>&1; then
1024 echo 'const TUNGETFEATURES = _TUNGETFEATURES_val' >> ${OUT}
1028 if ! grep '^const TUNSETOFFLOAD' ${OUT} >/dev/null 2>&1; then
1029 if grep '^const _TUNSETOFFLOAD_val' ${OUT} >/dev/null 2>&1; then
1030 echo 'const TUNSETOFFLOAD = _TUNSETOFFLOAD_val' >> ${OUT}
1034 if ! grep '^const TUNSETTXFILTER' ${OUT} >/dev/null 2>&1; then
1035 if grep '^const _TUNSETTXFILTER_val' ${OUT} >/dev/null 2>&1; then
1036 echo 'const TUNSETTXFILTER = _TUNSETTXFILTER_val' >> ${OUT}
1040 if ! grep '^const TUNGETIFF' ${OUT} >/dev/null 2>&1; then
1041 if grep '^const _TUNGETIFF_val' ${OUT} >/dev/null 2>&1; then
1042 echo 'const TUNGETIFF = _TUNGETIFF_val' >> ${OUT}
1046 if ! grep '^const TUNGETSNDBUF' ${OUT} >/dev/null 2>&1; then
1047 if grep '^const _TUNGETSNDBUF_val' ${OUT} >/dev/null 2>&1; then
1048 echo 'const TUNGETSNDBUF = _TUNGETSNDBUF_val' >> ${OUT}
1052 if ! grep '^const TUNSETSNDBUF' ${OUT} >/dev/null 2>&1; then
1053 if grep '^const _TUNSETSNDBUF_val' ${OUT} >/dev/null 2>&1; then
1054 echo 'const TUNSETSNDBUF = _TUNSETSNDBUF_val' >> ${OUT}
1058 if ! grep '^const TUNATTACHFILTER' ${OUT} >/dev/null 2>&1; then
1059 if grep '^const _TUNATTACHFILTER_val' ${OUT} >/dev/null 2>&1; then
1060 echo 'const TUNATTACHFILTER = _TUNATTACHFILTER_val' >> ${OUT}
1064 if ! grep '^const TUNDETACHFILTER' ${OUT} >/dev/null 2>&1; then
1065 if grep '^const _TUNDETACHFILTER_val' ${OUT} >/dev/null 2>&1; then
1066 echo 'const TUNDETACHFILTER = _TUNDETACHFILTER_val' >> ${OUT}
1070 if ! grep '^const TUNGETVNETHDRSZ' ${OUT} >/dev/null 2>&1; then
1071 if grep '^const _TUNGETVNETHDRSZ_val' ${OUT} >/dev/null 2>&1; then
1072 echo 'const TUNGETVNETHDRSZ = _TUNGETVNETHDRSZ_val' >> ${OUT}
1076 if ! grep '^const TUNSETVNETHDRSZ' ${OUT} >/dev/null 2>&1; then
1077 if grep '^const _TUNSETVNETHDRSZ_val' ${OUT} >/dev/null 2>&1; then
1078 echo 'const TUNSETVNETHDRSZ = _TUNSETVNETHDRSZ_val' >> ${OUT}
1082 if ! grep '^const TUNSETQUEUE' ${OUT} >/dev/null 2>&1; then
1083 if grep '^const _TUNSETQUEUE_val' ${OUT} >/dev/null 2>&1; then
1084 echo 'const TUNSETQUEUE = _TUNSETQUEUE_val' >> ${OUT}
1089 if ! grep '^const TUNSETIFINDEX' ${OUT} >/dev/null 2>&1; then
1090 if grep '^const _TUNSETIFINDEX_val' ${OUT} >/dev/null 2>&1; then
1091 echo 'const TUNSETIFINDEX = _TUNSETIFINDEX_val' >> ${OUT}
1095 if ! grep '^const TUNGETFILTER' ${OUT} >/dev/null 2>&1; then
1096 if grep '^const _TUNGETFILTER_val' ${OUT} >/dev/null 2>&1; then
1097 echo 'const TUNGETFILTER = _TUNGETFILTER_val' >> ${OUT}
1101 # The ioctl flags for terminal control
1102 grep '^const _TC[GS]ET' gen-sysinfo.go | grep -v _val | \
1103 sed -e 's/^\(const \)_\(TC[GS]ET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1104 if ! grep '^const TCGETS' ${OUT} >/dev/null 2>&1; then
1105 if grep '^const _TCGETS_val' ${OUT} >/dev/null 2>&1; then
1106 echo 'const TCGETS = _TCGETS_val' >> ${OUT}
1109 if ! grep '^const TCSETS' ${OUT} >/dev/null 2>&1; then
1110 if grep '^const _TCSETS_val' ${OUT} >/dev/null 2>&1; then
1111 echo 'const TCSETS = _TCSETS_val' >> ${OUT}
1115 # ioctl constants. Might fall back to 0 if TIOCNXCL is missing, too, but
1116 # needs handling in syscalls.exec.go.
1117 if ! grep '^const _TIOCSCTTY ' gen-sysinfo.go >/dev/null 2>&1; then
1118 if grep '^const _TIOCNXCL ' gen-sysinfo.go >/dev/null 2>&1; then
1119 echo "const TIOCSCTTY = TIOCNXCL" >> ${OUT}
1123 # The nlmsghdr struct.
1124 grep '^type _nlmsghdr ' gen-sysinfo.go | \
1125 sed -e 's/_nlmsghdr/NlMsghdr/' \
1126 -e 's/nlmsg_len/Len/' \
1127 -e 's/nlmsg_type/Type/' \
1128 -e 's/nlmsg_flags/Flags/' \
1129 -e 's/nlmsg_seq/Seq/' \
1130 -e 's/nlmsg_pid/Pid/' \
1131 >> ${OUT}
1133 # The nlmsg flags and operators.
1134 grep '^const _NLM' gen-sysinfo.go | \
1135 sed -e 's/^\(const \)_\(NLM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1137 # NLMSG_HDRLEN is defined as an expression using sizeof.
1138 if ! grep '^const NLMSG_HDRLEN' ${OUT} > /dev/null 2>&1; then
1139 if grep '^const _sizeof_nlmsghdr ' ${OUT} > /dev/null 2>&1; then
1140 echo 'const NLMSG_HDRLEN = (_sizeof_nlmsghdr + (NLMSG_ALIGNTO-1)) &^ (NLMSG_ALIGNTO-1)' >> ${OUT}
1144 # The rtmsg struct.
1145 grep '^type _rtmsg ' gen-sysinfo.go | \
1146 sed -e 's/_rtmsg/RtMsg/' \
1147 -e 's/rtm_family/Family/' \
1148 -e 's/rtm_dst_len/Dst_len/' \
1149 -e 's/rtm_src_len/Src_len/' \
1150 -e 's/rtm_tos/Tos/' \
1151 -e 's/rtm_table/Table/' \
1152 -e 's/rtm_protocol/Protocol/' \
1153 -e 's/rtm_scope/Scope/' \
1154 -e 's/rtm_type/Type/' \
1155 -e 's/rtm_flags/Flags/' \
1156 >> ${OUT}
1158 # The rtgenmsg struct.
1159 grep '^type _rtgenmsg ' gen-sysinfo.go | \
1160 sed -e 's/_rtgenmsg/RtGenmsg/' \
1161 -e 's/rtgen_family/Family/' \
1162 >> ${OUT}
1164 # The routing message flags.
1165 grep '^const _RT_' gen-sysinfo.go | \
1166 sed -e 's/^\(const \)_\(RT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1167 grep '^const _RTA' gen-sysinfo.go | \
1168 sed -e 's/^\(const \)_\(RTA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1169 grep '^const _RTF' gen-sysinfo.go | \
1170 sed -e 's/^\(const \)_\(RTF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1171 grep '^const _RTCF' gen-sysinfo.go | \
1172 sed -e 's/^\(const \)_\(RTCF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1173 grep '^const _RTM' gen-sysinfo.go | \
1174 sed -e 's/^\(const \)_\(RTM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1175 grep '^const _RTN' gen-sysinfo.go | \
1176 sed -e 's/^\(const \)_\(RTN[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1177 grep '^const _RTPROT' gen-sysinfo.go | \
1178 sed -e 's/^\(const \)_\(RTPROT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1180 # The ifinfomsg struct.
1181 grep '^type _ifinfomsg ' gen-sysinfo.go | \
1182 sed -e 's/_ifinfomsg/IfInfomsg/' \
1183 -e 's/ifi_family/Family/' \
1184 -e 's/ifi_type/Type/' \
1185 -e 's/ifi_index/Index/' \
1186 -e 's/ifi_flags/Flags/' \
1187 -e 's/ifi_change/Change/' \
1188 >> ${OUT}
1190 # The interface information types and flags.
1191 grep '^const _IFA' gen-sysinfo.go | \
1192 sed -e 's/^\(const \)_\(IFA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1193 grep '^const _IFLA' gen-sysinfo.go | \
1194 sed -e 's/^\(const \)_\(IFLA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1195 grep '^const _IFF' gen-sysinfo.go | \
1196 sed -e 's/^\(const \)_\(IFF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1197 grep '^const _IFNAMSIZ' gen-sysinfo.go | \
1198 sed -e 's/^\(const \)_\(IFNAMSIZ[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1199 grep '^const _SIOC' gen-sysinfo.go |
1200 sed -e 's/^\(const \)_\(SIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1202 # The ifaddrmsg struct.
1203 grep '^type _ifaddrmsg ' gen-sysinfo.go | \
1204 sed -e 's/_ifaddrmsg/IfAddrmsg/' \
1205 -e 's/ifa_family/Family/' \
1206 -e 's/ifa_prefixlen/Prefixlen/' \
1207 -e 's/ifa_flags/Flags/' \
1208 -e 's/ifa_scope/Scope/' \
1209 -e 's/ifa_index/Index/' \
1210 >> ${OUT}
1212 # The rtattr struct.
1213 grep '^type _rtattr ' gen-sysinfo.go | \
1214 sed -e 's/_rtattr/RtAttr/' \
1215 -e 's/rta_len/Len/' \
1216 -e 's/rta_type/Type/' \
1217 >> ${OUT}
1219 # The in_pktinfo struct.
1220 grep '^type _in_pktinfo ' gen-sysinfo.go | \
1221 sed -e 's/_in_pktinfo/Inet4Pktinfo/' \
1222 -e 's/ipi_ifindex/Ifindex/' \
1223 -e 's/ipi_spec_dst/Spec_dst/' \
1224 -e 's/ipi_addr/Addr/' \
1225 -e 's/_in_addr/[4]byte/g' \
1226 >> ${OUT}
1228 # The in6_pktinfo struct.
1229 grep '^type _in6_pktinfo ' gen-sysinfo.go | \
1230 sed -e 's/_in6_pktinfo/Inet6Pktinfo/' \
1231 -e 's/ipi6_addr/Addr/' \
1232 -e 's/ipi6_ifindex/Ifindex/' \
1233 -e 's/_in6_addr/[16]byte/' \
1234 >> ${OUT}
1236 # The termios struct.
1237 grep '^type _termios ' gen-sysinfo.go | \
1238 sed -e 's/_termios/Termios/' \
1239 -e 's/c_iflag/Iflag/' \
1240 -e 's/c_oflag/Oflag/' \
1241 -e 's/c_cflag/Cflag/' \
1242 -e 's/c_lflag/Lflag/' \
1243 -e 's/c_line/Line/' \
1244 -e 's/c_cc/Cc/' \
1245 -e 's/c_ispeed/Ispeed/' \
1246 -e 's/c_ospeed/Ospeed/' \
1247 >> ${OUT}
1249 # The termios constants.
1250 for n in IGNBRK BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL IUCLC \
1251 IXON IXANY IXOFF IMAXBEL IUTF8 OPOST OLCUC ONLCR OCRNL ONOCR ONLRET \
1252 OFILL OFDEL NLDLY NL0 NL1 CRDLY CR0 CR1 CR2 CR3 CS5 CS6 CS7 CS8 TABDLY \
1253 BSDLY VTDLY FFDLY CBAUD CBAUDEX CSIZE CSTOPB CREAD PARENB PARODD HUPCL \
1254 CLOCAL LOBLK CIBAUD CMSPAR CRTSCTS ISIG ICANON XCASE ECHO ECHOE ECHOK \
1255 ECHONL ECHOCTL ECHOPRT ECHOKE DEFECHO FLUSHO NOFLSH TOSTOP PENDIN IEXTEN \
1256 VINTR VQUIT VERASE VKILL VEOF VMIN VEOL VTIME VEOL2 VSWTCH VSTART VSTOP \
1257 VSUSP VDSUSP VLNEXT VWERASE VREPRINT VDISCARD VSTATUS TCSANOW TCSADRAIN \
1258 TCSAFLUSH TCIFLUSH TCOFLUSH TCIOFLUSH TCOOFF TCOON TCIOFF TCION B0 B50 \
1259 B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 \
1260 B38400 B57600 B115200 B230400 B460800 B500000 B576000 B921600 B1000000 \
1261 B1152000 B1500000 B2000000 B2500000 B3000000 B3500000 B4000000; do
1263 grep "^const _$n " gen-sysinfo.go | \
1264 sed -e 's/^\(const \)_\([^=]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1265 done
1267 # The mount flags
1268 grep '^const _MNT_' gen-sysinfo.go |
1269 sed -e 's/^\(const \)_\(MNT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1270 grep '^const _MS_' gen-sysinfo.go |
1271 sed -e 's/^\(const \)_\(MS_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1273 # The fallocate flags.
1274 grep '^const _FALLOC_' gen-sysinfo.go |
1275 sed -e 's/^\(const \)_\(FALLOC_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1277 # The statfs struct.
1278 # Prefer largefile variant if available.
1279 statfs=`grep '^type _statfs64 ' gen-sysinfo.go || true`
1280 if test "$statfs" != ""; then
1281 grep '^type _statfs64 ' gen-sysinfo.go
1282 else
1283 grep '^type _statfs ' gen-sysinfo.go
1284 fi | sed -e 's/type _statfs64/type Statfs_t/' \
1285 -e 's/type _statfs/type Statfs_t/' \
1286 -e 's/f_type/Type/' \
1287 -e 's/f_bsize/Bsize/' \
1288 -e 's/f_blocks/Blocks/' \
1289 -e 's/f_bfree/Bfree/' \
1290 -e 's/f_bavail/Bavail/' \
1291 -e 's/f_files/Files/' \
1292 -e 's/f_ffree/Ffree/' \
1293 -e 's/f_fsid/Fsid/' \
1294 -e 's/f_namelen/Namelen/' \
1295 -e 's/f_frsize/Frsize/' \
1296 -e 's/f_flags/Flags/' \
1297 -e 's/f_spare/Spare/' \
1298 >> ${OUT}
1300 # The timex struct.
1301 timex=`grep '^type _timex ' gen-sysinfo.go || true`
1302 if test "$timex" = ""; then
1303 timex=`grep '^// type _timex ' gen-sysinfo.go || true`
1304 if test "$timex" != ""; then
1305 timex=`echo $timex | sed -e 's|// ||' -e 's/INVALID-bit-field/int32/g'`
1308 if test "$timex" != ""; then
1309 echo "$timex" | \
1310 sed -e 's/_timex/Timex/' \
1311 -e 's/modes/Modes/' \
1312 -e 's/offset/Offset/' \
1313 -e 's/freq/Freq/' \
1314 -e 's/maxerror/Maxerror/' \
1315 -e 's/esterror/Esterror/' \
1316 -e 's/status/Status/' \
1317 -e 's/constant/Constant/' \
1318 -e 's/precision/Precision/' \
1319 -e 's/tolerance/Tolerance/' \
1320 -e 's/ time / Time /' \
1321 -e 's/tick/Tick/' \
1322 -e 's/ppsfreq/Ppsfreq/' \
1323 -e 's/jitter/Jitter/' \
1324 -e 's/shift/Shift/' \
1325 -e 's/stabil/Stabil/' \
1326 -e 's/jitcnt/Jitcnt/' \
1327 -e 's/calcnt/Calcnt/' \
1328 -e 's/errcnt/Errcnt/' \
1329 -e 's/stbcnt/Stbcnt/' \
1330 -e 's/tai/Tai/' \
1331 -e 's/_timeval/Timeval/' \
1332 >> ${OUT}
1335 # The rlimit struct.
1336 grep '^type _rlimit ' gen-sysinfo.go | \
1337 sed -e 's/_rlimit/Rlimit/' \
1338 -e 's/rlim_cur/Cur/' \
1339 -e 's/rlim_max/Max/' \
1340 >> ${OUT}
1342 # The RLIMIT constants.
1343 grep '^const _RLIMIT_' gen-sysinfo.go |
1344 sed -e 's/^\(const \)_\(RLIMIT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1345 grep '^const _RLIM_' gen-sysinfo.go |
1346 sed -e 's/^\(const \)_\(RLIM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1348 # The sysinfo struct.
1349 grep '^type _sysinfo ' gen-sysinfo.go | \
1350 sed -e 's/_sysinfo/Sysinfo_t/' \
1351 -e 's/uptime/Uptime/' \
1352 -e 's/loads/Loads/' \
1353 -e 's/totalram/Totalram/' \
1354 -e 's/freeram/Freeram/' \
1355 -e 's/sharedram/Sharedram/' \
1356 -e 's/bufferram/Bufferram/' \
1357 -e 's/totalswap/Totalswap/' \
1358 -e 's/freeswap/Freeswap/' \
1359 -e 's/procs/Procs/' \
1360 -e 's/totalhigh/Totalhigh/' \
1361 -e 's/freehigh/Freehigh/' \
1362 -e 's/mem_unit/Unit/' \
1363 >> ${OUT}
1365 # The ustat struct.
1366 grep '^type _ustat ' gen-sysinfo.go | \
1367 sed -e 's/_ustat/Ustat_t/' \
1368 -e 's/f_tfree/Tfree/' \
1369 -e 's/f_tinode/Tinoe/' \
1370 -e 's/f_fname/Fname/' \
1371 -e 's/f_fpack/Fpack/' \
1372 >> ${OUT}
1373 # Force it to be defined, as on some older GNU/Linux systems the
1374 # header file fails when using with <linux/filter.h>.
1375 if ! grep 'type _ustat ' gen-sysinfo.go >/dev/null 2>&1; then
1376 echo 'type Ustat_t struct { Tfree int32; Tinoe uint64; Fname [5+1]int8; Fpack [5+1]int8; }' >> ${OUT}
1379 # The utimbuf struct.
1380 grep '^type _utimbuf ' gen-sysinfo.go | \
1381 sed -e 's/_utimbuf/Utimbuf/' \
1382 -e 's/actime/Actime/' \
1383 -e 's/modtime/Modtime/' \
1384 >> ${OUT}
1386 # The LOCK flags for flock.
1387 grep '^const _LOCK_' gen-sysinfo.go |
1388 sed -e 's/^\(const \)_\(LOCK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1390 # The PRIO constants.
1391 grep '^const _PRIO_' gen-sysinfo.go | \
1392 sed -e 's/^\(const \)_\(PRIO_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1394 # The GNU/Linux LINUX_REBOOT flags.
1395 grep '^const _LINUX_REBOOT_' gen-sysinfo.go |
1396 sed -e 's/^\(const \)_\(LINUX_REBOOT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1398 # The GNU/Linux sock_filter struct.
1399 grep '^type _sock_filter ' gen-sysinfo.go | \
1400 sed -e 's/_sock_filter/SockFilter/' \
1401 -e 's/code/Code/' \
1402 -e 's/jt/Jt/' \
1403 -e 's/jf/Jf/' \
1404 -e 's/k /K /' \
1405 >> ${OUT}
1407 # The GNU/Linux sock_fprog struct.
1408 grep '^type _sock_fprog ' gen-sysinfo.go | \
1409 sed -e 's/_sock_fprog/SockFprog/' \
1410 -e 's/len/Len/' \
1411 -e 's/filter/Filter/' \
1412 -e 's/_sock_filter/SockFilter/' \
1413 >> ${OUT}
1415 # The GNU/Linux filter flags.
1416 grep '^const _BPF_' gen-sysinfo.go | \
1417 sed -e 's/^\(const \)_\(BPF_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1419 # The GNU/Linux nlattr struct.
1420 grep '^type _nlattr ' gen-sysinfo.go | \
1421 sed -e 's/_nlattr/NlAttr/' \
1422 -e 's/nla_len/Len/' \
1423 -e 's/nla_type/Type/' \
1424 >> ${OUT}
1426 # The GNU/Linux nlmsgerr struct.
1427 grep '^type _nlmsgerr ' gen-sysinfo.go | \
1428 sed -e 's/_nlmsgerr/NlMsgerr/' \
1429 -e 's/error/Error/' \
1430 -e 's/msg/Msg/' \
1431 -e 's/_nlmsghdr/NlMsghdr/' \
1432 >> ${OUT}
1434 # The GNU/Linux rtnexthop struct.
1435 grep '^type _rtnexthop ' gen-sysinfo.go | \
1436 sed -e 's/_rtnexthop/RtNexthop/' \
1437 -e 's/rtnh_len/Len/' \
1438 -e 's/rtnh_flags/Flags/' \
1439 -e 's/rtnh_hops/Hops/' \
1440 -e 's/rtnh_ifindex/Ifindex/' \
1441 >> ${OUT}
1443 # The GNU/Linux netlink flags.
1444 grep '^const _NETLINK_' gen-sysinfo.go | \
1445 sed -e 's/^\(const \)_\(NETLINK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1446 grep '^const _NLA_' gen-sysinfo.go | grep -v '_val =' | \
1447 sed -e 's/^\(const \)_\(NLA_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1449 if ! grep '^const NLA_HDRLEN' ${OUT} >/dev/null 2>&1; then
1450 if grep '^const _NLA_HDRLEN_val' ${OUT} >/dev/null 2>&1; then
1451 echo 'const NLA_HDRLEN = _NLA_HDRLEN_val' >> ${OUT}
1455 # The GNU/Linux packet socket flags.
1456 grep '^const _PACKET_' gen-sysinfo.go | \
1457 sed -e 's/^\(const \)_\(PACKET_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1459 # The GNU/Linux inotify_event struct.
1460 grep '^type _inotify_event ' gen-sysinfo.go | \
1461 sed -e 's/_inotify_event/InotifyEvent/' \
1462 -e 's/wd/Wd/' \
1463 -e 's/mask/Mask/' \
1464 -e 's/cookie/Cookie/' \
1465 -e 's/len/Len/' \
1466 -e 's/name/Name/' \
1467 -e 's/\[\]/[0]/' \
1468 -e 's/\[0\]byte/[0]int8/' \
1469 >> ${OUT}
1471 # The GNU/Linux CLONE flags.
1472 grep '^const _CLONE_' gen-sysinfo.go | \
1473 sed -e 's/^\(const \)_\(CLONE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1474 # We need some CLONE constants that are not defined in older versions
1475 # of glibc.
1476 if ! grep '^const CLONE_NEWUSER ' ${OUT} > /dev/null 2>&1; then
1477 echo "const CLONE_NEWUSER = 0x10000000" >> ${OUT}
1479 if ! grep '^const CLONE_NEWNET ' ${OUT} > /dev/null 2>&1; then
1480 echo "const CLONE_NEWNET = 0x40000000" >> ${OUT}
1483 # Struct sizes.
1484 set cmsghdr Cmsghdr ip_mreq IPMreq ip_mreqn IPMreqn ipv6_mreq IPv6Mreq \
1485 ifaddrmsg IfAddrmsg ifinfomsg IfInfomsg in_pktinfo Inet4Pktinfo \
1486 in6_pktinfo Inet6Pktinfo inotify_event InotifyEvent linger Linger \
1487 msghdr Msghdr nlattr NlAttr nlmsgerr NlMsgerr nlmsghdr NlMsghdr \
1488 rtattr RtAttr rtgenmsg RtGenmsg rtmsg RtMsg rtnexthop RtNexthop \
1489 sock_filter SockFilter sock_fprog SockFprog ucred Ucred \
1490 icmp6_filter ICMPv6Filter ip6_mtuinfo IPv6MTUInfo
1491 while test $# != 0; do
1492 nc=$1
1493 ngo=$2
1494 shift
1495 shift
1496 if grep "^const _sizeof_$nc =" gen-sysinfo.go >/dev/null 2>&1; then
1497 echo "const Sizeof$ngo = _sizeof_$nc" >> ${OUT}
1499 done
1501 # In order to compile the net package, we need some sizes to exist
1502 # even if the types do not.
1503 if ! grep 'const SizeofIPMreq ' ${OUT} >/dev/null 2>&1; then
1504 echo 'const SizeofIPMreq = 8' >> ${OUT}
1506 if ! grep 'const SizeofIPv6Mreq ' ${OUT} >/dev/null 2>&1; then
1507 echo 'const SizeofIPv6Mreq = 20' >> ${OUT}
1509 if ! grep 'const SizeofIPMreqn ' ${OUT} >/dev/null 2>&1; then
1510 echo 'const SizeofIPMreqn = 12' >> ${OUT}
1512 if ! grep 'const SizeofICMPv6Filter ' ${OUT} >/dev/null 2>&1; then
1513 echo 'const SizeofICMPv6Filter = 32' >> ${OUT}
1516 # The Solaris 11 Update 1 _zone_net_addr_t struct.
1517 grep '^type _zone_net_addr_t ' gen-sysinfo.go | \
1518 sed -e 's/_in6_addr/[16]byte/' \
1519 >> ${OUT}
1521 # The Solaris 12 _flow_arp_desc_t struct.
1522 grep '^type _flow_arp_desc_t ' gen-sysinfo.go | \
1523 sed -e 's/_in6_addr_t/[16]byte/g' \
1524 >> ${OUT}
1526 # The Solaris 12 _flow_l3_desc_t struct.
1527 grep '^type _flow_l3_desc_t ' gen-sysinfo.go | \
1528 sed -e 's/_in6_addr_t/[16]byte/g' \
1529 >> ${OUT}
1531 # The Solaris 12 _mac_ipaddr_t struct.
1532 grep '^type _mac_ipaddr_t ' gen-sysinfo.go | \
1533 sed -e 's/_in6_addr_t/[16]byte/g' \
1534 >> ${OUT}
1536 # The Solaris 12 _mactun_info_t struct.
1537 grep '^type _mactun_info_t ' gen-sysinfo.go | \
1538 sed -e 's/_in6_addr_t/[16]byte/g' \
1539 >> ${OUT}
1541 exit $?