Java From Scratch Hint: Added Optimizations
tush at yahoo.com
Thu Jul 18 11:39:59 PDT 2002
This is a multi-part message in MIME format.
Content-Type: text/plain; charset=us-ascii; format=flowed
LFS ID: 1377
TITLE: Compiling Java 2 SDK from Scratch
LFS VERSION: Any.
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.
* Optmizing the build.
* Added Problems and Workarounds section.
* Added fix by Harald Meier.
* 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
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:
You will need to register at the website and agree to the "SUN COMMUNITY SOURCE
LICENSE" before downloading the code. Note that the file
j2sdk-sec-1_4_0-src-scsl.zip is not needed.
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
SUN COMMUNITY SOURCE LICENSE:)
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.
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.
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
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:
cd $SRC &&
for i in j2sdk-1_4_0-*.zip ; do unzip $i; done
Apply the downloaded patch to fix some compilation problems.
cd $SRC &&
patch -Np1 -i j2sdk.patch
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.
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
stuff. People have reported problems when compiling the documentation. It
requires rpm and even then the documentation is not built. So be a good boy/girl
and do an
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.
The compilation will go awry if the following variables are set, so unset them.
I also remove any CFLAGS or CXXFLAGS settings since I don't like taking risks:)
Well, that was before, now I do like taking risks:)) So do the following to get
your CFLAGS and CXXFLAGS recognized. I have compiled with "-O3 -march=i686"
without problems. Also, I applied the combreloc patch to binutils:)
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. This is
entirely optional, I don't create the file.
echo "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 4 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.
The j2sdk-image is the built JDK, congrats:)
mkdir -p /opt/java &&
cp -a j2sdk-image /opt/java/j2sdk-1.4.0-tt &&
cd /opt/java &&
ln -s j2sdk-1.4.0-ttimage j2sdk
Add the following to your </etc/profile> or <~/.profile>. Many programs expect
the JAVA_HOME variable to find the JDK.
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
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.
Reported Problems & Workarounds:
* Harald Meier reported that if there are problems, try removing the "-z defs"
from LDFLAGS_COMMON from line 263 in the file
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