* config/avr/avr.md (*rotlhi2.15): Set length to 4.
[official-gcc.git] / libgo / mksysinfo.sh
blobe493ef072c1590aa131b7949af89636ae0a11275
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 #define _GNU_SOURCE
29 #define _LARGEFILE_SOURCE
30 #define _FILE_OFFSET_BITS 64
32 #include <sys/types.h>
33 #include <dirent.h>
34 #include <errno.h>
35 #include <fcntl.h>
36 #include <netinet/in.h>
37 /* <netinet/tcp.h> needs u_char/u_short, but <sys/bsd_types> is only
38 included by <netinet/in.h> if _SGIAPI (i.e. _SGI_SOURCE
39 && !_XOPEN_SOURCE.
40 <sys/termios.h> only defines TIOCNOTTY if !_XOPEN_SOURCE, while
41 <sys/ttold.h> does so unconditionally. */
42 #ifdef __sgi__
43 #include <sys/bsd_types.h>
44 #include <sys/ttold.h>
45 #endif
46 #include <netinet/tcp.h>
47 #include <signal.h>
48 #include <sys/ioctl.h>
49 #include <termios.h>
50 #if defined(HAVE_SYSCALL_H)
51 #include <syscall.h>
52 #endif
53 #if defined(HAVE_SYS_SYSCALL_H)
54 #include <sys/syscall.h>
55 #endif
56 #if defined(HAVE_SYS_EPOLL_H)
57 #include <sys/epoll.h>
58 #endif
59 #if defined(HAVE_SYS_MMAN_H)
60 #include <sys/mman.h>
61 #endif
62 #if defined(HAVE_SYS_PTRACE_H)
63 #include <sys/ptrace.h>
64 #endif
65 #include <sys/resource.h>
66 #include <sys/uio.h>
67 #include <sys/socket.h>
68 #include <sys/stat.h>
69 #include <sys/time.h>
70 #include <sys/wait.h>
71 #include <sys/un.h>
72 #if defined(HAVE_SYS_USER_H)
73 #include <sys/user.h>
74 #endif
75 #if defined(HAVE_SYS_UTSNAME_H)
76 #include <sys/utsname.h>
77 #endif
78 #if defined(HAVE_SYS_SELECT_H)
79 #include <sys/select.h>
80 #endif
81 #include <unistd.h>
82 #include <netdb.h>
83 #include <pwd.h>
84 #if defined(HAVE_LINUX_FILTER_H)
85 #include <linux/filter.h>
86 #endif
87 #if defined(HAVE_LINUX_NETLINK_H)
88 #include <linux/netlink.h>
89 #endif
90 #if defined(HAVE_LINUX_RTNETLINK_H)
91 #include <linux/rtnetlink.h>
92 #endif
93 #if defined(HAVE_NET_IF_H)
94 #include <net/if.h>
95 #endif
96 EOF
98 ${CC} -fdump-go-spec=gen-sysinfo.go -std=gnu99 -S -o sysinfo.s sysinfo.c
100 echo 'package syscall' > ${OUT}
101 echo 'import "unsafe"' >> ${OUT}
102 echo 'type _ unsafe.Pointer' >> ${OUT}
104 # Get all the consts and types, skipping ones which could not be
105 # represented in Go and ones which we need to rewrite. We also skip
106 # function declarations, as we don't need them here. All the symbols
107 # will all have a leading underscore.
108 grep -v '^// ' gen-sysinfo.go | \
109 grep -v '^func' | \
110 grep -v '^type _timeval ' | \
111 grep -v '^type _timespec_t ' | \
112 grep -v '^type _timespec ' | \
113 grep -v '^type _timestruc_t ' | \
114 grep -v '^type _epoll_' | \
115 grep -v 'in6_addr' | \
116 grep -v 'sockaddr_in6' | \
117 sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
118 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
119 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
120 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
121 >> ${OUT}
123 # The errno constants.
124 grep '^const _E' gen-sysinfo.go | \
125 sed -e 's/^\(const \)_\(E[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
127 # The O_xxx flags.
128 egrep '^const _(O|F|FD)_' gen-sysinfo.go | \
129 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
130 if ! grep '^const O_ASYNC' ${OUT} >/dev/null 2>&1; then
131 echo "const O_ASYNC = 0" >> ${OUT}
133 if ! grep '^const O_CLOEXEC' ${OUT} >/dev/null 2>&1; then
134 echo "const O_CLOEXEC = 0" >> ${OUT}
137 # The signal numbers.
138 grep '^const _SIG[^_]' gen-sysinfo.go | \
139 grep -v '^const _SIGEV_' | \
140 sed -e 's/^\(const \)_\(SIG[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
142 # The syscall numbers. We force the names to upper case.
143 grep '^const _SYS_' gen-sysinfo.go | \
144 sed -e 's/const _\(SYS_[^= ]*\).*$/\1/' | \
145 while read sys; do
146 sup=`echo $sys | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
147 echo "const $sup = _$sys" >> ${OUT}
148 done
150 # Stat constants.
151 grep '^const _S_' gen-sysinfo.go | \
152 sed -e 's/^\(const \)_\(S_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
154 # Mmap constants.
155 grep '^const _PROT_' gen-sysinfo.go | \
156 sed -e 's/^\(const \)_\(PROT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
157 grep '^const _MAP_' gen-sysinfo.go | \
158 sed -e 's/^\(const \)_\(MAP_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
160 # Process status constants.
161 grep '^const _W' gen-sysinfo.go |
162 sed -e 's/^\(const \)_\(W[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
163 # WSTOPPED was introduced in glibc 2.3.4.
164 if ! grep '^const _WSTOPPED = ' gen-sysinfo.go >/dev/null 2>&1; then
165 if grep '^const _WUNTRACED = ' gen-sysinfo.go > /dev/null 2>&1; then
166 echo 'const WSTOPPED = _WUNTRACED' >> ${OUT}
167 else
168 echo 'const WSTOPPED = 2' >> ${OUT}
171 if grep '^const ___WALL = ' gen-sysinfo.go >/dev/null 2>&1 \
172 && ! grep '^const _WALL = ' gen-sysinfo.go >/dev/null 2>&1; then
173 echo 'const WALL = ___WALL' >> ${OUT}
176 # Networking constants.
177 egrep '^const _(AF|SOCK|SOL|SO|IPPROTO|TCP|IP|IPV6)_' gen-sysinfo.go |
178 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
179 grep '^const _SOMAXCONN' gen-sysinfo.go |
180 sed -e 's/^\(const \)_\(SOMAXCONN[^= ]*\)\(.*\)$/\1\2 = _\2/' \
181 >> ${OUT}
182 grep '^const _SHUT_' gen-sysinfo.go |
183 sed -e 's/^\(const \)_\(SHUT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
185 # The net package requires a definition for IPV6ONLY.
186 if ! grep '^const IPV6_V6ONLY ' ${OUT} >/dev/null 2>&1; then
187 echo "const IPV6_V6ONLY = 0" >> ${OUT}
190 # pathconf constants.
191 grep '^const __PC' gen-sysinfo.go |
192 sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
194 # The epoll constants were picked up by the errno constants, but we
195 # need to be sure the EPOLLRDHUP is defined.
196 if ! grep '^const EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
197 echo "const EPOLLRDHUP = 0x2000" >> ${OUT}
200 # Ptrace constants.
201 grep '^const _PTRACE' gen-sysinfo.go |
202 sed -e 's/^\(const \)_\(PTRACE[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
203 # We need some ptrace options that are not defined in older versions
204 # of glibc.
205 if ! grep '^const PTRACE_SETOPTIONS' ${OUT} > /dev/null 2>&1; then
206 echo "const PTRACE_SETOPTIONS = 0x4200" >> ${OUT}
208 if ! grep '^const PTRACE_O_TRACESYSGOOD' ${OUT} > /dev/null 2>&1; then
209 echo "const PTRACE_O_TRACESYSGOOD = 0x1" >> ${OUT}
211 if ! grep '^const PTRACE_O_TRACEFORK' ${OUT} > /dev/null 2>&1; then
212 echo "const PTRACE_O_TRACEFORK = 0x2" >> ${OUT}
214 if ! grep '^const PTRACE_O_TRACEVFORK' ${OUT} > /dev/null 2>&1; then
215 echo "const PTRACE_O_TRACEVFORK = 0x4" >> ${OUT}
217 if ! grep '^const PTRACE_O_TRACECLONE' ${OUT} > /dev/null 2>&1; then
218 echo "const PTRACE_O_TRACECLONE = 0x8" >> ${OUT}
220 if ! grep '^const PTRACE_O_TRACEEXEC' ${OUT} > /dev/null 2>&1; then
221 echo "const PTRACE_O_TRACEEXEC = 0x10" >> ${OUT}
223 if ! grep '^const PTRACE_O_TRACEVFORKDONE' ${OUT} > /dev/null 2>&1; then
224 echo "const PTRACE_O_TRACEVFORKDONE = 0x20" >> ${OUT}
226 if ! grep '^const PTRACE_O_TRACEEXIT' ${OUT} > /dev/null 2>&1; then
227 echo "const PTRACE_O_TRACEEXIT = 0x40" >> ${OUT}
229 if ! grep '^const PTRACE_O_MASK' ${OUT} > /dev/null 2>&1; then
230 echo "const PTRACE_O_MASK = 0x7f" >> ${OUT}
232 if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev/null 2>&1; then
233 echo "const _PTRACE_GETEVENTMSG = 0x4201" >> ${OUT}
235 if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev/null 2>&1; then
236 echo "const PTRACE_EVENT_FORK = 1" >> ${OUT}
238 if ! grep '^const PTRACE_EVENT_VFORK' ${OUT} > /dev/null 2>&1; then
239 echo "const PTRACE_EVENT_VFORK = 2" >> ${OUT}
241 if ! grep '^const PTRACE_EVENT_CLONE' ${OUT} > /dev/null 2>&1; then
242 echo "const PTRACE_EVENT_CLONE = 3" >> ${OUT}
244 if ! grep '^const PTRACE_EVENT_EXEC' ${OUT} > /dev/null 2>&1; then
245 echo "const PTRACE_EVENT_EXEC = 4" >> ${OUT}
247 if ! grep '^const PTRACE_EVENT_VFORK_DONE' ${OUT} > /dev/null 2>&1; then
248 echo "const PTRACE_EVENT_VFORK_DONE = 5" >> ${OUT}
250 if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev/null 2>&1; then
251 echo "const PTRACE_EVENT_EXIT = 6" >> ${OUT}
253 if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev/null 2>&1; then
254 echo "const _PTRACE_TRACEME = 0" >> ${OUT}
257 # The registers returned by PTRACE_GETREGS. This is probably
258 # GNU/Linux specific; it should do no harm if there is no
259 # _user_regs_struct.
260 regs=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true`
261 if test "$regs" != ""; then
262 regs=`echo $regs | sed -e 's/type _user_regs_struct struct //' -e 's/[{}]//g'`
263 regs=`echo $regs | sed -e s'/^ *//'`
264 nregs=
265 while test -n "$regs"; do
266 field=`echo $regs | sed -e 's/^\([^;]*\);.*$/\1/'`
267 regs=`echo $regs | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
268 # Capitalize the first character of the field.
269 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
270 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
271 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
272 field="$f$r"
273 nregs="$nregs $field;"
274 done
275 echo "type PtraceRegs struct {$nregs }" >> ${OUT}
278 # Some basic types.
279 echo 'type Size_t _size_t' >> ${OUT}
280 echo "type Ssize_t _ssize_t" >> ${OUT}
281 if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go > /dev/null 2>&1; then
282 echo "type Offset_t _off64_t" >> ${OUT}
283 else
284 echo "type Offset_t _off_t" >> ${OUT}
286 echo "type Mode_t _mode_t" >> ${OUT}
287 echo "type Pid_t _pid_t" >> ${OUT}
288 echo "type Uid_t _uid_t" >> ${OUT}
289 echo "type Gid_t _gid_t" >> ${OUT}
290 echo "type Socklen_t _socklen_t" >> ${OUT}
292 # The long type, needed because that is the type that ptrace returns.
293 sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
294 if test "$sizeof_long" = "4"; then
295 echo "type _C_long int32" >> ${OUT}
296 elif test "$sizeof_long" = "8"; then
297 echo "type _C_long int64" >> ${OUT}
298 else
299 echo 1>&2 "mksysinfo.sh: could not determine size of long (got $sizeof_long)"
300 exit 1
303 # Solaris 2 needs _u?pad128_t, but its default definition in terms of long
304 # double is commented by -fdump-go-spec.
305 if grep "^// type _pad128_t" gen-sysinfo.go > /dev/null 2>&1; then
306 echo "type _pad128_t struct { _l [4]int32; }" >> ${OUT}
308 if grep "^// type _upad128_t" gen-sysinfo.go > /dev/null 2>&1; then
309 echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
312 # The time structures need special handling: we need to name the
313 # types, so that we can cast integers to the right types when
314 # assigning to the structures.
315 timeval=`grep '^type _timeval ' gen-sysinfo.go`
316 timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
317 timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
318 echo "type Timeval_sec_t $timeval_sec" >> ${OUT}
319 echo "type Timeval_usec_t $timeval_usec" >> ${OUT}
320 echo $timeval | \
321 sed -e 's/type _timeval /type Timeval /' \
322 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timeval_sec_t/' \
323 -e 's/tv_usec *[a-zA-Z0-9_]*/Usec Timeval_usec_t/' >> ${OUT}
324 timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
325 if test "$timespec" = ""; then
326 # IRIX 6.5 has __timespec instead.
327 timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
329 timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
330 timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
331 echo "type Timespec_sec_t $timespec_sec" >> ${OUT}
332 echo "type Timespec_nsec_t $timespec_nsec" >> ${OUT}
333 echo $timespec | \
334 sed -e 's/^type ___timespec /type Timespec /' \
335 -e 's/^type _timespec /type Timespec /' \
336 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timespec_sec_t/' \
337 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timespec_nsec_t/' >> ${OUT}
339 timestruc=`grep '^type _timestruc_t ' gen-sysinfo.go || true`
340 if test "$timestruc" != ""; then
341 timestruc_sec=`echo $timestruc | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
342 timestruc_nsec=`echo $timestruc | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
343 echo "type Timestruc_sec_t $timestruc_sec" >> ${OUT}
344 echo "type Timestruc_nsec_t $timestruc_nsec" >> ${OUT}
345 echo $timestruc | \
346 sed -e 's/^type _timestruc_t /type Timestruc /' \
347 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timestruc_sec_t/' \
348 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timestruc_nsec_t/' >> ${OUT}
351 # The stat type.
352 # Prefer largefile variant if available.
353 stat=`grep '^type _stat64 ' gen-sysinfo.go || true`
354 if test "$stat" != ""; then
355 grep '^type _stat64 ' gen-sysinfo.go
356 else
357 grep '^type _stat ' gen-sysinfo.go
358 fi | sed -e 's/type _stat64/type Stat_t/' \
359 -e 's/type _stat/type Stat_t/' \
360 -e 's/st_dev/Dev/' \
361 -e 's/st_ino/Ino/g' \
362 -e 's/st_nlink/Nlink/' \
363 -e 's/st_mode/Mode/' \
364 -e 's/st_uid/Uid/' \
365 -e 's/st_gid/Gid/' \
366 -e 's/st_rdev/Rdev/' \
367 -e 's/st_size/Size/' \
368 -e 's/st_blksize/Blksize/' \
369 -e 's/st_blocks/Blocks/' \
370 -e 's/st_atim/Atime/' \
371 -e 's/st_mtim/Mtime/' \
372 -e 's/st_ctim/Ctime/' \
373 -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
374 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
375 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
376 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
377 -e 's/Godump_[0-9] struct { \([^;]*;\) };/\1/g' \
378 >> ${OUT}
380 # The directory searching types.
381 # Prefer largefile variant if available.
382 dirent=`grep '^type _dirent64 ' gen-sysinfo.go || true`
383 if test "$dirent" != ""; then
384 grep '^type _dirent64 ' gen-sysinfo.go
385 else
386 grep '^type _dirent ' gen-sysinfo.go
387 fi | sed -e 's/type _dirent64/type Dirent/' \
388 -e 's/type _dirent/type Dirent/' \
389 -e 's/d_name \[0+1\]/d_name [0+256]/' \
390 -e 's/d_name/Name/' \
391 -e 's/]int8/]byte/' \
392 -e 's/d_ino/Ino/' \
393 -e 's/d_off/Off/' \
394 -e 's/d_reclen/Reclen/' \
395 -e 's/d_type/Type/' \
396 >> ${OUT}
397 echo "type DIR _DIR" >> ${OUT}
399 # The rusage struct.
400 rusage=`grep '^type _rusage struct' gen-sysinfo.go`
401 if test "$rusage" != ""; then
402 rusage=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'`
403 rusage=`echo $rusage | sed -e 's/^ *//'`
404 nrusage=
405 while test -n "$rusage"; do
406 field=`echo $rusage | sed -e 's/^\([^;]*\);.*$/\1/'`
407 rusage=`echo $rusage | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
408 # Drop the leading ru_, capitalize the next character.
409 field=`echo $field | sed -e 's/^ru_//'`
410 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
411 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
412 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
413 # Fix _timeval _timespec, and _timestruc_t.
414 r=`echo $r | sed -e s'/ _timeval$/ Timeval/'`
415 r=`echo $r | sed -e s'/ _timespec$/ Timespec/'`
416 r=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'`
417 field="$f$r"
418 nrusage="$nrusage $field;"
419 done
420 echo "type Rusage struct {$nrusage }" >> ${OUT}
421 else
422 echo "type Rusage struct {}" >> ${OUT}
425 # The RUSAGE constants.
426 grep '^const _RUSAGE_' gen-sysinfo.go | \
427 sed -e 's/^\(const \)_\(RUSAGE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
429 # The utsname struct.
430 grep '^type _utsname ' gen-sysinfo.go | \
431 sed -e 's/_utsname/Utsname/' \
432 -e 's/sysname/Sysname/' \
433 -e 's/nodename/Nodename/' \
434 -e 's/release/Release/' \
435 -e 's/version/Version/' \
436 -e 's/machine/Machine/' \
437 -e 's/domainname/Domainname/' \
438 >> ${OUT}
440 # The iovec struct.
441 iovec=`grep '^type _iovec ' gen-sysinfo.go`
442 iovec_len=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
443 echo "type Iovec_len_t $iovec_len" >> ${OUT}
444 echo $iovec | \
445 sed -e 's/_iovec/Iovec/' \
446 -e 's/iov_base/Base/' \
447 -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
448 >> ${OUT}
450 # The msghdr struct.
451 msghdr=`grep '^type _msghdr ' gen-sysinfo.go`
452 msghdr_controllen=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
453 echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT}
454 echo $msghdr | \
455 sed -e 's/_msghdr/Msghdr/' \
456 -e 's/msg_name/Name/' \
457 -e 's/msg_namelen/Namelen/' \
458 -e 's/msg_iov/Iov/' \
459 -e 's/msg_iovlen/Iovlen/' \
460 -e 's/_iovec/Iovec/' \
461 -e 's/msg_control/Control/' \
462 -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
463 -e 's/msg_flags/Flags/' \
464 >> ${OUT}
466 # The ip_mreq struct.
467 grep '^type _ip_mreq ' gen-sysinfo.go | \
468 sed -e 's/_ip_mreq/IPMreq/' \
469 -e 's/imr_multiaddr/Multiaddr/' \
470 -e 's/imr_interface/Interface/' \
471 -e 's/_in_addr/[4]byte/g' \
472 >> ${OUT}
474 # The size of the ip_mreq struct.
475 if grep 'type IPMreq ' ${OUT} > /dev/null 2>&1; then
476 echo 'var SizeofIPMreq = int(unsafe.Sizeof(IPMreq{}))' >> ${OUT}
479 # The ipv6_mreq struct.
480 grep '^type _ipv6_mreq ' gen-sysinfo.go | \
481 sed -e 's/_ipv6_mreq/IPv6Mreq/' \
482 -e 's/ipv6mr_multiaddr/Multiaddr/' \
483 -e 's/ipv6mr_interface/Interface/' \
484 -e 's/_in6_addr/[16]byte/' \
485 >> ${OUT}
487 # Try to guess the type to use for fd_set.
488 fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
489 fds_bits_type="_C_long"
490 if test "$fd_set" != ""; then
491 fds_bits_type=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
493 echo "type fds_bits_type $fds_bits_type" >> ${OUT}
495 # The addrinfo struct.
496 grep '^type _addrinfo ' gen-sysinfo.go | \
497 sed -e 's/_addrinfo/Addrinfo/g' \
498 -e 's/ ai_/ Ai_/g' \
499 >> ${OUT}
501 # The addrinfo flags.
502 grep '^const _AI_' gen-sysinfo.go | \
503 sed -e 's/^\(const \)_\(AI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
505 # The passwd struct.
506 grep '^type _passwd ' gen-sysinfo.go | \
507 sed -e 's/_passwd/Passwd/' \
508 -e 's/ pw_/ Pw_/g' \
509 >> ${OUT}
511 # The ioctl flags for the controlling TTY.
512 grep '^const _TIOC' gen-sysinfo.go | \
513 sed -e 's/^\(const \)_\(TIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
515 # The ioctl flags for terminal control
516 grep '^const _TC[GS]ET' gen-sysinfo.go | \
517 sed -e 's/^\(const \)_\(TC[GS]ET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
519 # ioctl constants. Might fall back to 0 if TIOCNXCL is missing, too, but
520 # needs handling in syscalls.exec.go.
521 if ! grep '^const _TIOCSCTTY ' gen-sysinfo.go >/dev/null 2>&1; then
522 if grep '^const _TIOCNXCL ' gen-sysinfo.go >/dev/null 2>&1; then
523 echo "const TIOCSCTTY = TIOCNXCL" >> ${OUT}
527 # The nlmsghdr struct.
528 grep '^type _nlmsghdr ' gen-sysinfo.go | \
529 sed -e 's/_nlmsghdr/NlMsghdr/' \
530 -e 's/nlmsg_len/Len/' \
531 -e 's/nlmsg_type/Type/' \
532 -e 's/nlmsg_flags/Flags/' \
533 -e 's/nlmsg_seq/Seq/' \
534 -e 's/nlmsg_pid/Pid/' \
535 >> ${OUT}
537 # The nlmsg flags and operators.
538 grep '^const _NLM' gen-sysinfo.go | \
539 sed -e 's/^\(const \)_\(NLM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
541 # NLMSG_HDRLEN is defined as an expression using sizeof.
542 if ! grep '^const NLMSG_HDRLEN' ${OUT} > /dev/null 2>&1; then
543 if grep '^type NlMsghdr ' ${OUT} > /dev/null 2>&1; then
544 echo 'var NLMSG_HDRLEN = int((unsafe.Sizeof(NlMsghdr{}) + (NLMSG_ALIGNTO-1)) &^ (NLMSG_ALIGNTO-1))' >> ${OUT}
548 # The rtmsg struct.
549 grep '^type _rtmsg ' gen-sysinfo.go | \
550 sed -e 's/_rtmsg/RtMsg/' \
551 -e 's/rtm_family/Family/' \
552 -e 's/rtm_dst_len/Dst_len/' \
553 -e 's/rtm_src_len/Src_len/' \
554 -e 's/rtm_tos/Tos/' \
555 -e 's/rtm_table/Table/' \
556 -e 's/rtm_protocol/Procotol/' \
557 -e 's/rtm_scope/Scope/' \
558 -e 's/rtm_type/Type/' \
559 -e 's/rtm_flags/Flags/' \
560 >> ${OUT}
562 # The size of the rtmsg struct.
563 if grep 'type RtMsg ' ${OUT} > /dev/null 2>&1; then
564 echo 'var SizeofRtMsg = int(unsafe.Sizeof(RtMsg{}))' >> ${OUT}
567 # The rtgenmsg struct.
568 grep '^type _rtgenmsg ' gen-sysinfo.go | \
569 sed -e 's/_rtgenmsg/RtGenmsg/' \
570 -e 's/rtgen_family/Family/' \
571 >> ${OUT}
573 # The routing message flags.
574 grep '^const _RTA' gen-sysinfo.go | \
575 sed -e 's/^\(const \)_\(RTA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
576 grep '^const _RTM' gen-sysinfo.go | \
577 sed -e 's/^\(const \)_\(RTM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
579 # The size of the rtgenmsg struct.
580 if grep 'type RtGenmsg ' ${OUT} > /dev/null 2>&1; then
581 echo 'var SizeofRtGenmsg = int(unsafe.Sizeof(RtGenmsg{}))' >> ${OUT}
584 # The ifinfomsg struct.
585 grep '^type _ifinfomsg ' gen-sysinfo.go | \
586 sed -e 's/_ifinfomsg/IfInfomsg/' \
587 -e 's/ifi_family/Family/' \
588 -e 's/ifi_type/Type/' \
589 -e 's/ifi_index/Index/' \
590 -e 's/ifi_flags/Flags/' \
591 -e 's/ifi_change/Change/' \
592 >> ${OUT}
594 # The interface information types and flags.
595 grep '^const _IFA' gen-sysinfo.go | \
596 sed -e 's/^\(const \)_\(IFA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
597 grep '^const _IFLA' gen-sysinfo.go | \
598 sed -e 's/^\(const \)_\(IFLA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
599 grep '^const _IFF' gen-sysinfo.go | \
600 sed -e 's/^\(const \)_\(IFF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
602 # The size of the ifinfomsg struct.
603 if grep 'type IfInfomsg ' ${OUT} > /dev/null 2>&1; then
604 echo 'var SizeofIfInfomsg = int(unsafe.Sizeof(IfInfomsg{}))' >> ${OUT}
607 # The ifaddrmsg struct.
608 grep '^type _ifaddrmsg ' gen-sysinfo.go | \
609 sed -e 's/_ifaddrmsg/IfAddrmsg/' \
610 -e 's/ifa_family/Family/' \
611 -e 's/ifa_prefixlen/Prefixlen/' \
612 -e 's/ifa_flags/Flags/' \
613 -e 's/ifa_scope/Scope/' \
614 -e 's/ifa_index/Index/' \
615 >> ${OUT}
617 # The size of the ifaddrmsg struct.
618 if grep 'type IfAddrmsg ' ${OUT} > /dev/null 2>&1; then
619 echo 'var SizeofIfAddrmsg = int(unsafe.Sizeof(IfAddrmsg{}))' >> ${OUT}
622 # The rtattr struct.
623 grep '^type _rtattr ' gen-sysinfo.go | \
624 sed -e 's/_rtattr/RtAttr/' \
625 -e 's/rta_len/Len/' \
626 -e 's/rta_type/Type/' \
627 >> ${OUT}
629 # The size of the rtattr struct.
630 if grep 'type RtAttr ' ${OUT} > /dev/null 2>&1; then
631 echo 'var SizeofRtAttr = int(unsafe.Sizeof(RtAttr{}))' >> ${OUT}
634 # The termios struct.
635 grep '^type _termios ' gen-sysinfo.go | \
636 sed -e 's/_termios/Termios/' \
637 -e 's/c_iflag/Iflag/' \
638 -e 's/c_oflag/Oflag/' \
639 -e 's/c_cflag/Cflag/' \
640 -e 's/c_lflag/Lflag/' \
641 -e 's/c_line/Line/' \
642 -e 's/c_cc/Cc/' \
643 -e 's/c_ispeed/Ispeed/' \
644 -e 's/c_ospeed/Ospeed/' \
645 >> ${OUT}
647 # The termios constants. The ones starting with 'E' were picked up above.
648 for n in IGNBRK BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL IUCLC \
649 IXON IXANY IXOFF IMAXBEL IUTF8 OPOST OLCUC ONLCR OCRNL ONOCR ONLRET \
650 OFILL OFDEL NLDLY NL0 NL1 CRDLY CR0 CR1 CR2 CR3 TABDLY BSDLY VTDLY \
651 FFDLY CBAUD CBAUDEX CSIZE CSTOPB CREAD PARENB PARODD HUPCL CLOCAL \
652 LOBLK CIBAUD CMSPAR CRTSCTS ISIG ICANON XCASE DEFECHK FLUSHO NOFLSH \
653 TOSTOP PENDIN IEXTEN VINTR VQUIT VERASE VKILL VEOF VMIN VEOL VTIME VEOL2 \
654 VSWTCH VSTART VSTOP VSUSP VDSUSP VLNEXT VWERASE VREPRINT VDISCARD VSTATUS \
655 TCSANOW TCSADRAIN, TCSAFLUSH TCIFLUSH TCOFLUSH TCIOFLUSH TCOOFF TCOON \
656 TCIOFF TCION B0 B50 B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 \
657 B4800 B9600 B19200 B38400 B57600 B115200 B230400; do
659 grep "^const _$n " gen-sysinfo.go | \
660 sed -e 's/^\(const \)_\([^=]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
661 done
663 exit $?