mkall.sh 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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")/.." && 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.go"
  70. ;;
  71. darwin_arm64)
  72. mkerrors="$mkerrors -m64"
  73. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  74. mkasm="go run mkasm.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://cgit.freebsd.org/src/plain/sys/kern/syscalls.master?h=stable/12'"
  86. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  87. ;;
  88. freebsd_amd64)
  89. mkerrors="$mkerrors -m64"
  90. mksysnum="go run mksysnum.go 'https://cgit.freebsd.org/src/plain/sys/kern/syscalls.master?h=stable/12'"
  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://cgit.freebsd.org/src/plain/sys/kern/syscalls.master?h=stable/12'"
  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://cgit.freebsd.org/src/plain/sys/kern/syscalls.master?h=stable/12'"
  104. mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
  105. ;;
  106. freebsd_riscv64)
  107. mkerrors="$mkerrors -m64"
  108. mksysnum="go run mksysnum.go 'https://cgit.freebsd.org/src/plain/sys/kern/syscalls.master?h=stable/12'"
  109. mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
  110. ;;
  111. netbsd_386)
  112. mkerrors="$mkerrors -m32"
  113. mksyscall="go run mksyscall.go -l32 -netbsd"
  114. mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
  115. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  116. ;;
  117. netbsd_amd64)
  118. mkerrors="$mkerrors -m64"
  119. mksyscall="go run mksyscall.go -netbsd"
  120. mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
  121. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  122. ;;
  123. netbsd_arm)
  124. mkerrors="$mkerrors"
  125. mksyscall="go run mksyscall.go -l32 -netbsd -arm"
  126. mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
  127. # Let the type of C char be signed for making the bare syscall
  128. # API consistent across platforms.
  129. mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
  130. ;;
  131. netbsd_arm64)
  132. mkerrors="$mkerrors -m64"
  133. mksyscall="go run mksyscall.go -netbsd"
  134. mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
  135. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  136. ;;
  137. openbsd_386)
  138. mkasm="go run mkasm.go"
  139. mkerrors="$mkerrors -m32"
  140. mksyscall="go run mksyscall.go -l32 -openbsd -libc"
  141. mksysctl="go run mksysctl_openbsd.go"
  142. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  143. ;;
  144. openbsd_amd64)
  145. mkasm="go run mkasm.go"
  146. mkerrors="$mkerrors -m64"
  147. mksyscall="go run mksyscall.go -openbsd -libc"
  148. mksysctl="go run mksysctl_openbsd.go"
  149. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  150. ;;
  151. openbsd_arm)
  152. mkasm="go run mkasm.go"
  153. mkerrors="$mkerrors"
  154. mksyscall="go run mksyscall.go -l32 -openbsd -arm -libc"
  155. mksysctl="go run mksysctl_openbsd.go"
  156. # Let the type of C char be signed for making the bare syscall
  157. # API consistent across platforms.
  158. mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
  159. ;;
  160. openbsd_arm64)
  161. mkasm="go run mkasm.go"
  162. mkerrors="$mkerrors -m64"
  163. mksyscall="go run mksyscall.go -openbsd -libc"
  164. mksysctl="go run mksysctl_openbsd.go"
  165. # Let the type of C char be signed for making the bare syscall
  166. # API consistent across platforms.
  167. mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
  168. ;;
  169. openbsd_mips64)
  170. mkasm="go run mkasm.go"
  171. mkerrors="$mkerrors -m64"
  172. mksyscall="go run mksyscall.go -openbsd -libc"
  173. mksysctl="go run mksysctl_openbsd.go"
  174. # Let the type of C char be signed for making the bare syscall
  175. # API consistent across platforms.
  176. mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
  177. ;;
  178. openbsd_ppc64)
  179. mkasm="go run mkasm.go"
  180. mkerrors="$mkerrors -m64"
  181. mksyscall="go run mksyscall.go -openbsd -libc"
  182. mksysctl="go run mksysctl_openbsd.go"
  183. # Let the type of C char be signed for making the bare syscall
  184. # API consistent across platforms.
  185. mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
  186. ;;
  187. openbsd_riscv64)
  188. mkasm="go run mkasm.go"
  189. mkerrors="$mkerrors -m64"
  190. mksyscall="go run mksyscall.go -openbsd -libc"
  191. mksysctl="go run mksysctl_openbsd.go"
  192. # Let the type of C char be signed for making the bare syscall
  193. # API consistent across platforms.
  194. mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
  195. ;;
  196. solaris_amd64)
  197. mksyscall="go run mksyscall_solaris.go"
  198. mkerrors="$mkerrors -m64"
  199. mksysnum=
  200. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  201. ;;
  202. illumos_amd64)
  203. mksyscall="go run mksyscall_solaris.go"
  204. mkerrors=
  205. mksysnum=
  206. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  207. ;;
  208. *)
  209. echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
  210. exit 1
  211. ;;
  212. esac
  213. (
  214. if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi
  215. case "$GOOS" in
  216. *)
  217. syscall_goos="syscall_$GOOS.go"
  218. case "$GOOS" in
  219. darwin | dragonfly | freebsd | netbsd | openbsd)
  220. syscall_goos="syscall_bsd.go $syscall_goos"
  221. ;;
  222. esac
  223. if [ -n "$mksyscall" ]; then
  224. if [ "$GOOSARCH" == "aix_ppc64" ]; then
  225. # aix/ppc64 script generates files instead of writing to stdin.
  226. 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 " ;
  227. elif [ "$GOOS" == "illumos" ]; then
  228. # illumos code generation requires a --illumos switch
  229. echo "$mksyscall -illumos -tags illumos,$GOARCH syscall_illumos.go |gofmt > zsyscall_illumos_$GOARCH.go";
  230. # illumos implies solaris, so solaris code generation is also required
  231. echo "$mksyscall -tags solaris,$GOARCH syscall_solaris.go syscall_solaris_$GOARCH.go |gofmt >zsyscall_solaris_$GOARCH.go";
  232. else
  233. echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go";
  234. fi
  235. fi
  236. esac
  237. if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi
  238. if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
  239. if [ -n "$mktypes" ]; then echo "$mktypes types_$GOOS.go | go run mkpost.go > ztypes_$GOOSARCH.go"; fi
  240. if [ -n "$mkasm" ]; then echo "$mkasm $GOOS $GOARCH"; fi
  241. ) | $run