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