Makefiles for JAVA

S

sasquatch

I've recently started developing JAVA apps for some of my courses, but I
work on both Windows and Unix. Can somebody point me in the direction of
any good tutorials on what exactly makefiles are and how to do them? Any
help is sincerely appreciated.

Alex Marshall
 
H

Harald Hein

sasquatch said:
I've recently started developing JAVA apps for some of my courses,
but I work on both Windows and Unix. Can somebody point me in the
direction of any good tutorials on what exactly makefiles are and
how to do them?

Makefiles are text files that the input files for a tool called make.
Actually, there are many, many versions of make out there, a lot of
them slightly incompatible when it comes to enhancements.

The original make was written by a guy called Stuard I. Feldman. He
wrote the Bell Labs Unix FORTRAN stuff and needed a build utility:
make. The name comes from the development cycle he used to build his
programs: think - edit - make - test.

A makefile consists of rules, and describes how to transform one type
of a file (e.g. a source code file) to another type (e.g. an object
module). If one (the source file) is newer than the other (the object
code) a script is triggers (e.g. running the compiler), to generate the
one from the other.

Many people have bashed heavily. IMHO this is uncalled. Make does
exactly what it is supposed to do, and a few things more. However, it
is not a general purpose scripting utility. Make has a certain rough
charme, but does not show its beauty to everyone.

Classic make and a lot of the modern enhanced version have a problem
with Java. It is easy and common to have circular references between
source files in Java. Classic make does not allow one to specify
circular references. Using such a make, you have to degrade your build
rules to "always compile everything" which results in loosing all
advantages of make. Fortunately Sun has published a version of make
that can handle this: http://developers.sun.com/dev/coolstuff/javamake/
If you use make, you migth want to get this one. Be careful, there are
several make versions out there which are called "javamake". Get the
one from Sun.

People will suggest an alternative for make when compiling Java. This
thing is called ant. I don't like it too much. The idea of a special
purpose scripting language based on XML doesn't appeal to me. You will
find that ant fans are very religious about the tool.
 
T

Thomas Kellerer

Harald said:
People will suggest an alternative for make when compiling Java. This
thing is called ant. I don't like it too much. The idea of a special
purpose scripting language based on XML doesn't appeal to me. You will
find that ant fans are very religious about the tool.

Well I like it, but I'm not "religious" about it. IMHO I find the ant files
easier to read and understand then make files. But I do think it's a matter
of taste. But it does ease the creation of Java binaries. Such as writing
the manifest information without an external manifest file, built in tar,
jar and zip support. I admit that there are numerous tools which can do
that as well, but still I like to have everything "in one place" :)

Btw: the creation of tar files on Windows and setting *nix file permissions
and flags (i.e. executable) is something I really like!

Thomas
 
D

Dale King

Harald Hein said:
:

Classic make and a lot of the modern enhanced version have a problem
with Java. It is easy and common to have circular references between
source files in Java. Classic make does not allow one to specify
circular references. Using such a make, you have to degrade your build
rules to "always compile everything" which results in loosing all
advantages of make. Fortunately Sun has published a version of make
that can handle this: http://developers.sun.com/dev/coolstuff/javamake/
If you use make, you migth want to get this one. Be careful, there are
several make versions out there which are called "javamake". Get the
one from Sun.

Just to be clear, javamake is not a version of the make tool. It is a
standalone tool that will handle dependencies and compile all of the source
affected by a change.
People will suggest an alternative for make when compiling Java. This
thing is called ant. I don't like it too much. The idea of a special
purpose scripting language based on XML doesn't appeal to me. You will
find that ant fans are very religious about the tool.

The real issue is that those religious about it will tell you that it
actually is an alternative to make. It is nothing of the kind. It is a
special-purpose XML scripting language. make is all about handling
dependencies between files and the steps to create them. Ant has little in
the way of expressing dependencies, including many ad-hoc, undocumented, and
insufficient attempts at dependency handling. It is easy to create scenarios
in Ant where you can edit a source file, run ant, have it report no
problems, and have an incorrect build. The goal of make is that this never
happens.

Note that javamake is usable as an ant task so that you can at least do that
to get your java building correct.
 
D

Dave Monroe

Harald Hein said:
Makefiles are text files that the input files for a tool called make.
Actually, there are many, many versions of make out there, a lot of
them slightly incompatible when it comes to enhancements.

The original make was written by a guy called Stuard I. Feldman. He
wrote the Bell Labs Unix FORTRAN stuff and needed a build utility:
make. The name comes from the development cycle he used to build his
programs: think - edit - make - test.

Wow, Harald, that brings back memories. Nice to know there are still
a few of us old Unix guys around.

Make is a good old tool and is probably adequate as a build utility
for a Java project.

Check out 'ant' (apache.org) - it might be better suited to the task.
That's what I usually wind up using.

My $0.02.

Dave Monroe
 
D

Dale King

Dave Monroe said:
Harald Hein <[email protected]> wrote in message

Wow, Harald, that brings back memories. Nice to know there are still
a few of us old Unix guys around.

Make is a good old tool and is probably adequate as a build utility
for a Java project.

Unfortunately, it isn't. It works for C/C++ because object files only depend
on source files. In Java class files depend on a source file and other class
files. This means that there can be circular dependencies in Java. The only
way to resolve some circular dependencies is to make sure that all the
necessary source files are compiled at the same time. Java has no means to
do this.
Check out 'ant' (apache.org) - it might be better suited to the task.
That's what I usually wind up using.

Unfortunately, ant is less suited to the task.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top