Lillian ran into a few minor problems trying to build ‘raw’ OpenJDK6 (i.e. the tarball direct from Sun without any of the numerous IcedTea patches, fixes and extensions) yesterday, and so I decided to give it a go as well. Unfortunately, it seems it still isn’t possible to build it out of the box on a modern GNU/Linux system. In the end, I had to apply three patches (effectively two as one was split into two by the HotSpot build changes in IcedTea).
patches/icedtea-gcc-4.3.patch from IcedTea6 is needed to fix some issues when building with GCC 4.3 which is the default on most current distributions. In released versions, this is a single patch, but in current Mercurial and the upcoming 1.4 release, the HotSpot changes in all patches are split off to enable the version of HotSpot used by the build to be changed.
patches/icedtea-no-bcopy.patch was needed to remove some local defines of some BSD functions such as
bcopy. There was some noise about taking this upstream on the mailing lists, but it’s not yet in a tarball it seems.
With these patches, I could build as follows:
$ mkdir openjdk
$ tar xzf openjdk-6-src-b14-25_nov_2008.tar.gz -C openjdk
$ cd openjdk
$ patch -Np1 < $ICEDTEA_SOURCES/patches/icedtea-gcc-4.3.patch
$ patch -Np1 < $ICEDTEA_SOURCES/patches/hotspot/original/icedtea-gcc-4.3.patch
$ patch -Np1 < $ICEDTEA_SOURCES/patches/icedtea-no-bcopy.patch
$ cd control/build
$ unset JAVA_HOME
$ unset LD_LIBRARY_PATH
$ JAVAC= LANG=C make ALT_BOOTDIR=$CURRENT_ICEDTEA_INSTALL \
IMPORT_BINARY_PLUGS=false ANT=/usr/bin/ant ANT_HOME=/usr/share/ant
>>>Finished making images @ Fri Jan 30 10:59:43 GMT 2009 ...
make: Leaving directory `/tmp/openjdk/jdk/make'
Control build finished: 09-01-30 10:59
$ ../build/linux-amd64/j2sdk-image/bin/java -version
openjdk version "1.6.0-internal"
OpenJDK Runtime Environment (build 1.6.0-internal-andrew_30_jan_2009_10_46-b00)
OpenJDK 64-Bit Server VM (build 11.0-b17, mixed mode)
You can build a bit quicker if you make use of parallelisation which I neglected to do here; add
PARALLEL_JOBS is how many processes you want to run simultaneously. The usual rule is number of cores plus one. IcedTea of course supports doing this too; just add
--with-parallel-jobs=$PARALLEL_JOBS when you run
configure and it will add the necessary make wizardry for you.
For the configuration,
CURRENT_ICEDTEA_INSTALL should point to your existing IcedTea install. This is the only way to build OpenJDK6; I didn't try it this time round, but I know from experience that it still needs a fair few patches to remove Sunisms from the OpenJDK source code in order to allow a GNU Classpath JDK like GCJ to be used instead. This shouldn't be a problem though; you'll find IcedTea in Fedora (
yum install java-1.6.0-openjdk), Gentoo (
emerge -v icedtea6-bin), Ubuntu and Debian testing (
aptitude install openjdk-6-jdk). The magic path is usually something like
java-1.6.0-openjdk on Fedora and
/usr/lib/jvm/icedtea6 on Gentoo.
ICEDTEA_SOURCES points to a copy of the IcedTea tree. If you get this from a release tarball rather than hg, then you don't need to try finding the second gcc patch... you'd have a hard time doing so
The OpenJDK build doesn't like environment variables like
JAVA_HOME being set. It also complains about you having any fancy modern locale set in
LANG so it's simplest just to run
JAVAC environment variable is a funny one; it allows the path to
javac to be overridden for the build, but it doesn't only override the binary path as it should, but also drops all the necessary memory and classpath options passed to it. Thus, I don't see how any build which sets
JAVAC could work... Gentoo seems to like to set both
JAVAC for some reason, so make sure they are unset before you build.
Of course, with the resulting build, you'll be missing a lot of features that IcedTea provides...
- A web plugin
- Java web start
- PulseAudio sound support
- Support for architectures like PPC, ARM and MIPS via Zero or CACAO
- A faster more recent HotSpot if you use the current Mercurial tree or the upcoming 1.4 release
- Lots of other lovely stuff provided by our patches including a more up-to-date version of Gervill, the results of the XRender pipeline project and support for testing your build with JTReg.
You also avoid the pain of having to remember those crazy make variables; it's just
./configure; make on most modern GNU/Linux systems; file a bug if that's not the case.
I still feel that the IcedTea project does a very important job in taking the raw materials provided by Sun and turning them into something useful. That's why you'll find it's IcedTea being shipped with all those distros, and not 'straight' OpenJDK (which in most cases actually means the version that may-eventually-be-1.7). Thanks to all the great developers for their continued efforts and for the support of Red Hat on this effort.
The other thing about your own build is you can't of course actually call it 'Java'; one of the things you need to do before you can is run it through the Java Compatibility Kit. It has lots of tests your build has to pass. Unfortunately, Sun still keep this as a horrible proprietary blob of code which means you have to sign up to get a copy, be 'approved' and then work on your testing in a dark clammy room in secret. Fortunately, the kind people at Red Hat have already undertaken this momentous task for you, so you can just grab one of the OpenJDK builds in Fedora which has already passed. Thus, according to Sun's FAQ, the Fedora binaries 'are compatible with the Java(TM) SE 6 platform'
Let's hope things continue to improve in the direction of making more things in the Java world open and Free. In the Free Java room at this year's FOSDEM (happening just next weekend), you'll be able to find out all about what's coming next and meet some of the brave people forging the new frontiers...