另客网go项目公用的代码库

mkall.sh 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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/10/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/10/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/10/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/10/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. openbsd_386)
  143. mkerrors="$mkerrors -m32"
  144. mksyscall="go run mksyscall.go -l32 -openbsd"
  145. mksysctl="./mksysctl_openbsd.pl"
  146. mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
  147. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  148. ;;
  149. openbsd_amd64)
  150. mkerrors="$mkerrors -m64"
  151. mksyscall="go run mksyscall.go -openbsd"
  152. mksysctl="./mksysctl_openbsd.pl"
  153. mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
  154. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  155. ;;
  156. openbsd_arm)
  157. mkerrors="$mkerrors"
  158. mksyscall="go run mksyscall.go -l32 -openbsd -arm"
  159. mksysctl="./mksysctl_openbsd.pl"
  160. mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
  161. # Let the type of C char be signed for making the bare syscall
  162. # API consistent across platforms.
  163. mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
  164. ;;
  165. solaris_amd64)
  166. mksyscall="go run mksyscall_solaris.go"
  167. mkerrors="$mkerrors -m64"
  168. mksysnum=
  169. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  170. ;;
  171. *)
  172. echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
  173. exit 1
  174. ;;
  175. esac
  176. (
  177. if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi
  178. case "$GOOS" in
  179. *)
  180. syscall_goos="syscall_$GOOS.go"
  181. case "$GOOS" in
  182. darwin | dragonfly | freebsd | netbsd | openbsd)
  183. syscall_goos="syscall_bsd.go $syscall_goos"
  184. ;;
  185. esac
  186. if [ -n "$mksyscall" ]; then
  187. if [ "$GOOSARCH" == "aix_ppc64" ]; then
  188. # aix/ppc64 script generates files instead of writing to stdin.
  189. 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 " ;
  190. elif [ "$GOOS" == "darwin" ]; then
  191. # pre-1.12, direct syscalls
  192. echo "$mksyscall -tags $GOOS,$GOARCH,!go1.12 $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.1_11.go";
  193. # 1.12 and later, syscalls via libSystem
  194. echo "$mksyscall -tags $GOOS,$GOARCH,go1.12 $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go";
  195. else
  196. echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go";
  197. fi
  198. fi
  199. esac
  200. if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi
  201. if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
  202. if [ -n "$mktypes" ]; then
  203. echo "$mktypes types_$GOOS.go | go run mkpost.go > ztypes_$GOOSARCH.go";
  204. if [ -n "$mkasm" ]; then echo "$mkasm $GOARCH"; fi
  205. fi
  206. ) | $run