Devon H. O'Dell | 553be84 | 2009-11-14 15:29:09 -0800 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 2 | # Copyright 2009 The Go Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style |
| 4 | # license that can be found in the LICENSE file. |
| 5 | |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 6 | # Generate Go code listing errors and other #defined constant |
| 7 | # values (ENAMETOOLONG etc.), by asking the preprocessor |
| 8 | # about the definitions. |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 9 | |
Russ Cox | 0b126c1 | 2009-12-01 16:53:43 -0800 | [diff] [blame] | 10 | unset LANG |
| 11 | export LC_ALL=C |
| 12 | export LC_CTYPE=C |
| 13 | |
Kai Backman | 534dbc7 | 2010-08-23 13:25:14 +0300 | [diff] [blame] | 14 | GCC=gcc |
Kai Backman | e5c884f | 2009-10-01 06:55:01 -0700 | [diff] [blame] | 15 | |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 16 | uname=$(uname) |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 17 | |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 18 | includes_Darwin=' |
Russ Cox | acd858e | 2011-01-18 14:02:41 -0500 | [diff] [blame] | 19 | #define _DARWIN_C_SOURCE |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 20 | #define KERNEL |
| 21 | #define _DARWIN_USE_64_BIT_INODE |
Mikio Hara | 9c97af9 | 2011-02-11 14:34:00 -0500 | [diff] [blame] | 22 | #include <sys/types.h> |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 23 | #include <sys/event.h> |
Jeff Hodges | 0ce57a7 | 2011-06-14 12:56:46 -0400 | [diff] [blame] | 24 | #include <sys/ptrace.h> |
Mikio Hara | 5c0aab9 | 2011-01-31 12:50:50 -0500 | [diff] [blame] | 25 | #include <sys/socket.h> |
| 26 | #include <sys/sockio.h> |
Mikio Hara | 9c97af9 | 2011-02-11 14:34:00 -0500 | [diff] [blame] | 27 | #include <sys/sysctl.h> |
Russ Cox | 48ae1f2 | 2011-04-06 17:52:02 -0400 | [diff] [blame] | 28 | #include <sys/mman.h> |
Mikio Hara | 9c97af9 | 2011-02-11 14:34:00 -0500 | [diff] [blame] | 29 | #include <sys/wait.h> |
Mikio Hara | 380f4ab | 2011-04-21 16:58:20 -0400 | [diff] [blame] | 30 | #include <net/bpf.h> |
Mikio Hara | 5c0aab9 | 2011-01-31 12:50:50 -0500 | [diff] [blame] | 31 | #include <net/if.h> |
Mikio Hara | 12376c9 | 2011-05-26 20:02:03 -0400 | [diff] [blame] | 32 | #include <net/if_types.h> |
Mikio Hara | 9c97af9 | 2011-02-11 14:34:00 -0500 | [diff] [blame] | 33 | #include <net/route.h> |
| 34 | #include <netinet/in.h> |
Mikio Hara | 5c0aab9 | 2011-01-31 12:50:50 -0500 | [diff] [blame] | 35 | #include <netinet/ip.h> |
| 36 | #include <netinet/ip_mroute.h> |
Ken Rockot | c8443d7 | 2011-06-22 18:07:20 -0400 | [diff] [blame] | 37 | #include <termios.h> |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 38 | ' |
| 39 | |
Joel Sing | 8f3f4c9 | 2013-08-24 01:51:25 +1000 | [diff] [blame] | 40 | includes_DragonFly=' |
| 41 | #include <sys/types.h> |
| 42 | #include <sys/event.h> |
| 43 | #include <sys/socket.h> |
| 44 | #include <sys/sockio.h> |
| 45 | #include <sys/sysctl.h> |
| 46 | #include <sys/mman.h> |
| 47 | #include <sys/wait.h> |
| 48 | #include <sys/ioctl.h> |
| 49 | #include <net/bpf.h> |
| 50 | #include <net/if.h> |
| 51 | #include <net/if_types.h> |
| 52 | #include <net/route.h> |
| 53 | #include <netinet/in.h> |
| 54 | #include <termios.h> |
| 55 | #include <netinet/ip.h> |
| 56 | #include <net/ip_mroute/ip_mroute.h> |
| 57 | ' |
| 58 | |
Devon H. O'Dell | 553be84 | 2009-11-14 15:29:09 -0800 | [diff] [blame] | 59 | includes_FreeBSD=' |
Mikio Hara | 9c97af9 | 2011-02-11 14:34:00 -0500 | [diff] [blame] | 60 | #include <sys/types.h> |
Devon H. O'Dell | 553be84 | 2009-11-14 15:29:09 -0800 | [diff] [blame] | 61 | #include <sys/event.h> |
Mikio Hara | 400ea84 | 2011-02-01 08:46:21 -0500 | [diff] [blame] | 62 | #include <sys/socket.h> |
| 63 | #include <sys/sockio.h> |
Mikio Hara | 9c97af9 | 2011-02-11 14:34:00 -0500 | [diff] [blame] | 64 | #include <sys/sysctl.h> |
Dave Cheney | 9dd92d5 | 2013-03-09 16:25:30 +1100 | [diff] [blame] | 65 | #include <sys/mman.h> |
Mikio Hara | 9c97af9 | 2011-02-11 14:34:00 -0500 | [diff] [blame] | 66 | #include <sys/wait.h> |
Ken Rockot | c8443d7 | 2011-06-22 18:07:20 -0400 | [diff] [blame] | 67 | #include <sys/ioctl.h> |
Mikio Hara | 5a59b9e | 2011-04-04 15:40:40 -0400 | [diff] [blame] | 68 | #include <net/bpf.h> |
Mikio Hara | 400ea84 | 2011-02-01 08:46:21 -0500 | [diff] [blame] | 69 | #include <net/if.h> |
Mikio Hara | 12376c9 | 2011-05-26 20:02:03 -0400 | [diff] [blame] | 70 | #include <net/if_types.h> |
Mikio Hara | 9c97af9 | 2011-02-11 14:34:00 -0500 | [diff] [blame] | 71 | #include <net/route.h> |
Mikio Hara | 400ea84 | 2011-02-01 08:46:21 -0500 | [diff] [blame] | 72 | #include <netinet/in.h> |
Russ Cox | dfacfd6 | 2011-06-27 11:02:32 -0400 | [diff] [blame] | 73 | #include <termios.h> |
Mikio Hara | 400ea84 | 2011-02-01 08:46:21 -0500 | [diff] [blame] | 74 | #include <netinet/ip.h> |
| 75 | #include <netinet/ip_mroute.h> |
Devon H. O'Dell | 553be84 | 2009-11-14 15:29:09 -0800 | [diff] [blame] | 76 | ' |
| 77 | |
Mikio Hara | 055b4f7 | 2011-12-16 19:51:25 +0900 | [diff] [blame] | 78 | includes_Linux=' |
| 79 | #define _LARGEFILE_SOURCE |
| 80 | #define _LARGEFILE64_SOURCE |
| 81 | #define _FILE_OFFSET_BITS 64 |
| 82 | #define _GNU_SOURCE |
| 83 | |
| 84 | #include <bits/sockaddr.h> |
| 85 | #include <sys/epoll.h> |
| 86 | #include <sys/inotify.h> |
| 87 | #include <sys/ioctl.h> |
| 88 | #include <sys/mman.h> |
| 89 | #include <sys/mount.h> |
Albert Strasheim | 2cb6fcf | 2012-01-09 21:37:46 +0900 | [diff] [blame] | 90 | #include <sys/prctl.h> |
Mikio Hara | 055b4f7 | 2011-12-16 19:51:25 +0900 | [diff] [blame] | 91 | #include <sys/stat.h> |
| 92 | #include <sys/types.h> |
Shenghou Ma | 46e30c7 | 2013-06-11 02:47:04 +0800 | [diff] [blame] | 93 | #include <sys/time.h> |
Mikio Hara | adbe59e | 2013-05-23 16:22:05 +0900 | [diff] [blame] | 94 | #include <sys/socket.h> |
Mikio Hara | 055b4f7 | 2011-12-16 19:51:25 +0900 | [diff] [blame] | 95 | #include <linux/if_addr.h> |
| 96 | #include <linux/if_ether.h> |
| 97 | #include <linux/if_tun.h> |
| 98 | #include <linux/filter.h> |
| 99 | #include <linux/netlink.h> |
| 100 | #include <linux/reboot.h> |
| 101 | #include <linux/rtnetlink.h> |
| 102 | #include <linux/ptrace.h> |
Rémy Oudompheng | d4f719e | 2013-08-23 22:26:49 +0200 | [diff] [blame] | 103 | #include <linux/sched.h> |
Mikio Hara | 055b4f7 | 2011-12-16 19:51:25 +0900 | [diff] [blame] | 104 | #include <linux/wait.h> |
Mikio Hara | adbe59e | 2013-05-23 16:22:05 +0900 | [diff] [blame] | 105 | #include <linux/icmpv6.h> |
Mikio Hara | 055b4f7 | 2011-12-16 19:51:25 +0900 | [diff] [blame] | 106 | #include <net/if.h> |
| 107 | #include <net/if_arp.h> |
| 108 | #include <net/route.h> |
| 109 | #include <netpacket/packet.h> |
Dave Cheney | bd9cd6e | 2013-09-13 15:01:22 +1000 | [diff] [blame] | 110 | #include <termios.h> |
Brad Fitzpatrick | abf5700 | 2013-02-27 15:51:51 -0800 | [diff] [blame] | 111 | |
| 112 | #ifndef MSG_FASTOPEN |
| 113 | #define MSG_FASTOPEN 0x20000000 |
| 114 | #endif |
Mikio Hara | 055b4f7 | 2011-12-16 19:51:25 +0900 | [diff] [blame] | 115 | ' |
| 116 | |
Christopher Nielsen | 5425db8 | 2011-12-20 03:57:58 +1100 | [diff] [blame] | 117 | includes_NetBSD=' |
| 118 | #include <sys/types.h> |
| 119 | #include <sys/param.h> |
| 120 | #include <sys/event.h> |
Joel Sing | 8f98443 | 2014-01-07 23:04:17 +1100 | [diff] [blame] | 121 | #include <sys/mman.h> |
Christopher Nielsen | 5425db8 | 2011-12-20 03:57:58 +1100 | [diff] [blame] | 122 | #include <sys/socket.h> |
| 123 | #include <sys/sockio.h> |
| 124 | #include <sys/sysctl.h> |
| 125 | #include <sys/termios.h> |
| 126 | #include <sys/ttycom.h> |
| 127 | #include <sys/wait.h> |
| 128 | #include <net/bpf.h> |
| 129 | #include <net/if.h> |
| 130 | #include <net/if_types.h> |
| 131 | #include <net/route.h> |
| 132 | #include <netinet/in.h> |
| 133 | #include <netinet/in_systm.h> |
| 134 | #include <netinet/ip.h> |
| 135 | #include <netinet/ip_mroute.h> |
| 136 | #include <netinet/if_ether.h> |
Joel Sing | 2a47e04 | 2012-05-14 10:40:13 -0700 | [diff] [blame] | 137 | |
| 138 | // Needed since <sys/param.h> refers to it... |
Joel Sing | 495a9dc | 2012-05-23 01:33:48 +1000 | [diff] [blame] | 139 | #define schedppq 1 |
Christopher Nielsen | 5425db8 | 2011-12-20 03:57:58 +1100 | [diff] [blame] | 140 | ' |
| 141 | |
Joel Sing | bf2d403 | 2011-08-22 23:24:32 -0400 | [diff] [blame] | 142 | includes_OpenBSD=' |
| 143 | #include <sys/types.h> |
| 144 | #include <sys/param.h> |
| 145 | #include <sys/event.h> |
Joel Sing | f40dd8f | 2014-01-13 11:25:48 +1100 | [diff] [blame^] | 146 | #include <sys/mman.h> |
Joel Sing | bf2d403 | 2011-08-22 23:24:32 -0400 | [diff] [blame] | 147 | #include <sys/socket.h> |
| 148 | #include <sys/sockio.h> |
| 149 | #include <sys/sysctl.h> |
| 150 | #include <sys/termios.h> |
| 151 | #include <sys/ttycom.h> |
| 152 | #include <sys/wait.h> |
| 153 | #include <net/bpf.h> |
| 154 | #include <net/if.h> |
| 155 | #include <net/if_types.h> |
| 156 | #include <net/route.h> |
| 157 | #include <netinet/in.h> |
| 158 | #include <netinet/in_systm.h> |
| 159 | #include <netinet/ip.h> |
| 160 | #include <netinet/ip_mroute.h> |
| 161 | #include <netinet/if_ether.h> |
| 162 | #include <net/if_bridge.h> |
| 163 | ' |
| 164 | |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 165 | includes=' |
| 166 | #include <sys/types.h> |
Andrea Spadaccini | 83c30f3 | 2011-12-08 15:12:08 +0900 | [diff] [blame] | 167 | #include <sys/file.h> |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 168 | #include <fcntl.h> |
| 169 | #include <dirent.h> |
| 170 | #include <sys/socket.h> |
| 171 | #include <netinet/in.h> |
Russ Cox | 8fbe8be | 2010-03-30 14:32:59 -0700 | [diff] [blame] | 172 | #include <netinet/ip.h> |
| 173 | #include <netinet/ip6.h> |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 174 | #include <netinet/tcp.h> |
| 175 | #include <errno.h> |
| 176 | #include <sys/signal.h> |
| 177 | #include <signal.h> |
Sébastien Paolacci | e2467f0 | 2011-11-19 15:17:40 +0900 | [diff] [blame] | 178 | #include <sys/resource.h> |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 179 | ' |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 180 | |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 181 | ccflags="$@" |
Russ Cox | 7906e31 | 2010-04-29 23:34:06 -0700 | [diff] [blame] | 182 | |
Mikio Hara | 44122ed | 2012-02-03 12:22:40 +0900 | [diff] [blame] | 183 | # Write go tool cgo -godefs input. |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 184 | ( |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 185 | echo package syscall |
| 186 | echo |
| 187 | echo '/*' |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 188 | indirect="includes_$(uname)" |
| 189 | echo "${!indirect} $includes" |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 190 | echo '*/' |
| 191 | echo 'import "C"' |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 192 | echo |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 193 | echo 'const (' |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 194 | |
| 195 | # The gcc command line prints all the #defines |
| 196 | # it encounters while processing the input |
Russ Cox | 7906e31 | 2010-04-29 23:34:06 -0700 | [diff] [blame] | 197 | echo "${!indirect} $includes" | $GCC -x c - -E -dM $ccflags | |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 198 | awk ' |
Joel Sing | bf2d403 | 2011-08-22 23:24:32 -0400 | [diff] [blame] | 199 | $1 != "#define" || $2 ~ /\(/ || $3 == "" {next} |
Mikio Hara | 6555cfc | 2010-12-09 13:55:59 -0500 | [diff] [blame] | 200 | |
Russ Cox | 23bf408 | 2010-05-03 11:11:01 -0700 | [diff] [blame] | 201 | $2 ~ /^E([ABCD]X|[BIS]P|[SD]I|S|FL)$/ {next} # 386 registers |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 202 | $2 ~ /^(SIGEV_|SIGSTKSZ|SIGRT(MIN|MAX))/ {next} |
Albert Strasheim | cf6c212 | 2010-12-07 13:40:14 -0500 | [diff] [blame] | 203 | $2 ~ /^(SCM_SRCRT)$/ {next} |
| 204 | $2 ~ /^(MAP_FAILED)$/ {next} |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 205 | |
Mikio Hara | 6555cfc | 2010-12-09 13:55:59 -0500 | [diff] [blame] | 206 | $2 !~ /^ETH_/ && |
Mikio Hara | 9c97af9 | 2011-02-11 14:34:00 -0500 | [diff] [blame] | 207 | $2 !~ /^EPROC_/ && |
| 208 | $2 !~ /^EQUIV_/ && |
| 209 | $2 !~ /^EXPR_/ && |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 210 | $2 ~ /^E[A-Z0-9_]+$/ || |
Francisco Souza | 61060ac | 2012-05-03 17:33:19 -0400 | [diff] [blame] | 211 | $2 ~ /^B[0-9_]+$/ || |
| 212 | $2 ~ /^V[A-Z0-9]+$/ || |
| 213 | $2 ~ /^CS[A-Z0-9]/ || |
| 214 | $2 ~ /^I(SIG|CANON|CRNL|EXTEN|MAXBEL|STRIP|UTF8)$/ || |
| 215 | $2 ~ /^IGN/ || |
| 216 | $2 ~ /^IX(ON|ANY|OFF)$/ || |
| 217 | $2 ~ /^IN(LCR|PCK)$/ || |
| 218 | $2 ~ /(^FLU?SH)|(FLU?SH$)/ || |
| 219 | $2 ~ /^C(LOCAL|READ)$/ || |
| 220 | $2 == "BRKINT" || |
| 221 | $2 == "HUPCL" || |
| 222 | $2 == "PENDIN" || |
| 223 | $2 == "TOSTOP" || |
| 224 | $2 ~ /^PAR/ || |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 225 | $2 ~ /^SIG[^_]/ || |
Francisco Souza | 61060ac | 2012-05-03 17:33:19 -0400 | [diff] [blame] | 226 | $2 ~ /^O[CNPFP][A-Z]+[^_][A-Z]+$/ || |
Balazs Lecz | 4bfcfcf | 2010-09-27 11:44:26 -0400 | [diff] [blame] | 227 | $2 ~ /^IN_/ || |
Andrea Spadaccini | 83c30f3 | 2011-12-08 15:12:08 +0900 | [diff] [blame] | 228 | $2 ~ /^LOCK_(SH|EX|NB|UN)$/ || |
Mikio Hara | adbe59e | 2013-05-23 16:22:05 +0900 | [diff] [blame] | 229 | $2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|ICMP6|TCP|EVFILT|NOTE|EV|SHUT|PROT|MAP|PACKET|MSG|SCM|MCL|DT|MADV|PR)_/ || |
| 230 | $2 == "ICMPV6_FILTER" || |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 231 | $2 == "SOMAXCONN" || |
| 232 | $2 == "NAME_MAX" || |
Mikio Hara | 6555cfc | 2010-12-09 13:55:59 -0500 | [diff] [blame] | 233 | $2 == "IFNAMSIZ" || |
Joel Sing | 495a9dc | 2012-05-23 01:33:48 +1000 | [diff] [blame] | 234 | $2 ~ /^CTL_(MAXNAME|NET|QUERY)$/ || |
| 235 | $2 ~ /^SYSCTL_VERS/ || |
David Anderson | ad102e1 | 2011-03-09 05:58:47 -0800 | [diff] [blame] | 236 | $2 ~ /^(MS|MNT)_/ || |
Mikio Hara | 6555cfc | 2010-12-09 13:55:59 -0500 | [diff] [blame] | 237 | $2 ~ /^TUN(SET|GET|ATTACH|DETACH)/ || |
Jeff Hodges | 0ce57a7 | 2011-06-14 12:56:46 -0400 | [diff] [blame] | 238 | $2 ~ /^(O|F|FD|NAME|S|PTRACE|PT)_/ || |
David Anderson | 05660b7 | 2011-03-09 05:45:08 -0800 | [diff] [blame] | 239 | $2 ~ /^LINUX_REBOOT_CMD_/ || |
| 240 | $2 ~ /^LINUX_REBOOT_MAGIC[12]$/ || |
Mikio Hara | 1d550bd | 2011-05-18 16:33:41 -0700 | [diff] [blame] | 241 | $2 !~ "NLA_TYPE_MASK" && |
Mikio Hara | b1d51c6 | 2013-02-24 12:04:48 +0900 | [diff] [blame] | 242 | $2 ~ /^(NETLINK|NLM|NLMSG|NLA|IFA|IFAN|RT|RTCF|RTN|RTPROT|RTNH|ARPHRD|ETH_P)_/ || |
Mikio Hara | 9c97af9 | 2011-02-11 14:34:00 -0500 | [diff] [blame] | 243 | $2 ~ /^SIOC/ || |
Ken Rockot | c8443d7 | 2011-06-22 18:07:20 -0400 | [diff] [blame] | 244 | $2 ~ /^TIOC/ || |
Mikio Hara | 12376c9 | 2011-05-26 20:02:03 -0400 | [diff] [blame] | 245 | $2 ~ /^(IFF|IFT|NET_RT|RTM|RTF|RTV|RTA|RTAX)_/ || |
Mikio Hara | 5a59b9e | 2011-04-04 15:40:40 -0400 | [diff] [blame] | 246 | $2 ~ /^BIOC/ || |
Sébastien Paolacci | e2467f0 | 2011-11-19 15:17:40 +0900 | [diff] [blame] | 247 | $2 ~ /^RUSAGE_(SELF|CHILDREN|THREAD)/ || |
| 248 | $2 ~ /^RLIMIT_(AS|CORE|CPU|DATA|FSIZE|NOFILE|STACK)|RLIM_INFINITY/ || |
Shenghou Ma | 46e30c7 | 2013-06-11 02:47:04 +0800 | [diff] [blame] | 249 | $2 ~ /^PRIO_(PROCESS|PGRP|USER)/ || |
Rémy Oudompheng | d4f719e | 2013-08-23 22:26:49 +0200 | [diff] [blame] | 250 | $2 ~ /^CLONE_[A-Z_]+/ || |
Mikio Hara | 380f4ab | 2011-04-21 16:58:20 -0400 | [diff] [blame] | 251 | $2 !~ /^(BPF_TIMEVAL)$/ && |
Mikio Hara | 5a59b9e | 2011-04-04 15:40:40 -0400 | [diff] [blame] | 252 | $2 ~ /^(BPF|DLT)_/ || |
Mikio Hara | 9c97af9 | 2011-02-11 14:34:00 -0500 | [diff] [blame] | 253 | $2 !~ "WMESGLEN" && |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 254 | $2 ~ /^W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", $2, $2)} |
Russ Cox | 23bf408 | 2010-05-03 11:11:01 -0700 | [diff] [blame] | 255 | $2 ~ /^__WCOREFLAG$/ {next} |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 256 | $2 ~ /^__W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", substr($2,3), $2)} |
Mikio Hara | 6555cfc | 2010-12-09 13:55:59 -0500 | [diff] [blame] | 257 | |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 258 | {next} |
| 259 | ' | sort |
| 260 | |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 261 | echo ')' |
| 262 | ) >_const.go |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 263 | |
Russ Cox | 35586f7 | 2012-02-13 13:52:37 -0500 | [diff] [blame] | 264 | # Pull out the error names for later. |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 265 | errors=$( |
Russ Cox | 7906e31 | 2010-04-29 23:34:06 -0700 | [diff] [blame] | 266 | echo '#include <errno.h>' | $GCC -x c - -E -dM $ccflags | |
Russ Cox | 0b126c1 | 2009-12-01 16:53:43 -0800 | [diff] [blame] | 267 | awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print $2 }' | |
| 268 | sort |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 269 | ) |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 270 | |
Russ Cox | 35586f7 | 2012-02-13 13:52:37 -0500 | [diff] [blame] | 271 | # Pull out the signal names for later. |
| 272 | signals=$( |
| 273 | echo '#include <signal.h>' | $GCC -x c - -E -dM $ccflags | |
| 274 | awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print $2 }' | |
| 275 | egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT)' | |
| 276 | sort |
| 277 | ) |
| 278 | |
Russ Cox | c017a82 | 2011-11-13 22:44:52 -0500 | [diff] [blame] | 279 | # Again, writing regexps to a file. |
| 280 | echo '#include <errno.h>' | $GCC -x c - -E -dM $ccflags | |
| 281 | awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print "^\t" $2 "[ \t]*=" }' | |
| 282 | sort >_error.grep |
Russ Cox | 35586f7 | 2012-02-13 13:52:37 -0500 | [diff] [blame] | 283 | echo '#include <signal.h>' | $GCC -x c - -E -dM $ccflags | |
| 284 | awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print "^\t" $2 "[ \t]*=" }' | |
| 285 | egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT)' | |
| 286 | sort >_signal.grep |
Russ Cox | c017a82 | 2011-11-13 22:44:52 -0500 | [diff] [blame] | 287 | |
Rob Pike | cd32498 | 2009-08-13 13:22:37 -0700 | [diff] [blame] | 288 | echo '// mkerrors.sh' "$@" |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 289 | echo '// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT' |
| 290 | echo |
Mikio Hara | 44122ed | 2012-02-03 12:22:40 +0900 | [diff] [blame] | 291 | go tool cgo -godefs -- "$@" _const.go >_error.out |
Russ Cox | 35586f7 | 2012-02-13 13:52:37 -0500 | [diff] [blame] | 292 | cat _error.out | grep -vf _error.grep | grep -vf _signal.grep |
Russ Cox | c017a82 | 2011-11-13 22:44:52 -0500 | [diff] [blame] | 293 | echo |
| 294 | echo '// Errors' |
| 295 | echo 'const (' |
| 296 | cat _error.out | grep -f _error.grep | sed 's/=\(.*\)/= Errno(\1)/' |
| 297 | echo ')' |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 298 | |
Russ Cox | 35586f7 | 2012-02-13 13:52:37 -0500 | [diff] [blame] | 299 | echo |
| 300 | echo '// Signals' |
| 301 | echo 'const (' |
| 302 | cat _error.out | grep -f _signal.grep | sed 's/=\(.*\)/= Signal(\1)/' |
| 303 | echo ')' |
| 304 | |
| 305 | # Run C program to print error and syscall strings. |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 306 | ( |
Russ Cox | 9feee91 | 2009-08-24 11:03:23 -0700 | [diff] [blame] | 307 | /bin/echo " |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 308 | #include <stdio.h> |
| 309 | #include <errno.h> |
| 310 | #include <ctype.h> |
| 311 | #include <string.h> |
Russ Cox | 35586f7 | 2012-02-13 13:52:37 -0500 | [diff] [blame] | 312 | #include <signal.h> |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 313 | |
| 314 | #define nelem(x) (sizeof(x)/sizeof((x)[0])) |
| 315 | |
| 316 | enum { A = 'A', Z = 'Z', a = 'a', z = 'z' }; // avoid need for single quotes below |
| 317 | |
| 318 | int errors[] = { |
| 319 | " |
| 320 | for i in $errors |
| 321 | do |
Russ Cox | 9feee91 | 2009-08-24 11:03:23 -0700 | [diff] [blame] | 322 | /bin/echo ' '$i, |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 323 | done |
| 324 | |
Russ Cox | 35586f7 | 2012-02-13 13:52:37 -0500 | [diff] [blame] | 325 | /bin/echo " |
| 326 | }; |
| 327 | |
| 328 | int signals[] = { |
| 329 | " |
| 330 | for i in $signals |
| 331 | do |
| 332 | /bin/echo ' '$i, |
| 333 | done |
| 334 | |
Russ Cox | 9feee91 | 2009-08-24 11:03:23 -0700 | [diff] [blame] | 335 | # Use /bin/echo to avoid builtin echo, |
| 336 | # which interprets \n itself |
| 337 | /bin/echo ' |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 338 | }; |
| 339 | |
Russ Cox | 9a96fb3 | 2010-09-24 13:37:02 -0400 | [diff] [blame] | 340 | static int |
| 341 | intcmp(const void *a, const void *b) |
| 342 | { |
| 343 | return *(int*)a - *(int*)b; |
| 344 | } |
| 345 | |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 346 | int |
| 347 | main(void) |
| 348 | { |
| 349 | int i, j, e; |
Russ Cox | 35586f7 | 2012-02-13 13:52:37 -0500 | [diff] [blame] | 350 | char buf[1024], *p; |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 351 | |
| 352 | printf("\n\n// Error table\n"); |
| 353 | printf("var errors = [...]string {\n"); |
Russ Cox | 9a96fb3 | 2010-09-24 13:37:02 -0400 | [diff] [blame] | 354 | qsort(errors, nelem(errors), sizeof errors[0], intcmp); |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 355 | for(i=0; i<nelem(errors); i++) { |
| 356 | e = errors[i]; |
Russ Cox | 9a96fb3 | 2010-09-24 13:37:02 -0400 | [diff] [blame] | 357 | if(i > 0 && errors[i-1] == e) |
| 358 | continue; |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 359 | strcpy(buf, strerror(e)); |
| 360 | // lowercase first letter: Bad -> bad, but STREAM -> STREAM. |
| 361 | if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) |
| 362 | buf[0] += a - A; |
| 363 | printf("\t%d: \"%s\",\n", e, buf); |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 364 | } |
| 365 | printf("}\n\n"); |
Russ Cox | 35586f7 | 2012-02-13 13:52:37 -0500 | [diff] [blame] | 366 | |
| 367 | printf("\n\n// Signal table\n"); |
| 368 | printf("var signals = [...]string {\n"); |
| 369 | qsort(signals, nelem(signals), sizeof signals[0], intcmp); |
| 370 | for(i=0; i<nelem(signals); i++) { |
| 371 | e = signals[i]; |
| 372 | if(i > 0 && signals[i-1] == e) |
| 373 | continue; |
| 374 | strcpy(buf, strsignal(e)); |
| 375 | // lowercase first letter: Bad -> bad, but STREAM -> STREAM. |
| 376 | if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) |
| 377 | buf[0] += a - A; |
| 378 | // cut trailing : number. |
| 379 | p = strrchr(buf, ":"[0]); |
| 380 | if(p) |
| 381 | *p = '\0'; |
| 382 | printf("\t%d: \"%s\",\n", e, buf); |
| 383 | } |
| 384 | printf("}\n\n"); |
| 385 | |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 386 | return 0; |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | ' |
| 390 | ) >_errors.c |
| 391 | |
Russ Cox | 35586f7 | 2012-02-13 13:52:37 -0500 | [diff] [blame] | 392 | $GCC $ccflags -o _errors _errors.c && $GORUN ./_errors && rm -f _errors.c _errors _const.go _error.grep _signal.grep _error.out |