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