JHBuild is a build script that was originally written to automate the process of building a GNOME module and its dependencies from CVS. JHBuild stores inter-package dependency information, so it is able to build a given package and all of its dependencies.
As an example of JHBuild's utility, consider GCJ. GCJ's AWT peers depend on GTK which in turn depends on 12 other packages directly or indirectly. Finding, checking out and building all of these packages by hand is time-consuming and tedious. JHBuild automates the process. It can check out and build all of the packages automatically, with a single command.
Previously JHBuild had no knowledge of GCJ. I've extended it with some module types and dependency information so that it can now build GCJ, GDB, some free Java test suites and the Java-GNOME language bindings.
These instructions were tested on a Fedora Core 3 machine but they're fairly generic so they should be applicable to other systems.
When you're developing packages like GCJ and Java-GNOME that use the GNU autotools, it's best to separate the build, source, and installation directories, if possible.
For example, in my home directory, I have top-level directories named sources, build, and install. The sources and build directories each have package-specific sub-directories. For example, for GCJ, the directories are set up like this: the sources are in ~/sources/gcc, GCJ is built in ~/build/gcj-bld and it is installed in ~/install.
The following instructions and sample files assume a directory layout similar to that described above.
First, create a directory where JHBuild should download all the package sources. For example, I created jhbuild-src directory in ~/sources.
Then checkout JHBuild from GNOME CVS: cvs -d :pserver:anonymous@anoncvs.gnome.org:/cvs/gnome login
Just hit "Enter" when prompted for a password.
cvs -d :pserver:anonymous@anoncvs.gnome.org:/cvs/gnome co jhbuild
Now run make install from the jhbuild directory. Files are installed in ~/bin, which you should add to your PATH. The README contains a good overview of how to use JHBuild.
Next, modify your ~/.jhbuildrc file to suit your setup. This JHBuild configuration file provides a good set of defaults. To use it, copy it to ~/.jhbuildrc (note the dot).
Make sure you have the following packages installed:
If you intend to build only the Java-GNOME bindings and not GCJ itself, then you should have GCJ installed on your system. (You can also build Java-GNOME with CVS GCJ -- jhbuild build gcj java-gnome -- but your mileage may vary).
First, run:
jhbuild bootstrap
Now run:
jhbuild build java-gnome
which will download, build and install the Java-GNOME bindings.
Likewise, to build GCJ and its dependencies, run:
jhbuild build gcj
Before attempting to compile a Java-GNOME program, enter the JHBuild shell, like this:
jhbuild shell
When you're in the JHBuild shell, all the relevant environment variables will point to the right places. This includes the CLASSPATH variable, which should include all the Java-GNOME jars.
Compile and run your program as you would any other Java program:
javac testgnome/TestGNOME.java
java testgnome.TestGNOME
The GCJ module file that is referenced in the sample jhbuildrc points to GCJ's java-gui-branch. As its name implies, this branch was created specifically for developing the the GUI parts of the Java class library -- the AWT and Swing. The branch's main features are a liberal commit policy and some build system improvements that speed up the edit-compile-test cycle.
Normally, all of libgcj's classes are linked into one large library, libgcj.so. On the GUI branch, libgcj.so has been split up into sub-libraries corresponding to several of the java.* name spaces: lib-java-awt.so, lib-javax-swing.so, lib-java-applet.so, and so on. That means that each rebuild only causes a fraction of the classes to be relinked, which makes rebuilds much faster.
Before attempting to compile an AWT or Swing program, enter the JHBuild shell, like this:
jhbuild shell
When you're in the JHBuild shell, all the relevant environment variables will point to the right places.
A typical gcj compile line looks like this:
gcj -g -O0 --main=TextAreaTest -o TextAreaTest TextAreaTest.java
This Makefile will save you some typing. It generates both a natively-compiled binary and a class file (which you can run with gij):
make TextAreaTest
When rebuilding libgcj, you can specify the specific library you'd like to rebuild. For example, if you made a change to a class in java.awt, you can rebuild lib-java-awt.so only, with this command, issued from the libjava build directory:
make {C,CPP,CXX,GCJ}FLAGS="-g -O0" CFLAGS_FOR_TARGET="-g -O0" lib-java-awt.la
The first argument may look a little strange; it expands to:
CFLAGS="-g -O0" CPPFLAGS="-g -O0" CXXFLAGS="-g -O0" GCJFLAGS="-g -O0"
which are the same arguments as the makeargs line in ~/.jhbuildrc.
The provided jhbuildrc points LD_LIBRARY_PATH to the libjava build directory, so there is no need to do a make install before re-running your test programs.