OSDN Git Service

* config/sparc/sparc-opts.h: New.
[pf3gnuchains/gcc-fork.git] / libgo / mksysinfo.sh
index d28f7ff..033c3ec 100755 (executable)
@@ -8,8 +8,8 @@
 
 # This shell script creates the sysinfo.go file which holds types and
 # constants extracted from the system header files.  This relies on a
-# hook in gcc: the -ggo option will generate debugging information in
-# Go syntax.
+# hook in gcc: the -fdump-go-spec option will generate debugging
+# information in Go syntax.
 
 # We currently #include all the files at once, which works, but leads
 # to exposing some names which ideally should not be exposed, as they
@@ -21,11 +21,20 @@ OUT=tmp-sysinfo.go
 
 set -e
 
-rm -f sysinfo.go
-
 rm -f sysinfo.c
 cat > sysinfo.c <<EOF
 #include "config.h"
+
+#define _GNU_SOURCE
+#define _LARGEFILE_SOURCE
+#define _FILE_OFFSET_BITS 64
+
+#if defined(__sun__) && defined(__svr4__)
+/* Needed by Solaris header files.  */
+#define _XOPEN_SOURCE 600
+#define __EXTENSIONS__
+#endif
+
 #include <sys/types.h>
 #include <dirent.h>
 #include <errno.h>
@@ -36,6 +45,9 @@ cat > sysinfo.c <<EOF
 #if defined(HAVE_SYSCALL_H)
 #include <syscall.h>
 #endif
+#if defined(HAVE_SYS_SYSCALL_H)
+#include <sys/syscall.h>
+#endif
 #if defined(HAVE_SYS_EPOLL_H)
 #include <sys/epoll.h>
 #endif
@@ -43,6 +55,7 @@ cat > sysinfo.c <<EOF
 #include <sys/ptrace.h>
 #endif
 #include <sys/resource.h>
+#include <sys/uio.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/time.h>
@@ -57,7 +70,7 @@ cat > sysinfo.c <<EOF
 #include <unistd.h>
 EOF
 
-${CC} -D_GNU_SOURCE -fdump-go-spec=gen-sysinfo.go -S -o sysinfo.s sysinfo.c
+${CC} -fdump-go-spec=gen-sysinfo.go -std=gnu99 -S -o sysinfo.s sysinfo.c
 
 echo 'package syscall' > ${OUT}
 
@@ -69,11 +82,13 @@ grep -v '^// ' gen-sysinfo.go | \
   grep -v '^func' | \
   grep -v '^type _timeval ' | \
   grep -v '^type _timespec ' | \
+  grep -v '^type _timestruc_t ' | \
   grep -v '^type _epoll_' | \
   grep -v 'in6_addr' | \
   grep -v 'sockaddr_in6' | \
   sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
       -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
+      -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
     >> ${OUT}
 
 # The errno constants.
@@ -83,6 +98,9 @@ grep '^const _E' gen-sysinfo.go | \
 # The O_xxx flags.
 grep '^const _\(O\|F\|FD\)_' gen-sysinfo.go | \
   sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+if ! grep '^const O_ASYNC' ${OUT} >/dev/null 2>&1; then
+  echo "const O_ASYNC = 0" >> ${OUT}
+fi
 if ! grep '^const O_CLOEXEC' ${OUT} >/dev/null 2>&1; then
   echo "const O_CLOEXEC = 0" >> ${OUT}
 fi
@@ -129,6 +147,11 @@ grep '^const _SOMAXCONN' gen-sysinfo.go |
 grep '^const _SHUT_' gen-sysinfo.go |
   sed -e 's/^\(const \)_\(SHUT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
 
+# The net package requires a definition for IPV6ONLY.
+if ! grep '^const IPV6_V6ONLY ' ${OUT} >/dev/null 2>&1; then
+  echo "const IPV6_V6ONLY = 0" >> ${OUT}
+fi
+
 # pathconf constants.
 grep '^const __PC' gen-sysinfo.go |
   sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
@@ -195,10 +218,14 @@ fi
 if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev/null 2>&1; then
   echo "const PTRACE_EVENT_EXIT = 6" >> ${OUT}
 fi
+if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev/null 2>&1; then
+  echo "const _PTRACE_TRACEME = 0" >> ${OUT}
+fi
 
 # The registers returned by PTRACE_GETREGS.  This is probably
-# GNU/Linux specific.
-regs=`grep '^type _user_regs_struct struct' gen-sysinfo.go`
+# GNU/Linux specific; it should do no harm if there is no
+# _user_regs_struct.
+regs=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true`
 if test "$regs" != ""; then
   regs=`echo $regs | sed -e 's/type _user_regs_struct struct //' -e 's/[{}]//g'`
   regs=`echo $regs | sed -e s'/^ *//'`
@@ -241,6 +268,15 @@ else
   exit 1
 fi
 
+# Solaris 2 needs _u?pad128_t, but its default definition in terms of long
+# double is commented by -fdump-go-spec.
+if grep "^// type _pad128_t" gen-sysinfo.go > /dev/null 2>&1; then
+  echo "type _pad128_t struct { _l [4]int32; }" >> ${OUT}
+fi
+if grep "^// type _upad128_t" gen-sysinfo.go > /dev/null 2>&1; then
+  echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
+fi
+
 # The time structures need special handling: we need to name the
 # types, so that we can cast integers to the right types when
 # assigning to the structures.
@@ -263,36 +299,60 @@ echo $timespec | \
       -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timespec_sec_t/' \
       -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timespec_nsec_t/' >> ${OUT}
 
+timestruc=`grep '^type _timestruc_t ' gen-sysinfo.go || true`
+if test "$timestruc" != ""; then
+  timestruc_sec=`echo $timestruc | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
+  timestruc_nsec=`echo $timestruc | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
+  echo "type Timestruc_sec_t $timestruc_sec" >> ${OUT}
+  echo "type Timestruc_nsec_t $timestruc_nsec" >> ${OUT}
+  echo $timestruc | \
+    sed -e 's/^type _timestruc_t /type Timestruc /' \
+        -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timestruc_sec_t/' \
+        -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timestruc_nsec_t/' >> ${OUT}
+fi
+
 # The stat type.
-grep 'type _stat ' gen-sysinfo.go | \
-  sed -e 's/type _stat/type Stat_t/' \
-      -e 's/st_dev/Dev/' \
-      -e 's/st_ino/Ino/' \
-      -e 's/st_nlink/Nlink/' \
-      -e 's/st_mode/Mode/' \
-      -e 's/st_uid/Uid/' \
-      -e 's/st_gid/Gid/' \
-      -e 's/st_rdev/Rdev/' \
-      -e 's/st_size/Size/' \
-      -e 's/st_blksize/Blksize/' \
-      -e 's/st_blocks/Blocks/' \
-      -e 's/st_atim/Atime/' \
-      -e 's/st_mtim/Mtime/' \
-      -e 's/st_ctim/Ctime/' \
-      -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
-      -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
-    >> ${OUT}
+# Prefer largefile variant if available.
+stat=`grep '^type _stat64 ' gen-sysinfo.go || true`
+if test "$stat" != ""; then
+  grep '^type _stat64 ' gen-sysinfo.go
+else
+  grep '^type _stat ' gen-sysinfo.go
+fi | sed -e 's/type _stat\(64\)\?/type Stat_t/' \
+         -e 's/st_dev/Dev/' \
+         -e 's/st_ino/Ino/g' \
+         -e 's/st_nlink/Nlink/' \
+         -e 's/st_mode/Mode/' \
+         -e 's/st_uid/Uid/' \
+         -e 's/st_gid/Gid/' \
+         -e 's/st_rdev/Rdev/' \
+         -e 's/st_size/Size/' \
+         -e 's/st_blksize/Blksize/' \
+         -e 's/st_blocks/Blocks/' \
+         -e 's/st_atim/Atime/' \
+         -e 's/st_mtim/Mtime/' \
+         -e 's/st_ctim/Ctime/' \
+         -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
+         -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
+         -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
+       >> ${OUT}
 
 # The directory searching types.
-grep '^type _dirent ' gen-sysinfo.go | \
-  sed -e 's/type _dirent/type Dirent/' \
-      -e 's/d_name/Name/' \
-      -e 's/]int8/]byte/' \
-      -e 's/d_ino/Ino/' \
-      -e 's/d_off/Off/' \
-      -e 's/d_reclen/Reclen/' \
-      -e 's/d_type/Type/' \
-    >> ${OUT}
+# Prefer largefile variant if available.
+dirent=`grep '^type _dirent64 ' gen-sysinfo.go || true`
+if test "$dirent" != ""; then
+  grep '^type _dirent64 ' gen-sysinfo.go
+else
+  grep '^type _dirent ' gen-sysinfo.go
+fi | sed -e 's/type _dirent\(64\)\?/type Dirent/' \
+         -e 's/d_name \[0+1\]/d_name [0+256]/' \
+         -e 's/d_name/Name/' \
+         -e 's/]int8/]byte/' \
+         -e 's/d_ino/Ino/' \
+         -e 's/d_off/Off/' \
+         -e 's/d_reclen/Reclen/' \
+         -e 's/d_type/Type/' \
+      >> ${OUT}
 echo "type DIR _DIR" >> ${OUT}
 
 # The rusage struct.
@@ -309,9 +369,10 @@ if test "$rusage" != ""; then
     f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
     r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
     f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
-    # Fix _timeval and _timespec.
+    # Fix _timeval _timespec, and _timestruc_t.
     r=`echo $r | sed -e s'/ _timeval$/ Timeval/'`
     r=`echo $r | sed -e s'/ _timespec$/ Timespec/'`
+    r=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'`
     field="$f$r"
     nrusage="$nrusage $field;"
   done
@@ -329,5 +390,38 @@ grep '^type _utsname ' gen-sysinfo.go | \
       -e 's/domainname/Domainname/' \
     >> ${OUT}
 
-mv -f ${OUT} sysinfo.go
+# The iovec struct.
+iovec=`grep '^type _iovec ' gen-sysinfo.go`
+iovec_len=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
+echo "type Iovec_len_t $iovec_len" >> ${OUT}
+echo $iovec | \
+    sed -e 's/_iovec/Iovec/' \
+      -e 's/iov_base/Base/' \
+      -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
+    >> ${OUT}
+
+# The msghdr struct.
+msghdr=`grep '^type _msghdr ' gen-sysinfo.go`
+msghdr_controllen=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
+echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT}
+echo $msghdr | \
+    sed -e 's/_msghdr/Msghdr/' \
+      -e 's/msg_name/Name/' \
+      -e 's/msg_namelen/Namelen/' \
+      -e 's/msg_iov/Iov/' \
+      -e 's/msg_iovlen/Iovlen/' \
+      -e 's/_iovec/Iovec/' \
+      -e 's/msg_control/Control/' \
+      -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
+      -e 's/msg_flags/Flags/' \
+    >> ${OUT}
+
+# The ip_mreq struct
+grep '^type _ip_mreq ' gen-sysinfo.go | \
+    sed -e 's/_ip_mreq/IpMreq/' \
+      -e 's/imr_multiaddr/Multiaddr/' \
+      -e 's/imr_interface/Interface/' \
+      -e 's/_in_addr/[4]byte/g' \
+    >> ${OUT}
+
 exit $?