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.

243 lines
8.3 KiB

  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 $(cd -- "$(dirname -- "$0")" && /bin/pwd):/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. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  70. mkasm="go run mkasm_darwin.go"
  71. ;;
  72. darwin_amd64)
  73. mkerrors="$mkerrors -m64"
  74. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  75. mkasm="go run mkasm_darwin.go"
  76. ;;
  77. darwin_arm)
  78. mkerrors="$mkerrors"
  79. mksyscall="go run mksyscall.go -l32"
  80. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  81. mkasm="go run mkasm_darwin.go"
  82. ;;
  83. darwin_arm64)
  84. mkerrors="$mkerrors -m64"
  85. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  86. mkasm="go run mkasm_darwin.go"
  87. ;;
  88. dragonfly_amd64)
  89. mkerrors="$mkerrors -m64"
  90. mksyscall="go run mksyscall.go -dragonfly"
  91. mksysnum="go run mksysnum.go 'https://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/sys/kern/syscalls.master'"
  92. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  93. ;;
  94. freebsd_386)
  95. mkerrors="$mkerrors -m32"
  96. mksyscall="go run mksyscall.go -l32"
  97. mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
  98. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  99. ;;
  100. freebsd_amd64)
  101. mkerrors="$mkerrors -m64"
  102. mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
  103. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  104. ;;
  105. freebsd_arm)
  106. mkerrors="$mkerrors"
  107. mksyscall="go run mksyscall.go -l32 -arm"
  108. mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
  109. # Let the type of C char be signed for making the bare syscall
  110. # API consistent across platforms.
  111. mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
  112. ;;
  113. freebsd_arm64)
  114. mkerrors="$mkerrors -m64"
  115. mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
  116. mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
  117. ;;
  118. netbsd_386)
  119. mkerrors="$mkerrors -m32"
  120. mksyscall="go run mksyscall.go -l32 -netbsd"
  121. mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
  122. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  123. ;;
  124. netbsd_amd64)
  125. mkerrors="$mkerrors -m64"
  126. mksyscall="go run mksyscall.go -netbsd"
  127. mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
  128. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  129. ;;
  130. netbsd_arm)
  131. mkerrors="$mkerrors"
  132. mksyscall="go run mksyscall.go -l32 -netbsd -arm"
  133. mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
  134. # Let the type of C char be signed for making the bare syscall
  135. # API consistent across platforms.
  136. mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
  137. ;;
  138. netbsd_arm64)
  139. mkerrors="$mkerrors -m64"
  140. mksyscall="go run mksyscall.go -netbsd"
  141. mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
  142. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  143. ;;
  144. openbsd_386)
  145. mkerrors="$mkerrors -m32"
  146. mksyscall="go run mksyscall.go -l32 -openbsd"
  147. mksysctl="go run mksysctl_openbsd.go"
  148. mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
  149. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  150. ;;
  151. openbsd_amd64)
  152. mkerrors="$mkerrors -m64"
  153. mksyscall="go run mksyscall.go -openbsd"
  154. mksysctl="go run mksysctl_openbsd.go"
  155. mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
  156. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  157. ;;
  158. openbsd_arm)
  159. mkerrors="$mkerrors"
  160. mksyscall="go run mksyscall.go -l32 -openbsd -arm"
  161. mksysctl="go run mksysctl_openbsd.go"
  162. mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
  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. ;;
  167. openbsd_arm64)
  168. mkerrors="$mkerrors -m64"
  169. mksyscall="go run mksyscall.go -openbsd"
  170. mksysctl="go run mksysctl_openbsd.go"
  171. mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
  172. # Let the type of C char be signed for making the bare syscall
  173. # API consistent across platforms.
  174. mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
  175. ;;
  176. openbsd_mips64)
  177. mkerrors="$mkerrors -m64"
  178. mksyscall="go run mksyscall.go -openbsd"
  179. mksysctl="go run mksysctl_openbsd.go"
  180. mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
  181. # Let the type of C char be signed for making the bare syscall
  182. # API consistent across platforms.
  183. mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
  184. ;;
  185. solaris_amd64)
  186. mksyscall="go run mksyscall_solaris.go"
  187. mkerrors="$mkerrors -m64"
  188. mksysnum=
  189. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  190. ;;
  191. illumos_amd64)
  192. mksyscall="go run mksyscall_solaris.go"
  193. mkerrors=
  194. mksysnum=
  195. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  196. ;;
  197. *)
  198. echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
  199. exit 1
  200. ;;
  201. esac
  202. (
  203. if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi
  204. case "$GOOS" in
  205. *)
  206. syscall_goos="syscall_$GOOS.go"
  207. case "$GOOS" in
  208. darwin | dragonfly | freebsd | netbsd | openbsd)
  209. syscall_goos="syscall_bsd.go $syscall_goos"
  210. ;;
  211. esac
  212. if [ -n "$mksyscall" ]; then
  213. if [ "$GOOSARCH" == "aix_ppc64" ]; then
  214. # aix/ppc64 script generates files instead of writing to stdin.
  215. 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 " ;
  216. elif [ "$GOOS" == "darwin" ]; then
  217. # 1.12 and later, syscalls via libSystem
  218. echo "$mksyscall -tags $GOOS,$GOARCH,go1.12 $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go";
  219. # 1.13 and later, syscalls via libSystem (including syscallPtr)
  220. echo "$mksyscall -tags $GOOS,$GOARCH,go1.13 syscall_darwin.1_13.go |gofmt >zsyscall_$GOOSARCH.1_13.go";
  221. elif [ "$GOOS" == "illumos" ]; then
  222. # illumos code generation requires a --illumos switch
  223. echo "$mksyscall -illumos -tags illumos,$GOARCH syscall_illumos.go |gofmt > zsyscall_illumos_$GOARCH.go";
  224. # illumos implies solaris, so solaris code generation is also required
  225. echo "$mksyscall -tags solaris,$GOARCH syscall_solaris.go syscall_solaris_$GOARCH.go |gofmt >zsyscall_solaris_$GOARCH.go";
  226. else
  227. echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go";
  228. fi
  229. fi
  230. esac
  231. if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi
  232. if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
  233. if [ -n "$mktypes" ]; then echo "$mktypes types_$GOOS.go | go run mkpost.go > ztypes_$GOOSARCH.go"; fi
  234. if [ -n "$mkasm" ]; then echo "$mkasm $GOARCH"; fi
  235. ) | $run