blob: 396aadf86de729ea230b7bc2d1f3c675c80a3fbe [file] [log] [blame]
Don Newton98fd8812019-09-23 15:15:02 -04001#!/usr/bin/env bash
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
6# This script runs or (given -n) prints suggested commands to generate files for
7# the Architecture/OS specified by the GOARCH and GOOS environment variables.
8# See README.md for more information about how the build system works.
9
10GOOSARCH="${GOOS}_${GOARCH}"
11
12# defaults
13mksyscall="go run mksyscall.go"
14mkerrors="./mkerrors.sh"
15zerrors="zerrors_$GOOSARCH.go"
16mksysctl=""
17zsysctl="zsysctl_$GOOSARCH.go"
18mksysnum=
19mktypes=
20mkasm=
21run="sh"
22cmd=""
23
24case "$1" in
25-syscalls)
26 for i in zsyscall*go
27 do
28 # Run the command line that appears in the first line
29 # of the generated file to regenerate it.
30 sed 1q $i | sed 's;^// ;;' | sh > _$i && gofmt < _$i > $i
31 rm _$i
32 done
33 exit 0
34 ;;
35-n)
36 run="cat"
37 cmd="echo"
38 shift
39esac
40
41case "$#" in
420)
43 ;;
44*)
45 echo 'usage: mkall.sh [-n]' 1>&2
46 exit 2
47esac
48
49if [[ "$GOOS" = "linux" ]]; then
50 # Use the Docker-based build system
51 # Files generated through docker (use $cmd so you can Ctl-C the build or run)
52 $cmd docker build --tag generate:$GOOS $GOOS
David K. Bainbridgee05cf0c2021-08-19 03:16:50 +000053 $cmd docker run --interactive --tty --volume $(cd -- "$(dirname -- "$0")" && /bin/pwd):/build generate:$GOOS
Don Newton98fd8812019-09-23 15:15:02 -040054 exit
55fi
56
57GOOSARCH_in=syscall_$GOOSARCH.go
58case "$GOOSARCH" in
59_* | *_ | _)
60 echo 'undefined $GOOS_$GOARCH:' "$GOOSARCH" 1>&2
61 exit 1
62 ;;
63aix_ppc)
64 mkerrors="$mkerrors -maix32"
65 mksyscall="go run mksyscall_aix_ppc.go -aix"
66 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
67 ;;
68aix_ppc64)
69 mkerrors="$mkerrors -maix64"
70 mksyscall="go run mksyscall_aix_ppc64.go -aix"
71 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
72 ;;
Don Newton98fd8812019-09-23 15:15:02 -040073darwin_amd64)
74 mkerrors="$mkerrors -m64"
Don Newton98fd8812019-09-23 15:15:02 -040075 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
76 mkasm="go run mkasm_darwin.go"
77 ;;
78darwin_arm64)
79 mkerrors="$mkerrors -m64"
Don Newton98fd8812019-09-23 15:15:02 -040080 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
81 mkasm="go run mkasm_darwin.go"
82 ;;
83dragonfly_amd64)
84 mkerrors="$mkerrors -m64"
85 mksyscall="go run mksyscall.go -dragonfly"
86 mksysnum="go run mksysnum.go 'https://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/sys/kern/syscalls.master'"
87 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
88 ;;
89freebsd_386)
90 mkerrors="$mkerrors -m32"
91 mksyscall="go run mksyscall.go -l32"
Don Newton7577f072020-01-06 12:41:11 -050092 mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
Don Newton98fd8812019-09-23 15:15:02 -040093 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
94 ;;
95freebsd_amd64)
96 mkerrors="$mkerrors -m64"
Don Newton7577f072020-01-06 12:41:11 -050097 mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
Don Newton98fd8812019-09-23 15:15:02 -040098 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
99 ;;
100freebsd_arm)
101 mkerrors="$mkerrors"
102 mksyscall="go run mksyscall.go -l32 -arm"
Don Newton7577f072020-01-06 12:41:11 -0500103 mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
Don Newton98fd8812019-09-23 15:15:02 -0400104 # Let the type of C char be signed for making the bare syscall
105 # API consistent across platforms.
106 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
107 ;;
108freebsd_arm64)
109 mkerrors="$mkerrors -m64"
Don Newton7577f072020-01-06 12:41:11 -0500110 mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
David K. Bainbridgee05cf0c2021-08-19 03:16:50 +0000111 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
Don Newton98fd8812019-09-23 15:15:02 -0400112 ;;
113netbsd_386)
114 mkerrors="$mkerrors -m32"
115 mksyscall="go run mksyscall.go -l32 -netbsd"
116 mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
117 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
118 ;;
119netbsd_amd64)
120 mkerrors="$mkerrors -m64"
121 mksyscall="go run mksyscall.go -netbsd"
122 mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
123 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
124 ;;
125netbsd_arm)
126 mkerrors="$mkerrors"
127 mksyscall="go run mksyscall.go -l32 -netbsd -arm"
128 mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
129 # Let the type of C char be signed for making the bare syscall
130 # API consistent across platforms.
131 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
132 ;;
Don Newton7577f072020-01-06 12:41:11 -0500133netbsd_arm64)
134 mkerrors="$mkerrors -m64"
135 mksyscall="go run mksyscall.go -netbsd"
136 mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
137 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
138 ;;
Don Newton98fd8812019-09-23 15:15:02 -0400139openbsd_386)
140 mkerrors="$mkerrors -m32"
141 mksyscall="go run mksyscall.go -l32 -openbsd"
Don Newton7577f072020-01-06 12:41:11 -0500142 mksysctl="go run mksysctl_openbsd.go"
Don Newton98fd8812019-09-23 15:15:02 -0400143 mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
144 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
145 ;;
146openbsd_amd64)
147 mkerrors="$mkerrors -m64"
148 mksyscall="go run mksyscall.go -openbsd"
Don Newton7577f072020-01-06 12:41:11 -0500149 mksysctl="go run mksysctl_openbsd.go"
Don Newton98fd8812019-09-23 15:15:02 -0400150 mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
151 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
152 ;;
153openbsd_arm)
154 mkerrors="$mkerrors"
155 mksyscall="go run mksyscall.go -l32 -openbsd -arm"
Don Newton7577f072020-01-06 12:41:11 -0500156 mksysctl="go run mksysctl_openbsd.go"
157 mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
158 # Let the type of C char be signed for making the bare syscall
159 # API consistent across platforms.
160 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
161 ;;
162openbsd_arm64)
163 mkerrors="$mkerrors -m64"
164 mksyscall="go run mksyscall.go -openbsd"
165 mksysctl="go run mksysctl_openbsd.go"
Don Newton98fd8812019-09-23 15:15:02 -0400166 mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
167 # Let the type of C char be signed for making the bare syscall
168 # API consistent across platforms.
169 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
170 ;;
David K. Bainbridgee05cf0c2021-08-19 03:16:50 +0000171openbsd_mips64)
172 mkerrors="$mkerrors -m64"
173 mksyscall="go run mksyscall.go -openbsd"
174 mksysctl="go run mksysctl_openbsd.go"
175 mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
176 # Let the type of C char be signed for making the bare syscall
177 # API consistent across platforms.
178 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
179 ;;
Don Newton98fd8812019-09-23 15:15:02 -0400180solaris_amd64)
181 mksyscall="go run mksyscall_solaris.go"
182 mkerrors="$mkerrors -m64"
183 mksysnum=
184 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
185 ;;
David K. Bainbridgee05cf0c2021-08-19 03:16:50 +0000186illumos_amd64)
187 mksyscall="go run mksyscall_solaris.go"
188 mkerrors=
189 mksysnum=
190 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
191 ;;
Don Newton98fd8812019-09-23 15:15:02 -0400192*)
193 echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
194 exit 1
195 ;;
196esac
197
198(
199 if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi
200 case "$GOOS" in
201 *)
202 syscall_goos="syscall_$GOOS.go"
203 case "$GOOS" in
204 darwin | dragonfly | freebsd | netbsd | openbsd)
205 syscall_goos="syscall_bsd.go $syscall_goos"
206 ;;
207 esac
208 if [ -n "$mksyscall" ]; then
209 if [ "$GOOSARCH" == "aix_ppc64" ]; then
210 # aix/ppc64 script generates files instead of writing to stdin.
211 echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in && gofmt -w zsyscall_$GOOSARCH.go && gofmt -w zsyscall_"$GOOSARCH"_gccgo.go && gofmt -w zsyscall_"$GOOSARCH"_gc.go " ;
212 elif [ "$GOOS" == "darwin" ]; then
Don Newton98fd8812019-09-23 15:15:02 -0400213 # 1.12 and later, syscalls via libSystem
214 echo "$mksyscall -tags $GOOS,$GOARCH,go1.12 $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go";
David K. Bainbridgee05cf0c2021-08-19 03:16:50 +0000215 # 1.13 and later, syscalls via libSystem (including syscallPtr)
216 echo "$mksyscall -tags $GOOS,$GOARCH,go1.13 syscall_darwin.1_13.go |gofmt >zsyscall_$GOOSARCH.1_13.go";
217 elif [ "$GOOS" == "illumos" ]; then
218 # illumos code generation requires a --illumos switch
219 echo "$mksyscall -illumos -tags illumos,$GOARCH syscall_illumos.go |gofmt > zsyscall_illumos_$GOARCH.go";
220 # illumos implies solaris, so solaris code generation is also required
221 echo "$mksyscall -tags solaris,$GOARCH syscall_solaris.go syscall_solaris_$GOARCH.go |gofmt >zsyscall_solaris_$GOARCH.go";
Don Newton98fd8812019-09-23 15:15:02 -0400222 else
223 echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go";
224 fi
225 fi
226 esac
227 if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi
228 if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
Don Newton7577f072020-01-06 12:41:11 -0500229 if [ -n "$mktypes" ]; then echo "$mktypes types_$GOOS.go | go run mkpost.go > ztypes_$GOOSARCH.go"; fi
Don Newton98fd8812019-09-23 15:15:02 -0400230 if [ -n "$mkasm" ]; then echo "$mkasm $GOARCH"; fi
Don Newton98fd8812019-09-23 15:15:02 -0400231) | $run