Example makefile for  Java

Back to Java Notes.

Assume the directory tree:
home/
   |- worm
            |-net
                  |- Network.java
                  |- Receiver.java
                  ...
                  |- TestMain.java
Also assume that the file Network.java (as well as all the others) is in the package worm.net;

Makefile ===========================================================================

# Makefile for the worm.net package.
#
# Last change Apr 29 2002 19:40
# by Jakub Holy
#
# !!!! If the source files are in the dir. home/worm/net/ then
# this Makefile should be copied to home/ and made there: home/$> make

# various MACROS (replaced by their 'content' later on)
# the package to be compiled (the directory containing .java files)
PACKAGE = worm/net/
# compilator flags ( usually nothing or -g for debugging)
CFLAGS =
# independent files (can be compiled together)
TESTCLASSES = ${PACKAGE}TestMain.java ${PACKAGE}TestClient.java
CLASSES = ${TESTCLASSES} ${PACKAGE}Network.java

# *********************************************** compile
# this is the default target to be made (because it's the 1st one)
net: receiver others

# RECEIVER stuff ------------------

# create stubs and skels
receiver: ReceiverImpl
 rmic worm.net.ReceiverImpl

# the implementation of the interface
ReceiverImpl:  Receiver.class
 javac ${PACKAGE}ReceiverImpl.java

# compile the interface
Receiver.class:  ${PACKAGE}Receiver.java
 javac ${PACKAGE}Receiver.java

# NON-Receiver stuff ----------------

others: ${CLASSES}
 javac ${CLASSES}

# ************************************************ clean
# remove all .class files
clean:
 rm -rf ${PACKAGE}*.class

# ************************************************ run tests
# this stuff is not important and may (will) be removed
# "make tmain" runs the main of the test
tmain:
 java worm.net.TestMain
tclient:
 java worm.net.TestClient