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
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_amd64)
84 mkerrors="$mkerrors -m64"
85 mksyscall="./mksyscall.pl -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 ;;
89freebsd_386)
90 mkerrors="$mkerrors -m32"
91 mksyscall="./mksyscall.pl -l32"
92 mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
93 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
94 ;;
95freebsd_amd64)
96 mkerrors="$mkerrors -m64"
97 mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
98 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
99 ;;
100freebsd_arm)
101 mkerrors="$mkerrors"
102 mksyscall="./mksyscall.pl -l32 -arm"
103 mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
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 ;;
108linux_sparc64)
109 GOOSARCH_in=syscall_linux_sparc64.go
110 unistd_h=/usr/include/sparc64-linux-gnu/asm/unistd.h
111 mkerrors="$mkerrors -m64"
112 mksysnum="./mksysnum_linux.pl $unistd_h"
113 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
114 ;;
115netbsd_386)
116 mkerrors="$mkerrors -m32"
117 mksyscall="./mksyscall.pl -l32 -netbsd"
118 mksysnum="curl -s 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_netbsd.pl"
119 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
120 ;;
121netbsd_amd64)
122 mkerrors="$mkerrors -m64"
123 mksyscall="./mksyscall.pl -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_arm)
128 mkerrors="$mkerrors"
129 mksyscall="./mksyscall.pl -l32 -netbsd -arm"
130 mksysnum="curl -s 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_netbsd.pl"
131 # Let the type of C char be signed for making the bare syscall
132 # API consistent across platforms.
133 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
134 ;;
135openbsd_386)
136 mkerrors="$mkerrors -m32"
137 mksyscall="./mksyscall.pl -l32 -openbsd"
138 mksysctl="./mksysctl_openbsd.pl"
139 mksysnum="curl -s 'http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl"
140 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
141 ;;
142openbsd_amd64)
143 mkerrors="$mkerrors -m64"
144 mksyscall="./mksyscall.pl -openbsd"
145 mksysctl="./mksysctl_openbsd.pl"
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_arm)
150 mkerrors="$mkerrors"
151 mksyscall="./mksyscall.pl -l32 -openbsd -arm"
152 mksysctl="./mksysctl_openbsd.pl"
153 mksysnum="curl -s 'http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl"
154 # Let the type of C char be signed for making the bare syscall
155 # API consistent across platforms.
156 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
157 ;;
158solaris_amd64)
159 mksyscall="./mksyscall_solaris.pl"
160 mkerrors="$mkerrors -m64"
161 mksysnum=
162 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
163 ;;
164*)
165 echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
166 exit 1
167 ;;
168esac
169
170(
171 if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi
172 case "$GOOS" in
173 *)
174 syscall_goos="syscall_$GOOS.go"
175 case "$GOOS" in
176 darwin | dragonfly | freebsd | netbsd | openbsd)
177 syscall_goos="syscall_bsd.go $syscall_goos"
178 ;;
179 esac
180 if [ -n "$mksyscall" ]; then echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go"; fi
181 ;;
182 esac
183 if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi
184 if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
185 if [ -n "$mktypes" ]; then
186 echo "$mktypes types_$GOOS.go | go run mkpost.go > ztypes_$GOOSARCH.go";
187 fi
188) | $run