mkall.sh 6.1 KB

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