DR 1511 - const volatile variables and ODR
[official-gcc.git] / libgo / mkrsysinfo.sh
blobb5c2c709c20765a7f6e072155c9a8addd6b1816e
1 #!/bin/sh
3 # Copyright 2016 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 runtime_sysinfo.go from gen-sysinfo.go and errno.i.
9 OUT=tmp-runtime_sysinfo.go
11 set -e
13 echo 'package runtime' > ${OUT}
15 # Get all the consts and types, skipping ones which could not be
16 # represented in Go and ones which we need to rewrite. We also skip
17 # function declarations, as we don't need them here. All the symbols
18 # will all have a leading underscore.
19 grep -v '^// ' gen-sysinfo.go | \
20 grep -v '^func' | \
21 grep -v '^type _timeval ' | \
22 grep -v '^type _timespec_t ' | \
23 grep -v '^type _timespec ' | \
24 grep -v '^type _epoll_' | \
25 grep -v 'in6_addr' | \
26 grep -v 'sockaddr_in6' | \
27 sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1timeval\2/g' \
28 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1timespec\2/g' \
29 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1timespec\2/g' \
30 >> ${OUT}
32 # The time structures need special handling: we need to name the
33 # types, so that we can cast integers to the right types when
34 # assigning to the structures.
35 timeval=`grep '^type _timeval ' gen-sysinfo.go`
36 timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
37 timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
38 echo "type timeval_sec_t $timeval_sec" >> ${OUT}
39 echo "type timeval_usec_t $timeval_usec" >> ${OUT}
40 echo $timeval | \
41 sed -e 's/type _timeval /type timeval /' \
42 -e 's/tv_sec *[a-zA-Z0-9_]*/tv_sec timeval_sec_t/' \
43 -e 's/tv_usec *[a-zA-Z0-9_]*/tv_usec timeval_usec_t/' >> ${OUT}
44 timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
45 if test "$timespec" = ""; then
46 # IRIX 6.5 has __timespec instead.
47 timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
49 timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
50 timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
51 echo "type timespec_sec_t $timespec_sec" >> ${OUT}
52 echo "type timespec_nsec_t $timespec_nsec" >> ${OUT}
53 echo $timespec | \
54 sed -e 's/^type ___timespec /type timespec /' \
55 -e 's/^type _timespec /type timespec /' \
56 -e 's/tv_sec *[a-zA-Z0-9_]*/tv_sec timespec_sec_t/' \
57 -e 's/tv_nsec *[a-zA-Z0-9_]*/tv_nsec timespec_nsec_t/' >> ${OUT}
58 echo >> ${OUT}
59 echo "func (ts *timespec) set_sec(x int64) {" >> ${OUT}
60 echo " ts.tv_sec = timespec_sec_t(x)" >> ${OUT}
61 echo "}" >> ${OUT}
62 echo >> ${OUT}
63 echo "func (ts *timespec) set_nsec(x int32) {" >> ${OUT}
64 echo " ts.tv_nsec = timespec_nsec_t(x)" >> ${OUT}
65 echo "}" >> ${OUT}
67 # The semt structure, for Solaris.
68 grep '^type _sem_t ' gen-sysinfo.go | \
69 sed -e 's/_sem_t/semt/' >> ${OUT}
71 # Solaris 2 needs _u?pad128_t, but its default definition in terms of long
72 # double is commented by -fdump-go-spec.
73 if grep "^// type _pad128_t" gen-sysinfo.go > /dev/null 2>&1; then
74 echo "type _pad128_t struct { _l [4]int32; }" >> ${OUT}
76 if grep "^// type _upad128_t" gen-sysinfo.go > /dev/null 2>&1; then
77 echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
80 # The Solaris 11 Update 1 _zone_net_addr_t struct.
81 grep '^type _zone_net_addr_t ' gen-sysinfo.go | \
82 sed -e 's/_in6_addr/[16]byte/' \
83 >> ${OUT}
85 # The Solaris 12 _flow_arp_desc_t struct.
86 grep '^type _flow_arp_desc_t ' gen-sysinfo.go | \
87 sed -e 's/_in6_addr_t/[16]byte/g' \
88 >> ${OUT}
90 # The Solaris 12 _flow_l3_desc_t struct.
91 grep '^type _flow_l3_desc_t ' gen-sysinfo.go | \
92 sed -e 's/_in6_addr_t/[16]byte/g' \
93 >> ${OUT}
95 # The Solaris 12 _mac_ipaddr_t struct.
96 grep '^type _mac_ipaddr_t ' gen-sysinfo.go | \
97 sed -e 's/_in6_addr_t/[16]byte/g' \
98 >> ${OUT}
100 # The Solaris 12 _mactun_info_t struct.
101 grep '^type _mactun_info_t ' gen-sysinfo.go | \
102 sed -e 's/_in6_addr_t/[16]byte/g' \
103 >> ${OUT}