#********************************************************************* # # (C) 2005 Yumetech, Inc # http://www.yumetech.com # # Makefile rules and useful functions for wide use for Java specific tasks # # Author: Justin Couch # Version: $Revision: 1.10 $ # #********************************************************************* # # Directories for standard stuff # include $(PROJECT_ROOT)/make/Makefile.inc JAVA_DEV_ROOT = $(JAVA_DIR) CLASS_DIR = $(BUILD_ROOT_DIR)/classes JAVADOC_DIR = $(DOCS_DIR)/javadoc JAR_DIR = $(BUILD_ROOT_DIR)/jars JAR_MAKE_DIR = $(BUILD_ROOT_DIR)/make/jar JAVA_SRC_DIR = $(JAVA_DEV_ROOT) DESTINATION = $(BUILD_ROOT_DIR)/classes JAR_TMP_DIR = $(BUILD_ROOT_DIR)/.jar_tmp MANIFEST_DIR = $(BUILD_ROOT_DIR)/make/manifest APP_JAR_DIR = $(APP_ROOT)/lib # # Built up tool information # ifdef JAVA_HOME JAVAC = $(JAVA_HOME)/bin/javac JAR = $(JAVA_HOME)/bin/jar JAVADOC = $(JAVA_HOME)/bin/javadoc JAR_INSTALL_DIR = $(JAVA_HOME)/jre/lib/ext else JAVAC = javac JAR = jar JAVADOC = javadoc endif EMPTY = SPACE = $(EMPTY) $(EMPTY) OS_NAME=$(shell uname) ifeq (, $(strip $(findstring CYGWIN, $(OS_NAME)))) PATH_SEP:=":" else IS_WIN32=t PATH_SEP:=";" endif ifdef JARS LOCAL_JARTMP = $(patsubst %,$(JAR_DIR)/%,$(JARS)) LOCAL_JARLIST = $(subst $(SPACE),$(PATH_SEP),$(LOCAL_JARTMP)) endif ifdef JARS_3RDPARTY OTHER_JARTMP = $(patsubst %,$(LIB_DIR)/%,$(JARS_3RDPARTY)) OTHER_JARLIST = $(subst $(SPACE),$(PATH_SEP),$(OTHER_JARTMP)) endif # if we have an app root, also append to the JAR list a variant using the # APP_ROOT as base ifdef APP_ROOT ifdef JARS_3RDPARTY APP_JARTMP = $(patsubst %,$(APP_JAR_DIR)/%,$(JARS_3RDPARTY)) # APP_JARLIST = $(subst $(SPACE),$(PATH_SEP),$(APP_JARTMP)) endif endif SOURCEPATH = $(JAVA_SRC_DIR) CP = $(CLASS_DIR) ifdef LOCAL_JARLIST ifdef CP CP :="$(CP)$(PATH_SEP)$(LOCAL_JARLIST)" else CP :="$(LOCAL_JARLIST)" endif endif ifdef OTHER_JARLIST ifdef CLASSPATH CP1:="$(CP)$(PATH_SEP)$(OTHER_JARLIST)" else CP1:= "$(OTHER_JARLIST)" endif endif ifdef CP1 CLASSPATH:="$(CP1)" else CLASSPATH:="$(CP)" endif JAVADOC_CLASSPATH=$(CLASS_DIR)$(PATH_SEP)$(OTHER_JARLIST) ifdef APP_ROOT ifdef APP_JARLIST CLASSPATH:=$(CLASSPATH)$(PATH_SEP)$(APP_JARLIST) endif CLASSPATH:=$(CLASSPATH)$(PATH_SEP)$(PROJECT_ROOT)/classes JAVADOC_CLASSPATH:=$(JAVADOC_CLASSPATH)$(PATH_SEP)$(PROJECT_ROOT)/classes endif # has the user defined an external classpath to use here? If so, append # it to the ordinary classpath. ifdef PROJECT_CLASSPATH CLASSPATH := $(CLASSPATH)$(PATH_SEP)"$(PROJECT_CLASSPATH)" JAVADOC_CLASSPATH := $(JAVADOC_CLASSPATH)$(PATH_SEP)"$(PROJECT_CLASSPATH)" ifndef IS_WIN32 CLASSPATH := $(subst ",,$(CLASSPATH)) JAVADOC_CLASSPATH := $(subst ",,$(JAVADOC_CLASSPATH)) endif endif # # Build rules. # PACKAGE_LOC = $(subst .,/,$(PACKAGE)) PACKAGE_DIR = $(DESTINATION)/$(PACKAGE_LOC) JAVA_FILES = $(filter %.java,$(SOURCE)) NONJAVA_FILES = $(patsubst %.java,,$(SOURCE)) CLASS_FILES = $(JAVA_FILES:%.java=$(PACKAGE_DIR)/%.class) OTHER_FILES = $(EXTRA:%=$(PACKAGE_DIR)/%) JNI_CLASS_FILES = $(JNI_SOURCE:%.java=$(PACKAGE_DIR)/%.class) JNI_PKG_PREFIX = $(subst .,_,$(PACKAGE)) JNI_HEADERS = $(JNI_SOURCE:%.java=%.h) JAR_CLASS_FILES = $(patsubst %, %/*.*, $(JAR_CONTENT)) #JAR_EXTRA_FILES = $(EXTRA_FILES:%=$(JAVA_SRC_DIR)/%) JAR_CONTENT_CMD = -C $(JAR_TMP_DIR) . $(patsubst %, -C $(JAVA_SRC_DIR) %, $(EXTRA_FILES)) LINK_FILES = $(patsubst %, -link %,$(LINK_URLS)) # Make a list of all packages involved ifdef PACKAGE PACKAGE_LIST = $(subst .,/,$(PACKAGE)) NATIVE_LIST = $(subst .,/,$(PACKAGE)) else PACKAGE_LIST = $(subst .,/,$(BUILD_ORDER)) NATIVE_LIST = $(subst .,/,$(NATIVE_PACKAGES)) endif PLIST_CLEAN = $(patsubst %,$(JAVA_SRC_DIR)/%/.clean,$(PACKAGE_LIST)) PLIST_BUILD = $(patsubst %,$(JAVA_SRC_DIR)/%/.build,$(PACKAGE_LIST)) JNI_LIST_BUILD = $(patsubst %,$(JAVA_SRC_DIR)/%/.native,$(NATIVE_LIST)) ifdef JAR_CONTENT JAR_CONTENT_LIST = $(strip $(JAR_CONTENT)) endif # # Option listing for the various commands # ifdef IGNORE_CYCLES JAVAC_OPTIONS = -d $(DESTINATION) -classpath $(CLASSPATH) \ -sourcepath $(SOURCEPATH) $(JAVAC_FLAGS) else JAVAC_OPTIONS = -d $(DESTINATION) -classpath $(CLASSPATH) \ -sourcepath $(SOURCEPATH)/$(PACKAGE_LOC) $(JAVAC_FLAGS) endif JAVAH_OPTIONS = -d $(INCLUDE_DIR) -classpath $(CLASSPATH) ifdef MANIFEST JAR_OPTIONS = -cmf JAR_MANIFEST = $(MANIFEST_DIR)/$(MANIFEST) else JAR_OPTIONS = -cf endif JAVADOC_OPTIONS = \ -d $(JAVADOC_DIR) \ -sourcepath $(JAVA_SRC_DIR) \ -classpath $(JAVADOC_CLASSPATH) \ -author \ -use \ -version \ -quiet \ -windowtitle $(WINDOWTITLE) \ -doctitle $(DOCTITLE) \ -header $(HEADER) \ -bottom $(BOTTOM) \ $(LINK_FILES) ifdef OVERVIEW JAVADOC_OPTIONS += -overview $(OVERVIEW) endif ifdef JAVADOC_FLAGS JAVADOC_OPTIONS += $(JAVADOC_FLAGS) endif # # General build rules # # Rule 0. Applied when make is called without targets. all: $(DESTINATION) $(CLASS_FILES) $(OTHER_FILES) # Rule 1. If the destination dir is missing then create it $(DESTINATION) : $(PRINT) Creating $(DESTINATION) @ $(MAKEDIR) $(DESTINATION) # Rule 2. Build JNI .h files. Invokes rule 6. jni : $(JNI_CLASS_FILES) $(JNI_HEADERS) # Rule 3. Change ".build" tag to "Makefile", thus call the package makefile # which in turn recalls this makefile with target all (rule 0). %.build : $(PRINT) Building directory $(subst .build,' ',$@) @ $(MAKE) -k -f $(subst .build,Makefile,$@) all # Rule 4. Call rule 3 for every package buildall : $(PLIST_BUILD) $(PRINT) Done build. # # Specific dependency build rules # # Rule 5. Building a .class file from a .java file $(PACKAGE_DIR)/%.class : $(JAVA_SRC_DIR)/$(PACKAGE_LOC)/%.java $(PRINT) Compiling $*.java @ $(JAVAC) $(JAVAC_OPTIONS) $< # Rule 6. Building a .class file from a .java file. Invokes rule 5. %.class : $(JAVA_SRC_DIR)/$(PACKAGE_LOC)/%.java @ $(MAKE) -k $(PACKAGE_DIR)/$@ # Rule 7. Building a JNI .h stub file from a .class file $(JAVA_SRC_DIR)/$(PACKAGE_LOC)/%.h : $(PACKAGE_DIR)/%.class $(PRINT) Creating header for $* @ $(JAVAH) $(JAVAH_OPTIONS) $(PACKAGE).$* # Rule 8. Building a JNI .h stub file from a class file. Invokes rule 7. %.h : %.class @ $(MAKE) -k $(JAVA_SRC_DIR)/$(PACKAGE_LOC)/$@ # Rule 9. Default behaviour within a package: Simply copy the object from src # to classes. Note that the location of this rule is important. It must be after # the package specifics. $(PACKAGE_DIR)/% : $(JAVA_DIR)/$(PACKAGE_LOC)/% $(MAKEDIR) $(PACKAGE_DIR) $(PRINT) Copying $* $(COPY) $< $@ $(CHMOD) u+rw $< # # Cleanups # # Rule 10. Remove all produced files (except javadoc) cleanall : $(DELETE) $(PACKAGE_DIR)/*.class $(OTHER_FILES) $(JNI_HEADERS) # Rule 11. Change ".clean" tag to "Makefile", thus call the package makefile # which in turn recalls this makefile with target cleanall (rule 10). %.clean : $(MAKE) -k -f $(subst .clean,Makefile,$@) cleanall # Rule 12: Call rule 11 for every package directory clean : $(PLIST_CLEAN) $(PRINT) Done clean. # # JAR file related stuff # # Rule 13. Build a jar file. $* strips the last phony .JAR extension. # Copy all the required directories to a temp dir and then build the # JAR from that. The -C option on the jar command recurses all the # directories, which we don't want because we want to control the # packaging structure. %.JAR : @ $(MAKEDIR) $(JAR_DIR) $(JAR_TMP_DIR) $(PRINT) Deleting the old JAR file @ $(DELETE) $(JAR_DIR)/$* $(PRINT) Building the new JAR file $* @ $(RMDIR) $(JAR_TMP_DIR)/* if [ -n "$(JAR_CLASS_FILES)" ] ; then \ for X in $(JAR_CONTENT_LIST) ; do \ $(MAKEDIR) $(JAR_TMP_DIR)/"$$X" ; \ $(COPY) $(CLASS_DIR)/"$$X"/*.* $(JAR_TMP_DIR)/"$$X" ; \ done ; \ fi if [ -x $(ECLIPSE_DIR)/plugins/$(subst _$(JAR_VERSION).jar,$(EMPTY),$*) ] ; then \ $(COPY) -r $(ECLIPSE_DIR)/plugins/$(subst _$(JAR_VERSION).jar,$(EMPTY),$*)/* $(JAR_TMP_DIR); \ fi if [ -n "$(INCLUDE_JARS)" ] ; then \ for X in $(INCLUDE_JARS) ; do \ $(COPY) $(JAR_DIR)/"$$X" $(JAR_TMP_DIR) ; \ done ; \ fi $(JAR) $(JAR_OPTIONS) $(JAR_MANIFEST) $(JAR_DIR)/$* $(JAR_CONTENT_CMD) # Rule 13. Create given jar file by invoking its Makefile which triggers # rule 12 %.jar : $(PRINT) Building JAR file $@ version $(JAR_VERSION) $(MAKE) -k -f $(patsubst %,$(JAR_MAKE_DIR)/Makefile.$*,$@) $(patsubst %,$*_$(JAR_VERSION).jar,$@).JAR $(PRINT) Cleaning up @ $(RMDIR) $(JAR_TMP_DIR) # Rule 14. Create all jar files by invoking rule 13 jar : $(JARS) $(PRINT) Done jars. # Rule 15. Build javadoc for all listed packages javadoc : @ $(MAKEDIR) $(JAVADOC_DIR) $(PRINT) Cleaning out old docs @ $(RMDIR) $(JAVADOC_DIR)/* @ $(PRINT) $(JAVADOC_PACKAGES) > $(JAVA_DEV_ROOT)/packages.tmp $(PRINT) Starting Javadoc process @ $(JAVADOC) $(JAVADOC_OPTIONS) @$(JAVA_DEV_ROOT)/packages.tmp @ $(DELETE) $(JAVA_DEV_ROOT)/packages.tmp $(PRINT) Done JavaDoc. # Rule 16. A combination of steps used for automatic building complete : clean buildall jar javadoc # Rule 17. Install the JAR files after we have created them install: $(JAR_INSTALL_DIR) $(PRINT) Copying JAR files to $(JAR_INSTALL_DIR) $(COPY) $(JAR_DIR)/* $(JAR_INSTALL_DIR) # Rule 18. Copy the properties files to the classes directory properties: $(OTHER_FILES)