mkall.sh 8.0 KB

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