1 #!/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
10 GOOSARCH="${GOOS}_${GOARCH}"
11
12 # defaults
13 mksyscall="go run mksyscall.go"
14 mkerrors="./mkerrors.sh"
15 zerrors="zerrors_$GOOSARCH.go"
16 mksysctl=""
17 zsysctl="zsysctl_$GOOSARCH.go"
18 mksysnum=
19 mktypes=
20 mkasm=
21 run="sh"
22 cmd=""
23
24 case "$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
39 esac
40
41 case "$#" in
42 0)
43 ;;
44 *)
45 echo 'usage: mkall.sh [-n]' 1>&2
46 exit 2
47 esac
48
49 if [[ "$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
53 $cmd docker run --interactive --tty --volume $(cd -- "$(dirname -- "$0")/.." && /bin/pwd):/build generate:$GOOS
54 exit
55 fi
56
57 GOOSARCH_in=syscall_$GOOSARCH.go
58 case "$GOOSARCH" in
59 _* | *_ | _)
60 echo 'undefined $GOOS_$GOARCH:' "$GOOSARCH" 1>&2
61 exit 1
62 ;;
63 aix_ppc)
64 mkerrors="$mkerrors -maix32"
65 mksyscall="go run mksyscall_aix_ppc.go -aix"
66 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
67 ;;
68 aix_ppc64)
69 mkerrors="$mkerrors -maix64"
70 mksyscall="go run mksyscall_aix_ppc64.go -aix"
71 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
72 ;;
73 darwin_amd64)
74 mkerrors="$mkerrors -m64"
75 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
76 mkasm="go run mkasm_darwin.go"
77 ;;
78 darwin_arm64)
79 mkerrors="$mkerrors -m64"
80 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
81 mkasm="go run mkasm_darwin.go"
82 ;;
83 dragonfly_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 ;;
89 freebsd_386)
90 mkerrors="$mkerrors -m32"
91 mksyscall="go run mksyscall.go -l32"
92 mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
93 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
94 ;;
95 freebsd_amd64)
96 mkerrors="$mkerrors -m64"
97 mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
98 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
99 ;;
100 freebsd_arm)
101 mkerrors="$mkerrors"
102 mksyscall="go run mksyscall.go -l32 -arm"
103 mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
104 # 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 ;;
108 freebsd_arm64)
109 mkerrors="$mkerrors -m64"
110 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"
112 ;;
113 netbsd_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 ;;
119 netbsd_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 ;;
125 netbsd_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 ;;
133 netbsd_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 ;;
139 openbsd_386)
140 mkerrors="$mkerrors -m32"
141 mksyscall="go run mksyscall.go -l32 -openbsd"
142 mksysctl="go run mksysctl_openbsd.go"
143 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 ;;
146 openbsd_amd64)
147 mkerrors="$mkerrors -m64"
148 mksyscall="go run mksyscall.go -openbsd"
149 mksysctl="go run mksysctl_openbsd.go"
150 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 ;;
153 openbsd_arm)
154 mkerrors="$mkerrors"
155 mksyscall="go run mksyscall.go -l32 -openbsd -arm"
156 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 ;;
162 openbsd_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 ;;
171 openbsd_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 ;;
180 solaris_amd64)
181 mksyscall="go run mksyscall_solaris.go"
182 mkerrors="$mkerrors -m64"
183 mksysnum=
184 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
185 ;;
186 illumos_amd64)
187 mksyscall="go run mksyscall_solaris.go"
188 mkerrors=
189 mksysnum=
190 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
191 ;;
192 *)
193 echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
194 exit 1
195 ;;
196 esac
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
213 # 1.12 and later, syscalls via libSystem
214 echo "$mksyscall -tags $GOOS,$GOARCH,go1.12 $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go";
215 # 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";
222 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
232
View as plain text