@@ -0,0 +1,157 @@
1+{ stdenv, lib, fetchurl, bash, pkg-config, autoconf, cpio, file, which, unzip
2+, zip, perl, cups, freetype, alsaLib, libjpeg, giflib, libpng, zlib, lcms2
3+, libX11, libICE, libXrender, libXext, libXt, libXtst, libXi, libXinerama
4+, libXcursor, libXrandr, fontconfig, openjdk14-bootstrap
5+, setJavaClassPath
6+, headless ? false
7+, enableJavaFX ? openjfx.meta.available, openjfx
8+, enableGnome2 ? true, gtk3, gnome_vfs, glib, GConf
9+}:
10+
11+let
12+ major = "14";
13+ update = ".0.2";
14+ build = "-ga";
15+
16+ openjdk = stdenv.mkDerivation rec {
17+ pname = "openjdk" + lib.optionalString headless "-headless";
18+ version = "${major}${update}${build}";
19+
20+ src = fetchurl {
21+ url = "https://hg.openjdk.java.net/jdk-updates/jdk${major}u/archive/jdk-${version}.tar.gz";
22+ sha256 = "1s1pc6ihzf0awp4hbaqfxmbica0hnrg8nr7s0yd2hfn7nan8xmf3";
23+ };
24+
25+ nativeBuildInputs = [ pkg-config autoconf ];
26+ buildInputs = [
27+ cpio file which unzip zip perl zlib cups freetype alsaLib libjpeg giflib
28+ libpng zlib lcms2 libX11 libICE libXrender libXext libXtst libXt libXtst
29+ libXi libXinerama libXcursor libXrandr fontconfig openjdk14-bootstrap
30+ ] ++ lib.optionals (!headless && enableGnome2) [
31+ gtk3 gnome_vfs GConf glib
32+ ];
33+
34+ patches = [
35+ ./fix-java-home-jdk10.patch
36+ ./read-truststore-from-env-jdk10.patch
37+ ./currency-date-range-jdk10.patch
38+ ./increase-javadoc-heap-jdk13.patch
39+ # -Wformat etc. are stricter in newer gccs, per
40+ # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79677
41+ # so grab the work-around from
42+ # https://src.fedoraproject.org/rpms/java-openjdk/pull-request/24
43+ (fetchurl {
44+ url = "https://src.fedoraproject.org/rpms/java-openjdk/raw/06c001c7d87f2e9fe4fedeef2d993bcd5d7afa2a/f/rh1673833-remove_removal_of_wformat_during_test_compilation.patch";
45+ sha256 = "082lmc30x64x583vqq00c8y0wqih3y4r0mp1c4bqq36l22qv6b6r";
46+ })
47+ ] ++ lib.optionals (!headless && enableGnome2) [
48+ ./swing-use-gtk-jdk13.patch
49+ ];
50+
51+ prePatch = ''
52+ chmod +x configure
53+ patchShebangs --build configure
54+ '';
55+
56+ configureFlags = [
57+ "--with-boot-jdk=${openjdk14-bootstrap.home}"
58+ "--enable-unlimited-crypto"
59+ "--with-native-debug-symbols=internal"
60+ "--with-libjpeg=system"
61+ "--with-giflib=system"
62+ "--with-libpng=system"
63+ "--with-zlib=system"
64+ "--with-lcms=system"
65+ "--with-stdc++lib=dynamic"
66+ ] ++ lib.optional stdenv.isx86_64 "--with-jvm-features=zgc"
67+ ++ lib.optional headless "--enable-headless-only"
68+ ++ lib.optional (!headless && enableJavaFX) "--with-import-modules=${openjfx}";
69+
70+ separateDebugInfo = true;
71+
72+ NIX_CFLAGS_COMPILE = "-Wno-error";
73+
74+ NIX_LDFLAGS = toString (lib.optionals (!headless) [
75+ "-lfontconfig" "-lcups" "-lXinerama" "-lXrandr" "-lmagic"
76+ ] ++ lib.optionals (!headless && enableGnome2) [
77+ "-lgtk-3" "-lgio-2.0" "-lgnomevfs-2" "-lgconf-2"
78+ ]);
79+
80+ buildFlags = [ "all" ];
81+
82+ installPhase = ''
83+ mkdir -p $out/lib
84+
85+ mv build/*/images/jdk $out/lib/openjdk
86+
87+ # Remove some broken manpages.
88+ rm -rf $out/lib/openjdk/man/ja*
89+
90+ # Mirror some stuff in top-level.
91+ mkdir -p $out/share
92+ ln -s $out/lib/openjdk/include $out/include
93+ ln -s $out/lib/openjdk/man $out/share/man
94+ ln -s $out/lib/openjdk/lib/src.zip $out/lib/src.zip
95+
96+ # jni.h expects jni_md.h to be in the header search path.
97+ ln -s $out/include/linux/*_md.h $out/include/
98+
99+ # Remove crap from the installation.
100+ rm -rf $out/lib/openjdk/demo
101+ ${lib.optionalString headless ''
102+ rm $out/lib/openjdk/lib/{libjsound,libfontmanager}.so
103+ ''}
104+
105+ ln -s $out/lib/openjdk/bin $out/bin
106+ '';
107+
108+ preFixup = ''
109+ # Propagate the setJavaClassPath setup hook so that any package
110+ # that depends on the JDK has $CLASSPATH set up properly.
111+ mkdir -p $out/nix-support
112+ #TODO or printWords? cf https://github.com/NixOS/nixpkgs/pull/27427#issuecomment-317293040
113+ echo -n "${setJavaClassPath}" > $out/nix-support/propagated-build-inputs
114+
115+ # Set JAVA_HOME automatically.
116+ mkdir -p $out/nix-support
117+ cat <<EOF > $out/nix-support/setup-hook
118+ if [ -z "\''${JAVA_HOME-}" ]; then export JAVA_HOME=$out/lib/openjdk; fi
119+ EOF
120+ '';
121+
122+ postFixup = ''
123+ # Build the set of output library directories to rpath against
124+ LIBDIRS=""
125+ for output in $outputs; do
126+ if [ "$output" = debug ]; then continue; fi
127+ LIBDIRS="$(find $(eval echo \$$output) -name \*.so\* -exec dirname {} \+ | sort | uniq | tr '\n' ':'):$LIBDIRS"
128+ done
129+ # Add the local library paths to remove dependencies on the bootstrap
130+ for output in $outputs; do
131+ if [ "$output" = debug ]; then continue; fi
132+ OUTPUTDIR=$(eval echo \$$output)
133+ BINLIBS=$(find $OUTPUTDIR/bin/ -type f; find $OUTPUTDIR -name \*.so\*)
134+ echo "$BINLIBS" | while read i; do
135+ patchelf --set-rpath "$LIBDIRS:$(patchelf --print-rpath "$i")" "$i" || true
136+ patchelf --shrink-rpath "$i" || true
137+ done
138+ done
139+ '';
140+
141+ disallowedReferences = [ openjdk14-bootstrap ];
142+
143+ meta = with stdenv.lib; {
144+ homepage = "https://openjdk.java.net/";
145+ license = licenses.gpl2;
146+ description = "The open-source Java Development Kit";
147+ maintainers = with maintainers; [ edwtjo ];
148+ platforms = [ "i686-linux" "x86_64-linux" "aarch64-linux" "armv7l-linux" "armv6l-linux" ];
149+ };
150+
151+ passthru = {
152+ architecture = "";
153+ home = "${openjdk}/lib/openjdk";
154+ inherit gtk3;
155+ };
156+ };
157+in openjdk