Update Java From Scratch hint

Tushar Teredesai tush at yahoo.com
Fri Jul 5 00:17:51 PDT 2002

This is a multi-part message in MIME format.
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Update URL for downloading patch. Got may bug reports:)

Tushar Teredesai
LFS ID: 1377

Content-Type: text/plain;
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;

TITLE:		Compiling Java 2 SDK from Scratch


AUTHOR:		Tushar Teredesai <Tush at Yahoo.Com>

	How to compile Java 2 SDK Source (available from Sun) using gcc3 so that
	you can use it as a plugin for your shiny new gcc3 compiled mozilla.


Change Log:
	* First public version.

This hint and the attached patch is only useful for people who have accepted SUN
COMMUNITY SOURCE LICENSE for the Java 2 Platform Standard Edition. Note that you
are not allowed to distribute the resulting JDK/JRE and you also cannot use the
resulting JDK to compile programs for distribution unless they pass Sun's
compatiblity tests. In short don't use the resulting JDK except for your
personal use.

Pre-requisites (post LFS):
	* XFree86 <http://freshmeat.net/projects/xfree86/>
        * InfoZip Zip and Unzip <http://freshmeat.net/projects/zip/>
        * InfoZip Unzip <http://freshmeat.net/projects/unzip/>
	* GNU cpio <http://freshmeat.net/projects/cpio>
        * Turbo C Shell <http://freshmeat.net/projects/tcsh/>
	* Sun JDK 1.4 <http://freshmeat.net/projects/sunjdk/>

The JDK has a circular dependency and hence requires a Java compiler to compile
some parts for bootstrapping. You can install the JDK in a non-standard location
for compiling the SDK and then delete it. Also, it needs a 1.4 version JDK
according to Sun's website. If you don't want to install the jdk permenantly, I
have included instructions on how to install it for the duration of the

Install cpio binary in /bin or make a symlink to the it from /bin.

Note that when I build the SDK, I had many packages already installed, so I
don't have the exact dependencies. If anyone runs into any problems regarding
missing dependencies, let me know and I will update this section.

Packages to download:
	* Java 2 SDK Source <http://wwws.sun.com/software/java2/download.html>
>From Sun's website, download the following files:
	- j2sdk-1_4_0-src-scsl.zip
	- j2sdk-1_4_0-motif-linux-i386.zip
	- j2sdk-1_4_0-mozilla_headers-unix.zip
You will need to register at the website and agree to the "SUN COMMUNITY SOURCE
LICENSE" before downloading the code.

The Java Source doesn't work well with locally installed mozilla and motif
headers and requires the download of the header files from the above site where
you download the source.

	* My Patch <http://www.geocities.com/tush/lfs/>
The patch fixes some non-gcc3 compliant code and few missing library links. It
took me some time to understand the build process and to figure out how to link
additional libraries. You agree that by downloading the patch, you accept the

Alternate site:
This hint is also available at <http://www.geocities.com/tush/lfs>. The latest
version of the hint is usually available there.

Compiling Java 2 SDK:

This hint, unlike the mozilla and openoffice hints, is short and sweet:)

I will refer to the root of the source tree as $SRC.
	cd $SRC

If you don't have JDK 1.4 installed, you can install the JDK in the current
directory for the duration of the compilation.
	chmod +x j2sdk-1_4_0_01-linux-i586.bin &&

This location is referred to as JAVA_HOME. So set the variable now.
	export JAVA_HOME=$SRC/j2sdk1.4.0_01
Also since the JDK binary from Sun is linked against gcc2, download it from 
<http://www.linuxfromscratch.org/~timothy/misc/> and move it where the jdk can
find it.
	mv libstdc++-* $JAVA_HOME/jre/lib/i386/
Try running $JAVA_HOME/bin/java and if it reports any missing libraries, make
appropriate links in $JAVA_HOME/jre/lib/i386.

Unzip all the files in this directory:
	for i in j2sdk-1_4_0-*.zip ; do unzip $i; done

Apply the downloaded patch to fix some compilation problems.

Now we will set some variables required by the build.

The following variables should point to where we unzipped the respective header
	export ALT_MOTIF_DIR=$SRC &&

The Makefiles set the following variable to a ridiculous value. So change it.
	export ALT_DEVTOOLS_PATH="/usr/bin"

The following two variables are not required to be set, but if set they will
give the value you want when running "javac -version". I like to set them to
non-default values so that I can identify when I am switching between JDKs.
	export MILESTONE="ttcompiled" &&
	export BUILD_NUMBER=`date +%s`

Set this variable if you don't need to build the documentation and other related
	export DEV_ONLY=true

There is also a variable J2RE_ONLY which if set to true builds only the Runtime
Env. Avoid setting that. Or if you like adventure, set it and try...

This one took me a long time to figure out. After getting some build errors
related to pthread variables, as per the standard practice I tried setting
LDFLAGS, but continued getting the same errors; grepping thru the make files
gave me the following variable.
	export OTHER_LDFLAGS="-lpthread"

The compilation will go awry if the following variables are set, so unset them.
	unset JAVA_HOME
I also remove any CFLAGS or CXXFLAGS settings since I don't like taking risks:)

The build also looks for a Redhat Release 6.1. Though the error is not show
stopping, if you want you can make a file for the duration of the build.
	cat "Red Hat Linux release 6.1 (LFS)" > /etc/redhat-release

Now the most simple part of the build.
	cd $SRC/control/make &&

The build took around 3 hours on my PIII-800.

If anytime during the build, you would like to start from scratch, you can do a
"make clobber" in $SRC/control/make to go back to the beginning.

The built SDK and JRE are in the following directory.
	cd $SRC/control/build/linux-i386

The j2sdk-image is the built JDK, congrats:)
	mkdir -p /opt/java &&
	cp -a j2sdk-image /opt/java &&
	cd /opt/java &&
	ln -s j2sdk-image j2sdk

Add the following to your </etc/profile> or <~/.profile>. Many programs expect
the JAVA_HOME variable to find the JDK.
	export JAVA_HOME=/opt/java/j2sdk
	export PATH=$PATH:$JAVA_HOME/bin

Tip: You can install multiple jdk's in /opt/java, changing between them is just
as easy as:
	ln -sf j2sdk-<required-version> j2sdk

Link the java plugin we built for mozilla. After all that was the main reason
for me compiling jdk from scratch! Check out the mozilla hint on how to do this.

Now LFS CVS is all ready for big time. The first system out there to be
completely gcc3:))

If you deviate from the hint and you run into problems, first try following the
hint exactly to see if it works. Also, if you deviate from the hint and run into
successes, please let me know so that I can add the same to the hint.

Don't forget to send me bug reports and enhancements so that I can keep the hint
updated. An appropriate place to discuss problems is the blfs-support mailing


Unsubscribe: send email to listar at linuxfromscratch.org
and put 'unsubscribe hints' in the subject header of the message

More information about the hints mailing list