Matteo Scandolo | 1f49bf5 | 2018-11-20 13:56:45 -0800 | [diff] [blame] | 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 | |
| 10 | GOOSARCH="${GOOS}_${GOARCH}" |
| 11 | |
| 12 | # defaults |
| 13 | mksyscall="./mksyscall.pl" |
| 14 | mkerrors="./mkerrors.sh" |
| 15 | zerrors="zerrors_$GOOSARCH.go" |
| 16 | mksysctl="" |
| 17 | zsysctl="zsysctl_$GOOSARCH.go" |
| 18 | mksysnum= |
| 19 | mktypes= |
| 20 | run="sh" |
| 21 | cmd="" |
| 22 | |
| 23 | case "$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 |
| 38 | esac |
| 39 | |
| 40 | case "$#" in |
| 41 | 0) |
| 42 | ;; |
| 43 | *) |
| 44 | echo 'usage: mkall.sh [-n]' 1>&2 |
| 45 | exit 2 |
| 46 | esac |
| 47 | |
| 48 | if [[ "$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 |
| 54 | fi |
| 55 | |
| 56 | GOOSARCH_in=syscall_$GOOSARCH.go |
| 57 | case "$GOOSARCH" in |
| 58 | _* | *_ | _) |
| 59 | echo 'undefined $GOOS_$GOARCH:' "$GOOSARCH" 1>&2 |
| 60 | exit 1 |
| 61 | ;; |
| 62 | aix_ppc) |
| 63 | mkerrors="$mkerrors -maix32" |
| 64 | mksyscall="./mksyscall_aix_ppc.pl -aix" |
| 65 | mktypes="GOARCH=$GOARCH go tool cgo -godefs" |
| 66 | ;; |
| 67 | aix_ppc64) |
| 68 | mkerrors="$mkerrors -maix64" |
| 69 | mksyscall="./mksyscall_aix_ppc64.pl -aix" |
| 70 | mktypes="GOARCH=$GOARCH go tool cgo -godefs" |
| 71 | ;; |
| 72 | darwin_386) |
| 73 | mkerrors="$mkerrors -m32" |
| 74 | mksyscall="./mksyscall.pl -l32" |
| 75 | mksysnum="./mksysnum_darwin.pl $(xcrun --show-sdk-path --sdk macosx)/usr/include/sys/syscall.h" |
| 76 | mktypes="GOARCH=$GOARCH go tool cgo -godefs" |
| 77 | ;; |
| 78 | darwin_amd64) |
| 79 | mkerrors="$mkerrors -m64" |
| 80 | mksysnum="./mksysnum_darwin.pl $(xcrun --show-sdk-path --sdk macosx)/usr/include/sys/syscall.h" |
| 81 | mktypes="GOARCH=$GOARCH go tool cgo -godefs" |
| 82 | ;; |
| 83 | darwin_arm) |
| 84 | mkerrors="$mkerrors" |
| 85 | mksysnum="./mksysnum_darwin.pl $(xcrun --show-sdk-path --sdk iphoneos)/usr/include/sys/syscall.h" |
| 86 | mktypes="GOARCH=$GOARCH go tool cgo -godefs" |
| 87 | ;; |
| 88 | darwin_arm64) |
| 89 | mkerrors="$mkerrors -m64" |
| 90 | mksysnum="./mksysnum_darwin.pl $(xcrun --show-sdk-path --sdk iphoneos)/usr/include/sys/syscall.h" |
| 91 | mktypes="GOARCH=$GOARCH go tool cgo -godefs" |
| 92 | ;; |
| 93 | dragonfly_amd64) |
| 94 | mkerrors="$mkerrors -m64" |
| 95 | mksyscall="./mksyscall.pl -dragonfly" |
| 96 | mksysnum="curl -s 'http://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/sys/kern/syscalls.master' | ./mksysnum_dragonfly.pl" |
| 97 | mktypes="GOARCH=$GOARCH go tool cgo -godefs" |
| 98 | ;; |
| 99 | freebsd_386) |
| 100 | mkerrors="$mkerrors -m32" |
| 101 | mksyscall="./mksyscall.pl -l32" |
| 102 | mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl" |
| 103 | mktypes="GOARCH=$GOARCH go tool cgo -godefs" |
| 104 | ;; |
| 105 | freebsd_amd64) |
| 106 | mkerrors="$mkerrors -m64" |
| 107 | mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl" |
| 108 | mktypes="GOARCH=$GOARCH go tool cgo -godefs" |
| 109 | ;; |
| 110 | freebsd_arm) |
| 111 | mkerrors="$mkerrors" |
| 112 | mksyscall="./mksyscall.pl -l32 -arm" |
| 113 | mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl" |
| 114 | # Let the type of C char be signed for making the bare syscall |
| 115 | # API consistent across platforms. |
| 116 | mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char" |
| 117 | ;; |
| 118 | linux_sparc64) |
| 119 | GOOSARCH_in=syscall_linux_sparc64.go |
| 120 | unistd_h=/usr/include/sparc64-linux-gnu/asm/unistd.h |
| 121 | mkerrors="$mkerrors -m64" |
| 122 | mksysnum="./mksysnum_linux.pl $unistd_h" |
| 123 | mktypes="GOARCH=$GOARCH go tool cgo -godefs" |
| 124 | ;; |
| 125 | netbsd_386) |
| 126 | mkerrors="$mkerrors -m32" |
| 127 | mksyscall="./mksyscall.pl -l32 -netbsd" |
| 128 | mksysnum="curl -s 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_netbsd.pl" |
| 129 | mktypes="GOARCH=$GOARCH go tool cgo -godefs" |
| 130 | ;; |
| 131 | netbsd_amd64) |
| 132 | mkerrors="$mkerrors -m64" |
| 133 | mksyscall="./mksyscall.pl -netbsd" |
| 134 | mksysnum="curl -s 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_netbsd.pl" |
| 135 | mktypes="GOARCH=$GOARCH go tool cgo -godefs" |
| 136 | ;; |
| 137 | netbsd_arm) |
| 138 | mkerrors="$mkerrors" |
| 139 | mksyscall="./mksyscall.pl -l32 -netbsd -arm" |
| 140 | mksysnum="curl -s 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_netbsd.pl" |
| 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 | ;; |
| 145 | openbsd_386) |
| 146 | mkerrors="$mkerrors -m32" |
| 147 | mksyscall="./mksyscall.pl -l32 -openbsd" |
| 148 | mksysctl="./mksysctl_openbsd.pl" |
| 149 | mksysnum="curl -s 'http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl" |
| 150 | mktypes="GOARCH=$GOARCH go tool cgo -godefs" |
| 151 | ;; |
| 152 | openbsd_amd64) |
| 153 | mkerrors="$mkerrors -m64" |
| 154 | mksyscall="./mksyscall.pl -openbsd" |
| 155 | mksysctl="./mksysctl_openbsd.pl" |
| 156 | mksysnum="curl -s 'http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl" |
| 157 | mktypes="GOARCH=$GOARCH go tool cgo -godefs" |
| 158 | ;; |
| 159 | openbsd_arm) |
| 160 | mkerrors="$mkerrors" |
| 161 | mksyscall="./mksyscall.pl -l32 -openbsd -arm" |
| 162 | mksysctl="./mksysctl_openbsd.pl" |
| 163 | mksysnum="curl -s 'http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl" |
| 164 | # Let the type of C char be signed for making the bare syscall |
| 165 | # API consistent across platforms. |
| 166 | mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char" |
| 167 | ;; |
| 168 | solaris_amd64) |
| 169 | mksyscall="./mksyscall_solaris.pl" |
| 170 | mkerrors="$mkerrors -m64" |
| 171 | mksysnum= |
| 172 | mktypes="GOARCH=$GOARCH go tool cgo -godefs" |
| 173 | ;; |
| 174 | *) |
| 175 | echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2 |
| 176 | exit 1 |
| 177 | ;; |
| 178 | esac |
| 179 | |
| 180 | ( |
| 181 | if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi |
| 182 | case "$GOOS" in |
| 183 | *) |
| 184 | syscall_goos="syscall_$GOOS.go" |
| 185 | case "$GOOS" in |
| 186 | darwin | dragonfly | freebsd | netbsd | openbsd) |
| 187 | syscall_goos="syscall_bsd.go $syscall_goos" |
| 188 | ;; |
| 189 | esac |
| 190 | if [ -n "$mksyscall" ]; then |
| 191 | if [ "$GOOSARCH" == "aix_ppc64" ]; then |
| 192 | # aix/ppc64 script generates files instead of writing to stdin. |
| 193 | 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 " ; |
| 194 | else |
| 195 | echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go"; |
| 196 | fi |
| 197 | fi |
| 198 | esac |
| 199 | if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi |
| 200 | if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi |
| 201 | if [ -n "$mktypes" ]; then |
| 202 | echo "$mktypes types_$GOOS.go | go run mkpost.go > ztypes_$GOOSARCH.go"; |
| 203 | fi |
| 204 | ) | $run |