blob: c3a08092687e6ece249ba67d901871ebb8ea03a1 [file] [log] [blame]
David K. Bainbridge215e0242017-09-05 23:18:24 -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="./mksyscall.pl"
14mkerrors="./mkerrors.sh"
15zerrors="zerrors_$GOOSARCH.go"
16mksysctl=""
17zsysctl="zsysctl_$GOOSARCH.go"
18mksysnum=
19mktypes=
20run="sh"
21cmd=""
22
23case "$1" in
24-syscalls)
25 for i in zsyscall*go
26 do
27 # Run the command line that appears in the first line
28 # of the generated file to regenerate it.
29 sed 1q $i | sed 's;^// ;;' | sh > _$i && gofmt < _$i > $i
30 rm _$i
31 done
32 exit 0
33 ;;
34-n)
35 run="cat"
36 cmd="echo"
37 shift
38esac
39
40case "$#" in
410)
42 ;;
43*)
44 echo 'usage: mkall.sh [-n]' 1>&2
45 exit 2
46esac
47
48if [[ "$GOOS" = "linux" ]] && [[ "$GOARCH" != "sparc64" ]]; then
49 # Use then new build system
50 # Files generated through docker (use $cmd so you can Ctl-C the build or run)
51 $cmd docker build --tag generate:$GOOS $GOOS
52 $cmd docker run --interactive --tty --volume $(dirname "$(readlink -f "$0")"):/build generate:$GOOS
53 exit
54fi
55
56GOOSARCH_in=syscall_$GOOSARCH.go
57case "$GOOSARCH" in
58_* | *_ | _)
59 echo 'undefined $GOOS_$GOARCH:' "$GOOSARCH" 1>&2
60 exit 1
61 ;;
62darwin_386)
63 mkerrors="$mkerrors -m32"
64 mksyscall="./mksyscall.pl -l32"
65 mksysnum="./mksysnum_darwin.pl $(xcrun --show-sdk-path --sdk macosx)/usr/include/sys/syscall.h"
66 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
67 ;;
68darwin_amd64)
69 mkerrors="$mkerrors -m64"
70 mksysnum="./mksysnum_darwin.pl $(xcrun --show-sdk-path --sdk macosx)/usr/include/sys/syscall.h"
71 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
72 ;;
73darwin_arm)
74 mkerrors="$mkerrors"
75 mksysnum="./mksysnum_darwin.pl $(xcrun --show-sdk-path --sdk iphoneos)/usr/include/sys/syscall.h"
76 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
77 ;;
78darwin_arm64)
79 mkerrors="$mkerrors -m64"
80 mksysnum="./mksysnum_darwin.pl $(xcrun --show-sdk-path --sdk iphoneos)/usr/include/sys/syscall.h"
81 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
82 ;;
83dragonfly_386)
84 mkerrors="$mkerrors -m32"
85 mksyscall="./mksyscall.pl -l32 -dragonfly"
86 mksysnum="curl -s 'http://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/sys/kern/syscalls.master' | ./mksysnum_dragonfly.pl"
87 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
88 ;;
89dragonfly_amd64)
90 mkerrors="$mkerrors -m64"
91 mksyscall="./mksyscall.pl -dragonfly"
92 mksysnum="curl -s 'http://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/sys/kern/syscalls.master' | ./mksysnum_dragonfly.pl"
93 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
94 ;;
95freebsd_386)
96 mkerrors="$mkerrors -m32"
97 mksyscall="./mksyscall.pl -l32"
98 mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
99 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
100 ;;
101freebsd_amd64)
102 mkerrors="$mkerrors -m64"
103 mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
104 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
105 ;;
106freebsd_arm)
107 mkerrors="$mkerrors"
108 mksyscall="./mksyscall.pl -l32 -arm"
109 mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
110 # Let the type of C char be signed for making the bare syscall
111 # API consistent across platforms.
112 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
113 ;;
114linux_sparc64)
115 GOOSARCH_in=syscall_linux_sparc64.go
116 unistd_h=/usr/include/sparc64-linux-gnu/asm/unistd.h
117 mkerrors="$mkerrors -m64"
118 mksysnum="./mksysnum_linux.pl $unistd_h"
119 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
120 ;;
121netbsd_386)
122 mkerrors="$mkerrors -m32"
123 mksyscall="./mksyscall.pl -l32 -netbsd"
124 mksysnum="curl -s 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_netbsd.pl"
125 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
126 ;;
127netbsd_amd64)
128 mkerrors="$mkerrors -m64"
129 mksyscall="./mksyscall.pl -netbsd"
130 mksysnum="curl -s 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_netbsd.pl"
131 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
132 ;;
133netbsd_arm)
134 mkerrors="$mkerrors"
135 mksyscall="./mksyscall.pl -l32 -netbsd -arm"
136 mksysnum="curl -s 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_netbsd.pl"
137 # Let the type of C char be signed for making the bare syscall
138 # API consistent across platforms.
139 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
140 ;;
141openbsd_386)
142 mkerrors="$mkerrors -m32"
143 mksyscall="./mksyscall.pl -l32 -openbsd"
144 mksysctl="./mksysctl_openbsd.pl"
145 zsysctl="zsysctl_openbsd.go"
146 mksysnum="curl -s 'http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl"
147 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
148 ;;
149openbsd_amd64)
150 mkerrors="$mkerrors -m64"
151 mksyscall="./mksyscall.pl -openbsd"
152 mksysctl="./mksysctl_openbsd.pl"
153 zsysctl="zsysctl_openbsd.go"
154 mksysnum="curl -s 'http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl"
155 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
156 ;;
157openbsd_arm)
158 mkerrors="$mkerrors"
159 mksyscall="./mksyscall.pl -l32 -openbsd -arm"
160 mksysctl="./mksysctl_openbsd.pl"
161 zsysctl="zsysctl_openbsd.go"
162 mksysnum="curl -s 'http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl"
163 # Let the type of C char be signed for making the bare syscall
164 # API consistent across platforms.
165 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
166 ;;
167solaris_amd64)
168 mksyscall="./mksyscall_solaris.pl"
169 mkerrors="$mkerrors -m64"
170 mksysnum=
171 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
172 ;;
173*)
174 echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
175 exit 1
176 ;;
177esac
178
179(
180 if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi
181 case "$GOOS" in
182 *)
183 syscall_goos="syscall_$GOOS.go"
184 case "$GOOS" in
185 darwin | dragonfly | freebsd | netbsd | openbsd)
186 syscall_goos="syscall_bsd.go $syscall_goos"
187 ;;
188 esac
189 if [ -n "$mksyscall" ]; then echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go"; fi
190 ;;
191 esac
192 if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi
193 if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
194 if [ -n "$mktypes" ]; then
195 echo "$mktypes types_$GOOS.go | go run mkpost.go > ztypes_$GOOSARCH.go";
196 fi
197) | $run