ohair@425: # ohair@425: # Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. ohair@425: # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ohair@425: # ohair@425: # This code is free software; you can redistribute it and/or modify it ohair@425: # under the terms of the GNU General Public License version 2 only, as ohair@425: # published by the Free Software Foundation. Oracle designates this ohair@425: # particular file as subject to the "Classpath" exception as provided ohair@425: # by Oracle in the LICENSE file that accompanied this code. ohair@425: # ohair@425: # This code is distributed in the hope that it will be useful, but WITHOUT ohair@425: # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ohair@425: # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ohair@425: # version 2 for more details (a copy is included in the LICENSE file that ohair@425: # accompanied this code). ohair@425: # ohair@425: # You should have received a copy of the GNU General Public License version ohair@425: # 2 along with this work; if not, write to the Free Software Foundation, ohair@425: # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ohair@425: # ohair@425: # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@425: # or visit www.oracle.com if you need additional information or have any ohair@425: # questions. ohair@425: # ohair@425: ohair@425: # The complexity of this makefile is not the fault of make, but the fault ohair@425: # of javac and javah. The basic problems are: ohair@425: # ohair@425: # 1) Compiling a single Java source file unpredictably generates anything ohair@425: # between zero (0!) and an infinite number of .class files! ohair@425: # 2) There is no hint, for which classes javah needs to be run, ohair@425: # and it happily generates .h files for classes with no native methods. ohair@425: # 3) javac and javah do not cleanup anything, for example if an internal ohair@425: # class (potentially with native methods) is removed from a Java source file. ohair@425: # ohair@425: # This makefile is a tribute to GNU make. And yes, it was harder to write than it is ohair@425: # to read. The include/excludes of directories and files are only a temporary measure ohair@425: # to work around the messy jdk sources that put platform specific code in src/share/classes. ohair@425: # ohair@425: # We should move most of the functionality of this makefile into a ohair@425: # smart javac/javah/javadoc/jar combo tool. sjavac ? ohair@425: # ohair@425: # I.e. 1) It always generates a single output, a zip-file from a number of source roots. ohair@425: # The zip file contains information that enable incremental builds with full ohair@425: # dependency tracking between packages. ohair@425: # 2) It automatically generates the right .h files. ohair@425: # 3) It keeps its house clean. ohair@425: # *) Generates intermediate files to be used for javadoc generation later. ohair@425: # and does all the other useful things that this makefile does, such as: ohair@425: # use all cores for compilation, reuse the running JVM for all compilations, ohair@425: # and has pubapi dependency tracking to minimize the number of files ohair@425: # that need to be recompiled during an incremental build. ohair@425: # ohair@425: # A zip file, or several zip files combined, can then be converted to a .jar file, or to a .jmod file. ohair@425: # ohair@425: # This would make this makefile much much simpler. I.e. make can be used ohair@425: # for its real purpose, track dependencies and trigger a recompile if a ohair@425: # dependency has changed. ohair@425: # ohair@425: # When you read this source. Remember that $(sort ...) has the side effect ohair@425: # of removing duplicates. It is actually this side effect that is ohair@425: # desired whenever sort is used below! ohair@425: ohair@425: ifeq (,$(_MAKEBASE_GMK)) ohair@425: $(error You must include MakeBase.gmk prior to including JavaCompilation.gmk) ohair@425: endif ohair@425: ohair@425: FALSE_FIND_PATTERN:=-name FILE_NAME_THAT_DOESNT_EXIST ohair@425: ohair@425: # If compilation of java package fails, then the public api file for that ohair@425: # package will not be genereated. We add this fallback rule to generate ohair@425: # an empty pubapi file. ohair@425: %.api: ohair@425: if test ! -f $@; then $(MKDIR) -p $(@D); $(TOUCH) $@; fi ohair@425: ohair@425: define SetupJavaCompiler ohair@425: # param 1 is for example BOOT_JAVAC or NEW_JAVAC ohair@425: # This is the name later used to decide which java compiler to use. ohair@425: # param 2-9 are named args. ohair@425: # JVM:=The jvm used to run the javac/javah command ohair@425: # JAVAC:=The javac jar and bootstrap classpath changes, or just bin/javac if JVM is left out ohair@425: # JAVAH:=The javah jar and bootstrap classpath changes, or just bin/javah if JVM is left out ohair@425: # FLAGS:=Flags to be supplied to javac ohair@425: # MODE:=SINGLE_THREADED_BATCH (primarily for old javac) or MULTI_CORE_CONCURRENT ohair@425: # only for MULTI_CORE_CONCURRENT are the options below relevant: ohair@425: # SERVER_DIR:=Use a javac server (-XDserver) and store the server related files here ohair@425: # SERVER_JVM:=Use this JVM for the server. Defaults to the JVM above. ohair@425: # USE_DEPS:=true means use -XDdeps,-XDpubapi and -XDnativeapi to track java dependencies ohair@425: $(if $2,$1_$(strip $2)) ohair@425: $(if $3,$1_$(strip $3)) ohair@425: $(if $4,$1_$(strip $4)) ohair@425: $(if $5,$1_$(strip $5)) ohair@425: $(if $6,$1_$(strip $6)) ohair@425: $(if $7,$1_$(strip $7)) ohair@425: $(if $8,$1_$(strip $8)) ohair@425: $(if $9,$1_$(strip $9)) erikj@458: $(if $(10),$(error Internal makefile error: Too many arguments to SetupJavaCompiler, please update JavaCompilation.gmk)) ohair@425: ohair@425: ifeq ($$($1_MODE),MULTI_CORE_CONCURRENT) ohair@425: ifneq (,$$($1_SERVER_DIR)) ohair@425: # A javac server has been requested. ohair@425: # The port file contains the tcp/ip on which the server listens ohair@425: # and the cookie necessary to talk to the server. ohair@425: $1_JAVAC_PORTFILE:=$$($1_SERVER_DIR)/$1.port ohair@425: ifeq ($$($1_SERVER_JVM),) ohair@425: # You can use a different JVM to run the background javac server. ohair@425: # But if not set, it defaults to the same JVM that is used to start ohair@425: # the javac command. ohair@425: $1_SERVER_JVM:=$$($1_JVM) ohair@425: endif ohair@425: # Set the $1_REMOTE to spawn a background javac server. ohair@425: $1_REMOTE:=-XDserver:portfile=$$($1_JAVAC_PORTFILE),poolsize=$(JAVAC_SERVER_CORES),javac=$$(subst $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_JAVAC)))) ohair@425: endif ohair@425: endif ohair@425: endef ohair@425: ohair@425: define SetupArchive ohair@425: # param 1 is for example ARCHIVE_MYPACKAGE ohair@425: # param 2 are the dependecies ohair@425: # param 3,4,5,6,7,8,9 are named args. ohair@425: # SRCS:=List of directories in where to find files to add to archive ohair@425: # SUFFIXES:=File suffixes to include in jar ohair@425: # INCLUDES:=List of directories/packages in SRCS that should be included ohair@425: # EXCLUDES:=List of directories/packages in SRCS that should be excluded ohair@425: # EXCLUDE_FILES:=List of files in SRCS that should be excluded ohair@425: # EXTRA_FILES:=List of files in SRCS that should be included regardless of suffix match. ohair@425: # JAR:=Jar file to create ohair@425: # MANIFEST:=Optional manifest file template. ohair@425: # JARMAIN:=Optional main class to add to manifest erikj@445: # JARINDEX := ohair@425: # SKIP_METAINF:=Set to prevent contents of an META-INF directory to be automatically ohair@425: # added to the archive. ohair@425: # EXTRA_MANIFEST_ATTR:=Extra attribute to add to manifest. erikj@458: # CHECK_COMPRESS_JAR Check the COMPRESS_JAR variable ohair@425: $(if $3,$1_$(strip $3)) ohair@425: $(if $4,$1_$(strip $4)) ohair@425: $(if $5,$1_$(strip $5)) ohair@425: $(if $6,$1_$(strip $6)) ohair@425: $(if $7,$1_$(strip $7)) ohair@425: $(if $8,$1_$(strip $8)) ohair@425: $(if $9,$1_$(strip $9)) ohair@425: $(if $(10),$1_$(strip $(10))) ohair@425: $(if $(11),$1_$(strip $(11))) ohair@425: $(if $(12),$1_$(strip $(12))) ohair@425: $(if $(13),$1_$(strip $(13))) ohair@425: $(if $(14),$1_$(strip $(14))) erikj@445: $(if $(15),$1_$(strip $(15))) erikj@458: $(if $(16),$(error Internal makefile error: Too many arguments to SetupArchive, please update JavaCompilation.gmk)) ohair@425: ohair@425: $1_JARMAIN:=$(strip $$($1_JARMAIN)) ohair@425: $1_JARNAME:=$$(notdir $$($1_JAR)) ohair@425: $1_MANIFEST_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_manifest ohair@425: $1_DELETESS_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletess ohair@425: $1_DELETES_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletes ohair@425: $1_PUBAPI_NOTIFICATIONS_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_pubapi_notifications ohair@425: $1_NATIVEAPI_NOTIFICATIONS_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_native_notifications ohair@425: $1_NATIVEAPI_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_native ohair@425: $1_BIN:=$$(dir $$($1_JAR)) erikj@445: ohair@425: ifeq (,$$($1_SUFFIXES)) ohair@425: # No suffix was set, default to classes. ohair@425: $1_SUFFIXES:=.class ohair@425: endif ohair@425: # Convert suffixes to a find expression ohair@425: $1_FIND_PATTERNS:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_SUFFIXES)) erikj@445: # On windows, a lot of includes/excludes risk making the command line too long, so erikj@445: # writing the grep patterns to files. ohair@425: ifneq (,$$($1_INCLUDES)) erikj@445: $1_GREP_INCLUDE_PATTERNS:=$$(foreach src,$$($1_SRCS),\ erikj@445: $$(addprefix $$(src)/,$$($1_INCLUDES))) erikj@445: $$(eval $$(call ListPathsSafelyNow,$1_GREP_INCLUDE_PATTERNS,\n, \ erikj@445: >> $$($1_BIN)/_the.$$($1_JARNAME)_include)) erikj@445: $1_GREP_INCLUDES:=| $(GREP) -f $$($1_BIN)/_the.$$($1_JARNAME)_include ohair@425: endif ohair@425: ifneq (,$$($1_EXCLUDES)$$($1_EXCLUDE_FILES)) erikj@445: $1_GREP_EXCLUDE_PATTERNS:=$$(foreach src,$$($1_SRCS),$$(addprefix $$(src)/,\ erikj@445: $$($1_EXCLUDES) $$($1_EXCLUDE_FILES))) erikj@445: $$(eval $$(call ListPathsSafelyNow,$1_GREP_EXCLUDE_PATTERNS,\n, \ erikj@445: >> $$($1_BIN)/_the.$$($1_JARNAME)_exclude)) erikj@445: $1_GREP_EXCLUDES:=| $(GREP) -v -f $$($1_BIN)/_the.$$($1_JARNAME)_exclude ohair@425: endif ohair@425: erikj@445: ifneq (,$$($1_JARINDEX)) erikj@445: $1_JARINDEX = (cd $$(dir $$@) && $(JAR) -i $$(notdir $$@)) erikj@445: else erikj@445: $1_JARINDEX = true erikj@445: endif erikj@445: # When this macro is run in the same makefile as the java compilation, dependencies are transfered erikj@445: # in make variables. When the macro is run in a different makefile than the java compilation, the erikj@445: # dependencies need to be found in the filesystem. erikj@445: $1_ALL_SRCS:=$$(foreach src,$$($1_SRCS),$$(shell ($(FIND) $$(src) -type f \ erikj@445: -a \( $$($1_FIND_PATTERNS) \) $$($1_GREP_INCLUDES) \ erikj@445: $$($1_GREP_EXCLUDES) && $(ECHO) $$($1_EXTRA_FILES)))) erikj@445: ifeq (,$$($1_SKIP_METAINF)) erikj@445: $1_ALL_SRCS+=$$(foreach src,$$($1_SRCS),$$(shell $(FIND) $$(src)/META-INF -type f 2> /dev/null)) erikj@445: endif erikj@445: erikj@445: ohair@425: # Utility macros, to make the shell script receipt somewhat easier to dechipher. ohair@425: ohair@425: # The capture contents macro finds all files (matching the patterns, typically ohair@425: # .class and .prp) that are newer than the jar-file, ie the new content to be put into the jar. ohair@425: $1_CAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS),(($(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) -a -newer $$@ $$($1_GREP_INCLUDES) $$($1_GREP_EXCLUDES) && $(ECHO) $$($1_EXTRA_FILES)) | $(SED) 's|$$(src)/||g' > $$(src)/_the.$$($1_JARNAME)_contents) && ) ohair@425: # The capture metainf macro finds all files below the META-INF directory that are newer than the jar-file. ohair@425: ifeq (,$$($1_SKIP_METAINF)) ohair@425: $1_CAPTURE_METAINF =$$(foreach src,$$($1_SRCS),($(FIND) $$(src)/META-INF -type f -a -newer $$@ 2> /dev/null | $(SED) 's|$$(src)/||g' >> $$(src)/_the.$$($1_JARNAME)_contents ) && ) ohair@425: endif ohair@425: # The capture deletes macro finds all deleted files and concatenates them. The resulting file ohair@425: # tells us what to remove from the jar-file. ohair@425: $1_CAPTURE_DELETES=$$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.deleted -newer $$@ -exec $(SED) 's|$$(src)||g' \{\} >> $$($1_DELETES_FILE) \;) &&) ohair@425: # The capture pubapi notifications scans for pubapi change notifications. If such notifications are ohair@425: # found, then we will build the classes leading up to the jar again, to take into account the new timestamps ohair@425: # on the changed pubapi files. ohair@425: $1_CAPTURE_PUBAPI_NOTIFICATIONS=$$(foreach src,$$($1_SRCS),\ ohair@425: (cd $$(src) && \ ohair@425: $(FIND) . -name _the.package.api.notify -exec dirname \{\} \; >> $$($1_PUBAPI_NOTIFICATIONS_FILE) ; \ ohair@425: true) &&) ohair@425: # The update contents macro updates the jar file with the previously capture contents. ohair@425: $1_UPDATE_CONTENTS=$$(foreach src,$$($1_SRCS),\ ohair@425: (cd $$(src) && \ ohair@425: if [ -s _the.$$($1_JARNAME)_contents ]; then \ ohair@425: $(ECHO) " updating" `$(WC) -l _the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'` files && \ ohair@425: $(JAR) uf $$@ @_the.$$($1_JARNAME)_contents; \ ohair@425: fi) &&) ohair@425: # The s-variants of the above macros are used when the jar is created from scratch. ohair@425: $1_SCAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS),\ erikj@445: (($(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) $$($1_GREP_INCLUDES) \ erikj@445: $$($1_GREP_EXCLUDES) && $(ECHO) $$($1_EXTRA_FILES)) | $(SED) 's|$$(src)/||g' > \ erikj@445: $$(src)/_the.$$($1_JARNAME)_contents) && ) erikj@445: ohair@425: ifeq (,$$($1_SKIP_METAINF)) ohair@425: $1_SCAPTURE_METAINF=$$(foreach src,$$($1_SRCS),\ erikj@445: ($(FIND) $$(src)/META-INF -type f 2> /dev/null | $(SED) 's|$$(src)/||g' >> \ erikj@445: $$(src)/_the.$$($1_JARNAME)_contents) && ) ohair@425: endif ohair@425: $1_SUPDATE_CONTENTS=$$(foreach src,$$($1_SRCS),\ ohair@425: (cd $$(src) && $(JAR) uf $$@ @$$(src)/_the.$$($1_JARNAME)_contents) &&) erikj@445: ohair@425: # The TOUCH macro is used to make sure all timestamps are identical for package files and the pubapi files. ohair@425: # If we do not do this, we get random recompilations, the next time we run make, since the order of package building is random, ohair@425: # ie independent of package --dependes on-> public api of another package. This is of course ohair@425: # due to the fact that Java source often (always?) has circular dependencies. (Thus there is no correct order ohair@425: # to compile packages, and we can just as well do them in a random order. Which we do.) ohair@425: $1_TOUCH_API_FILES=$$(foreach src,$$($1_SRCS),\ ohair@425: ($(FIND) $$(src) -name _the.package.api -exec $(TOUCH) -r $$($1_JAR) \{\} \; ; true) && \ ohair@425: ($(FIND) $$(src) -name _the.package -exec $(TOUCH) -r $$($1_JAR) \{\} \; ; true) &&) ohair@425: # Use a slightly shorter name for logging, but with enough path to identify this jar. ohair@425: $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_JAR)) erikj@458: erikj@458: ifneq (,$$($1_CHECK_COMPRESS_JAR)) erikj@458: $1_JAR_CREATE_OPTIONS := c0fm erikj@458: ifeq ($(COMPRESS_JARS), true) erikj@458: $1_JAR_CREATE_OPTIONS := cfm erikj@458: endif erikj@458: else erikj@458: $1_JAR_CREATE_OPTIONS := cfm erikj@458: endif erikj@458: ohair@425: # Here is the rule that creates/updates the jar file. erikj@445: $$($1_JAR) : $2 $$($1_ALL_SRC) ohair@425: $(MKDIR) -p $$($1_BIN) ohair@425: if [ -n "$$($1_MANIFEST)" ]; then \ ohair@425: $(SED) -e "s#@@RELEASE@@#$(RELEASE)#" \ ohair@425: -e "s#@@COMPANY_NAME@@#$(COMPANY_NAME)#" $$($1_MANIFEST) > $$($1_MANIFEST_FILE); \ ohair@425: else \ ohair@425: $(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE); \ ohair@425: fi erikj@445: if [ -n "$$(strip $$($1_JARMAIN))" ]; then \ erikj@445: $(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE); \ erikj@445: fi ohair@425: if [ -n "$$($1_EXTRA_MANIFEST_ATTR)" ]; then \ erikj@445: $(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE); \ ohair@425: fi ohair@425: +if [ -s $$@ ]; then \ ohair@425: $(RM) -r $$($1_PUBAPI_NOTIFICATIONS_FILE) && \ ohair@425: $$($1_CAPTURE_PUBAPI_NOTIFICATIONS) \ ohair@425: if [ -s $$($1_PUBAPI_NOTIFICATIONS_FILE) ]; then \ ohair@425: $(ECHO) Public api change detected in: && \ ohair@425: $(CAT) $$($1_PUBAPI_NOTIFICATIONS_FILE) | $(TR) '/' '.' | $(SED) 's|^..||g' | $(SED) 's|\.$$$$||g' | $(AWK) '{print " "$$$$1}' && \ ohair@425: $$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.api.notify $(FIND_DELETE); true) &&) \ ohair@425: $(MAKE) -f $(word 1,$(MAKEFILE_LIST)) $$($1_JAR) ; \ ohair@425: else \ ohair@425: $(ECHO) Modifying $$($1_NAME) && \ ohair@425: $$($1_CAPTURE_CONTENTS) \ ohair@425: $$($1_CAPTURE_METAINF) \ ohair@425: $(RM) $$($1_DELETES_FILE) && \ ohair@425: $$($1_CAPTURE_DELETES) \ ohair@425: $(CAT) $$($1_DELETES_FILE) > $$($1_DELETESS_FILE) && \ ohair@425: if [ -s $$($1_DELETESS_FILE) ]; then \ ohair@425: $(ECHO) " deleting" `$(WC) -l $$($1_DELETESS_FILE) | $(AWK) '{ print $$$$1 }'` files && \ ohair@425: $(ZIP) -q -d $$@ `$(CAT) $$($1_DELETESS_FILE)` ; \ ohair@425: fi && \ ohair@425: $$($1_UPDATE_CONTENTS) true && \ erikj@445: $$($1_JARINDEX) && \ ohair@425: $$($1_TOUCH_API_FILES) true && \ ohair@425: $$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.api.notify $(FIND_DELETE); true) &&) true ; \ ohair@425: fi ; \ ohair@425: else \ erikj@458: $(ECHO) Creating $$($1_NAME) && $(JAR) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) && \ ohair@425: $$($1_SCAPTURE_CONTENTS) \ ohair@425: $$($1_SCAPTURE_METAINF) \ ohair@425: $$($1_SUPDATE_CONTENTS) \ erikj@445: $$($1_JARINDEX) && \ ohair@425: $$($1_TOUCH_API_FILES) true && \ ohair@425: $(RM) -r $$($1_NATIVEAPI_NOTIFICATIONS_FILE) $$($1_NATIVEAPI_FILE) && \ ohair@425: $$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name "*.notify" $(FIND_DELETE); true) &&) true ; \ ohair@425: fi; ohair@425: ohair@425: endef ohair@425: ohair@425: define append_to ohair@425: $(ECHO) "$1" >> $2 ohair@425: endef ohair@425: ohair@425: define SetupZipArchive ohair@425: # param 1 is for example ZIP_MYSOURCE ohair@425: # param 2,3,4,5,6,7,8,9 are named args. erikj@445: # SRC,ZIP,INCLUDES,EXCLUDES,EXCLUDE_FILES,SUFFIXES,EXTRA_DEPS ohair@425: $(if $2,$1_$(strip $2)) ohair@425: $(if $3,$1_$(strip $3)) ohair@425: $(if $4,$1_$(strip $4)) ohair@425: $(if $5,$1_$(strip $5)) ohair@425: $(if $6,$1_$(strip $6)) ohair@425: $(if $7,$1_$(strip $7)) ohair@425: $(if $8,$1_$(strip $8)) ohair@425: $(if $9,$1_$(strip $9)) erikj@458: $(if $(10),$(error Internal makefile error: Too many arguments to SetupZipArchive, please update JavaCompilation.gmk)) ohair@425: ohair@425: # Find all files in the source tree. erikj@445: $1_SUFFIX_FILTER := $$(patsubst %,-o -name $(DQUOTE)*%$(DQUOTE),$$($1_SUFFIXES)) erikj@445: $1_ALL_SRCS := $$(foreach i,$$($1_SRC), $$(shell $(FIND) $$i -type f -a ! -name "_the.*" \( -name FALSE_DUMMY $$($1_SUFFIX_FILTER) \) )) ohair@425: ohair@425: ifneq ($$($1_INCLUDES),) ohair@425: $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES)))) erikj@445: ifneq ($$($1_SUFFIXES),) erikj@445: $1_ZIP_INCLUDES := $$(foreach s,$$($1_SUFFIXES),\ erikj@445: $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$$s$(DQUOTE),$$($1_INCLUDES)))) erikj@445: else erikj@445: $1_ZIP_INCLUDES := $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_INCLUDES))) erikj@445: endif ohair@425: $1_ALL_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_SRCS)) ohair@425: endif ohair@425: ifneq ($$($1_EXCLUDES),) ohair@425: $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES)))) ohair@425: $1_ZIP_EXCLUDES := $$(addprefix -x$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_EXCLUDES))) ohair@425: $1_ALL_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS)) ohair@425: endif ohair@425: ohair@425: # Use a slightly shorter name for logging, but with enough path to identify this zip. ohair@425: $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_ZIP)) ohair@425: ohair@425: # Now $1_ALL_SRCS should contain all sources that are going to be put into the zip. ohair@425: # I.e. the zip -i and -x options should match the filtering done in the makefile. ohair@425: # Explicitly excluded files can be given with absolute path. The patsubst solution ohair@425: # isn't perfect but the likelyhood of an absolute path to match something in a src ohair@425: # dir is very small. erikj@445: $$($1_ZIP) : $$($1_ALL_SRCS) $$($1_EXTRA_DEPS) ohair@425: $(MKDIR) -p $$(@D) ohair@425: $(ECHO) Updating $$($1_NAME) ohair@425: $$(foreach i,$$($1_SRC),(cd $$i && $(ZIP) -qru $$@ . $$($1_ZIP_INCLUDES) $$($1_ZIP_EXCLUDES) -x \*_the.\* $$(addprefix -x$(SPACE),$$(patsubst $$i/%,%,$$($1_EXCLUDE_FILES)))) ;) true ohair@425: $(TOUCH) $$@ ohair@425: endef ohair@425: ohair@425: define add_file_to_copy ohair@425: # param 1 = BUILD_MYPACKAGE ohair@425: # parma 2 = The source file to copy. ohair@425: $2_TARGET:=$2 ohair@425: # Remove the source prefix. ohair@425: $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET))) ohair@425: # Now we can setup the depency that will trigger the copying. ohair@425: $$($1_BIN)$$($2_TARGET) : $2 ohair@425: $(MKDIR) -p $$(@D) ohair@425: $(CP) $$< $$@ ohair@425: $(CHMOD) -f ug+w $$@ ohair@425: ohair@425: # And do not forget this target ohair@425: $1_ALL_COPY_TARGETS += $$($1_BIN)$$($2_TARGET) ohair@425: endef ohair@425: ohair@425: ohair@425: # This macro is used only for properties files that are to be ohair@425: # copied over to the classes directory in cleaned form: ohair@425: # Previously this was inconsistently done in different repositories. ohair@425: # This is the new clean standard. ohair@425: define add_file_to_copy_and_clean ohair@425: # param 1 = BUILD_MYPACKAGE ohair@425: # parma 2 = The source file to copy and clean. ohair@425: $2_TARGET:=$2 ohair@425: # Remove the source prefix. ohair@425: $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET))) ohair@425: # Now we can setup the depency that will trigger the copying. ohair@425: $$($1_BIN)$$($2_TARGET) : $2 ohair@425: $(MKDIR) -p $$(@D) ohair@425: $(ECHO) Cleaning $$($2_TARGET) ohair@425: $(CAT) $$< | $(SED) -e 's/\([^\\]\):/\1\\:/g' -e 's/\([^\\]\)=/\1\\=/g' -e 's/#.*/#/g' \ ohair@425: | $(SED) \ ohair@425: -e 's/\\u0020/\x20/g' \ ohair@425: -e 's/\\u003A/\x3A/g' \ ohair@425: -e 's/\\u006B/\x6B/g' \ ohair@425: -e 's/\\u0075/\x75/g' \ ohair@425: -e 's/\\u00A0/\xA0/g' \ ohair@425: -e 's/\\u00A3/\xA3/g' \ ohair@425: -e 's/\\u00B0/\xB0/g' \ ohair@425: -e 's/\\u00B7/\xB7/g' \ ohair@425: -e 's/\\u00BA/\xBA/g' \ ohair@425: -e 's/\\u00BF/\xBF/g' \ ohair@425: -e 's/\\u00C0/\xC0/g' \ ohair@425: -e 's/\\u00C1/\xC1/g' \ ohair@425: -e 's/\\u00C2/\xC2/g' \ ohair@425: -e 's/\\u00C4/\xC4/g' \ ohair@425: -e 's/\\u00C5/\xC5/g' \ ohair@425: -e 's/\\u00C8/\xC8/g' \ ohair@425: -e 's/\\u00C9/\xC9/g' \ ohair@425: -e 's/\\u00CA/\xCA/g' \ ohair@425: -e 's/\\u00CD/\xCD/g' \ ohair@425: -e 's/\\u00CE/\xCE/g' \ ohair@425: -e 's/\\u00D3/\xD3/g' \ ohair@425: -e 's/\\u00D4/\xD4/g' \ ohair@425: -e 's/\\u00D6/\xD6/g' \ ohair@425: -e 's/\\u00DA/\xDA/g' \ ohair@425: -e 's/\\u00DC/\xDC/g' \ ohair@425: -e 's/\\u00DD/\xDD/g' \ ohair@425: -e 's/\\u00DF/\xDF/g' \ ohair@425: -e 's/\\u00E0/\xE0/g' \ ohair@425: -e 's/\\u00E1/\xE1/g' \ ohair@425: -e 's/\\u00E2/\xE2/g' \ ohair@425: -e 's/\\u00E3/\xE3/g' \ ohair@425: -e 's/\\u00E4/\xE4/g' \ ohair@425: -e 's/\\u00E5/\xE5/g' \ ohair@425: -e 's/\\u00E6/\xE6/g' \ ohair@425: -e 's/\\u00E7/\xE7/g' \ ohair@425: -e 's/\\u00E8/\xE8/g' \ ohair@425: -e 's/\\u00E9/\xE9/g' \ ohair@425: -e 's/\\u00EA/\xEA/g' \ ohair@425: -e 's/\\u00EB/\xEB/g' \ ohair@425: -e 's/\\u00EC/\xEC/g' \ ohair@425: -e 's/\\u00ED/\xED/g' \ ohair@425: -e 's/\\u00EE/\xEE/g' \ ohair@425: -e 's/\\u00EF/\xEF/g' \ ohair@425: -e 's/\\u00F1/\xF1/g' \ ohair@425: -e 's/\\u00F2/\xF2/g' \ ohair@425: -e 's/\\u00F3/\xF3/g' \ ohair@425: -e 's/\\u00F4/\xF4/g' \ ohair@425: -e 's/\\u00F5/\xF5/g' \ ohair@425: -e 's/\\u00F6/\xF6/g' \ ohair@425: -e 's/\\u00F9/\xF9/g' \ ohair@425: -e 's/\\u00FA/\xFA/g' \ ohair@425: -e 's/\\u00FC/\xFC/g' \ ohair@425: -e 's/\\u0020/\x20/g' \ ohair@425: -e 's/\\u003f/\x3f/g' \ ohair@425: -e 's/\\u006f/\x6f/g' \ ohair@425: -e 's/\\u0075/\x75/g' \ ohair@425: -e 's/\\u00a0/\xa0/g' \ ohair@425: -e 's/\\u00a3/\xa3/g' \ ohair@425: -e 's/\\u00b0/\xb0/g' \ ohair@425: -e 's/\\u00ba/\xba/g' \ ohair@425: -e 's/\\u00bf/\xbf/g' \ ohair@425: -e 's/\\u00c1/\xc1/g' \ ohair@425: -e 's/\\u00c4/\xc4/g' \ ohair@425: -e 's/\\u00c5/\xc5/g' \ ohair@425: -e 's/\\u00c8/\xc8/g' \ ohair@425: -e 's/\\u00c9/\xc9/g' \ ohair@425: -e 's/\\u00ca/\xca/g' \ ohair@425: -e 's/\\u00cd/\xcd/g' \ ohair@425: -e 's/\\u00d6/\xd6/g' \ ohair@425: -e 's/\\u00dc/\xdc/g' \ ohair@425: -e 's/\\u00dd/\xdd/g' \ ohair@425: -e 's/\\u00df/\xdf/g' \ ohair@425: -e 's/\\u00e0/\xe0/g' \ ohair@425: -e 's/\\u00e1/\xe1/g' \ ohair@425: -e 's/\\u00e2/\xe2/g' \ ohair@425: -e 's/\\u00e3/\xe3/g' \ ohair@425: -e 's/\\u00e4/\xe4/g' \ ohair@425: -e 's/\\u00e5/\xe5/g' \ ohair@425: -e 's/\\u00e7/\xe7/g' \ ohair@425: -e 's/\\u00e8/\xe8/g' \ ohair@425: -e 's/\\u00e9/\xe9/g' \ ohair@425: -e 's/\\u00ea/\xea/g' \ ohair@425: -e 's/\\u00eb/\xeb/g' \ ohair@425: -e 's/\\u00ec/\xec/g' \ ohair@425: -e 's/\\u00ed/\xed/g' \ ohair@425: -e 's/\\u00ee/\xee/g' \ ohair@425: -e 's/\\u00ef/\xef/g' \ ohair@425: -e 's/\\u00f0/\xf0/g' \ ohair@425: -e 's/\\u00f1/\xf1/g' \ ohair@425: -e 's/\\u00f2/\xf2/g' \ ohair@425: -e 's/\\u00f3/\xf3/g' \ ohair@425: -e 's/\\u00f4/\xf4/g' \ ohair@425: -e 's/\\u00f5/\xf5/g' \ ohair@425: -e 's/\\u00f6/\xf6/g' \ ohair@425: -e 's/\\u00f7/\xf7/g' \ ohair@425: -e 's/\\u00f8/\xf8/g' \ ohair@425: -e 's/\\u00f9/\xf9/g' \ ohair@425: -e 's/\\u00fa/\xfa/g' \ ohair@425: -e 's/\\u00fc/\xfc/g' \ ohair@425: -e 's/\\u00ff/\xff/g' \ ohair@425: | $(SED) -e '/^#/d' -e '/^$$$$/d' \ ohair@425: -e :a -e '/\\$$$$/N; s/\\\n//; ta' \ ohair@425: -e 's/^[ \t]*//;s/[ \t]*$$$$//' \ erikj@445: -e 's/\\=/=/' | LANG=C $(SORT) > $$@ ohair@425: $(CHMOD) -f ug+w $$@ ohair@425: ohair@425: # And do not forget this target ohair@425: $1_ALL_COPY_CLEAN_TARGETS += $$($1_BIN)$$($2_TARGET) ohair@425: endef ohair@425: ohair@425: define add_java_package ohair@425: # param 1 = BUILD_MYPACKAGE ohair@425: # param 2 = the package target file (_the.package) ohair@425: # param 3 = src roots, all of them, separated with space ohair@425: # param 4 = bin root ohair@425: # param 5 = include these dependecies ohair@425: # param 6 = not used ohair@425: # param 7 = if non-empty, then use -Xdeps and -Xpubapi ohair@425: # param 8 = xremote configuration, or empty. ohair@425: # param 9 = javac command ohair@425: # param 10 = javac flags ohair@425: # param 11 = exclude these files! ohair@425: # param 12 = only include these files! ohair@425: # param 13 = javah command ohair@425: # param 14 = override src roots to be passed into -sourcepath, ugly ugly ugly, do not use this! ohair@425: # it is only here to workaround ugly things in the source code in the jdk that ought ohair@425: # to be fixed instead! ohair@425: ifdef $2_USED_BY ohair@425: $$(error Attempting to add the package $2 from $3 which is already added with sources from $$($2_USED_BY)) ohair@425: endif ohair@425: $2_USED_BY:=$3 ohair@425: # Remove the _the.package file to get the target bin dir for the classes in this package. ohair@425: $2_PACKAGE_BDIR:=$(dir $2) ohair@425: # The source roots separated with a path separator (: or ; depending on os) ohair@425: # (The patsubst is necessary to trim away unnecessary spaces.) ohair@425: ifneq ($(14),) ohair@425: $2_SRCROOTSC:=$(subst $(SPACE),$(PATH_SEP),$(strip $(patsubst %,%,$(14)))) ohair@425: else ohair@425: $2_SRCROOTSC:=$(subst $(SPACE),$(PATH_SEP),$(strip $(patsubst %,%,$3))) ohair@425: endif ohair@425: # Suffix the package path to the src roots, to get a list of all possible source locations ohair@425: # for this package. ohair@425: $2_PACKAGE_SDIRS:=$$(foreach i,$3,$$(subst $4,$$i,$$($2_PACKAGE_BDIR))) ohair@425: # Use wildcard in all potential source locations to find the actual sources. ohair@425: $2_PACKAGE_SRCS:=$$(filter-out $(11),$$(wildcard $$(addsuffix *.java,$$($2_PACKAGE_SDIRS)))) ohair@425: ifneq ($(12),) ohair@425: # Filter on include file filter if set. ohair@425: $2_PACKAGE_SRCS:=$$(filter $(12),$$($2_PACKAGE_SRCS)) ohair@425: endif ohair@425: # Generate a proper package name from the file name. ohair@425: $2_PACKAGE:=$(patsubst .%.,%,$(subst /,.,$(subst $4,,$(dir $2)))) ohair@425: # Use a javac server for this package? ohair@425: $2_REMOTE:=$8 ohair@425: ohair@425: # Include previously generated information about what classes are output by this package ohair@425: # and what sources were used for the compile. ohair@425: -include $$($2_PACKAGE_BDIR)_the.package.d ohair@425: ohair@425: # Include the notify, file, that exists if the package has been compiled during a previous make round. ohair@425: # I.e. we are now dealing with a compile triggered by a pubapi change. ohair@425: -include $$($2_PACKAGE_BDIR)_the.package.notify ohair@425: ohair@425: # If the notify file existed, then $$($2_NOTIFIED) will be equal to true. ohair@425: # Use this information to block dependency tracking for this package. ohair@425: # This is necessary to cut the circular dependency chains that are so common in Java sources. ohair@425: ohair@425: ifneq ($$($2_NOTIFIED),true) ohair@425: # No need to block, since this package has not yet been recompiled. ohair@425: # Thus include previously generated dependency information. (if it exists) ohair@425: -include $$($2_PACKAGE_BDIR)_the.package.dddd ohair@425: # else ohair@425: # $$(info WAS NOTIFIED $2) ohair@425: endif ohair@425: ohair@425: # Should we create proper dependencies between packages? ohair@425: ifneq ($7,) ohair@425: # The flag: -XDpubapi:file=foo,package=mypack,notify writes a file foo that contains a ohair@425: # database of the public api of the classes supplied on the command line and are ohair@425: # inside the package mypack. If foo already exists, javac will only write to foo, ohair@425: # if there is a change in the pubapi. I.e. we can use the timestamp of this file ohair@425: # for triggering dependencies. "notify" means create a "file" suffixed with notify ohair@425: # if the pubapi really changed. ohair@425: $2_PUBAPI=-XDpubapi=file=$$($2_PACKAGE_BDIR)_the.package.api,notify,package=$$($2_PACKAGE) ohair@425: # The flag: -XDnativeapi:file=foo,package=mypack,notify works similar to pubabi, but ohair@425: # instead tracks native methods. This file can be used to trigger dependencies for ohair@425: # native compilations. ohair@425: $2_NATIVEAPI=-XDnativeapi=file=$$($2_PACKAGE_BDIR)_the.package.native,notify,package=$$($2_PACKAGE) ohair@425: # The flag -XDdeps:file=foo.deps,groupon=package writes a foo.deps file containing packages dependencies: ohair@425: # java.net : java.io java.lang ohair@425: # I.e. the classes in .net depend on the public apis of java.io and java.lang ohair@425: # The dependencies can be grouped on classes instead (groupon=class) ohair@425: # java.net.Bar : java.io.Socket java.lang.String ohair@425: $2_DEPS:=-XDdeps=file=$$($2_PACKAGE_BDIR)_the.package.deps,groupon=package ohair@425: # The next command rewrites the deps output from javac into a proper makefile dependency. ohair@425: # The dependencies are always to an .api file generated by the pubapi option above. ohair@425: # This is necessary since java package dependencies are almost always circular. ohair@425: $2_APPEND_DEPS:=($(CAT) $$($2_PACKAGE_BDIR)_the.package.deps | $(TR) '.' '/' | $(AWK) '{ print "$4/" $$$$3 }' | sort > $$($2_PACKAGE_BDIR)_the.package.ddd && $(GREP) -f $$($2_PACKAGE_BDIR)_the.package.ddd $5 | $(AWK) '{ print "$(dir $2)_the.package : " $$$$1 "_the.package.api" }' > $$($2_PACKAGE_BDIR)_the.package.dddd ; true) ohair@425: else ohair@425: # If not using dependencies, use $2 as fallback to trigger regeneration of javah header files. ohair@425: # This will generate a surplus of header files, but this does not hurt compilation. ohair@425: $2_NATIVEAPICHANGE_TRIGGER:=$2 ohair@425: $2_FETCH_NATIVEAPICHANGE_CLASSES:=$(CAT) $$($2_PACKAGE_BDIR)_the.package.now|$(GREP) -v '\$$$$'|$(SED) -e 's|$4/||g'|$(SED) 's|.class||g'| $(TR) '/' '.' ohair@425: endif ohair@425: ohair@425: # The _the.package file is dependent on the java files inside the package. ohair@425: # Fill the _the.package file with a list of the java files and compile them ohair@425: # to class files. ohair@425: $2 : $$($2_PACKAGE_SRCS) ohair@425: $(MKDIR) -p $$($2_PACKAGE_BDIR) ohair@425: $(RM) $2.tmp ohair@425: $$(call ListPathsSafely,$2_PACKAGE_SRCS,\n, >> $2.tmp) ohair@425: $(ECHO) $$($2_PACKAGE_BDIR)*.class | $(GREP) -v \*.class | $(TR) ' ' '\n' > $$($2_PACKAGE_BDIR)_the.package.prev ohair@425: $(RM) $$($2_PACKAGE_BDIR)*.class $$($2_PACKAGE_BDIR)*.notify $$($2_PACKAGE_BDIR)*.deleted ohair@425: $(ECHO) Compiling `$(WC) $2.tmp | $(TR) -s ' ' | $(CUT) -f 2 -d ' '` files in package $(patsubst $4/%/,%,$(dir $2.tmp)) ohair@425: $9 $$($2_REMOTE) $$($2_DEPS) $$($2_PUBAPI) $$($2_NATIVEAPI) $(10) -implicit:none -sourcepath "$$($2_SRCROOTSC)" -d $4 @$2.tmp ohair@425: $(ECHO) $$($2_PACKAGE_BDIR)*.class | $(GREP) -v \*.class | $(TR) ' ' '\n' > $$($2_PACKAGE_BDIR)_the.package.now ohair@425: ($(GREP) -xvf $$($2_PACKAGE_BDIR)_the.package.now $$($2_PACKAGE_BDIR)_the.package.prev > $$($2_PACKAGE_BDIR)_the.package.deleted;true) ohair@425: $(ECHO) $1_CLASSES += `$(CAT) $$($2_PACKAGE_BDIR)_the.package.now` | \ ohair@425: $(SED) 's/\$$$$/\$$$$\$$$$/g' > $$($2_PACKAGE_BDIR)_the.package.d ohair@425: $(ECHO) $1_JAVAS += $$($2_PACKAGE_SRCS) >> $$($2_PACKAGE_BDIR)_the.package.d ohair@425: $(ECHO) $2_NOTIFIED:=true > $$($2_PACKAGE_BDIR)_the.package.notify ohair@425: $$($2_APPEND_DEPS) ohair@425: $$($2_COPY_FILES) ohair@425: $(MV) -f $2.tmp $2 ohair@425: endef ohair@425: ohair@425: define remove_string ohair@425: $2 := $$(subst $1,,$$($2)) ohair@425: endef ohair@425: ohair@425: define replace_space_with_pathsep ohair@425: $1:=$(subst $(SPACE),$(PATH_SEP),$(strip $(patsubst %,%,$2))) ohair@425: endef ohair@425: ohair@425: define SetupJavaCompilation ohair@425: # param 1 is for example BUILD_MYPACKAGE ohair@425: # param 2,3,4,5,6,7,8 are named args. ohair@425: # SETUP:=must point to a previously setup java compiler, for example: SETUP:=BOOTJAVAC ohair@425: # JVM:=path to ..bin/java ohair@425: # ADD_JAVAC_FLAGS:=javac flags to append to the default ones. ohair@425: # SRC:=one or more directories to search for sources ohair@425: # BIN:=store classes here ohair@425: # INCLUDES:=myapp.foo means will only compile java files in myapp.foo or any of its sub-packages. ohair@425: # EXCLUDES:=myapp.foo means will do not compile java files in myapp.foo or any of its sub-packages. ohair@425: # COPY:=.prp means copy all prp files to the corresponding package in BIN. ohair@425: # CLEAN:=.properties means copy and clean all properties file to the corresponding package in BIN. ohair@425: # COPY_FILES:=myapp/foo/setting.txt means copy this file over to the package myapp/foo ohair@425: # SRCZIP:=Create a src.zip based on the found sources and copied files. ohair@425: # INCLUDE_FILES:="com/sun/SolarisFoobar.java" means only compile this file! ohair@425: # EXCLUDE_FILES:="com/sun/SolarisFoobar.java" means do not compile this particular file! ohair@425: # "SolarisFoobar.java" means do not compile SolarisFoobar, wherever it is found. ohair@425: # JAVAC_SOURCE_PATH_UGLY_OVERRIDE:=Don't use this. This forces an explicit -sourcepath to javac. ohair@425: # Its only here until we cleanup some nasty source code pasta in the jdk. ohair@425: # HEADERS:=path to directory where all generated c-headers are written. erikj@445: # DEPENDS:=Extra dependecy ohair@425: $(if $2,$1_$(strip $2)) ohair@425: $(if $3,$1_$(strip $3)) ohair@425: $(if $4,$1_$(strip $4)) ohair@425: $(if $5,$1_$(strip $5)) ohair@425: $(if $6,$1_$(strip $6)) ohair@425: $(if $7,$1_$(strip $7)) ohair@425: $(if $8,$1_$(strip $8)) ohair@425: $(if $9,$1_$(strip $9)) ohair@425: $(if $(10),$1_$(strip $(10))) ohair@425: $(if $(11),$1_$(strip $(11))) ohair@425: $(if $(12),$1_$(strip $(12))) ohair@425: $(if $(13),$1_$(strip $(13))) ohair@425: $(if $(14),$1_$(strip $(14))) erikj@458: $(if $(15),$(error Internal makefile error: Too many arguments to SetupJavaCompilation, please update JavaCompilation.gmk)) ohair@425: ohair@425: # Extract the info from the java compiler setup. ohair@425: $1_MODE := $$($$($1_SETUP)_MODE) ohair@425: ifneq (SINGLE_THREADED_BATCH,$$($1_MODE)) ohair@425: ifneq (MULTI_CORE_CONCURRENT,$$($1_MODE)) ohair@425: $$(error The Java compilation $1 refers to a non-existant java compiler setup $$($1_SETUP)) ohair@425: endif ohair@425: endif ohair@425: $1_USE_DEPS := $$($$($1_SETUP)_USE_DEPS) ohair@425: $1_REMOTE := $$($$($1_SETUP)_REMOTE) ohair@425: $1_JVM := $$($$($1_SETUP)_JVM) ohair@425: $1_JAVAC := $$($$($1_SETUP)_JAVAC) ohair@425: $1_JAVAH := $$($$($1_SETUP)_JAVAH) ohair@425: $1_FLAGS := $$($$($1_SETUP)_FLAGS) $(JAVAC_FLAGS) $$($1_ADD_JAVAC_FLAGS) ohair@425: ohair@425: # Handle addons and overrides. ohair@425: $1_SRC:=$$(call ADD_SRCS,$$($1_SRC)) ohair@425: # Make sure the dirs exist. ohair@425: $$(shell $(MKDIR) -p $$($1_SRC) $$($1_BIN)) ohair@425: # Find all files in the source trees. ohair@425: $1_ALL_SRCS := $$(filter-out $(OVR_SRCS),$$(foreach i,$$($1_SRC),$$(shell $(FIND) $$i -type f))) ohair@425: # Extract the java files. ohair@425: ifneq ($$($1_EXCLUDE_FILES),) ohair@425: $1_EXCLUDE_FILES_PATTERN:=$$(addprefix %,$$($1_EXCLUDE_FILES)) ohair@425: endif ohair@425: $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$(filter %.java,$$($1_ALL_SRCS))) ohair@425: ifneq ($$($1_INCLUDE_FILES),) ohair@425: $1_INCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES))) ohair@425: $1_SRCS := $$(filter $$($1_INCLUDE_FILES), $$($1_SRCS)) ohair@425: endif ohair@425: $1_PKGS := $$(sort $$(dir $$($1_SRCS))) ohair@425: # Remove the source root from each found path. ohair@425: $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$1_PKGS))) ohair@425: $1_PKGS := $$(sort $$($1_PKGS)) ohair@425: # There can be only a single bin dir root, no need to foreach over the roots. ohair@425: $1_BINS := $$(shell $(FIND) $$($1_BIN) -name "*.class") ohair@425: ohair@425: # Now we have a list of all java files to compile: $$($1_SRCS) ohair@425: # and we have a list of all existing class files: $$($1_BINS) ohair@425: erikj@458: # Create the corresponding smart javac wrapper command line. erikj@458: $1_SJAVAC_ARGS:=$$(addprefix -x ,$$(addsuffix .*,$$(subst /,.,$$($1_EXCLUDES)))) \ erikj@458: $$(addprefix -i ,$$(addsuffix .*,$$(subst /,.,$$($1_INCLUDES)))) \ erikj@458: $$(addprefix -xf *,$$(strip $$($1_EXCLUDE_FILES))) \ erikj@458: $$(addprefix -if *,$$(strip $$($1_INCLUDE_FILES))) -src $$(subst $$(SPACE),$$(PATH_SEP),$$(strip $$($1_SRC))) erikj@458: ohair@425: # Prepend the source/bin path to the filter expressions. ohair@425: ifneq ($$($1_INCLUDES),) ohair@425: $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES)))) ohair@425: $1_PKG_INCLUDES := $$(addprefix /,$$(addsuffix /%,$$($1_INCLUDES))) ohair@425: $1_BIN_INCLUDES := $$(addprefix $$($1_BIN)/,$$(addsuffix /%,$$($1_INCLUDES))) ohair@425: $1_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS)) ohair@425: $1_PKGS := $$(filter $$($1_PKG_INCLUDES),$$($1_PKGS)) ohair@425: $1_BINS := $$(filter $$($1_BIN_INCLUDES),$$($1_BINS)) ohair@425: endif ohair@425: ifneq ($$($1_EXCLUDES),) ohair@425: $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES)))) ohair@425: $1_PKG_EXCLUDES := $$(addprefix /,$$(addsuffix /%,$$($1_EXCLUDES))) ohair@425: $1_BIN_EXCLUDES := $$(addprefix $$($1_BIN)/,$$(addsuffix /%,$$($1_EXCLUDES))) ohair@425: $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS)) ohair@425: $1_PKGS := $$(filter-out $$($1_PKG_EXCLUDES),$$($1_PKGS)) ohair@425: $1_BINS := $$(filter-out $$($1_BIN_EXCLUDES),$$($1_BINS)) ohair@425: endif ohair@425: ohair@425: # Find all files to be copied from source to bin. ohair@425: ifneq (,$$($1_COPY)) ohair@425: # Rewrite list of patterns into a find statement. ohair@425: $1_COPY_PATTERN:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_COPY)) ohair@425: # Search for all files to be copied. ohair@425: $1_ALL_COPIES := $$(foreach i,$$($1_SRC), $$(shell $(FIND) $$i \( $$($1_COPY_PATTERN) \) -a -type f)) ohair@425: # Copy these explicitly ohair@425: $1_ALL_COPIES += $$($1_COPY_FILES) ohair@425: # Copy must also respect filters. ohair@425: ifneq (,$$($1_INCLUDES)) ohair@425: $1_ALL_COPIES := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_COPIES)) ohair@425: endif ohair@425: ifneq (,$$($1_EXCLUDES)) ohair@425: $1_ALL_COPIES := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_COPIES)) ohair@425: endif ohair@425: ifneq (,$$($1_EXCLUDE_FILES)) ohair@425: $1_ALL_COPIES := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_COPIES)) ohair@425: endif ohair@425: # All files below META-INF are always copied. ohair@425: $1_ALL_COPIES += $$(foreach i,$$($1_SRC), $$(shell $(FIND) $$i/META-INF -type f 2> /dev/null)) ohair@425: ifneq (,$$($1_ALL_COPIES)) ohair@425: # Yep, there are files to be copied! ohair@425: $1_ALL_COPY_TARGETS:= ohair@425: $$(foreach i,$$($1_ALL_COPIES),$$(eval $$(call add_file_to_copy,$1,$$i))) ohair@425: # Now we can depend on $$($1_ALL_COPY_TARGETS) to copy all files! ohair@425: endif ohair@425: endif ohair@425: ohair@425: # Find all property files to be copied and cleaned from source to bin. ohair@425: ifneq (,$$($1_CLEAN)) ohair@425: # Rewrite list of patterns into a find statement. ohair@425: $1_CLEAN_PATTERN:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_CLEAN)) ohair@425: # Search for all files to be copied. ohair@425: $1_ALL_CLEANS := $$(foreach i,$$($1_SRC), $$(shell $(FIND) $$i \( $$($1_CLEAN_PATTERN) \) -a -type f)) ohair@425: # Copy and clean must also respect filters. ohair@425: ifneq (,$$($1_INCLUDES)) ohair@425: $1_ALL_CLEANS := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_CLEANS)) ohair@425: endif ohair@425: ifneq (,$$($1_EXCLUDES)) ohair@425: $1_ALL_CLEANS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_CLEANS)) ohair@425: endif ohair@425: ifneq (,$$($1_EXCLUDE_FILES)) ohair@425: $1_ALL_CLEANS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_CLEANS)) ohair@425: endif ohair@425: ifneq (,$$($1_ALL_CLEANS)) ohair@425: # Yep, there are files to be copied and cleaned! ohair@425: $1_ALL_COPY_CLEAN_TARGETS:= ohair@425: $$(foreach i,$$($1_ALL_CLEANS),$$(eval $$(call add_file_to_copy_and_clean,$1,$$i))) ohair@425: # Now we can depend on $$($1_ALL_COPY_CLEAN_TARGETS) to copy all files! ohair@425: endif ohair@425: endif ohair@425: ohair@425: # Find all the directories that contain java sources, each directory ohair@425: # corresponds to a package because we expect the source ohair@425: # code to be organized in this standardized way! ohair@425: $1_SDIRS := $$(sort $$(dir $$($1_SRCS))) ohair@425: # Now prefix each package with the bin root. ohair@425: $1_BDIRS := $$(foreach i,$$($1_PKGS),$$(addprefix $$($1_BIN),$$i)) ohair@425: # Now create a list of the packages that are about to compile. This list is ohair@425: # later used to filter out dependencies that point outside of this set. ohair@425: $$(shell $(RM) $$($1_BIN)/_the.list_of_packages) ohair@425: $$(eval $$(call ListPathsSafelyNow,$1_BDIRS,\n, >> $$($1_BIN)/_the.list_of_packages)) ohair@425: ohair@425: ifeq ($$($1_MODE),SINGLE_THREADED_BATCH) ohair@425: # Ok, we will feed all the found java files into a single javac invocation. ohair@425: # There can be no dependency checking, nor incremental builds. It is ohair@425: # the best we can do with the old javac. If the javac supports a javac server ohair@425: # then we can use the javac server. ohair@425: ohair@425: # We can depend on this target file to trigger a regeneration of all the sources ohair@425: $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_BIN)/_the.batch ohair@425: ohair@425: # Prep the source paths. ohair@425: ifneq ($$($1_JAVAC_SOURCE_PATH_UGLY_OVERRIDE),) ohair@425: $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_JAVAC_SOURCE_PATH_UGLY_OVERRIDE))) ohair@425: else ohair@425: $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_SRC))) ohair@425: endif ohair@425: erikj@445: ifneq (,$$($1_HEADERS)) erikj@445: $1_HEADERS_ARG := -h $$($1_HEADERS) erikj@445: endif erikj@445: ohair@425: # Create a sed expression to remove the source roots and to replace / with . ohair@425: # and remove .java at the end. ohair@425: $1_REWRITE_INTO_CLASSES:=$$(foreach i,$$($1_SRC),-e 's|$$i/||g') -e 's|/|.|g' -e 's|.java$$$$||g' ohair@425: ohair@425: # Here is the batch rules that depends on all the sources. erikj@445: $$($1_BIN)/_the.batch: $$($1_SRCS) $$($1_DEPENDS) ohair@425: $(MKDIR) -p $$(@D) ohair@425: $(RM) $$($1_BIN)/_the.batch $$($1_BIN)/_the.batch.tmp ohair@425: $$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.batch.tmp) ohair@425: $(ECHO) Compiling `$(WC) $$($1_BIN)/_the.batch.tmp | $(TR) -s ' ' | $(CUT) -f 2 -d ' '` files in batch $1 erikj@458: ifeq ($$($1_NOSJAVAC),) erikj@458: ifeq ($$(ENABLE_SJAVAC),yes) erikj@458: mkdir -p $$($1_BIN)_sjavac erikj@458: $$($1_JVM) $$(word 1,$$($1_JAVAC)) com.sun.tools.javac.smart.Main $$($1_SJAVAC_ARGS) -mfl $$($1_BIN)/_the.batch.tmp -d $$($1_BIN)_sjavac erikj@458: endif erikj@458: endif erikj@445: ($$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) -implicit:none -sourcepath "$$($1_SRCROOTSC)" -d $$($1_BIN) $$($1_HEADERS_ARG) @$$($1_BIN)/_the.batch.tmp && \ ohair@425: $(MV) $$($1_BIN)/_the.batch.tmp $$($1_BIN)/_the.batch) ohair@425: else ohair@425: # Ok, we have a modern javac server running! ohair@425: # Since a single Java file can generate zero to an infinity number of .class files ohair@425: # the exact number and names of the .class files will only be known after the compile. ohair@425: # Thus after the compile, a list of the generated classes will be stored in _the.package.d ohair@425: # which is included by the makefile during the next compile. These .d files will ohair@425: # add the generated class names to the BUILD_MYPACKAGE_CLASSES variable and used java file names ohair@425: # to the BUILD_MYPACKAGE_JAVAS variable. ohair@425: $1_CLASSES := ohair@425: $1_JAVAS := ohair@425: # Create a file in each package that represents the package dependency. ohair@425: # This file (_the.package) will also contain a list of the source files ohair@425: # to be compiled for this package. ohair@425: $1 := $$(sort $$(patsubst %,%_the.package,$$($1_BDIRS))) ohair@425: # Now call add_java_package for each package to create the dependencies. ohair@425: $$(foreach p,$$($1),$$(eval $$(call add_java_package,$1,$$p,$$($1_SRC),$$($1_BIN),$$($1_BIN)/_the.list_of_packages,NOTUSED,$$($1_USE_DEPS),$$($1_REMOTE),$$($1_JVM) $$($1_JAVAC),$$($1_FLAGS),$$($1_EXCLUDE_FILES_PATTERN) $(OVR_SRCS),$$($1_INCLUDE_FILES),$$($1_JVM) $$($1_JAVAH),$$($1_JAVAC_SOURCE_PATH_UGLY_OVERRIDE)))) ohair@425: # All dependencies are setup, now we only need to depend on $1 (aka $(BUILD_MYPACKAGE)) ohair@425: # and they will automatically be built! ohair@425: ohair@425: # Now add on any files to copy targets ohair@425: $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1) ohair@425: # Remove the set of found classes from the set of all previously known classes ohair@425: # and the remainder is the set of missing classes. ohair@425: $1_MISSING_CLASSES:=$$(filter-out $$($1_BINS),$$($1_CLASSES)) ohair@425: $1_PKGS_MISSING_CLASSES:=$$(sort $$(dir $$($1_MISSING_CLASSES))) ohair@425: # Remove the set of found java files from the set of all previously known java files ohair@425: # the remainder is Java files that have gone missing. ohair@425: $1_MISSING_JAVAS:=$$(filter-out $$($1_SRCS),$$($1_JAVAS)) ohair@425: $1_PKGS_MISSING_JAVAS:=$$(sort $$(dir $$($1_MISSING_JAVAS))) ohair@425: # Remove each source root from the found paths. ohair@425: $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$1_PKGS_MISSING_JAVAS))) ohair@425: # Finally remove duplicates and prefix with the binary path instead. ohair@425: $1_PKGS_MISSING_JAVAS:= $$(addprefix $$($1_BIN),$$(sort $$($1_PKGS_MISSING_JAVAS))) ohair@425: ohair@425: # Remove the set of all theoretical classes from the set of found classes. ohair@425: # the remainder is the set of superfluous classes. ohair@425: $1_SUPERFLUOUS_CLASSES:=$$(sort $$(filter-out $$($1_CLASSES),$$($1_BINS))) ohair@425: $1_PKGS_SUPERFLUOUS_CLASSES:=$$(sort $$(dir $$($1_SUPERFLUOUS_CLASSES))) ohair@425: ohair@425: # Now delete the _the.package files inside the problematic dirs. ohair@425: # This will force a rebuild of these packages! ohair@425: $1_FOO:=$$(sort $$($1_PKGS_MISSING_CLASSES) \ ohair@425: $$($1_PKGS_SUPERFLUOUS_CLASSES) \ ohair@425: $$($1_PKGS_MISSING_JAVAS)) ohair@425: # ifneq (,$$($1_FOO)) ohair@425: # $$(info MESSED UP PACKAGES $$($1_FOO)) ohair@425: # endif ohair@425: ohair@425: $$(shell $(RM) $$(addsuffix _the.package,$$(sort $$($1_PKGS_MISSING_CLASSES) \ ohair@425: $$($1_PKGS_SUPERFLUOUS_CLASSES) \ ohair@425: $$($1_PKGS_MISSING_JAVAS)))) ohair@425: ohair@425: # Normal makefile dependencies based on timestamps will detect the normal use case ohair@425: # when Java files are simply added or modified. ohair@425: endif ohair@425: ohair@425: ifneq (,$$($1_JAR)) ohair@425: ohair@425: ifeq (,$$($1_SUFFIXES)) ohair@425: $1_SUFFIXES:=.class $$($1_CLEAN) $$($1_COPY) ohair@425: endif ohair@425: ohair@425: # A jar file was specified. Set it up. ohair@425: $$(eval $$(call SetupArchive,ARCHIVE_$1,$$($1),\ ohair@425: SRCS:=$$($1_BIN),\ ohair@425: SUFFIXES:=$$($1_SUFFIXES),\ ohair@425: EXCLUDE:=$$($1_EXCLUDES),\ ohair@425: INCLUDES:=$$($1_INCLUDES),\ ohair@425: EXTRA_FILES:=$$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS),\ ohair@425: JAR:=$$($1_JAR),\ ohair@425: JARMAIN:=$$($1_JARMAIN),\ ohair@425: MANIFEST:=$$($1_MANIFEST),\ ohair@425: EXTRA_MANIFEST_ATTR:=$$($1_EXTRA_MANIFEST_ATTR),\ erikj@445: JARINDEX:=$$($1_JARINDEX),\ ohair@425: HEADERS:=$$($1_HEADERS),\ ohair@425: SETUP:=$$($1_SETUP))) ohair@425: endif ohair@425: ohair@425: ifneq (,$$($1_SRCZIP)) ohair@425: # A srczip file was specified. Set it up. ohair@425: $$(eval $$(call SetupZipArchive,ARCHIVE_$1,\ ohair@425: SRC:=$$($1_SRC),\ ohair@425: ZIP:=$$($1_SRCZIP),\ ohair@425: INCLUDES:=$$($1_INCLUDES),\ ohair@425: EXCLUDES:=$$($1_EXCLUDES),\ ohair@425: EXCLUDE_FILES:=$$($1_EXCLUDE_FILES))) ohair@425: endif ohair@425: ohair@425: endef