>>> "Matt Fair" <[EMAIL PROTECTED]> 17-Jun-01 4:43:06 AM >>>
Is there a good way to create a good Makefile
for JAVA projects? Right now all I am doing is in
my Makefile I have: javac $(find . -name \*.java)
I do something similar to Per. Below is the text of a makefile I use
which can be adapted to different projects; simply update the
SOURCEFILES variable.
I've not found a situation where this doesn't do what I want. More
importantly it's quicker than caclulating dependancies all the time,
though it does take some understanding on the part of the developer
about what has changed.
Nic Ferrier
# JCD Makefile
# (c) Nic Ferrier - Tapsell-Ferrier Limited 2001
#
# You are free to redistribute this file. NO WARRANTY or fitness
# for purpose is implied by this notice.
#
# What goes on here?
# The SOURCEFILES should be a list of all the sources in your
project.
# The CC-CLASSPATH should be the compilation classpath for your
project.
#
# make compile
#
# Causes the classes that need to be compiled (because of changes
against
# the relevant .class file) to be compiled.
#
# make recompile
#
# Causes all the source files within the project to be compiled.
#
##set by configure
SRCDIR = .
SOURCEDIR=$(SRCDIR)/source
#the source files belonging to the project
#These can be altered by Emacs JCD mode.
SOURCEFILES = $(SOURCEDIR)/filename1.java \
$(SOURCEDIR)/filename2.java
#the desination directory for compilations
CC-DESTDIR = bin
#add extra directories or jar files here
CC-CLASSPATH = $(CC-DESTDIR)
#a mangling of the SOURCEFILES list above
CLASSESLIST=$(subst .java,.class,$(subst
$(SOURCEDIR)/,$(CC-DESTDIR)/,$(foreach dir,$(SOURCEFILES),$(dir))))
##variables which define some usefull constants
newline:=\\n
empty:=
space:=$(empty) $(empty)
#The default is to associate "all" with "compile"
all: compile
##rules predefined by the Makefile.
##These should be flexible enough for any project as long
##as the project conforms to the structure required above.
#the compilation target
#This is intended for developers who are constantly compiling stuff
#
#NOTE: this has to use a shell if test because the GNU-Make
$(wildcard)
#doesn't work properly. If it did we could do this:
#
# compile: $(CLASSLIST)
# ifeq "$(wildcard filelist.mak)" "filelist.mak"
# javac -classpath $(subst $(space),:,$(CC-CLASSPATH)) -d
$(CC-DESTDIR) @filelist.mak
# @rm filelist.mak
# else
# @echo Nothing to be done for compile.
# endif
#
#I think that would be a lot better and have reported the fault with
#the $(wildcard) function to [EMAIL PROTECTED]
#The problem is that it does not recognise the existance of files
created
#within commands caused by pre-requisites.
compile: $(CLASSESLIST)
@if [ -e filelist.mak ] ; then \
echo javac -classpath $(subst $(space),:,$(CC-CLASSPATH))
-d $(CC-DESTDIR) @filelist.mak ; \
javac -classpath $(subst $(space),:,$(CC-CLASSPATH)) -d
$(CC-DESTDIR) @filelist.mak ; \
rm filelist.mak ; \
else echo Nothing to be done for compile ; \
fi
#recompile all the source files
.PHONY: recompile
recompile: clean-filelist all-source-files
javac -classpath $(subst $(space),:,$(CC-CLASSPATH)) -d
$(CC-DESTDIR) @filelist.mak
@rm filelist.mak
#make the source file list be the list of all files
.PHONY: all-source-files
all-source-files:
$(foreach sourcefile,$(SOURCEFILES),$(shell echo $(sourcefile)
>> filelist.mak))
#ensures that the filelist is fresh each time
#This simply removes the file list (after ensuring that it exists)
.PHONY: clean-filelist
clean-filelist:
@echo done > filelist.mak
@rm filelist.mak
#target matching class files to source files
$(CC-DESTDIR)/%.class: $(SOURCEDIR)/%.java
@echo $? >> filelist.mak
##End Makefile
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]