blob: d257fac50576ea59348ee5213f72faa0535b0fbd [file] [log] [blame]
Holger Hildebrandtfa074992020-03-27 15:42:06 +00001#!/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
53 $cmd docker run --interactive --tty --volume $(cd -- "$(dirname -- "$0")" && /bin/pwd):/build generate:$GOOS
54 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 ;;
73darwin_386)
74 mkerrors="$mkerrors -m32"
75 mksyscall="go run mksyscall.go -l32"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000076 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
77 mkasm="go run mkasm_darwin.go"
78 ;;
79darwin_amd64)
80 mkerrors="$mkerrors -m64"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000081 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
82 mkasm="go run mkasm_darwin.go"
83 ;;
84darwin_arm)
85 mkerrors="$mkerrors"
86 mksyscall="go run mksyscall.go -l32"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000087 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
88 mkasm="go run mkasm_darwin.go"
89 ;;
90darwin_arm64)
91 mkerrors="$mkerrors -m64"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000092 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
93 mkasm="go run mkasm_darwin.go"
94 ;;
95dragonfly_amd64)
96 mkerrors="$mkerrors -m64"
97 mksyscall="go run mksyscall.go -dragonfly"
98 mksysnum="go run mksysnum.go 'https://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/sys/kern/syscalls.master'"
99 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
100 ;;
101freebsd_386)
102 mkerrors="$mkerrors -m32"
103 mksyscall="go run mksyscall.go -l32"
104 mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
105 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
106 ;;
107freebsd_amd64)
108 mkerrors="$mkerrors -m64"
109 mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
110 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
111 ;;
112freebsd_arm)
113 mkerrors="$mkerrors"
114 mksyscall="go run mksyscall.go -l32 -arm"
115 mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
116 # Let the type of C char be signed for making the bare syscall
117 # API consistent across platforms.
118 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
119 ;;
120freebsd_arm64)
121 mkerrors="$mkerrors -m64"
122 mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
Andrea Campanellaaec20bd2021-02-25 12:41:34 +0100123 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000124 ;;
125netbsd_386)
126 mkerrors="$mkerrors -m32"
127 mksyscall="go run mksyscall.go -l32 -netbsd"
128 mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
129 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
130 ;;
131netbsd_amd64)
132 mkerrors="$mkerrors -m64"
133 mksyscall="go run mksyscall.go -netbsd"
134 mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
135 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
136 ;;
137netbsd_arm)
138 mkerrors="$mkerrors"
139 mksyscall="go run mksyscall.go -l32 -netbsd -arm"
140 mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
141 # Let the type of C char be signed for making the bare syscall
142 # API consistent across platforms.
143 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
144 ;;
145netbsd_arm64)
146 mkerrors="$mkerrors -m64"
147 mksyscall="go run mksyscall.go -netbsd"
148 mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
149 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
150 ;;
151openbsd_386)
152 mkerrors="$mkerrors -m32"
153 mksyscall="go run mksyscall.go -l32 -openbsd"
154 mksysctl="go run mksysctl_openbsd.go"
155 mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
156 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
157 ;;
158openbsd_amd64)
159 mkerrors="$mkerrors -m64"
160 mksyscall="go run mksyscall.go -openbsd"
161 mksysctl="go run mksysctl_openbsd.go"
162 mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
163 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
164 ;;
165openbsd_arm)
166 mkerrors="$mkerrors"
167 mksyscall="go run mksyscall.go -l32 -openbsd -arm"
168 mksysctl="go run mksysctl_openbsd.go"
169 mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
170 # Let the type of C char be signed for making the bare syscall
171 # API consistent across platforms.
172 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
173 ;;
174openbsd_arm64)
175 mkerrors="$mkerrors -m64"
176 mksyscall="go run mksyscall.go -openbsd"
177 mksysctl="go run mksysctl_openbsd.go"
178 mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
179 # Let the type of C char be signed for making the bare syscall
180 # API consistent across platforms.
181 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
182 ;;
Andrea Campanellaaec20bd2021-02-25 12:41:34 +0100183openbsd_mips64)
184 mkerrors="$mkerrors -m64"
185 mksyscall="go run mksyscall.go -openbsd"
186 mksysctl="go run mksysctl_openbsd.go"
187 mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
188 # Let the type of C char be signed for making the bare syscall
189 # API consistent across platforms.
190 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
191 ;;
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000192solaris_amd64)
193 mksyscall="go run mksyscall_solaris.go"
194 mkerrors="$mkerrors -m64"
195 mksysnum=
196 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
197 ;;
Andrea Campanellaaec20bd2021-02-25 12:41:34 +0100198illumos_amd64)
199 mksyscall="go run mksyscall_solaris.go"
200 mkerrors=
201 mksysnum=
202 mktypes=
203 ;;
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000204*)
205 echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
206 exit 1
207 ;;
208esac
209
210(
211 if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi
212 case "$GOOS" in
213 *)
214 syscall_goos="syscall_$GOOS.go"
215 case "$GOOS" in
216 darwin | dragonfly | freebsd | netbsd | openbsd)
217 syscall_goos="syscall_bsd.go $syscall_goos"
218 ;;
219 esac
220 if [ -n "$mksyscall" ]; then
221 if [ "$GOOSARCH" == "aix_ppc64" ]; then
222 # aix/ppc64 script generates files instead of writing to stdin.
223 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 " ;
224 elif [ "$GOOS" == "darwin" ]; then
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000225 # 1.12 and later, syscalls via libSystem
226 echo "$mksyscall -tags $GOOS,$GOARCH,go1.12 $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go";
227 # 1.13 and later, syscalls via libSystem (including syscallPtr)
228 echo "$mksyscall -tags $GOOS,$GOARCH,go1.13 syscall_darwin.1_13.go |gofmt >zsyscall_$GOOSARCH.1_13.go";
Andrea Campanellaaec20bd2021-02-25 12:41:34 +0100229 elif [ "$GOOS" == "illumos" ]; then
230 # illumos code generation requires a --illumos switch
231 echo "$mksyscall -illumos -tags illumos,$GOARCH syscall_illumos.go |gofmt > zsyscall_illumos_$GOARCH.go";
232 # illumos implies solaris, so solaris code generation is also required
233 echo "$mksyscall -tags solaris,$GOARCH syscall_solaris.go syscall_solaris_$GOARCH.go |gofmt >zsyscall_solaris_$GOARCH.go";
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000234 else
235 echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go";
236 fi
237 fi
238 esac
239 if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi
240 if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
241 if [ -n "$mktypes" ]; then echo "$mktypes types_$GOOS.go | go run mkpost.go > ztypes_$GOOSARCH.go"; fi
242 if [ -n "$mkasm" ]; then echo "$mkasm $GOARCH"; fi
243) | $run