libgo: Update to weekly.2011-11-18.
[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 #define _GNU_SOURCE
29 #define _LARGEFILE_SOURCE
30 #define _FILE_OFFSET_BITS 64
31
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
97
98 ${CC} -fdump-go-spec=gen-sysinfo.go -std=gnu99 -S -o sysinfo.s sysinfo.c
99
100 echo 'package syscall' > ${OUT}
101 echo 'import "unsafe"' >> ${OUT}
102 echo 'type _ unsafe.Pointer' >> ${OUT}
103
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}
122
123 # The errno constants. These get type Errno.
124 echo '#include <errno.h>' | ${CC} -x c - -E -dM | \
125 egrep '#define E[A-Z0-9_]+ ' | \
126 sed -e 's/^#define \(E[A-Z0-9_]*\) .*$/const \1 = Errno(_\1)/' >> ${OUT}
127
128 # The O_xxx flags.
129 egrep '^const _(O|F|FD)_' gen-sysinfo.go | \
130 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
131 if ! grep '^const O_ASYNC' ${OUT} >/dev/null 2>&1; then
132 echo "const O_ASYNC = 0" >> ${OUT}
133 fi
134 if ! grep '^const O_CLOEXEC' ${OUT} >/dev/null 2>&1; then
135 echo "const O_CLOEXEC = 0" >> ${OUT}
136 fi
137
138 # The signal numbers.
139 grep '^const _SIG[^_]' gen-sysinfo.go | \
140 grep -v '^const _SIGEV_' | \
141 sed -e 's/^\(const \)_\(SIG[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
142
143 # The syscall numbers. We force the names to upper case.
144 grep '^const _SYS_' gen-sysinfo.go | \
145 sed -e 's/const _\(SYS_[^= ]*\).*$/\1/' | \
146 while read sys; do
147 sup=`echo $sys | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
148 echo "const $sup = _$sys" >> ${OUT}
149 done
150
151 # Stat constants.
152 grep '^const _S_' gen-sysinfo.go | \
153 sed -e 's/^\(const \)_\(S_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
154
155 # Mmap constants.
156 grep '^const _PROT_' gen-sysinfo.go | \
157 sed -e 's/^\(const \)_\(PROT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
158 grep '^const _MAP_' gen-sysinfo.go | \
159 sed -e 's/^\(const \)_\(MAP_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
160
161 # Process status constants.
162 grep '^const _W' gen-sysinfo.go |
163 sed -e 's/^\(const \)_\(W[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
164 # WSTOPPED was introduced in glibc 2.3.4.
165 if ! grep '^const _WSTOPPED = ' gen-sysinfo.go >/dev/null 2>&1; then
166 if grep '^const _WUNTRACED = ' gen-sysinfo.go > /dev/null 2>&1; then
167 echo 'const WSTOPPED = _WUNTRACED' >> ${OUT}
168 else
169 echo 'const WSTOPPED = 2' >> ${OUT}
170 fi
171 fi
172 if grep '^const ___WALL = ' gen-sysinfo.go >/dev/null 2>&1 \
173 && ! grep '^const _WALL = ' gen-sysinfo.go >/dev/null 2>&1; then
174 echo 'const WALL = ___WALL' >> ${OUT}
175 fi
176
177 # Networking constants.
178 egrep '^const _(AF|SOCK|SOL|SO|IPPROTO|TCP|IP|IPV6)_' gen-sysinfo.go |
179 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
180 grep '^const _SOMAXCONN' gen-sysinfo.go |
181 sed -e 's/^\(const \)_\(SOMAXCONN[^= ]*\)\(.*\)$/\1\2 = _\2/' \
182 >> ${OUT}
183 grep '^const _SHUT_' gen-sysinfo.go |
184 sed -e 's/^\(const \)_\(SHUT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
185
186 # The net package requires a definition for IPV6ONLY.
187 if ! grep '^const IPV6_V6ONLY ' ${OUT} >/dev/null 2>&1; then
188 echo "const IPV6_V6ONLY = 0" >> ${OUT}
189 fi
190
191 # pathconf constants.
192 grep '^const __PC' gen-sysinfo.go |
193 sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
194
195 # epoll constants.
196 grep '^const _EPOLL' gen-sysinfo.go |
197 sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
198 # Make sure EPOLLRDHUP is defined.
199 if ! grep '^const EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
200 echo "const EPOLLRDHUP = 0x2000" >> ${OUT}
201 fi
202
203 # Ptrace constants.
204 grep '^const _PTRACE' gen-sysinfo.go |
205 sed -e 's/^\(const \)_\(PTRACE[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
206 # We need some ptrace options that are not defined in older versions
207 # of glibc.
208 if ! grep '^const PTRACE_SETOPTIONS' ${OUT} > /dev/null 2>&1; then
209 echo "const PTRACE_SETOPTIONS = 0x4200" >> ${OUT}
210 fi
211 if ! grep '^const PTRACE_O_TRACESYSGOOD' ${OUT} > /dev/null 2>&1; then
212 echo "const PTRACE_O_TRACESYSGOOD = 0x1" >> ${OUT}
213 fi
214 if ! grep '^const PTRACE_O_TRACEFORK' ${OUT} > /dev/null 2>&1; then
215 echo "const PTRACE_O_TRACEFORK = 0x2" >> ${OUT}
216 fi
217 if ! grep '^const PTRACE_O_TRACEVFORK' ${OUT} > /dev/null 2>&1; then
218 echo "const PTRACE_O_TRACEVFORK = 0x4" >> ${OUT}
219 fi
220 if ! grep '^const PTRACE_O_TRACECLONE' ${OUT} > /dev/null 2>&1; then
221 echo "const PTRACE_O_TRACECLONE = 0x8" >> ${OUT}
222 fi
223 if ! grep '^const PTRACE_O_TRACEEXEC' ${OUT} > /dev/null 2>&1; then
224 echo "const PTRACE_O_TRACEEXEC = 0x10" >> ${OUT}
225 fi
226 if ! grep '^const PTRACE_O_TRACEVFORKDONE' ${OUT} > /dev/null 2>&1; then
227 echo "const PTRACE_O_TRACEVFORKDONE = 0x20" >> ${OUT}
228 fi
229 if ! grep '^const PTRACE_O_TRACEEXIT' ${OUT} > /dev/null 2>&1; then
230 echo "const PTRACE_O_TRACEEXIT = 0x40" >> ${OUT}
231 fi
232 if ! grep '^const PTRACE_O_MASK' ${OUT} > /dev/null 2>&1; then
233 echo "const PTRACE_O_MASK = 0x7f" >> ${OUT}
234 fi
235 if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev/null 2>&1; then
236 echo "const _PTRACE_GETEVENTMSG = 0x4201" >> ${OUT}
237 fi
238 if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev/null 2>&1; then
239 echo "const PTRACE_EVENT_FORK = 1" >> ${OUT}
240 fi
241 if ! grep '^const PTRACE_EVENT_VFORK' ${OUT} > /dev/null 2>&1; then
242 echo "const PTRACE_EVENT_VFORK = 2" >> ${OUT}
243 fi
244 if ! grep '^const PTRACE_EVENT_CLONE' ${OUT} > /dev/null 2>&1; then
245 echo "const PTRACE_EVENT_CLONE = 3" >> ${OUT}
246 fi
247 if ! grep '^const PTRACE_EVENT_EXEC' ${OUT} > /dev/null 2>&1; then
248 echo "const PTRACE_EVENT_EXEC = 4" >> ${OUT}
249 fi
250 if ! grep '^const PTRACE_EVENT_VFORK_DONE' ${OUT} > /dev/null 2>&1; then
251 echo "const PTRACE_EVENT_VFORK_DONE = 5" >> ${OUT}
252 fi
253 if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev/null 2>&1; then
254 echo "const PTRACE_EVENT_EXIT = 6" >> ${OUT}
255 fi
256 if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev/null 2>&1; then
257 echo "const _PTRACE_TRACEME = 0" >> ${OUT}
258 fi
259
260 # The registers returned by PTRACE_GETREGS. This is probably
261 # GNU/Linux specific; it should do no harm if there is no
262 # _user_regs_struct.
263 regs=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true`
264 if test "$regs" != ""; then
265 regs=`echo $regs | sed -e 's/type _user_regs_struct struct //' -e 's/[{}]//g'`
266 regs=`echo $regs | sed -e s'/^ *//'`
267 nregs=
268 while test -n "$regs"; do
269 field=`echo $regs | sed -e 's/^\([^;]*\);.*$/\1/'`
270 regs=`echo $regs | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
271 # Capitalize the first character of the field.
272 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
273 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
274 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
275 field="$f$r"
276 nregs="$nregs $field;"
277 done
278 echo "type PtraceRegs struct {$nregs }" >> ${OUT}
279 fi
280
281 # Some basic types.
282 echo 'type Size_t _size_t' >> ${OUT}
283 echo "type Ssize_t _ssize_t" >> ${OUT}
284 if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go > /dev/null 2>&1; then
285 echo "type Offset_t _off64_t" >> ${OUT}
286 else
287 echo "type Offset_t _off_t" >> ${OUT}
288 fi
289 echo "type Mode_t _mode_t" >> ${OUT}
290 echo "type Pid_t _pid_t" >> ${OUT}
291 echo "type Uid_t _uid_t" >> ${OUT}
292 echo "type Gid_t _gid_t" >> ${OUT}
293 echo "type Socklen_t _socklen_t" >> ${OUT}
294
295 # The long type, needed because that is the type that ptrace returns.
296 sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
297 if test "$sizeof_long" = "4"; then
298 echo "type _C_long int32" >> ${OUT}
299 elif test "$sizeof_long" = "8"; then
300 echo "type _C_long int64" >> ${OUT}
301 else
302 echo 1>&2 "mksysinfo.sh: could not determine size of long (got $sizeof_long)"
303 exit 1
304 fi
305
306 # Solaris 2 needs _u?pad128_t, but its default definition in terms of long
307 # double is commented by -fdump-go-spec.
308 if grep "^// type _pad128_t" gen-sysinfo.go > /dev/null 2>&1; then
309 echo "type _pad128_t struct { _l [4]int32; }" >> ${OUT}
310 fi
311 if grep "^// type _upad128_t" gen-sysinfo.go > /dev/null 2>&1; then
312 echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
313 fi
314
315 # The time structures need special handling: we need to name the
316 # types, so that we can cast integers to the right types when
317 # assigning to the structures.
318 timeval=`grep '^type _timeval ' gen-sysinfo.go`
319 timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
320 timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
321 echo "type Timeval_sec_t $timeval_sec" >> ${OUT}
322 echo "type Timeval_usec_t $timeval_usec" >> ${OUT}
323 echo $timeval | \
324 sed -e 's/type _timeval /type Timeval /' \
325 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timeval_sec_t/' \
326 -e 's/tv_usec *[a-zA-Z0-9_]*/Usec Timeval_usec_t/' >> ${OUT}
327 timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
328 if test "$timespec" = ""; then
329 # IRIX 6.5 has __timespec instead.
330 timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
331 fi
332 timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
333 timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
334 echo "type Timespec_sec_t $timespec_sec" >> ${OUT}
335 echo "type Timespec_nsec_t $timespec_nsec" >> ${OUT}
336 echo $timespec | \
337 sed -e 's/^type ___timespec /type Timespec /' \
338 -e 's/^type _timespec /type Timespec /' \
339 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timespec_sec_t/' \
340 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timespec_nsec_t/' >> ${OUT}
341
342 timestruc=`grep '^type _timestruc_t ' gen-sysinfo.go || true`
343 if test "$timestruc" != ""; then
344 timestruc_sec=`echo $timestruc | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
345 timestruc_nsec=`echo $timestruc | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
346 echo "type Timestruc_sec_t $timestruc_sec" >> ${OUT}
347 echo "type Timestruc_nsec_t $timestruc_nsec" >> ${OUT}
348 echo $timestruc | \
349 sed -e 's/^type _timestruc_t /type Timestruc /' \
350 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timestruc_sec_t/' \
351 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timestruc_nsec_t/' >> ${OUT}
352 fi
353
354 # The stat type.
355 # Prefer largefile variant if available.
356 stat=`grep '^type _stat64 ' gen-sysinfo.go || true`
357 if test "$stat" != ""; then
358 grep '^type _stat64 ' gen-sysinfo.go
359 else
360 grep '^type _stat ' gen-sysinfo.go
361 fi | sed -e 's/type _stat64/type Stat_t/' \
362 -e 's/type _stat/type Stat_t/' \
363 -e 's/st_dev/Dev/' \
364 -e 's/st_ino/Ino/g' \
365 -e 's/st_nlink/Nlink/' \
366 -e 's/st_mode/Mode/' \
367 -e 's/st_uid/Uid/' \
368 -e 's/st_gid/Gid/' \
369 -e 's/st_rdev/Rdev/' \
370 -e 's/st_size/Size/' \
371 -e 's/st_blksize/Blksize/' \
372 -e 's/st_blocks/Blocks/' \
373 -e 's/st_atim/Atime/' \
374 -e 's/st_mtim/Mtime/' \
375 -e 's/st_ctim/Ctime/' \
376 -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
377 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
378 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
379 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
380 -e 's/Godump_[0-9] struct { \([^;]*;\) };/\1/g' \
381 >> ${OUT}
382
383 # The directory searching types.
384 # Prefer largefile variant if available.
385 dirent=`grep '^type _dirent64 ' gen-sysinfo.go || true`
386 if test "$dirent" != ""; then
387 grep '^type _dirent64 ' gen-sysinfo.go
388 else
389 grep '^type _dirent ' gen-sysinfo.go
390 fi | sed -e 's/type _dirent64/type Dirent/' \
391 -e 's/type _dirent/type Dirent/' \
392 -e 's/d_name \[0+1\]/d_name [0+256]/' \
393 -e 's/d_name/Name/' \
394 -e 's/]int8/]byte/' \
395 -e 's/d_ino/Ino/' \
396 -e 's/d_off/Off/' \
397 -e 's/d_reclen/Reclen/' \
398 -e 's/d_type/Type/' \
399 >> ${OUT}
400 echo "type DIR _DIR" >> ${OUT}
401
402 # The rusage struct.
403 rusage=`grep '^type _rusage struct' gen-sysinfo.go`
404 if test "$rusage" != ""; then
405 rusage=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'`
406 rusage=`echo $rusage | sed -e 's/^ *//'`
407 nrusage=
408 while test -n "$rusage"; do
409 field=`echo $rusage | sed -e 's/^\([^;]*\);.*$/\1/'`
410 rusage=`echo $rusage | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
411 # Drop the leading ru_, capitalize the next character.
412 field=`echo $field | sed -e 's/^ru_//'`
413 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
414 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
415 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
416 # Fix _timeval _timespec, and _timestruc_t.
417 r=`echo $r | sed -e s'/ _timeval$/ Timeval/'`
418 r=`echo $r | sed -e s'/ _timespec$/ Timespec/'`
419 r=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'`
420 field="$f$r"
421 nrusage="$nrusage $field;"
422 done
423 echo "type Rusage struct {$nrusage }" >> ${OUT}
424 else
425 echo "type Rusage struct {}" >> ${OUT}
426 fi
427
428 # The RUSAGE constants.
429 grep '^const _RUSAGE_' gen-sysinfo.go | \
430 sed -e 's/^\(const \)_\(RUSAGE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
431
432 # The utsname struct.
433 grep '^type _utsname ' gen-sysinfo.go | \
434 sed -e 's/_utsname/Utsname/' \
435 -e 's/sysname/Sysname/' \
436 -e 's/nodename/Nodename/' \
437 -e 's/release/Release/' \
438 -e 's/version/Version/' \
439 -e 's/machine/Machine/' \
440 -e 's/domainname/Domainname/' \
441 >> ${OUT}
442
443 # The iovec struct.
444 iovec=`grep '^type _iovec ' gen-sysinfo.go`
445 iovec_len=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
446 echo "type Iovec_len_t $iovec_len" >> ${OUT}
447 echo $iovec | \
448 sed -e 's/_iovec/Iovec/' \
449 -e 's/iov_base/Base/' \
450 -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
451 >> ${OUT}
452
453 # The msghdr struct.
454 msghdr=`grep '^type _msghdr ' gen-sysinfo.go`
455 msghdr_controllen=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
456 echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT}
457 echo $msghdr | \
458 sed -e 's/_msghdr/Msghdr/' \
459 -e 's/msg_name/Name/' \
460 -e 's/msg_namelen/Namelen/' \
461 -e 's/msg_iov/Iov/' \
462 -e 's/msg_iovlen/Iovlen/' \
463 -e 's/_iovec/Iovec/' \
464 -e 's/msg_control/Control/' \
465 -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
466 -e 's/msg_flags/Flags/' \
467 >> ${OUT}
468
469 # The ip_mreq struct.
470 grep '^type _ip_mreq ' gen-sysinfo.go | \
471 sed -e 's/_ip_mreq/IPMreq/' \
472 -e 's/imr_multiaddr/Multiaddr/' \
473 -e 's/imr_interface/Interface/' \
474 -e 's/_in_addr/[4]byte/g' \
475 >> ${OUT}
476
477 # The size of the ip_mreq struct.
478 if grep 'type IPMreq ' ${OUT} > /dev/null 2>&1; then
479 echo 'var SizeofIPMreq = int(unsafe.Sizeof(IPMreq{}))' >> ${OUT}
480 fi
481
482 # The ipv6_mreq struct.
483 grep '^type _ipv6_mreq ' gen-sysinfo.go | \
484 sed -e 's/_ipv6_mreq/IPv6Mreq/' \
485 -e 's/ipv6mr_multiaddr/Multiaddr/' \
486 -e 's/ipv6mr_interface/Interface/' \
487 -e 's/_in6_addr/[16]byte/' \
488 >> ${OUT}
489
490 # Try to guess the type to use for fd_set.
491 fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
492 fds_bits_type="_C_long"
493 if test "$fd_set" != ""; then
494 fds_bits_type=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
495 fi
496 echo "type fds_bits_type $fds_bits_type" >> ${OUT}
497
498 # The addrinfo struct.
499 grep '^type _addrinfo ' gen-sysinfo.go | \
500 sed -e 's/_addrinfo/Addrinfo/g' \
501 -e 's/ ai_/ Ai_/g' \
502 >> ${OUT}
503
504 # The addrinfo flags and errors.
505 grep '^const _AI_' gen-sysinfo.go | \
506 sed -e 's/^\(const \)_\(AI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
507 grep '^const _EAI_' gen-sysinfo.go | \
508 sed -e 's/^\(const \)_\(EAI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
509
510 # The passwd struct.
511 grep '^type _passwd ' gen-sysinfo.go | \
512 sed -e 's/_passwd/Passwd/' \
513 -e 's/ pw_/ Pw_/g' \
514 >> ${OUT}
515
516 # The ioctl flags for the controlling TTY.
517 grep '^const _TIOC' gen-sysinfo.go | \
518 sed -e 's/^\(const \)_\(TIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
519
520 # The ioctl flags for terminal control
521 grep '^const _TC[GS]ET' gen-sysinfo.go | \
522 sed -e 's/^\(const \)_\(TC[GS]ET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
523
524 # ioctl constants. Might fall back to 0 if TIOCNXCL is missing, too, but
525 # needs handling in syscalls.exec.go.
526 if ! grep '^const _TIOCSCTTY ' gen-sysinfo.go >/dev/null 2>&1; then
527 if grep '^const _TIOCNXCL ' gen-sysinfo.go >/dev/null 2>&1; then
528 echo "const TIOCSCTTY = TIOCNXCL" >> ${OUT}
529 fi
530 fi
531
532 # The nlmsghdr struct.
533 grep '^type _nlmsghdr ' gen-sysinfo.go | \
534 sed -e 's/_nlmsghdr/NlMsghdr/' \
535 -e 's/nlmsg_len/Len/' \
536 -e 's/nlmsg_type/Type/' \
537 -e 's/nlmsg_flags/Flags/' \
538 -e 's/nlmsg_seq/Seq/' \
539 -e 's/nlmsg_pid/Pid/' \
540 >> ${OUT}
541
542 # The nlmsg flags and operators.
543 grep '^const _NLM' gen-sysinfo.go | \
544 sed -e 's/^\(const \)_\(NLM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
545
546 # NLMSG_HDRLEN is defined as an expression using sizeof.
547 if ! grep '^const NLMSG_HDRLEN' ${OUT} > /dev/null 2>&1; then
548 if grep '^type NlMsghdr ' ${OUT} > /dev/null 2>&1; then
549 echo 'var NLMSG_HDRLEN = int((unsafe.Sizeof(NlMsghdr{}) + (NLMSG_ALIGNTO-1)) &^ (NLMSG_ALIGNTO-1))' >> ${OUT}
550 fi
551 fi
552
553 # The rtmsg struct.
554 grep '^type _rtmsg ' gen-sysinfo.go | \
555 sed -e 's/_rtmsg/RtMsg/' \
556 -e 's/rtm_family/Family/' \
557 -e 's/rtm_dst_len/Dst_len/' \
558 -e 's/rtm_src_len/Src_len/' \
559 -e 's/rtm_tos/Tos/' \
560 -e 's/rtm_table/Table/' \
561 -e 's/rtm_protocol/Procotol/' \
562 -e 's/rtm_scope/Scope/' \
563 -e 's/rtm_type/Type/' \
564 -e 's/rtm_flags/Flags/' \
565 >> ${OUT}
566
567 # The size of the rtmsg struct.
568 if grep 'type RtMsg ' ${OUT} > /dev/null 2>&1; then
569 echo 'var SizeofRtMsg = int(unsafe.Sizeof(RtMsg{}))' >> ${OUT}
570 fi
571
572 # The rtgenmsg struct.
573 grep '^type _rtgenmsg ' gen-sysinfo.go | \
574 sed -e 's/_rtgenmsg/RtGenmsg/' \
575 -e 's/rtgen_family/Family/' \
576 >> ${OUT}
577
578 # The routing message flags.
579 grep '^const _RTA' gen-sysinfo.go | \
580 sed -e 's/^\(const \)_\(RTA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
581 grep '^const _RTM' gen-sysinfo.go | \
582 sed -e 's/^\(const \)_\(RTM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
583
584 # The size of the rtgenmsg struct.
585 if grep 'type RtGenmsg ' ${OUT} > /dev/null 2>&1; then
586 echo 'var SizeofRtGenmsg = int(unsafe.Sizeof(RtGenmsg{}))' >> ${OUT}
587 fi
588
589 # The ifinfomsg struct.
590 grep '^type _ifinfomsg ' gen-sysinfo.go | \
591 sed -e 's/_ifinfomsg/IfInfomsg/' \
592 -e 's/ifi_family/Family/' \
593 -e 's/ifi_type/Type/' \
594 -e 's/ifi_index/Index/' \
595 -e 's/ifi_flags/Flags/' \
596 -e 's/ifi_change/Change/' \
597 >> ${OUT}
598
599 # The interface information types and flags.
600 grep '^const _IFA' gen-sysinfo.go | \
601 sed -e 's/^\(const \)_\(IFA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
602 grep '^const _IFLA' gen-sysinfo.go | \
603 sed -e 's/^\(const \)_\(IFLA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
604 grep '^const _IFF' gen-sysinfo.go | \
605 sed -e 's/^\(const \)_\(IFF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
606
607 # The size of the ifinfomsg struct.
608 if grep 'type IfInfomsg ' ${OUT} > /dev/null 2>&1; then
609 echo 'var SizeofIfInfomsg = int(unsafe.Sizeof(IfInfomsg{}))' >> ${OUT}
610 fi
611
612 # The ifaddrmsg struct.
613 grep '^type _ifaddrmsg ' gen-sysinfo.go | \
614 sed -e 's/_ifaddrmsg/IfAddrmsg/' \
615 -e 's/ifa_family/Family/' \
616 -e 's/ifa_prefixlen/Prefixlen/' \
617 -e 's/ifa_flags/Flags/' \
618 -e 's/ifa_scope/Scope/' \
619 -e 's/ifa_index/Index/' \
620 >> ${OUT}
621
622 # The size of the ifaddrmsg struct.
623 if grep 'type IfAddrmsg ' ${OUT} > /dev/null 2>&1; then
624 echo 'var SizeofIfAddrmsg = int(unsafe.Sizeof(IfAddrmsg{}))' >> ${OUT}
625 fi
626
627 # The rtattr struct.
628 grep '^type _rtattr ' gen-sysinfo.go | \
629 sed -e 's/_rtattr/RtAttr/' \
630 -e 's/rta_len/Len/' \
631 -e 's/rta_type/Type/' \
632 >> ${OUT}
633
634 # The size of the rtattr struct.
635 if grep 'type RtAttr ' ${OUT} > /dev/null 2>&1; then
636 echo 'var SizeofRtAttr = int(unsafe.Sizeof(RtAttr{}))' >> ${OUT}
637 fi
638
639 # The termios struct.
640 grep '^type _termios ' gen-sysinfo.go | \
641 sed -e 's/_termios/Termios/' \
642 -e 's/c_iflag/Iflag/' \
643 -e 's/c_oflag/Oflag/' \
644 -e 's/c_cflag/Cflag/' \
645 -e 's/c_lflag/Lflag/' \
646 -e 's/c_line/Line/' \
647 -e 's/c_cc/Cc/' \
648 -e 's/c_ispeed/Ispeed/' \
649 -e 's/c_ospeed/Ospeed/' \
650 >> ${OUT}
651
652 # The termios constants.
653 for n in IGNBRK BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL IUCLC \
654 IXON IXANY IXOFF IMAXBEL IUTF8 OPOST OLCUC ONLCR OCRNL ONOCR ONLRET \
655 OFILL OFDEL NLDLY NL0 NL1 CRDLY CR0 CR1 CR2 CR3 TABDLY BSDLY VTDLY \
656 FFDLY CBAUD CBAUDEX CSIZE CSTOPB CREAD PARENB PARODD HUPCL CLOCAL \
657 LOBLK CIBAUD CMSPAR CRTSCTS ISIG ICANON XCASE ECHO ECHOE ECHOK ECHONL \
658 ECHOCTL ECHOPRT ECHOKE DEFECHO FLUSHO NOFLSH TOSTOP PENDIN IEXTEN VINTR \
659 VQUIT VERASE VKILL VEOF VMIN VEOL VTIME VEOL2 VSWTCH VSTART VSTOP VSUSP \
660 VDSUSP VLNEXT VWERASE VREPRINT VDISCARD VSTATUS TCSANOW TCSADRAIN \
661 TCSAFLUSH TCIFLUSH TCOFLUSH TCIOFLUSH TCOOFF TCOON TCIOFF TCION B0 B50 \
662 B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 \
663 B38400 B57600 B115200 B230400; do
664
665 grep "^const _$n " gen-sysinfo.go | \
666 sed -e 's/^\(const \)_\([^=]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
667 done
668
669 exit $?