本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

228 lines
7.7KB

  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="go run mksyscall.go"
  11. mkerrors="./mkerrors.sh"
  12. zerrors="zerrors_$GOOSARCH.go"
  13. mksysctl=""
  14. zsysctl="zsysctl_$GOOSARCH.go"
  15. mksysnum=
  16. mktypes=
  17. mkasm=
  18. run="sh"
  19. cmd=""
  20. case "$1" in
  21. -syscalls)
  22. for i in zsyscall*go
  23. do
  24. # Run the command line that appears in the first line
  25. # of the generated file to regenerate it.
  26. sed 1q $i | sed 's;^// ;;' | sh > _$i && gofmt < _$i > $i
  27. rm _$i
  28. done
  29. exit 0
  30. ;;
  31. -n)
  32. run="cat"
  33. cmd="echo"
  34. shift
  35. esac
  36. case "$#" in
  37. 0)
  38. ;;
  39. *)
  40. echo 'usage: mkall.sh [-n]' 1>&2
  41. exit 2
  42. esac
  43. if [[ "$GOOS" = "linux" ]]; then
  44. # Use the Docker-based build system
  45. # Files generated through docker (use $cmd so you can Ctl-C the build or run)
  46. $cmd docker build --tag generate:$GOOS $GOOS
  47. $cmd docker run --interactive --tty --volume $(dirname "$(readlink -f "$0")"):/build generate:$GOOS
  48. exit
  49. fi
  50. GOOSARCH_in=syscall_$GOOSARCH.go
  51. case "$GOOSARCH" in
  52. _* | *_ | _)
  53. echo 'undefined $GOOS_$GOARCH:' "$GOOSARCH" 1>&2
  54. exit 1
  55. ;;
  56. aix_ppc)
  57. mkerrors="$mkerrors -maix32"
  58. mksyscall="go run mksyscall_aix_ppc.go -aix"
  59. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  60. ;;
  61. aix_ppc64)
  62. mkerrors="$mkerrors -maix64"
  63. mksyscall="go run mksyscall_aix_ppc64.go -aix"
  64. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  65. ;;
  66. darwin_386)
  67. mkerrors="$mkerrors -m32"
  68. mksyscall="go run mksyscall.go -l32"
  69. mksysnum="go run mksysnum.go $(xcrun --show-sdk-path --sdk macosx)/usr/include/sys/syscall.h"
  70. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  71. mkasm="go run mkasm_darwin.go"
  72. ;;
  73. darwin_amd64)
  74. mkerrors="$mkerrors -m64"
  75. mksysnum="go run mksysnum.go $(xcrun --show-sdk-path --sdk macosx)/usr/include/sys/syscall.h"
  76. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  77. mkasm="go run mkasm_darwin.go"
  78. ;;
  79. darwin_arm)
  80. mkerrors="$mkerrors"
  81. mksyscall="go run mksyscall.go -l32"
  82. mksysnum="go run mksysnum.go $(xcrun --show-sdk-path --sdk iphoneos)/usr/include/sys/syscall.h"
  83. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  84. mkasm="go run mkasm_darwin.go"
  85. ;;
  86. darwin_arm64)
  87. mkerrors="$mkerrors -m64"
  88. mksysnum="go run mksysnum.go $(xcrun --show-sdk-path --sdk iphoneos)/usr/include/sys/syscall.h"
  89. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  90. mkasm="go run mkasm_darwin.go"
  91. ;;
  92. dragonfly_amd64)
  93. mkerrors="$mkerrors -m64"
  94. mksyscall="go run mksyscall.go -dragonfly"
  95. mksysnum="go run mksysnum.go 'https://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/sys/kern/syscalls.master'"
  96. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  97. ;;
  98. freebsd_386)
  99. mkerrors="$mkerrors -m32"
  100. mksyscall="go run mksyscall.go -l32"
  101. mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
  102. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  103. ;;
  104. freebsd_amd64)
  105. mkerrors="$mkerrors -m64"
  106. mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
  107. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  108. ;;
  109. freebsd_arm)
  110. mkerrors="$mkerrors"
  111. mksyscall="go run mksyscall.go -l32 -arm"
  112. mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
  113. # Let the type of C char be signed for making the bare syscall
  114. # API consistent across platforms.
  115. mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
  116. ;;
  117. freebsd_arm64)
  118. mkerrors="$mkerrors -m64"
  119. mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
  120. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  121. ;;
  122. netbsd_386)
  123. mkerrors="$mkerrors -m32"
  124. mksyscall="go run mksyscall.go -l32 -netbsd"
  125. mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
  126. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  127. ;;
  128. netbsd_amd64)
  129. mkerrors="$mkerrors -m64"
  130. mksyscall="go run mksyscall.go -netbsd"
  131. mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
  132. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  133. ;;
  134. netbsd_arm)
  135. mkerrors="$mkerrors"
  136. mksyscall="go run mksyscall.go -l32 -netbsd -arm"
  137. mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
  138. # Let the type of C char be signed for making the bare syscall
  139. # API consistent across platforms.
  140. mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
  141. ;;
  142. netbsd_arm64)
  143. mkerrors="$mkerrors -m64"
  144. mksyscall="go run mksyscall.go -netbsd"
  145. mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
  146. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  147. ;;
  148. openbsd_386)
  149. mkerrors="$mkerrors -m32"
  150. mksyscall="go run mksyscall.go -l32 -openbsd"
  151. mksysctl="go run mksysctl_openbsd.go"
  152. mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
  153. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  154. ;;
  155. openbsd_amd64)
  156. mkerrors="$mkerrors -m64"
  157. mksyscall="go run mksyscall.go -openbsd"
  158. mksysctl="go run mksysctl_openbsd.go"
  159. mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
  160. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  161. ;;
  162. openbsd_arm)
  163. mkerrors="$mkerrors"
  164. mksyscall="go run mksyscall.go -l32 -openbsd -arm"
  165. mksysctl="go run mksysctl_openbsd.go"
  166. mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
  167. # Let the type of C char be signed for making the bare syscall
  168. # API consistent across platforms.
  169. mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
  170. ;;
  171. openbsd_arm64)
  172. mkerrors="$mkerrors -m64"
  173. mksyscall="go run mksyscall.go -openbsd"
  174. mksysctl="go run mksysctl_openbsd.go"
  175. mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
  176. # Let the type of C char be signed for making the bare syscall
  177. # API consistent across platforms.
  178. mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
  179. ;;
  180. solaris_amd64)
  181. mksyscall="go run mksyscall_solaris.go"
  182. mkerrors="$mkerrors -m64"
  183. mksysnum=
  184. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  185. ;;
  186. *)
  187. echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
  188. exit 1
  189. ;;
  190. esac
  191. (
  192. if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi
  193. case "$GOOS" in
  194. *)
  195. syscall_goos="syscall_$GOOS.go"
  196. case "$GOOS" in
  197. darwin | dragonfly | freebsd | netbsd | openbsd)
  198. syscall_goos="syscall_bsd.go $syscall_goos"
  199. ;;
  200. esac
  201. if [ -n "$mksyscall" ]; then
  202. if [ "$GOOSARCH" == "aix_ppc64" ]; then
  203. # aix/ppc64 script generates files instead of writing to stdin.
  204. 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 " ;
  205. elif [ "$GOOS" == "darwin" ]; then
  206. # pre-1.12, direct syscalls
  207. echo "$mksyscall -tags $GOOS,$GOARCH,!go1.12 $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.1_11.go";
  208. # 1.12 and later, syscalls via libSystem
  209. echo "$mksyscall -tags $GOOS,$GOARCH,go1.12 $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go";
  210. else
  211. echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go";
  212. fi
  213. fi
  214. esac
  215. if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi
  216. if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
  217. if [ -n "$mktypes" ]; then echo "$mktypes types_$GOOS.go | go run mkpost.go > ztypes_$GOOSARCH.go"; fi
  218. if [ -n "$mkasm" ]; then echo "$mkasm $GOARCH"; fi
  219. ) | $run
上海开阖软件有限公司 沪ICP备12045867号-1