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.

275 lines
7.6 KiB

  1. # Copyright 1999-2021 Gentoo Authors
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=6
  4. inherit autotools check-reqs flag-o-matic java-pkg-2 java-vm-2 multiprocessing pax-utils toolchain-funcs
  5. # we need -ga tag to fetch tarball and unpack it, but exact number everywhere else to
  6. # set build version properly
  7. MY_PV="${PV%_p*}-ga"
  8. SLOT="${MY_PV%%[.+]*}"
  9. DESCRIPTION="Open source implementation of the Java programming language"
  10. HOMEPAGE="https://openjdk.java.net"
  11. SRC_URI="https://hg.${PN}.java.net/jdk-updates/jdk${SLOT}u/archive/jdk-${MY_PV}.tar.bz2 -> ${P}.tar.bz2"
  12. LICENSE="GPL-2"
  13. KEYWORDS="amd64 ~arm arm64 ~ppc64"
  14. IUSE="alsa cups debug doc examples gentoo-vm headless-awt javafx +jbootstrap +pch selinux source systemtap"
  15. COMMON_DEPEND="
  16. media-libs/freetype:2=
  17. media-libs/giflib:0/7
  18. media-libs/harfbuzz:=
  19. media-libs/libpng:0=
  20. media-libs/lcms:2=
  21. sys-libs/zlib
  22. virtual/jpeg:0=
  23. systemtap? ( dev-util/systemtap )
  24. "
  25. # Many libs are required to build, but not to run, make is possible to remove
  26. # by listing conditionally in RDEPEND unconditionally in DEPEND
  27. RDEPEND="
  28. ${COMMON_DEPEND}
  29. >=sys-apps/baselayout-java-0.1.0-r1
  30. !headless-awt? (
  31. x11-libs/libX11
  32. x11-libs/libXext
  33. x11-libs/libXi
  34. x11-libs/libXrandr
  35. x11-libs/libXrender
  36. x11-libs/libXt
  37. x11-libs/libXtst
  38. )
  39. alsa? ( media-libs/alsa-lib )
  40. cups? ( net-print/cups )
  41. selinux? ( sec-policy/selinux-java )
  42. "
  43. DEPEND="
  44. ${COMMON_DEPEND}
  45. app-arch/zip
  46. media-libs/alsa-lib
  47. net-print/cups
  48. x11-base/xorg-proto
  49. x11-libs/libX11
  50. x11-libs/libXext
  51. x11-libs/libXi
  52. x11-libs/libXrandr
  53. x11-libs/libXrender
  54. x11-libs/libXt
  55. x11-libs/libXtst
  56. javafx? ( dev-java/openjfx:${SLOT}= )
  57. || (
  58. dev-java/openjdk-bin:${SLOT}
  59. dev-java/openjdk:${SLOT}
  60. )
  61. "
  62. REQUIRED_USE="javafx? ( alsa !headless-awt )"
  63. S="${WORKDIR}/jdk${SLOT}u-jdk-${MY_PV}"
  64. # The space required to build varies wildly depending on USE flags,
  65. # ranging from 2GB to 16GB. This function is certainly not exact but
  66. # should be close enough to be useful.
  67. openjdk_check_requirements() {
  68. local M
  69. M=2048
  70. M=$(( $(usex jbootstrap 2 1) * $M ))
  71. M=$(( $(usex debug 3 1) * $M ))
  72. M=$(( $(usex doc 320 0) + $(usex source 128 0) + 192 + $M ))
  73. CHECKREQS_DISK_BUILD=${M}M check-reqs_pkg_${EBUILD_PHASE}
  74. }
  75. pkg_pretend() {
  76. openjdk_check_requirements
  77. if [[ ${MERGE_TYPE} != binary ]]; then
  78. has ccache ${FEATURES} && die "FEATURES=ccache doesn't work with ${PN}, bug #677876"
  79. fi
  80. }
  81. pkg_setup() {
  82. openjdk_check_requirements
  83. java-vm-2_pkg_setup
  84. JAVA_PKG_WANT_BUILD_VM="openjdk-${SLOT} openjdk-bin-${SLOT}"
  85. JAVA_PKG_WANT_SOURCE="${SLOT}"
  86. JAVA_PKG_WANT_TARGET="${SLOT}"
  87. # The nastiness below is necessary while the gentoo-vm USE flag is
  88. # masked. First we call java-pkg-2_pkg_setup if it looks like the
  89. # flag was unmasked against one of the possible build VMs. If not,
  90. # we try finding one of them in their expected locations. This would
  91. # have been slightly less messy if openjdk-bin had been installed to
  92. # /opt/${PN}-${SLOT} or if there was a mechanism to install a VM env
  93. # file but disable it so that it would not normally be selectable.
  94. local vm
  95. for vm in ${JAVA_PKG_WANT_BUILD_VM}; do
  96. if [[ -d ${EPREFIX}/usr/lib/jvm/${vm} ]]; then
  97. java-pkg-2_pkg_setup
  98. return
  99. fi
  100. done
  101. if has_version --host-root dev-java/openjdk:${SLOT}; then
  102. export JDK_HOME=${EPREFIX}/usr/$(get_libdir)/openjdk-${SLOT}
  103. else
  104. if [[ ${MERGE_TYPE} != "binary" ]]; then
  105. JDK_HOME=$(best_version --host-root dev-java/openjdk-bin:${SLOT})
  106. [[ -n ${JDK_HOME} ]] || die "Build VM not found!"
  107. JDK_HOME=${JDK_HOME#*/}
  108. JDK_HOME=${EPREFIX}/opt/${JDK_HOME%-r*}
  109. export JDK_HOME
  110. fi
  111. fi
  112. }
  113. src_prepare() {
  114. default
  115. chmod +x configure || die
  116. }
  117. src_configure() {
  118. # Work around stack alignment issue, bug #647954. in case we ever have x86
  119. use x86 && append-flags -mincoming-stack-boundary=2
  120. # Work around -fno-common ( GCC10 default ), bug #713180
  121. append-flags -fcommon
  122. # Enabling full docs appears to break doc building. If not
  123. # explicitly disabled, the flag will get auto-enabled if pandoc and
  124. # graphviz are detected. pandoc has loads of dependencies anyway.
  125. local myconf=(
  126. --disable-ccache
  127. --enable-full-docs=no
  128. --with-boot-jdk="${JDK_HOME}"
  129. --with-extra-cflags="${CFLAGS}"
  130. --with-extra-cxxflags="${CXXFLAGS}"
  131. --with-extra-ldflags="${LDFLAGS}"
  132. --with-freetype=system
  133. --with-giflib=system
  134. --with-harfbuzz=system
  135. --with-lcms=system
  136. --with-libjpeg=system
  137. --with-libpng=system
  138. --with-native-debug-symbols=$(usex debug internal none)
  139. --with-vendor-name="Gentoo"
  140. --with-vendor-url="https://gentoo.org"
  141. --with-vendor-bug-url="https://bugs.gentoo.org"
  142. --with-vendor-vm-bug-url="https://bugs.openjdk.java.net"
  143. --with-vendor-version-string="${PVR}"
  144. --with-version-pre=""
  145. --with-version-string="${PV%_p*}"
  146. --with-version-build="${PV#*_p}"
  147. --with-zlib=system
  148. --enable-dtrace=$(usex systemtap yes no)
  149. --enable-headless-only=$(usex headless-awt yes no)
  150. $(tc-is-clang && echo "--with-toolchain-type=clang")
  151. )
  152. if use javafx; then
  153. local zip="${EPREFIX%/}/usr/$(get_libdir)/openjfx-${SLOT}/javafx-exports.zip"
  154. if [[ -r ${zip} ]]; then
  155. myconf+=( --with-import-modules="${zip}" )
  156. else
  157. die "${zip} not found or not readable"
  158. fi
  159. fi
  160. # PaX breaks pch, bug #601016
  161. if use pch && ! host-is-pax; then
  162. myconf+=( --enable-precompiled-headers )
  163. else
  164. myconf+=( --disable-precompiled-headers )
  165. fi
  166. (
  167. unset _JAVA_OPTIONS JAVA JAVA_TOOL_OPTIONS JAVAC XARGS
  168. CFLAGS= CXXFLAGS= LDFLAGS= \
  169. CONFIG_SITE=/dev/null \
  170. econf "${myconf[@]}"
  171. )
  172. }
  173. src_compile() {
  174. local myemakeargs=(
  175. JOBS=$(makeopts_jobs)
  176. LOG=debug
  177. CFLAGS_WARNINGS_ARE_ERRORS= # No -Werror
  178. $(usex doc docs '')
  179. $(usex jbootstrap bootcycle-images product-images)
  180. )
  181. emake "${myemakeargs[@]}" -j1 #nowarn
  182. }
  183. src_install() {
  184. local dest="/usr/$(get_libdir)/${PN}-${SLOT}"
  185. local ddest="${ED}${dest#/}"
  186. cd "${S}"/build/*-release/images/jdk || die
  187. # Create files used as storage for system preferences.
  188. mkdir .systemPrefs || die
  189. touch .systemPrefs/.system.lock || die
  190. touch .systemPrefs/.systemRootModFile || die
  191. # Oracle and IcedTea have libjsoundalsa.so depending on
  192. # libasound.so.2 but OpenJDK only has libjsound.so. Weird.
  193. if ! use alsa ; then
  194. rm -v lib/libjsound.* || die
  195. fi
  196. if ! use examples ; then
  197. rm -vr demo/ || die
  198. fi
  199. if ! use source ; then
  200. rm -v lib/src.zip || die
  201. fi
  202. rm -v lib/security/cacerts || die
  203. dodir "${dest}"
  204. cp -pPR * "${ddest}" || die
  205. dosym ../../../../../etc/ssl/certs/java/cacerts "${dest}"/lib/security/cacerts
  206. # must be done before running itself
  207. java-vm_set-pax-markings "${ddest}"
  208. einfo "Creating the Class Data Sharing archives and disabling usage tracking"
  209. "${ddest}/bin/java" -server -Xshare:dump -Djdk.disableLastUsageTracking || die
  210. use gentoo-vm && java-vm_install-env "${FILESDIR}"/${PN}-${SLOT}.env.sh
  211. java-vm_revdep-mask
  212. java-vm_sandbox-predict /dev/random /proc/self/coredump_filter
  213. if use doc ; then
  214. docinto html
  215. dodoc -r "${S}"/build/*-release/images/docs/*
  216. dosym ../../../usr/share/doc/"${PF}" /usr/share/doc/"${PN}-${SLOT}"
  217. fi
  218. }
  219. pkg_postinst() {
  220. java-vm-2_pkg_postinst
  221. if use gentoo-vm ; then
  222. ewarn "WARNING! You have enabled the gentoo-vm USE flag, making this JDK"
  223. ewarn "recognised by the system. This will almost certainly break"
  224. ewarn "many java ebuilds as they are not ready for openjdk-11"
  225. else
  226. ewarn "The experimental gentoo-vm USE flag has not been enabled so this JDK"
  227. ewarn "will not be recognised by the system. For example, simply calling"
  228. ewarn "\"java\" will launch a different JVM. This is necessary until Gentoo"
  229. ewarn "fully supports Java ${SLOT}. This JDK must therefore be invoked using its"
  230. ewarn "absolute location under ${EPREFIX}/usr/$(get_libdir)/${PN}-${SLOT}."
  231. fi
  232. }