Typo
[linux_from_scratch_hints.git] / OLD / javafromscratch.txt
blobfb71138fbb1af22740b9ebeb156a1189d3cbf946
1 TITLE:          Compiling Java 2 SDK from Scratch
3 LFS VERSION:    LFS-4.0
5 AUTHOR:         Tushar Teredesai <Tushar@LinuxFromScratch.Org>
7 SYNOPSIS:
8         How to compile Java 2 SDK Source (available from Sun) using gcc3 so that
9         you can use it as a plugin for your shiny new gcc3 compiled mozilla.
11 HINT:
13 Primary Location of this hint:
14         http://www.linuxfromscratch.org/~tushar/
15 The latest version of the hint and any relevant patches are available at that
16 site. Please refer to the primary location before submitting
17 bug-reports/enhancements to this hint.
19 You may freely copy this document or create derivate works or distribute the
20 document in any format. At your discretion, you may give credit to the original
21 author:)
23 Use the hint at your own risk. Neither the author, nor the Linux From Scratch
24 project accepts any reponsibility for anything that happens when using these
25 documents or associated files.
27 An appropriate place to discuss this hint is blfs-support MailingList/NewsGroup
28 at LinuxFromScratch.Org.
30 Change Log:
31 [2002-01-13]
32         * Updated to j2sdk-1.4.1.
33         * Added fix so that system installed motif libraries are not linked.
34 [2003-01-03]
35         * Added fix for lesstif to avoid conflict with gcj headers.
36 [2002-12-25]
37         * Changed primary location and e-mail address.
38 [2002-11-13]
39         * Removed -O3 from the Makefiles since it causes miscompilation.
40 [2002-10-27]
41         * Upgraded the included zlib 1.1.3 to 1.1.4.
42 [2002-10-24]
43         * Added compiling against system installed dynamic lesstif.
44         * Added warning about OpenMotif in the workaround sections.
45         * Fixed typo in libstdc++ version.
46 [2002-09-26]
47         * Added info on making make verbose.
48         * Added note on CFLAGS.
49         * Added note for insanity mode.
50 [2002-08-31]
51         * Added discussion on renaming i386 directories to i?86.
52 [2002-07-24]
53         * Added link to German translation.
54 [2002-07-19]
55         * Added CLASSPATH mini-hint.
56 [2002-07-18]
57         * Optmizing the build.
58         * Added Problems and Workarounds section.
59         * Added fix by Harald Meier.
60 [2002-06-20]
61         * First public version.
63 NOTE:
64 This hint and the attached patch is only useful for people who have accepted SUN
65 COMMUNITY SOURCE LICENSE for the Java 2 Platform Standard Edition. Note that you
66 are not allowed to distribute the resulting JDK/JRE and you also cannot use the
67 resulting JDK to compile programs for distribution unless they pass Sun's
68 compatiblity tests. In short don't use the resulting JDK except for your
69 personal use.
71 Future Plans:
72 * Use system installed Mozilla headers and build only Mozilla-1.0 plugin and
73   Netscape Plugin. [Check the unfinished patch.]
74 * Remove the dependency on the sun's binary jdk and to use some source based
75   compiler such as jikes/japhar/kaffe for bootstrapping.
77 Translations:
78         * German by Jens Gutzeit
79                 <http://lfsforum.org/howtos/read.php?howto=7>
81 Pre-requisites (post LFS):
82         * XFree86
83                 <http://freshmeat.net/projects/xfree86/>
84         * InfoZip Zip and Unzip
85                 <http://freshmeat.net/projects/zip/>
86         * InfoZip Unzip
87                 <http://freshmeat.net/projects/unzip/>
88         * GNU cpio
89                 <http://freshmeat.net/projects/cpio>
90         * Tenex C Shell
91                 <http://freshmeat.net/projects/tcsh/>
92         * Sun JDK 1.4
93                 <http://freshmeat.net/projects/sunjdk/>
94 Installation of all these packages is covered in the BLFS book at
95 <http://beyond.linuxfromscratch.org>.
97 The JDK has a circular dependency and hence requires a Java compiler to compile
98 some parts for bootstrapping. You can install the JDK in a non-standard location
99 for compiling the SDK and then delete it. Also, it needs a 1.4 version JDK
100 according to Sun's website. If you don't want to install the jdk permenantly, I
101 have included instructions on how to install it for the duration of the
102 compilation. Using the same instructions, you can install the precompiled JDK
103 available from Sun.
105 Note that when I build the SDK, I had many packages already installed, so I
106 don't have the exact dependencies. If anyone runs into any problems regarding
107 missing dependencies, let me know and I will update this section.
109 Packages to download:
110         * Zlib 1.1.4
111                 <http://freshmeat.net/projects/zlib>
112 Though this library may already be installed, you will need the source code to
113 update the source code that comes with j2sdk.
114         * Java 2 SDK Source <http://wwws.sun.com/software/java2/download.html>
115 From Sun's website, download the following files (you will need to sign up and
116 agree to SCSL):
117         - j2sdk-1_4_1-src-scsl-a.zip
118         - j2sdk-1_4_1-src-scsl-b.zip
119         - j2sdk-1_4_1-mozilla_headers-unix.zip
120 The last zip file may be referred to as Mozilla binaries at the above URL.
121 You will need to register at the website and agree to the "SUN COMMUNITY SOURCE
122 LICENSE" before downloading the code. Note that the file
123 j2sdk-sec-1_4_1-src-scsl.zip is not needed (unless you have a certificate from a
124 certificate authority).
126 Also download the patches from the primary site of this hint. Each patch should
127 have a short blurb on what it does.
128 You agree that by downloading the patch, you accept the SUN COMMUNITY SOURCE
129 LICENSE:)
131 This hint, unlike the mozilla and openoffice hints, is short and sweet:)
134 Installing the Binary Version for Bootstrapping:
136 You need an existing JDK Version 1.4 to bootstrap the build. You can use the
137 instructions below to install the jdk either in the current directory or in a
138 system wide directory (e.g. /opt/java/j2sdk-precompiled-1.4).
139         VERSION=1.4.1_01
140         V=`echo ${VERSION} | sed -e "s/\./_/g"`
141         # Check out where the tar file begins and extract it
142         T=`grep -a tail j2sdk-${V}-linux-i?86.bin | cut -f 2 -d " "`
143         tail $T j2sdk-${V}-linux-i?86.bin > install.sfx.$$
144         chmod +x install.sfx.$$
145         # Extract the files and move them to where we want the jdk installed.
146         ./install.sfx.$$
147         cd j2sdk${VERSION}
148         install -d /opt/java/j2sdk-precompiled-1.4.1
149         mv * /opt/java/j2sdk-precompiled-1.4.1
151 This location is referred to as JAVA_HOME. So set the variable now.
152         export JAVA_HOME=/opt/java/j2sdk-precompiled-1.4.1
153 Sun's binary JDK is linked against gcc2 libraries, hence you will need the gcc2
154 libraries for compatibility reasons. There are two options to get this library.
155 One is to compile gcc2 (with c++) in a temporary prefix (such as /var/tmp) and
156 then move the resulting shared libraries in /var/tmp/lib to /usr/lib. Another
157 option is to download the precompiled library from
158 <http://www.linuxfromscratch.org/~timothy/misc and move it to where the JDK can
159 find it.
160         mv libstdc++-* $JAVA_HOME/jre/lib/i386/
161 Try running $JAVA_HOME/bin/java and if it reports any missing libraries, make
162 appropriate links. For example, if you are using gcc-2.95.3 libs, then make the
163 following symlink.
164         ln -sf libstdc++-libc6.3-2.so.3 libstdc++-libc6.1-1.so.2
167 Compiling Java 2 SDK:
169 Unzip all the files where you plan to compile JDK:
170         cd $SRC
172 The source files are split into two (a & b) so just combine them together using
173 cat:
174         cat j2sdk-1_4_1-src-scsl-{a,b}.zip > j2sdk-1_4_1-src-scsl.zip
176 Now unzip the two files
177         unzip j2sdk-1_4_1-src-scsl.zip
178         unzip j2sdk-1_4_1-mozilla_headers-unix.zip
180 Apply the patches to fix the syntax and various other issues.
181 Sun includes the Motif version it needs and compiles it. To avoid linking with
182 the system installed libXm.a we change the name of the internal motif library
183 that is built. Linking against system installed libXm leads to crashes.
185 Now we will set some variables required by the build.
186         export ALT_BOOTDIR="$JAVA_HOME"
188 The following variable should point to where mozilla headers are unzipped.
189         export ALT_MOZILLA_PATH=$SRC
191 The Makefiles set the following variable to a ridiculous value. So change it.
192         export ALT_DEVTOOLS_PATH="/usr/bin"
194 The following two variables are not required to be set, but if set they will
195 give the value you want when running "javac -version". I like to set them to
196 non-default values so that I can identify when I am switching between JDKs. Note
197 that these variables cannot contain spaces.
198         export MILESTONE="ttcompiled" &&
199         export BUILD_NUMBER=`date +%s`
201 We will need a root certificates file since it is not included in the source. We
202 use the cacerts file that is available with the precompiled j2sdk we installed
203         export ALT_CACERTS_FILE=${ALT_BOOTDIR}/jre/lib/security/cacerts
205 Set this variable if you don't need to build the documentation and other related
206 stuff. People have reported problems when compiling the documentation. It
207 requires rpm and even then the documentation is not built. So be a good boy/girl
208 and do an
209         export DEV_ONLY=true
211 There is also a variable J2RE_ONLY which if set to true builds only the Runtime
212 Env. Avoid setting that. Or if you like adventure, set it and try... then do a
213 make clobber and come back to this point.
215 The compilation will go awry if the following variables are set, so unset them.
216         unset JAVA_HOME
217         unset CLASSPATH
219 The build process uses two different variables to read the optimization flags.
220 During the first phase (hotspot build) it uses C{,XX}FLAGS while during the
221 second phase (j2se build) it uses OTHER_C{,XX}FLAGS. Setting CFLAGS gave me core
222 dumps during the second phase of the build. I unset C{,XX}FLAGS and set
223 OTHER_C{,XX}FLAGS to "-march=i686 -fomit-frame-pointer -s". Also unset the
224 LDFLAGS variable (same reason). If you set any of these variables, the build
225 WILL fail!!!
227 Using any optimizations causes miscompilation when using gcc3, especially in
228 java.lang.Math class. Thanks to a Gentoo user Bernhard Stegmaier
229 <stegmaie@db.fmi.uni-passau.de> for reporting the bug and the fix. Hence avoid
230 the use of any "-O?" flags. Also, some of the Makefiles hardcode "-O3", to
231 remove this do the following:
232         for i in hotspot/build/linux/makefiles/gcc.make \
233                 hotspot/build/solaris/makefiles/gcc.make \
234                 j2se/make/sun/image/generic/Makefile
235         do
236                 chmod +w $i
237                 cp $i $i.orig
238                 sed -e "s:\-O3:\-march=i686 \-fomit\-frame\-pointer \-s:g" \
239                         $i.orig > $i
240         done
241 For test case please refer to:
242 http://archive.linuxfromscratch.org/mail-archives/blfs-support/2002/11/0247.html
244 If you would like make to output verbose messages instead of the boring
245 "Compiling xxx..." messages, set the following variable:
246         export MAKE_VERBOSE=true
248 Since you are building JDK for an unsupported platform, according to Sun you are
249 insane:) Hence the following variable has to be set to affirm that you really
250 are insane:))
251         export INSANE=true
253 The build also looks for a Redhat Release 6.1. Though the error is not show
254 stopping, if you want you can make a file for the duration of the build. This is
255 entirely optional; and just included here for the record in case someone sends
256 me a bug report (if the file does not exist, Make prints a message indicating a
257 fatal error occured (though the compilation does not stop). Again, for the
258 record, I don't create this file.
259         echo "Red Hat Linux release 6.1 (LFS)" > /etc/redhat-release
261 The source includes zlib-1.1.3 which has known security problems, so it is
262 prudent to upgrade the included zlib. Sun renamed some of the files in the zlib
263 distribution. Hence we also need to do the same. Also, linking to the dynamic
264 version is not trivial (I don't even know if it is possible) since the JDK build
265 uses some files from the zlib distribution, it doesn't build any static or
266 dynamic version of the zlib.
267         ZLIB_VERSION=1.1.4
268         cd $SRC/j2se/src/share/native/java/util/zip
269         rm -rf $SRC/zlib-1.1.3
270         tar -xvzf $SRC/zlib-${ZLIB_VERSION}.tar.*
271         cd zlib-${ZLIB_VERSION}
272         mv adler32.c zadler32.c
273         mv crc32.c zcrc32.c
274         cd $SRC/j2se/make/java/zip/
275         cp Makefile Makefile.orig
276         chmod +w Makefile
277         sed -e "s:1.1.3:${ZLIB_VERSION}:" Makefile.orig > Makefile
279 Now the most simple part of the build.
280         cd $SRC/control/make &&
281         make
283 The build took around 4 hours on my PIII-800.
285 If anytime during the build, you would like to start from scratch, you can do a
286 "make clobber" in $SRC/control/make to go back to the beginning.
288 The built SDK and JRE are in the following directory.
289         cd $SRC/control/build/linux-i?86
291 The j2sdk-image is the built JDK, congrats:)
292         mkdir -p /opt/java &&
293         cp -a j2sdk-image /opt/java/j2sdk-1.4.1-tt &&
294         cd /opt/java &&
295         ln -nsf j2sdk-1.4.0-tt j2sdk
297 Add the following to your </etc/profile> or <~/.profile>. Many programs expect
298 the JAVA_HOME variable to find the JDK.
299         export JAVA_HOME=/opt/java/j2sdk
300         export PATH=$PATH:$JAVA_HOME/bin
302 Tip: You can install multiple jdk's in /opt/java, changing between them is just
303 as easy as:
304         ln -nsf j2sdk-<required-version> j2sdk
306 Link the java plugin we built for mozilla. After all that was the main reason
307 for me compiling jdk from scratch! Check out the mozilla hint on how to do this.
308 Also since we used the dynamic version of the lesstif libraries, moz will need
309 to preload the lesstif library, else the plugin will crash.
311 Now LFS CVS is all ready for big time. The first system out there to be
312 completely gcc3:))
314 If you deviate from the hint and you run into problems, first try following the
315 hint exactly to see if it works. Also, if you deviate from the hint and run into
316 successes, please let me know so that I can add the same to the hint.
318 Reported Problems & Workarounds:
320 * Harald Meier reported that if there are problems, try removing the "-z defs"
321   from LDFLAGS_COMMON from line 263 in the file
322   $SRC/j2se/make/common/Defs-linux.gmk.
323 * Parkanyi Balazs and Kelledin reported that trying to manually run java_vm
324   results in unresolved libraries. Adding the relevant directories to
325   /etc/ld.so.conf does not fix the problem (unless of course you have a 386
326   CPU.) The solution suggested was to rename the i386 directories to i<x>86
327   where <x> should be replaced by whatever your CPU is. So for a Pentium, you
328   would rename the i386 directories to i586. For more info, refer to
329   <http://www.cs.helsinki.fi/linux/linux-kernel/2001-25/0014.html>. Note that
330   Mozilla wrapper script takes care of all this when it loads the java_vm, so
331   you only have to do this if you need to run java_vm on the command line.
332 * Sam Halliday reported that if the partition where you are compiling runs out
333   space, the build gives some very strange errors rather than the usual "Out of
334   disk space" error.
336 CLASSPATH script:
338 This part is not related to compiling Java, but seemed like a nice place to put
339 this mini-hint:)
341 It is a big pain to update the CLASSPATH everytime a new package is installed. A
342 nice trick I use is to create a directory called /opt/classes and whenever I
343 install a java related package that installs a jar file, I make a link to the
344 relevant jar files from /opt/classes. I use the following script to
345 automatically create the CLASSPATH entries.
346         #!/bin/sh
347         # SetClassPath
348         if [ -z $CLASSPATH ]
349         then
350                 CLASSPATH=.
351         else
352                 CLASSPATH=$CLASSPATH:.
353         fi
354         for i in $(ls /opt/classes/*.jar)
355         do
356                 CLASSPATH=$CLASSPATH:$i
357         done
358         echo $CLASSPATH
359 and in /etc/profile I add the following line.
360         export CLASSPATH=`SetClassPath`
362 Don't forget to send me bug reports and enhancements so that I can keep the hint
363 updated.