@@ -0,0 +1,258 @@
1+{ stdenv, lib, fetchurl, bash, cpio, pkgconfig, file, which, unzip, zip, cups, freetype
2+, alsaLib, bootjdk, cacert, perl, liberation_ttf, fontconfig, zlib, lndir
3+, libX11, libICE, libXrender, libXext, libXt, libXtst, libXi, libXinerama, libXcursor
4+, libjpeg, giflib
5+, setJavaClassPath
6+, minimal ? false
7+#, enableInfinality ? true # font rendering patch
8+, enableGnome2 ? true, gtk2, gnome_vfs, glib, GConf
9+}:
10+
11+let
12+
13+ /**
14+ * The JRE libraries are in directories that depend on the CPU.
15+ */
16+ architecture =
17+ if stdenv.system == "i686-linux" then
18+ "i386"
19+ else if stdenv.system == "x86_64-linux" then
20+ "amd64"
21+ else
22+ throw "openjdk requires i686-linux or x86_64 linux";
23+
24+ update = "";
25+ build = "180";
26+ baseurl = "http://hg.openjdk.java.net/jdk9/jdk9";
27+ repover = "jdk-9${update}+${build}";
28+ paxflags = if stdenv.isi686 then "msp" else "m";
29+ jdk9 = fetchurl {
30+ url = "${baseurl}/archive/${repover}.tar.gz";
31+ sha256 = "05f3i6p35nh4lwh17znkmwbb8ccw1hl1qs5hnqivpph27lpdpqnn";
32+ };
33+ langtools = fetchurl {
34+ url = "${baseurl}/langtools/archive/${repover}.tar.gz";
35+ sha256 = "0gpgg0mz29jvfck6p6kqqyi3b9lx3d4s3h0dnriswmjnw0dy3bc6";
36+ };
37+ hotspot = fetchurl {
38+ url = "${baseurl}/hotspot/archive/${repover}.tar.gz";
39+ sha256 = "1zb0pzfgnykpllm9ibwqqrzhbsxdxq1cj5rdmd5h51qjfzd8k3js";
40+ };
41+ corba = fetchurl {
42+ url = "${baseurl}/corba/archive/${repover}.tar.gz";
43+ sha256 = "1rv4gcidr0b71d7wkchx4g3gxkirpg98y0mlicqaah1vmvx3knkp";
44+ };
45+ jdk = fetchurl {
46+ url = "${baseurl}/jdk/archive/${repover}.tar.gz";
47+ sha256 = "1g3dwszz7v8812fp53vpsbmd5ingzwym8kwz4iq45bf0d1df95x9";
48+ };
49+ jaxws = fetchurl {
50+ url = "${baseurl}/jaxws/archive/${repover}.tar.gz";
51+ sha256 = "0f7vblr4c322rvjgaim8lp91s9gkf1sf31mgzhl433h5m5hs5z26";
52+ };
53+ jaxp = fetchurl {
54+ url = "${baseurl}/jaxp/archive/${repover}.tar.gz";
55+ sha256 = "1c552q4360aqfr8h6720ckk8sn4fw8c5nix5gc826sj4vrk7gqz2";
56+ };
57+ nashorn = fetchurl {
58+ url = "${baseurl}/nashorn/archive/${repover}.tar.gz";
59+ sha256 = "1hi9152w94gkwypj32nlxzp7ryzc04pp72qvr4z9m2vdc85hglhc";
60+ };
61+ openjdk9 = stdenv.mkDerivation {
62+ # name = "openjdk-9u${update}b${build}";
63+ name = "openjdk-9ea-b${build}";
64+
65+ srcs = [ jdk9 langtools hotspot corba jdk jaxws jaxp nashorn ];
66+ sourceRoot = ".";
67+
68+ outputs = [ "out" "jre" ];
69+
70+ nativeBuildInputs = [ pkgconfig ];
71+ buildInputs = [
72+ cpio file which unzip zip perl bootjdk zlib cups freetype alsaLib
73+ libjpeg giflib libX11 libICE libXext libXrender libXtst libXt libXtst
74+ libXi libXinerama libXcursor lndir fontconfig
75+ ] ++ lib.optionals (!minimal && enableGnome2) [
76+ gtk2 gnome_vfs GConf glib
77+ ];
78+
79+ #move the seven other source dirs under the main jdk8u directory,
80+ #with version suffixes removed, as the remainder of the build will expect
81+ prePatch = ''
82+ mainDir=$(find . -maxdepth 1 -name jdk9\*);
83+ find . -maxdepth 1 -name \*jdk\* -not -name jdk9\* | awk -F- '{print $1}' | while read p; do
84+ mv $p-* $mainDir/$p
85+ done
86+ cd $mainDir
87+ '';
88+
89+ patches = [
90+ ./fix-java-home-jdk9.patch
91+ ./read-truststore-from-env-jdk9.patch
92+ ./currency-date-range-jdk8.patch
93+ #] ++ lib.optionals (!minimal && enableInfinality) [
94+ # ./004_add-fontconfig.patch
95+ # ./005_enable-infinality.patch
96+ ] ++ lib.optionals (!minimal && enableGnome2) [
97+ ./swing-use-gtk-jdk9.patch
98+ ];
99+
100+ preConfigure = ''
101+ chmod +x configure
102+ substituteInPlace configure --replace /bin/bash "${bash}/bin/bash"
103+
104+ configureFlagsArray=(
105+ "--with-boot-jdk=${bootjdk.home}"
106+ "--with-update-version=${update}"
107+ "--with-build-number=${build}"
108+ "--with-milestone=fcs"
109+ "--enable-unlimited-crypto"
110+ "--disable-debug-symbols"
111+ "--disable-freetype-bundling"
112+ "--with-zlib=system"
113+ "--with-giflib=system"
114+ "--with-stdc++lib=dynamic"
115+
116+ # glibc 2.24 deprecated readdir_r so we need this
117+ # See https://www.mail-archive.com/openembedded-devel@lists.openembedded.org/msg49006.html
118+ "--with-extra-cflags=-Wno-error=deprecated-declarations -Wno-error=format-contains-nul -Wno-error=unused-result"
119+ ''
120+ + lib.optionalString minimal "\"--enable-headless-only\""
121+ + ");";
122+
123+ NIX_LDFLAGS= lib.optionals (!minimal) [
124+ "-lfontconfig" "-lcups" "-lXinerama" "-lXrandr" "-lmagic"
125+ ] ++ lib.optionals (!minimal && enableGnome2) [
126+ "-lgtk-x11-2.0" "-lgio-2.0" "-lgnomevfs-2" "-lgconf-2"
127+ ];
128+
129+ buildFlags = [ "all" ];
130+
131+ installPhase = ''
132+ mkdir -p $out/lib/openjdk $out/share $jre/lib/openjdk
133+
134+ cp -av build/*/images/jdk/* $out/lib/openjdk
135+
136+ # Remove some broken manpages.
137+ rm -rf $out/lib/openjdk/man/ja*
138+
139+ # Mirror some stuff in top-level.
140+ mkdir $out/include $out/share/man
141+ ln -s $out/lib/openjdk/include/* $out/include/
142+ ln -s $out/lib/openjdk/man/* $out/share/man/
143+
144+ # jni.h expects jni_md.h to be in the header search path.
145+ ln -s $out/include/linux/*_md.h $out/include/
146+
147+ # Copy the JRE to a separate output and setup fallback fonts
148+ cp -av build/*/images/jre $jre/lib/openjdk/
149+ mkdir $out/lib/openjdk/jre
150+ ${lib.optionalString (!minimal) ''
151+ mkdir -p $jre/lib/openjdk/jre/lib/fonts/fallback
152+ lndir ${liberation_ttf}/share/fonts/truetype $jre/lib/openjdk/jre/lib/fonts/fallback
153+ ''}
154+
155+ # Remove crap from the installation.
156+ rm -rf $out/lib/openjdk/demo
157+ ${lib.optionalString minimal ''
158+ for d in $out/lib/openjdk/lib $jre/lib/openjdk/jre/lib; do
159+ rm ''${d}/{libjsound,libjsoundalsa,libawt*,libfontmanager}.so
160+ done
161+ ''}
162+
163+ lndir $jre/lib/openjdk/jre $out/lib/openjdk/jre
164+
165+ # Make sure cmm/*.pf are not symlinks:
166+ # https://youtrack.jetbrains.com/issue/IDEA-147272
167+ # in 9, it seems no *.pf files end up in $out ... ?
168+ # rm -rf $out/lib/openjdk/jre/lib/cmm
169+ # ln -s {$jre,$out}/lib/openjdk/jre/lib/cmm
170+
171+ # Set PaX markings
172+ exes=$(file $out/lib/openjdk/bin/* $jre/lib/openjdk/jre/bin/* 2> /dev/null | grep -E 'ELF.*(executable|shared object)' | sed -e 's/: .*$//')
173+ echo "to mark: *$exes*"
174+ for file in $exes; do
175+ echo "marking *$file*"
176+ paxmark ${paxflags} "$file"
177+ done
178+
179+ # Remove duplicate binaries.
180+ for i in $(cd $out/lib/openjdk/bin && echo *); do
181+ if [ "$i" = java ]; then continue; fi
182+ if cmp -s $out/lib/openjdk/bin/$i $jre/lib/openjdk/jre/bin/$i; then
183+ ln -sfn $jre/lib/openjdk/jre/bin/$i $out/lib/openjdk/bin/$i
184+ fi
185+ done
186+
187+ # Generate certificates.
188+ (
189+ cd $jre/lib/openjdk/jre/lib/security
190+ rm cacerts
191+ perl ${./generate-cacerts.pl} $jre/lib/openjdk/jre/bin/keytool ${cacert}/etc/ssl/certs/ca-bundle.crt
192+ )
193+
194+ ln -s $out/lib/openjdk/bin $out/bin
195+ ln -s $jre/lib/openjdk/jre/bin $jre/bin
196+ ln -s $jre/lib/openjdk/jre $out/jre
197+ '';
198+
199+ # FIXME: this is unnecessary once the multiple-outputs branch is merged.
200+ preFixup = ''
201+ prefix=$jre stripDirs "$stripDebugList" "''${stripDebugFlags:--S}"
202+ patchELF $jre
203+ propagatedNativeBuildInputs+=" $jre"
204+
205+ # Propagate the setJavaClassPath setup hook from the JRE so that
206+ # any package that depends on the JRE has $CLASSPATH set up
207+ # properly.
208+ mkdir -p $jre/nix-support
209+ #TODO or printWords? cf https://github.com/NixOS/nixpkgs/pull/27427#issuecomment-317293040
210+ echo -n "${setJavaClassPath}" > $jre/nix-support/propagated-native-build-inputs
211+
212+ # Set JAVA_HOME automatically.
213+ mkdir -p $out/nix-support
214+ cat <<EOF > $out/nix-support/setup-hook
215+ if [ -z "\$JAVA_HOME" ]; then export JAVA_HOME=$out/lib/openjdk; fi
216+ EOF
217+ '';
218+
219+ postFixup = ''
220+ # Build the set of output library directories to rpath against
221+ LIBDIRS=""
222+ for output in $outputs; do
223+ LIBDIRS="$(find $(eval echo \$$output) -name \*.so\* -exec dirname {} \+ | sort | uniq | tr '\n' ':'):$LIBDIRS"
224+ done
225+
226+ # Add the local library paths to remove dependencies on the bootstrap
227+ for output in $outputs; do
228+ OUTPUTDIR=$(eval echo \$$output)
229+ BINLIBS=$(find $OUTPUTDIR/bin/ -type f; find $OUTPUTDIR -name \*.so\*)
230+ echo "$BINLIBS" | while read i; do
231+ patchelf --set-rpath "$LIBDIRS:$(patchelf --print-rpath "$i")" "$i" || true
232+ patchelf --shrink-rpath "$i" || true
233+ done
234+ done
235+
236+ # Test to make sure that we don't depend on the bootstrap
237+ for output in $outputs; do
238+ if grep -q -r '${bootjdk}' $(eval echo \$$output); then
239+ echo "Extraneous references to ${bootjdk} detected"
240+ exit 1
241+ fi
242+ done
243+ '';
244+
245+ meta = with stdenv.lib; {
246+ homepage = http://openjdk.java.net/;
247+ license = licenses.gpl2;
248+ description = "The open-source Java Development Kit";
249+ maintainers = with maintainers; [ edwtjo ];
250+ platforms = platforms.linux;
251+ };
252+
253+ passthru = {
254+ inherit architecture;
255+ home = "${openjdk9}/lib/openjdk";
256+ };
257+ };
258+in openjdk9