blob: 396aadf86de729ea230b7bc2d1f3c675c80a3fbe [file] [log] [blame]
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001#!/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. Bainbridgec415efe2021-08-19 13:05:21 +000053 $cmd docker run --interactive --tty --volume $(cd -- "$(dirname -- "$0")" && /bin/pwd):/build generate:$GOOS
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070054 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 ;;
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070073darwin_amd64)
74 mkerrors="$mkerrors -m64"
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070075 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
76 mkasm="go run mkasm_darwin.go"
77 ;;
78darwin_arm64)
79 mkerrors="$mkerrors -m64"
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070080 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"
David K. Bainbridgec415efe2021-08-19 13:05:21 +000092 mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070093 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
94 ;;
95freebsd_amd64)
96 mkerrors="$mkerrors -m64"
David K. Bainbridgec415efe2021-08-19 13:05:21 +000097 mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070098 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
99 ;;
100freebsd_arm)
101 mkerrors="$mkerrors"
102 mksyscall="go run mksyscall.go -l32 -arm"
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000103 mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700104 # 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"
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000110 mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
111 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700112 ;;
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 ;;
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000133netbsd_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 ;;
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700139openbsd_386)
140 mkerrors="$mkerrors -m32"
141 mksyscall="go run mksyscall.go -l32 -openbsd"
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000142 mksysctl="go run mksysctl_openbsd.go"
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700143 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"
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000149 mksysctl="go run mksysctl_openbsd.go"
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700150 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"
David K. Bainbridgec415efe2021-08-19 13:05:21 +0000156 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"
166 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 ;;
171openbsd_mips64)
172 mkerrors="$mkerrors -m64"
173 mksyscall="go run mksyscall.go -openbsd"
174 mksysctl="go run mksysctl_openbsd.go"
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700175 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 ;;
180solaris_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. Bainbridgec415efe2021-08-19 13:05:21 +0000186illumos_amd64)
187 mksyscall="go run mksyscall_solaris.go"
188 mkerrors=
189 mksysnum=
190 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
191 ;;
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700192*)
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
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700213 # 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. Bainbridgec415efe2021-08-19 13:05:21 +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";
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -0700222 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
229 if [ -n "$mktypes" ]; then echo "$mktypes types_$GOOS.go | go run mkpost.go > ztypes_$GOOSARCH.go"; fi
230 if [ -n "$mkasm" ]; then echo "$mkasm $GOARCH"; fi
231) | $run