go-1.8.ebuild 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. # Copyright 1999-2017 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=6
  4. export CBUILD=${CBUILD:-${CHOST}}
  5. export CTARGET=${CTARGET:-${CHOST}}
  6. MY_PV=${PV/_/}
  7. inherit toolchain-funcs
  8. BOOTSTRAP_DIST="https://dev.gentoo.org/~williamh/dist"
  9. BOOTSTRAP_VERSION="bootstrap-1.8"
  10. BOOTSTRAP_URI="
  11. amd64? ( ${BOOTSTRAP_DIST}/go-linux-amd64-${BOOTSTRAP_VERSION}.tbz )
  12. arm? ( ${BOOTSTRAP_DIST}/go-linux-arm-${BOOTSTRAP_VERSION}.tbz )
  13. arm64? ( ${BOOTSTRAP_DIST}/go-linux-arm64-${BOOTSTRAP_VERSION}.tbz )
  14. ppc64? (
  15. ${BOOTSTRAP_DIST}/go-linux-ppc64-${BOOTSTRAP_VERSION}.tbz
  16. ${BOOTSTRAP_DIST}/go-linux-ppc64le-${BOOTSTRAP_VERSION}.tbz
  17. )
  18. s390? ( ${BOOTSTRAP_DIST}/go-linux-s390x-${BOOTSTRAP_VERSION}.tbz )
  19. x86? ( ${BOOTSTRAP_DIST}/go-linux-386-${BOOTSTRAP_VERSION}.tbz )
  20. amd64-fbsd? ( ${BOOTSTRAP_DIST}/go-freebsd-amd64-${BOOTSTRAP_VERSION}.tbz )
  21. x86-fbsd? ( ${BOOTSTRAP_DIST}/go-freebsd-386-${BOOTSTRAP_VERSION}.tbz )
  22. x64-macos? ( ${BOOTSTRAP_DIST}/go-darwin-amd64-${BOOTSTRAP_VERSION}.tbz )
  23. x64-solaris? ( ${BOOTSTRAP_DIST}/go-solaris-amd64-${BOOTSTRAP_VERSION}.tbz )
  24. "
  25. case ${PV} in
  26. *9999*)
  27. EGIT_REPO_URI="git://github.com/golang/go.git"
  28. inherit git-r3
  29. ;;
  30. *)
  31. SRC_URI="https://storage.googleapis.com/golang/go${MY_PV}.src.tar.gz "
  32. S="${WORKDIR}"/go
  33. case ${PV} in
  34. *_beta*|*_rc*) ;;
  35. *)
  36. KEYWORDS="-* ~amd64 ~arm ~arm64 ~ppc64 ~x86 ~amd64-fbsd ~x86-fbsd ~x64-macos ~x64-solaris"
  37. # The upstream tests fail under portage but pass if the build is
  38. # run according to their documentation [1].
  39. # I am restricting the tests on released versions until this is
  40. # solved.
  41. # [1] https://golang.org/issues/18442
  42. RESTRICT="test"
  43. ;;
  44. esac
  45. esac
  46. SRC_URI+="!gccgo? ( ${BOOTSTRAP_URI} )"
  47. DESCRIPTION="A concurrent garbage collected and typesafe programming language"
  48. HOMEPAGE="http://www.golang.org"
  49. LICENSE="BSD"
  50. SLOT="0/${PV}"
  51. IUSE="gccgo"
  52. DEPEND="gccgo? ( >=sys-devel/gcc-5[go] )"
  53. RDEPEND="!<dev-go/go-tools-0_pre20150902"
  54. # These test data objects have writable/executable stacks.
  55. QA_EXECSTACK="
  56. usr/lib/go/src/debug/elf/testdata/*.obj
  57. usr/lib/go/src/go/internal/gccgoimporter/testdata/unicode.gox
  58. usr/lib/go/src/go/internal/gccgoimporter/testdata/time.gox
  59. "
  60. # Do not complain about CFLAGS, etc, since Go doesn't use them.
  61. QA_FLAGS_IGNORED='.*'
  62. REQUIRES_EXCLUDE="/usr/lib/go/src/debug/elf/testdata/*"
  63. # The tools in /usr/lib/go should not cause the multilib-strict check to fail.
  64. QA_MULTILIB_PATHS="usr/lib/go/pkg/tool/.*/.*"
  65. # Do not strip this package. Stripping is unsupported upstream and may
  66. # fail.
  67. RESTRICT+=" strip"
  68. DOCS=(
  69. AUTHORS
  70. CONTRIBUTING.md
  71. CONTRIBUTORS
  72. PATENTS
  73. README.md
  74. )
  75. go_arch()
  76. {
  77. # By chance most portage arch names match Go
  78. local portage_arch=$(tc-arch $@)
  79. case "${portage_arch}" in
  80. x86) echo 386;;
  81. x64-*) echo amd64;;
  82. ppc64) [[ $(tc-endian $@) = big ]] && echo ppc64 || echo ppc64le ;;
  83. s390) echo s390x ;;
  84. *) echo "${portage_arch}";;
  85. esac
  86. }
  87. go_arm()
  88. {
  89. case "${1:-${CHOST}}" in
  90. armv5*) echo 5;;
  91. armv6*) echo 6;;
  92. armv7*) echo 7;;
  93. *)
  94. die "unknown GOARM for ${1:-${CHOST}}"
  95. ;;
  96. esac
  97. }
  98. go_os()
  99. {
  100. case "${1:-${CHOST}}" in
  101. *-linux*) echo linux;;
  102. *-darwin*) echo darwin;;
  103. *-freebsd*) echo freebsd;;
  104. *-netbsd*) echo netbsd;;
  105. *-openbsd*) echo openbsd;;
  106. *-solaris*) echo solaris;;
  107. *-cygwin*|*-interix*|*-winnt*)
  108. echo windows
  109. ;;
  110. *)
  111. die "unknown GOOS for ${1:-${CHOST}}"
  112. ;;
  113. esac
  114. }
  115. go_tuple()
  116. {
  117. echo "$(go_os $@)_$(go_arch $@)"
  118. }
  119. go_cross_compile()
  120. {
  121. [[ $(go_tuple ${CBUILD}) != $(go_tuple) ]]
  122. }
  123. pkg_pretend()
  124. {
  125. # make.bash does not understand cross-compiling a cross-compiler
  126. if [[ $(go_tuple) != $(go_tuple ${CTARGET}) ]]; then
  127. die "CHOST CTARGET pair unsupported: CHOST=${CHOST} CTARGET=${CTARGET}"
  128. fi
  129. }
  130. src_unpack()
  131. {
  132. if [[ ${PV} = 9999 ]]; then
  133. git-r3_src_unpack
  134. fi
  135. default
  136. }
  137. src_compile()
  138. {
  139. export GOROOT_BOOTSTRAP="${WORKDIR}"/go-$(go_os)-$(go_arch)-bootstrap
  140. if use gccgo; then
  141. mkdir -p "${GOROOT_BOOTSTRAP}/bin" || die
  142. local go_binary=$(gcc-config --get-bin-path)/go-$(gcc-major-version)
  143. [[ -x ${go_binary} ]] || go_binary=$(
  144. find "${EPREFIX}"/usr/${CHOST}/gcc-bin/*/go-$(gcc-major-version) |
  145. sort -V | tail -n1)
  146. [[ -x ${go_binary} ]] ||
  147. die "go-$(gcc-major-version): command not found"
  148. ln -s "${go_binary}" "${GOROOT_BOOTSTRAP}/bin/go" || die
  149. fi
  150. export GOROOT_FINAL="${EPREFIX}"/usr/lib/go
  151. export GOROOT="$(pwd)"
  152. export GOBIN="${GOROOT}/bin"
  153. # Go's build script does not use BUILD/HOST/TARGET consistently. :(
  154. export GOHOSTARCH=$(go_arch ${CBUILD})
  155. export GOHOSTOS=$(go_os ${CBUILD})
  156. export CC=$(tc-getBUILD_CC)
  157. export GOARCH=$(go_arch)
  158. export GOOS=$(go_os)
  159. export CC_FOR_TARGET=$(tc-getCC)
  160. export CXX_FOR_TARGET=$(tc-getCXX)
  161. if [[ ${ARCH} == arm ]]; then
  162. export GOARM=$(go_arm)
  163. fi
  164. elog "GOROOT_BOOTSTRAP is ${GOROOT_BOOTSTRAP}"
  165. cd src
  166. ./make.bash || die "build failed"
  167. }
  168. src_test()
  169. {
  170. go_cross_compile && return 0
  171. cd src
  172. PATH="${GOBIN}:${PATH}" \
  173. ./run.bash -no-rebuild || die "tests failed"
  174. }
  175. src_install()
  176. {
  177. local bin_path f x
  178. dodir /usr/lib/go
  179. # There is a known issue which requires the source tree to be installed [1].
  180. # Once this is fixed, we can consider using the doc use flag to control
  181. # installing the doc and src directories.
  182. # [1] https://golang.org/issue/2775
  183. #
  184. # deliberately use cp to retain permissions
  185. cp -R api bin doc lib pkg misc src test "${ED}"/usr/lib/go
  186. if go_cross_compile; then
  187. bin_path="bin/$(go_tuple)"
  188. else
  189. bin_path=bin
  190. fi
  191. for x in ${bin_path}/*; do
  192. f=${x##*/}
  193. dosym ../lib/go/${bin_path}/${f} /usr/bin/${f}
  194. done
  195. einstalldocs
  196. }