blob: 1e5c59d0dd2ea32766ae526c644edc9d1a4d56b0 [file] [log] [blame]
Scott Bakere7144bc2019-10-01 14:16:47 -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
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/10/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/10/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/10/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/10/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 ;;
149openbsd_386)
150 mkerrors="$mkerrors -m32"
151 mksyscall="go run mksyscall.go -l32 -openbsd"
152 mksysctl="./mksysctl_openbsd.pl"
153 mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
154 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
155 ;;
156openbsd_amd64)
157 mkerrors="$mkerrors -m64"
158 mksyscall="go run mksyscall.go -openbsd"
159 mksysctl="./mksysctl_openbsd.pl"
160 mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
161 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
162 ;;
163openbsd_arm)
164 mkerrors="$mkerrors"
165 mksyscall="go run mksyscall.go -l32 -openbsd -arm"
166 mksysctl="./mksysctl_openbsd.pl"
167 mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
168 # Let the type of C char be signed for making the bare syscall
169 # API consistent across platforms.
170 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
171 ;;
172solaris_amd64)
173 mksyscall="go run mksyscall_solaris.go"
174 mkerrors="$mkerrors -m64"
175 mksysnum=
176 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
177 ;;
178*)
179 echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
180 exit 1
181 ;;
182esac
183
184(
185 if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi
186 case "$GOOS" in
187 *)
188 syscall_goos="syscall_$GOOS.go"
189 case "$GOOS" in
190 darwin | dragonfly | freebsd | netbsd | openbsd)
191 syscall_goos="syscall_bsd.go $syscall_goos"
192 ;;
193 esac
194 if [ -n "$mksyscall" ]; then
195 if [ "$GOOSARCH" == "aix_ppc64" ]; then
196 # aix/ppc64 script generates files instead of writing to stdin.
197 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 " ;
198 elif [ "$GOOS" == "darwin" ]; then
199 # pre-1.12, direct syscalls
200 echo "$mksyscall -tags $GOOS,$GOARCH,!go1.12 $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.1_11.go";
201 # 1.12 and later, syscalls via libSystem
202 echo "$mksyscall -tags $GOOS,$GOARCH,go1.12 $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go";
203 else
204 echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go";
205 fi
206 fi
207 esac
208 if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi
209 if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
210 if [ -n "$mktypes" ]; then echo "$mktypes types_$GOOS.go | go run mkpost.go > ztypes_$GOOSARCH.go"; fi
211 if [ -n "$mkasm" ]; then echo "$mkasm $GOARCH"; fi
212) | $run