1{ stdenv, fetchurl, unzip, zip, procps, coreutils, alsaLib, ant, freetype
2, which, bootjdk, nettools, xorg, file
3, fontconfig, cpio, cacert, perl, setJavaClassPath
4, minimal ? false
5}:
6
7let
8
9 /**
10 * The JRE libraries are in directories that depend on the CPU.
11 */
12 architecture =
13 if stdenv.system == "i686-linux" then
14 "i386"
15 else if stdenv.system == "x86_64-linux" then
16 "amd64"
17 else
18 throw "openjdk requires i686-linux or x86_64 linux";
19
20 update = "80";
21
22 build = "32";
23
24 # On x86 for heap sizes over 700MB disable SEGMEXEC and PAGEEXEC as well.
25 paxflags = if stdenv.isi686 then "msp" else "m";
26
27 cupsSrc = fetchurl {
28 url = http://ftp.easysw.com/pub/cups/1.5.4/cups-1.5.4-source.tar.bz2;
29 md5 = "de3006e5cf1ee78a9c6145ce62c4e982";
30 };
31
32 baseurl = "http://hg.openjdk.java.net/jdk7u/jdk7u";
33 repover = "jdk7u${update}-b${build}";
34 jdk7 = fetchurl {
35 url = "${baseurl}/archive/${repover}.tar.gz";
36 sha256 = "1r8xnn87nmqaq2f8i3cp3i9ngq66k0c0wgkdq5cf59lkgs8wkcdi";
37 };
38 langtools = fetchurl {
39 url = "${baseurl}/langtools/archive/${repover}.tar.gz";
40 sha256 = "01alj6pfrjqyf4irll9wg34h4w9nmb3973lvbacs528qm1nxgh9r";
41 };
42 hotspot = fetchurl {
43 url = "${baseurl}/hotspot/archive/${repover}.tar.gz";
44 sha256 = "14zla8axmg5344zf45i4cj7yyli0kmdjsh9yalmzqaphpkqjqpf2";
45 };
46 corba = fetchurl {
47 url = "${baseurl}/corba/archive/${repover}.tar.gz";
48 sha256 = "19z3ay3f2q7r2ra03c6wy8b5rbdbrkq5g2dzhrqcg0n4iydd3c40";
49 };
50 jdk = fetchurl {
51 url = "${baseurl}/jdk/archive/${repover}.tar.gz";
52 sha256 = "1q0r2l9bz2cyx4fq79x6cb2f5xycw83hl5cn1d1mazgsckp590lb";
53 };
54 jaxws = fetchurl {
55 url = "${baseurl}/jaxws/archive/${repover}.tar.gz";
56 sha256 = "1lp0mww2x3b6xavb7idrzckh6iw8jd6s1fvqgfvzs853z4ifksqj";
57 };
58 jaxp = fetchurl {
59 url = "${baseurl}/jaxp/archive/${repover}.tar.gz";
60 sha256 = "0pd874dkgxkb7frxg4n9py61kkhhck4x33dcynynwb3vl6k6iy79";
61 };
62 openjdk = stdenv.mkDerivation rec {
63 name = "openjdk-7u${update}b${build}";
64
65 srcs = [ jdk7 langtools hotspot corba jdk jaxws jaxp ];
66 sourceRoot = ".";
67
68 outputs = [ "out" "jre" ];
69
70 buildInputs =
71 [ unzip procps ant which zip cpio nettools alsaLib
72 xorg.libX11 xorg.libXt xorg.libXext xorg.libXrender xorg.libXtst
73 xorg.libXi xorg.libXinerama xorg.libXcursor xorg.lndir
74 fontconfig perl file bootjdk
75 ];
76
77 NIX_LDFLAGS = if minimal then null else "-lfontconfig -lXcursor -lXinerama";
78
79 postUnpack = ''
80 ls | grep jdk | grep -v '^jdk7u' | awk -F- '{print $1}' | while read p; do
81 mv $p-* $(ls | grep '^jdk7u')/$p
82 done
83 cd jdk7u-*
84
85 sed -i -e "s@/usr/bin/test@${coreutils}/bin/test@" \
86 -e "s@/bin/ls@${coreutils}/bin/ls@" \
87 hotspot/make/linux/makefiles/sa.make
88
89 sed -i "s@/bin/echo -e@${coreutils}/bin/echo -e@" \
90 {jdk,corba}/make/common/shared/Defs-utils.gmk
91
92 tar xf ${cupsSrc}
93 cupsDir=$(echo $(pwd)/cups-*)
94 makeFlagsArray+=(CUPS_HEADERS_PATH=$cupsDir)
95 '';
96
97 patches = [
98 ./cppflags-include-fix.patch
99 ./fix-java-home.patch
100 ./paxctl.patch
101 ./read-truststore-from-env.patch
102 ./currency-date-range.patch
103 ./linux-4.0.patch
104 ];
105
106 NIX_NO_SELF_RPATH = true;
107
108 makeFlags = [
109 "SORT=${coreutils}/bin/sort"
110 "ALSA_INCLUDE=${alsaLib}/include/alsa/version.h"
111 "FREETYPE_HEADERS_PATH=${freetype}/include"
112 "FREETYPE_LIB_PATH=${freetype}/lib"
113 "MILESTONE=${update}"
114 "BUILD_NUMBER=b${build}"
115 "USRBIN_PATH="
116 "COMPILER_PATH="
117 "DEVTOOLS_PATH="
118 "UNIXCOMMAND_PATH="
119 "BOOTDIR=${bootjdk.home}"
120 "STATIC_CXX=false"
121 "UNLIMITED_CRYPTO=1"
122 "FULL_DEBUG_SYMBOLS=0"
123 ] ++ stdenv.lib.optional minimal "BUILD_HEADLESS=1";
124
125 configurePhase = "true";
126
127 preBuild = ''
128 # We also need to PaX-mark in the middle of the build
129 substituteInPlace hotspot/make/linux/makefiles/launcher.make \
130 --replace XXX_PAXFLAGS_XXX ${paxflags}
131 substituteInPlace jdk/make/common/Program.gmk \
132 --replace XXX_PAXFLAGS_XXX ${paxflags}
133 '';
134
135 installPhase = ''
136 mkdir -p $out/lib/openjdk $out/share $jre/lib/openjdk
137
138 cp -av build/*/j2sdk-image/* $out/lib/openjdk
139
140 # Move some stuff to top-level.
141 mv $out/lib/openjdk/include $out/include
142 mv $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 # Remove some broken manpages.
148 rm -rf $out/share/man/ja*
149
150 # Remove crap from the installation.
151 rm -rf $out/lib/openjdk/demo $out/lib/openjdk/sample
152
153 # Move the JRE to a separate output.
154 mv $out/lib/openjdk/jre $jre/lib/openjdk/
155 mkdir $out/lib/openjdk/jre
156 lndir $jre/lib/openjdk/jre $out/lib/openjdk/jre
157
158 rm -rf $out/lib/openjdk/jre/bin
159 ln -s $out/lib/openjdk/bin $out/lib/openjdk/jre/bin
160
161 # Set PaX markings
162 exes=$(file $out/lib/openjdk/bin/* $jre/lib/openjdk/jre/bin/* 2> /dev/null | grep -E 'ELF.*(executable|shared object)' | sed -e 's/: .*$//')
163 echo "to mark: *$exes*"
164 for file in $exes; do
165 echo "marking *$file*"
166 paxmark ${paxflags} "$file"
167 done
168
169 # Remove duplicate binaries.
170 for i in $(cd $out/lib/openjdk/bin && echo *); do
171 if [ "$i" = java ]; then continue; fi
172 if cmp -s $out/lib/openjdk/bin/$i $jre/lib/openjdk/jre/bin/$i; then
173 ln -sfn $jre/lib/openjdk/jre/bin/$i $out/lib/openjdk/bin/$i
174 fi
175 done
176
177 # Generate certificates.
178 pushd $jre/lib/openjdk/jre/lib/security
179 rm cacerts
180 perl ${./generate-cacerts.pl} $jre/lib/openjdk/jre/bin/keytool ${cacert}/etc/ssl/certs/ca-bundle.crt
181 popd
182
183 ln -s $out/lib/openjdk/bin $out/bin
184 ln -s $jre/lib/openjdk/jre/bin $jre/bin
185 ''; # */
186
187 # FIXME: this is unnecessary once the multiple-outputs branch is merged.
188 preFixup = ''
189 prefix=$jre stripDirs "$stripDebugList" "''${stripDebugFlags:--S}"
190 patchELF $jre
191 propagatedNativeBuildInputs+=" $jre"
192
193 # Propagate the setJavaClassPath setup hook from the JRE so that
194 # any package that depends on the JRE has $CLASSPATH set up
195 # properly.
196 mkdir -p $jre/nix-support
197 echo -n "${setJavaClassPath}" > $jre/nix-support/propagated-native-build-inputs
198
199 # Set JAVA_HOME automatically.
200 mkdir -p $out/nix-support
201 cat <<EOF > $out/nix-support/setup-hook
202 if [ -z "\$JAVA_HOME" ]; then export JAVA_HOME=$out/lib/openjdk; fi
203 EOF
204 '';
205
206 postFixup = ''
207 # Build the set of output library directories to rpath against
208 LIBDIRS=""
209 for output in $outputs; do
210 LIBDIRS="$(find $(eval echo \$$output) -name \*.so\* -exec dirname {} \; | sort | uniq | tr '\n' ':'):$LIBDIRS"
211 done
212
213 # Add the local library paths to remove dependencies on the bootstrap
214 for output in $outputs; do
215 OUTPUTDIR="$(eval echo \$$output)"
216 BINLIBS="$(find $OUTPUTDIR/bin/ -type f; find $OUTPUTDIR -name \*.so\*)"
217 echo "$BINLIBS" | while read i; do
218 patchelf --set-rpath "$LIBDIRS:$(patchelf --print-rpath "$i")" "$i" || true
219 patchelf --shrink-rpath "$i" || true
220 done
221 done
222
223 # Test to make sure that we don't depend on the bootstrap
224 for output in $outputs; do
225 if grep -q -r '${bootjdk}' $(eval echo \$$output); then
226 echo "Extraneous references to ${bootjdk} detected"
227 exit 1
228 fi
229 done
230 '';
231
232 meta = {
233 homepage = http://openjdk.java.net/;
234 license = stdenv.lib.licenses.gpl2;
235 description = "The open-source Java Development Kit";
236 maintainers = [ stdenv.lib.maintainers.eelco ];
237 platforms = stdenv.lib.platforms.linux;
238 };
239
240 passthru = {
241 inherit architecture;
242 home = "${openjdk}/lib/openjdk";
243 };
244 };
245in openjdk