# (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. # # # This is a GNU makefile for building projects with java source code. # It offers 3 built in targets: # # compile creates the .class files in some destination directory. # This is the preferred mode of operation. The class files # are created in a sub-directory called ./classes. # # debug creates .class files in the source directory, with # the source code, this is needed for some debuggers # but it's not a very safe thing to do. # # JAR_FILE creates a jar file from the contents of the ./classes # directory plus any manifest.mf that you might have # in your JAR_DIRECTORY # # Both these targets have matching cleansing targets: # # compile-clean # debug-clean # # The variables mentioned above (JAR_FILE and JAR_DIRECTORY) are # documented in the first section of the makefile which is authored # so that users can alter it if they need to. # # This makefile can be very easily adapted for use in many different # projects. The next section includes the variables that are per project. # These are variables that pretty much every project will need. # Used only as a convieniance for definitions of source # and jar directories, when this Makefile is built by autoconf # the PROJECT_ROOT should be set to: @srcdir@ PROJECT_ROOT := @srcdir@ # Tool definitions. JAVAC := @JAVA_CC@ JAVAC_OPTS := -g JAR_TOOL := @JAR_TOOL@ # The name of the target jar file. # You don't have to have a target jar file, but it's a bit more # useful than just creating .class files. JAR_FILE = paperclips.jar # The directory where jar files for the project live. # This is like the project "ext" dir. All the jar files in this # directory will be used to make the classpath for compiles. # You can also put a "manifest.mf" in the directory to be picked # up and used when building jar files. JAR_DIRECTORY = $(PROJECT_ROOT)/lib # The directory where all dependant source files are located. SOURCEDIR = $(PROJECT_ROOT)/source # Source files are the dependancies of the project. # Developers should add each source file to the list here. # Each file must be prefixed withn the $(SOURCEDIR) variable. # Each file but the last must be followed by the line # continue character "\". SOURCEFILES = $(SOURCEDIR)/gnu/inet/http/ChunkedOutputStream.java \ $(SOURCEDIR)/gnu/inet/mime/base64/Base64InputStream.java \ $(SOURCEDIR)/gnu/inet/mime/base64/Base64OutputStream.java \ $(SOURCEDIR)/gnu/paperclips/http/BufferingStream.java \ $(SOURCEDIR)/gnu/paperclips/http/ChunkingOutputStream.java \ $(SOURCEDIR)/gnu/paperclips/http/ContentLengthOutputStream.java \ $(SOURCEDIR)/gnu/paperclips/http/HTTPConnection.java \ $(SOURCEDIR)/gnu/paperclips/http/HTTPInStream.java \ $(SOURCEDIR)/gnu/paperclips/http/HTTPOutStream.java \ $(SOURCEDIR)/gnu/paperclips/http/HTTPRequest.java \ $(SOURCEDIR)/gnu/paperclips/http/HTTPResponse.java \ $(SOURCEDIR)/gnu/paperclips/http/HTTPUtils.java \ $(SOURCEDIR)/gnu/paperclips/http/HTTPHost.java \ $(SOURCEDIR)/gnu/paperclips/http/HttpTimeOutException.java \ $(SOURCEDIR)/gnu/paperclips/http/LowImpedanceInputStream.java \ $(SOURCEDIR)/gnu/paperclips/http/LowImpedanceOutputStream.java \ $(SOURCEDIR)/gnu/paperclips/http/LowImpedanceServletOutputStream.java \ $(SOURCEDIR)/gnu/paperclips/io/ByteBufferInputStream.java \ $(SOURCEDIR)/gnu/paperclips/io/ByteBufferOutputStream.java \ $(SOURCEDIR)/gnu/paperclips/io/InputStreamReader.java \ $(SOURCEDIR)/gnu/paperclips/loading/ServletLoader.java \ $(SOURCEDIR)/gnu/paperclips/loading/WARClassLoader.java \ $(SOURCEDIR)/gnu/paperclips/filters/WebLog.java \ $(SOURCEDIR)/gnu/paperclips/servlets/AutoMapper.java \ $(SOURCEDIR)/gnu/paperclips/servlets/DebugServlet.java \ $(SOURCEDIR)/gnu/paperclips/servlets/WWW.java \ $(SOURCEDIR)/gnu/paperclips/urlhandlers/FURLHandler.java \ $(SOURCEDIR)/gnu/paperclips/urlhandlers/FileConnection.java \ $(SOURCEDIR)/gnu/paperclips/utils/CleverTokenizer.java \ $(SOURCEDIR)/gnu/paperclips/utils/TimedLogWriter.java \ $(SOURCEDIR)/gnu/paperclips/utils/ListXML.java \ $(SOURCEDIR)/gnu/paperclips/paperclips.java \ $(SOURCEDIR)/gnu/paperclips/AttributeAdapter.java \ $(SOURCEDIR)/gnu/paperclips/WebApp.java \ $(SOURCEDIR)/gnu/paperclips/FileServer.java \ $(SOURCEDIR)/gnu/paperclips/URIMapping.java \ $(SOURCEDIR)/gnu/paperclips/BadResourceMapping.java \ $(SOURCEDIR)/gnu/paperclips/LogWriter.java \ $(SOURCEDIR)/gnu/paperclips/Dispatcher.java \ $(SOURCEDIR)/gnu/paperclips/RequestableServlet.java \ $(SOURCEDIR)/gnu/paperclips/Session.java \ $(SOURCEDIR)/gnu/paperclips/Service.java \ $(SOURCEDIR)/gnu/paperclips/HttpSessionManager.java \ $(SOURCEDIR)/gnu/paperclips/URIMap.java \ $(SOURCEDIR)/gnu/paperclips/PURLConnection.java \ $(SOURCEDIR)/gnu/paperclips/PURLHandler.java \ $(SOURCEDIR)/gnu/paperclips/Requestable.java \ $(SOURCEDIR)/gnu/paperclips/RequestFilter.java \ $(SOURCEDIR)/gnu/paperclips/URIPattern.java \ $(SOURCEDIR)/gnu/paperclips/ServiceFailure.java \ $(SOURCEDIR)/gnu/paperclips/Int.java \ $(SOURCEDIR)/gnu/paperclips/MimeRegistry.java # The default make target. # You can put anything in here, use all as a proxy for # one of the makefile predefined targets (compile or debug) # or add more sophisticated targets. all: $(JAR_FILE) $(JAR_FILE)(META-INF/mime.types) # The default clean target. .SILENT: clean .IGNORE: clean clean: compile-clean debug-clean -rm $(JAR_FILE) # Add the mime types to the JAR file. $(JAR_FILE)(META-INF/mime.types): mime.types mkdir META-INF ; cp mime.types META-INF ; $(JAR_TOOL) uf $@ META-INF ; rm -r META-INF # This is a useful target for developers, it causes make to # output the current project classpath. This means you can set a # CLASSPATH environment variable as `make classpath` and it # will keep in touch with the necessary classpath. classpath: @echo $(PROJ_CLASSPATH) # End of per project configuration. # From here on, the makefile does not need to be altered unless you are # hacking something extreemly unusual. # # I hope that the makefile below this is still readable, if it is not # please get in touch with Nic Ferrier to see if he # can explain it. # Macros to assist java compile rules. # The class file compilation directory (for non debug compiles). DESTINATION = ./classes # Classes are derived from source files. DEBUGCLASSES = $(SOURCEFILES:.java=.class) # Destination class files are classes in the destination dir. DESTCLASSES = $(DEBUGCLASSES:$(SOURCEDIR)%=$(DESTINATION)%) # The project classpath is defined as all jar files in the # project's jar directory. PROJ_JAR_FILES = $(wildcard $(JAR_DIRECTORY)/*.jar) PROJ_CLASSPATH = $(call PATH-MAKER,$(PROJ_JAR_FILES)) # The compilation classpath is the project classpath # plus the destination directory. This is important because # the compile targets don't always compile everything. MK-CLASSPATH = $(1):$(PROJ_CLASSPATH) # A function to expand to the compiler. # Specify the destination directory as an argument in a $(call). COMPILER = $(JAVAC) $(JAVAC_OPTS) -d $(1) -classpath $(call MK-CLASSPATH,$(1)) @filelist # Setup the manifest if necessary MANIFEST = $(wildcard $(JAR_DIRECTORY)/manifest.mf) # Switches for JARing JAR_OPTS = $(if $(MANIFEST),-cfm,-cf) # The jar file building target. # The jar file is made of *everything* in the destination directory. $(JAR_FILE): init-filelist $(DESTCLASSES) compile-files $(JAR_TOOL) $(JAR_OPTS) $(JAR_FILE) $(MANIFEST) -C $(DESTINATION) . # Building targets. # This rule builds the destination directory for compiles. $(DESTINATION): mkdir $@ # A variable to represent the list of all files. DEPEND_LIST = $(shell cat filelist) # The compilation targets. .PHONY: compile compile-files debug init-filelist # This rule recreates the filelist. # It has the nasty side effect of writing a blank line to the file # but compilers don't seem to mind that. init-filelist: @echo > filelist debug: init-filelist $(DEBUGCLASSES) debug-files debug-files: $(if $(DEPEND_LIST),$(call COMPILER,$(DESTINATION))) compile: init-filelist $(DESTCLASSES) compile-files compile-files: $(DESTINATION) $(if $(DEPEND_LIST),$(call COMPILER,$(DESTINATION))) # Automatically match a source file to it's dependant class file. $(DESTINATION)/%.class: $(SOURCEDIR)/%.java @echo $? >> filelist $(SOURCEDIR)/%.class: $(SOURCEDIR)/%.java @echo $? >> filelist # Cleaning targets. # A function which cleans the class files from all the directories # which are found in the supplied list ($1). # If you pass this a file list, eg: the destination classes list, # it will clean all the diectories within the list. The dirs # themselves are not deleted but all the .class files within them # are. CLASS-CLEAN = -rm $(sort $(addsuffix *.class,$(dir $(1)))) 2> /dev/null # Cleaning targets for the compilation targets. .IGNORE: compile-clean clean-compiled-classes debug-clean .SILENT: compile-clean clean-compiled-classes debug-clean .PHONY: compile-clean clean-compiled-classes debug-clean compile-clean: clean-compiled-classes clean-filelist -rm -r $(DESTINATION) clean-compiled-classes: $(call CLASS-CLEAN,$(DESTCLASSES)) debug-clean: clean-filelist $(call CLASS-CLEAN,$(DEBUGCLASSES)) # A target to ensure the removal of the filelist. .PHONY: clean-filelist clean-filelist: @if [ -e filelist.mak ] ; then rm filelist.mak ; fi # Generic functions. # Create a search path from a space separated list. ifeq (${OS},Windows_NT) PATH-MAKER = $(subst $(space),;,$(1)) else PATH-MAKER = $(subst $(space),:,$(1)) endif # Create a space separated word from a directory path DIRPATH = $(subst /,$(space), $(1)) # Variables which define some useful constants newline:=\\n empty:= space:=$(empty) $(empty)