blob: 5a22eca96761284a760ad2d3648a0a659ef9e3c2 [file] [log] [blame]
onkarkundargi72cfd362020-02-27 12:34:37 +05301#!/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 $(dirname "$(readlink -f "$0")"):/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"
76 mksysnum="go run mksysnum.go $(xcrun --show-sdk-path --sdk macosx)/usr/include/sys/syscall.h"
77 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
78 mkasm="go run mkasm_darwin.go"
79 ;;
80darwin_amd64)
81 mkerrors="$mkerrors -m64"
82 mksysnum="go run mksysnum.go $(xcrun --show-sdk-path --sdk macosx)/usr/include/sys/syscall.h"
83 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
84 mkasm="go run mkasm_darwin.go"
85 ;;
86darwin_arm)
87 mkerrors="$mkerrors"
88 mksyscall="go run mksyscall.go -l32"
89 mksysnum="go run mksysnum.go $(xcrun --show-sdk-path --sdk iphoneos)/usr/include/sys/syscall.h"
90 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
91 mkasm="go run mkasm_darwin.go"
92 ;;
93darwin_arm64)
94 mkerrors="$mkerrors -m64"
95 mksysnum="go run mksysnum.go $(xcrun --show-sdk-path --sdk iphoneos)/usr/include/sys/syscall.h"
96 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
97 mkasm="go run mkasm_darwin.go"
98 ;;
99dragonfly_amd64)
100 mkerrors="$mkerrors -m64"
101 mksyscall="go run mksyscall.go -dragonfly"
102 mksysnum="go run mksysnum.go 'https://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/sys/kern/syscalls.master'"
103 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
104 ;;
105freebsd_386)
106 mkerrors="$mkerrors -m32"
107 mksyscall="go run mksyscall.go -l32"
108 mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
109 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
110 ;;
111freebsd_amd64)
112 mkerrors="$mkerrors -m64"
113 mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
114 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
115 ;;
116freebsd_arm)
117 mkerrors="$mkerrors"
118 mksyscall="go run mksyscall.go -l32 -arm"
119 mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
120 # Let the type of C char be signed for making the bare syscall
121 # API consistent across platforms.
122 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
123 ;;
124freebsd_arm64)
125 mkerrors="$mkerrors -m64"
126 mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
127 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
128 ;;
129netbsd_386)
130 mkerrors="$mkerrors -m32"
131 mksyscall="go run mksyscall.go -l32 -netbsd"
132 mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
133 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
134 ;;
135netbsd_amd64)
136 mkerrors="$mkerrors -m64"
137 mksyscall="go run mksyscall.go -netbsd"
138 mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
139 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
140 ;;
141netbsd_arm)
142 mkerrors="$mkerrors"
143 mksyscall="go run mksyscall.go -l32 -netbsd -arm"
144 mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
145 # Let the type of C char be signed for making the bare syscall
146 # API consistent across platforms.
147 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
148 ;;
149netbsd_arm64)
150 mkerrors="$mkerrors -m64"
151 mksyscall="go run mksyscall.go -netbsd"
152 mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
153 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
154 ;;
155openbsd_386)
156 mkerrors="$mkerrors -m32"
157 mksyscall="go run mksyscall.go -l32 -openbsd"
158 mksysctl="go run mksysctl_openbsd.go"
159 mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
160 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
161 ;;
162openbsd_amd64)
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 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
168 ;;
169openbsd_arm)
170 mkerrors="$mkerrors"
171 mksyscall="go run mksyscall.go -l32 -openbsd -arm"
172 mksysctl="go run mksysctl_openbsd.go"
173 mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
174 # Let the type of C char be signed for making the bare syscall
175 # API consistent across platforms.
176 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
177 ;;
178openbsd_arm64)
179 mkerrors="$mkerrors -m64"
180 mksyscall="go run mksyscall.go -openbsd"
181 mksysctl="go run mksysctl_openbsd.go"
182 mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
183 # Let the type of C char be signed for making the bare syscall
184 # API consistent across platforms.
185 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
186 ;;
187solaris_amd64)
188 mksyscall="go run mksyscall_solaris.go"
189 mkerrors="$mkerrors -m64"
190 mksysnum=
191 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
192 ;;
193*)
194 echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
195 exit 1
196 ;;
197esac
198
199(
200 if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi
201 case "$GOOS" in
202 *)
203 syscall_goos="syscall_$GOOS.go"
204 case "$GOOS" in
205 darwin | dragonfly | freebsd | netbsd | openbsd)
206 syscall_goos="syscall_bsd.go $syscall_goos"
207 ;;
208 esac
209 if [ -n "$mksyscall" ]; then
210 if [ "$GOOSARCH" == "aix_ppc64" ]; then
211 # aix/ppc64 script generates files instead of writing to stdin.
212 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 " ;
213 elif [ "$GOOS" == "darwin" ]; then
214 # pre-1.12, direct syscalls
215 echo "$mksyscall -tags $GOOS,$GOARCH,!go1.12 $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.1_11.go";
216 # 1.12 and later, syscalls via libSystem
217 echo "$mksyscall -tags $GOOS,$GOARCH,go1.12 $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go";
218 else
219 echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go";
220 fi
221 fi
222 esac
223 if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi
224 if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
225 if [ -n "$mktypes" ]; then echo "$mktypes types_$GOOS.go | go run mkpost.go > ztypes_$GOOSARCH.go"; fi
226 if [ -n "$mkasm" ]; then echo "$mkasm $GOARCH"; fi
227) | $run