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