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@478: # This makefile is much simpler now that it can use the smart javac wrapper ohair@478: # for dependency tracking between java packages and incremental compiles. ohair@478: # It could be even more simple if we added support for incremental jar updates ohair@478: # directly from the smart javac wrapper. ohair@478: ohair@478: # Cleaning/copying properties here is not a good solution. The properties ohair@478: # should be cleaned/copied by a annotation processor in sjavac. ohair@478: 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: define SetupJavaCompiler ohrstrom@607: # param 1 is for example GENERATE_OLD_BYTECODE or GENERATE_NEW_JDKBYTECODE ohrstrom@607: # This is the name of the compiler setup. 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: # FLAGS:=Flags to be supplied to javac 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@494: $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE)) ohair@494: $(call LogSetupMacroEntry,SetupJavaCompiler($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)) ohair@494: $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompiler, please update JavaCompilation.gmk)) ohair@425: ohair@494: # The port file contains the tcp/ip on which the server listens ohair@494: # and the cookie necessary to talk to the server. ohair@494: $1_SJAVAC_PORTFILE:=$$($1_SERVER_DIR)/server.port ohair@494: # You can use a different JVM to run the background javac server. ohair@494: ifeq ($$($1_SERVER_JVM),) ohair@494: # It defaults to the same JVM that is used to start the javac command. ohair@494: $1_SERVER_JVM:=$$($1_JVM) 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 ohair@478: # JARINDEX:=true means generate the index in the jar file. 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@494: ohair@494: # NOTE: $2 is dependencies, not a named argument! ohair@494: $(foreach i,3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE)) ohair@494: $(call LogSetupMacroEntry,SetupArchive($1),,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)) erikj@673: $(if $(findstring $(LOG_LEVEL),debug trace), $(info *[2] = $(strip $2))) 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_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))) ohair@494: # If there are a lot of include patterns, output to file to shorten command lines ohair@494: ifeq ($$(word 20,$$($1_GREP_INCLUDE_PATTERNS)),) ohair@494: $1_GREP_INCLUDES:=| $(GREP) $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_INCLUDE_PATTERNS)) ohair@494: else erikj@557: $1_GREP_INCLUDE_OUTPUT:=$(RM) $$($1_BIN)/_the.$$($1_JARNAME)_include && \ erikj@557: $$(strip $$(call ListPathsSafely,$1_GREP_INCLUDE_PATTERNS,\n, \ erikj@557: >> $$($1_BIN)/_the.$$($1_JARNAME)_include)) ohair@494: $1_GREP_INCLUDES:=| $(GREP) -f $$($1_BIN)/_the.$$($1_JARNAME)_include ohair@494: endif 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))) ohair@494: # If there are a lot of include patterns, output to file to shorten command lines ohair@494: ifeq ($$(word 20,$$($1_GREP_EXCLUDE_PATTERNS)),) ohair@494: $1_GREP_EXCLUDES:=| $(GREP) -v $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_EXCLUDE_PATTERNS)) ohair@494: else erikj@557: $1_GREP_EXCLUDE_OUTPUT=$(RM) $$($1_BIN)/_the.$$($1_JARNAME)_exclude && \ erikj@557: $$(strip $$(call ListPathsSafely,$1_GREP_EXCLUDE_PATTERNS,\n, \ erikj@557: >> $$($1_BIN)/_the.$$($1_JARNAME)_exclude)) ohair@494: $1_GREP_EXCLUDES:=| $(GREP) -v -f $$($1_BIN)/_the.$$($1_JARNAME)_exclude ohair@494: endif ohair@425: endif ohair@425: ohair@478: # Check if this jar needs to have its index generated. 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@557: # When this macro is run in the same makefile as the java compilation, dependencies are erikj@557: # transfered in make variables. When the macro is run in a different makefile than the erikj@557: # java compilation, the dependencies need to be found in the filesystem. ohair@478: ifneq (,$2) ohair@478: $1_DEPS:=$2 ohair@478: else erikj@611: $1_DEPS:=$$(filter $$(addprefix %,$$($1_SUFFIXES)),\ erikj@611: $$(call CacheFind,$$($1_SRCS))) erikj@557: ifneq (,$$($1_GREP_INCLUDE_PATTERNS)) erikj@557: $1_DEPS:=$$(filter $$(addsuffix %,$$($1_GREP_INCLUDE_PATTERNS)),$$($1_DEPS)) erikj@557: endif erikj@557: ifneq (,$$($1_GREP_EXCLUDE_PATTERNS)) erikj@557: $1_DEPS:=$$(filter-out $$(addsuffix %,$$($1_GREP_EXCLUDE_PATTERNS)),$$($1_DEPS)) erikj@557: endif ohair@494: # The subst of \ is needed because $ has to be escaped with \ in EXTRA_FILES for the command ohair@494: # lines, but not here for use in make dependencies. erikj@557: $1_DEPS+=$$(subst \,,$$(foreach src,$$($1_SRCS),$$(addprefix $$(src)/,$$($1_EXTRA_FILES)))) ohair@478: ifeq (,$$($1_SKIP_METAINF)) erikj@751: $1_DEPS+=$$(call CacheFind,$$(wildcard $$(addsuffix /META-INF,$$($1_SRCS)))) ohair@478: endif erikj@445: endif 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. simonis@971: # NOTICE: please leave the parentheses space separated otherwise the AIX build will break! ohair@494: $1_CAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS),\ simonis@971: ( ( $(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) -a -newer $$@ $$($1_GREP_INCLUDES) \ ohair@494: $$($1_GREP_EXCLUDES) | $(SED) 's|$$(src)/||g' &&\ simonis@971: $(ECHO) $$(subst $$(src)/,,$$($1_EXTRA_FILES) ) ) > \ simonis@971: $$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE) ) 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@494: $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 ) $$(NEWLINE)) 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@494: $1_CAPTURE_DELETES=$$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.deleted -newer $$@ -exec $(SED) 's|$$(src)||g' \{\} >> $$($1_DELETES_FILE) \;) $$(NEWLINE)) ohair@425: # The update contents macro updates the jar file with the previously capture contents. simonis@971: # Use 'wc -w' to see if the contents file is empty. ohair@425: $1_UPDATE_CONTENTS=$$(foreach src,$$($1_SRCS),\ ohair@425: (cd $$(src) && \ simonis@971: if [ "`$(WC) -w _the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'`" -gt "0" ]; then \ ohair@425: $(ECHO) " updating" `$(WC) -l _the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'` files && \ ohair@478: $(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @_the.$$($1_JARNAME)_contents; \ ohair@494: fi) $$(NEWLINE)) ohair@425: # The s-variants of the above macros are used when the jar is created from scratch. simonis@971: # NOTICE: please leave the parentheses space separated otherwise the AIX build will break! ohair@425: $1_SCAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS),\ simonis@971: ( ( $(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) $$($1_GREP_INCLUDES) \ ohair@494: $$($1_GREP_EXCLUDES) | $(SED) 's|$$(src)/||g' &&\ simonis@971: $$(subst $$(src)/,,$(ECHO) $$($1_EXTRA_FILES) ) ) > \ simonis@971: $$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE) ) 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' >> \ ohair@494: $$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE)) ohair@425: endif ohair@425: $1_SUPDATE_CONTENTS=$$(foreach src,$$($1_SRCS),\ ohair@494: (cd $$(src) && $(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @$$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE)) erikj@445: 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 ohair@478: $1_JAR_UPDATE_OPTIONS := u0f erikj@458: ifeq ($(COMPRESS_JARS), true) erikj@458: $1_JAR_CREATE_OPTIONS := cfm ohair@478: $1_JAR_UPDATE_OPTIONS := uf erikj@458: endif erikj@458: else erikj@458: $1_JAR_CREATE_OPTIONS := cfm ohair@478: $1_JAR_UPDATE_OPTIONS := uf erikj@458: endif erikj@458: ohair@425: # Here is the rule that creates/updates the jar file. ohair@478: $$($1_JAR) : $$($1_DEPS) ohair@425: $(MKDIR) -p $$($1_BIN) erikj@557: $$($1_GREP_INCLUDE_OUTPUT) erikj@557: $$($1_GREP_EXCLUDE_OUTPUT) ohair@494: $$(if $$($1_MANIFEST),\ ohair@425: $(SED) -e "s#@@RELEASE@@#$(RELEASE)#" \ ohair@494: -e "s#@@COMPANY_NAME@@#$(COMPANY_NAME)#" $$($1_MANIFEST) > $$($1_MANIFEST_FILE) \ ohair@494: ,\ ohair@494: $(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE)) ohair@494: $$(if $$($1_JARMAIN),$(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE)) ohair@494: $$(if $$($1_EXTRA_MANIFEST_ATTR),$(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE)) ohair@494: $$(if $$(wildcard $$@),\ ohair@494: $(ECHO) Modifying $$($1_NAME) $$(NEWLINE)\ ohair@478: $$($1_CAPTURE_CONTENTS) \ ohair@478: $$($1_CAPTURE_METAINF) \ ohair@494: $(RM) $$($1_DELETES_FILE) $$(NEWLINE)\ ohair@478: $$($1_CAPTURE_DELETES) \ ohair@494: $(CAT) $$($1_DELETES_FILE) > $$($1_DELETESS_FILE) $$(NEWLINE)\ ohair@478: if [ -s $$($1_DELETESS_FILE) ]; then \ ohair@478: $(ECHO) " deleting" `$(WC) -l $$($1_DELETESS_FILE) | $(AWK) '{ print $$$$1 }'` files && \ ohair@478: $(ZIP) -q -d $$@ `$(CAT) $$($1_DELETESS_FILE)` ; \ ohair@494: fi $$(NEWLINE) \ ohair@494: $$($1_UPDATE_CONTENTS) true $$(NEWLINE) \ ohair@494: $$($1_JARINDEX) && true \ ohair@494: ,\ ohair@494: $(ECHO) Creating $$($1_NAME) && $(JAR) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) $$(NEWLINE) \ ohair@425: $$($1_SCAPTURE_CONTENTS) \ ohair@425: $$($1_SCAPTURE_METAINF) \ ohair@425: $$($1_SUPDATE_CONTENTS) \ ohair@494: $$($1_JARINDEX) && true ) ohair@425: 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@568: # SRC,ZIP,INCLUDES,INCLUDE_FILES,EXCLUDES,EXCLUDE_FILES,SUFFIXES,EXTRA_DEPS ohair@494: $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE)) ohair@494: $(call LogSetupMacroEntry,SetupZipArchive($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)) ohair@494: $(if $(16),$(error Internal makefile error: Too many arguments to SetupZipArchive, please update JavaCompilation.gmk)) ohair@425: erikj@751: # To avoid running find over too large sets of files, which causes make to crash erikj@751: # on some configurations (cygwin), use INCLUDES and INCLUDE_FILES to build a set erikj@751: # of directories to run find in, if available. erikj@751: ifneq ($$($1_INCLUDES)$$($1_INCLUDE_FILES),) erikj@751: $1_FIND_LIST := $$(wildcard $$(foreach i,$$($1_SRC),\ erikj@751: $$(addprefix $$i/,$$($1_INCLUDES) $$($1_INCLUDE_FILES)))) erikj@751: else erikj@751: $1_FIND_LIST := $$($1_SRC) erikj@751: endif erikj@751: ohair@425: # Find all files in the source tree. erikj@557: $1_ALL_SRCS := $$(call not-containing,_the.,\ erikj@751: $$(filter $$(addprefix %,$$($1_SUFFIXES)),$$(call CacheFind,$$($1_FIND_LIST)))) ohair@425: ohair@425: ifneq ($$($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 erikj@568: endif erikj@568: ifneq ($$($1_INCLUDE_FILES),) erikj@568: $1_ZIP_INCLUDES += $$(addprefix -i$(SPACE),$$($1_INCLUDE_FILES)) erikj@568: 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@494: $1_ALL_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_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@531: # If zip has nothing to do, it returns 12 and would fail the build. Check for 12 erikj@531: # and only fail if it's not. erikj@445: $$($1_ZIP) : $$($1_ALL_SRCS) $$($1_EXTRA_DEPS) ohair@425: $(MKDIR) -p $$(@D) ohair@425: $(ECHO) Updating $$($1_NAME) erikj@531: $$(foreach i,$$($1_SRC),(cd $$i && $(ZIP) -qru $$@ . $$($1_ZIP_INCLUDES) $$($1_ZIP_EXCLUDES) -x \*_the.\* $$(addprefix -x$(SPACE),$$(patsubst $$i/%,%,$$($1_EXCLUDE_FILES))) || test "$$$$?" = "12" )$$(NEWLINE)) 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@478: # This is the new clean standard. Though it is to be superseded by ohair@478: # a standard annotation processor from with sjavac. 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: $(CAT) $$< | $(SED) -e 's/\([^\\]\):/\1\\:/g' -e 's/\([^\\]\)=/\1\\=/g' -e 's/#.*/#/g' \ ohair@494: | $(SED) -f "$(SRC_ROOT)/common/makefiles/support/unicode2x.sed" \ 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 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@494: $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE)) ohair@494: $(call LogSetupMacroEntry,SetupJavaCompilation($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)) ohair@494: $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompilation, please update JavaCompilation.gmk)) ohair@425: ohair@478: # Extract the info from the java compiler setup. ohair@478: $1_JVM := $$($$($1_SETUP)_JVM) ohair@478: $1_JAVAC := $$($$($1_SETUP)_JAVAC) ohair@478: $1_FLAGS := $$($$($1_SETUP)_FLAGS) $(JAVAC_FLAGS) $$($1_ADD_JAVAC_FLAGS) ohair@478: ifeq ($$($1_JAVAC),) ohair@425: $$(error The Java compilation $1 refers to a non-existant java compiler setup $$($1_SETUP)) ohair@425: endif ohair@494: $1_SJAVAC_PORTFILE := $$($$($1_SETUP)_SJAVAC_PORTFILE) ohair@494: $1_SERVER_JVM := $$($$($1_SETUP)_SERVER_JVM) ohair@425: ohair@478: # Handle addons and overrides. ohair@478: $1_SRC:=$$(call ADD_SRCS,$$($1_SRC)) ohair@478: # Make sure the dirs exist. ohair@494: $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupJavaCompilation $1 contains missing directory $$d))) ohair@494: $$(eval $$(call MakeDir,$$($1_BIN))) ohair@478: # Find all files in the source trees. erikj@557: $1_ALL_SRCS += $$(filter-out $(OVR_SRCS),$$(call CacheFind,$$($1_SRC))) ohair@478: # Extract the java files. ohair@478: ifneq ($$($1_EXCLUDE_FILES),) ohair@478: $1_EXCLUDE_FILES_PATTERN:=$$(addprefix %,$$($1_EXCLUDE_FILES)) ohair@478: endif ohair@478: $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$(filter %.java,$$($1_ALL_SRCS))) ohair@478: ifneq ($$($1_INCLUDE_FILES),) ohair@478: $1_INCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES))) ohair@478: $1_SRCS := $$(filter $$($1_INCLUDE_FILES), $$($1_SRCS)) ohair@478: endif ohair@425: ohair@478: # Now we have a list of all java files to compile: $$($1_SRCS) ohair@425: ohair@478: # Create the corresponding smart javac wrapper command line. ohair@478: $1_SJAVAC_ARGS:=$$(addprefix -x ,$$(addsuffix .*,$$(subst /,.,$$($1_EXCLUDES)))) \ ohair@478: $$(addprefix -i ,$$(addsuffix .*,$$(subst /,.,$$($1_INCLUDES)))) \ ohair@478: $$(addprefix -xf *,$$(strip $$($1_EXCLUDE_FILES))) \ ohair@478: $$(addprefix -if *,$$(strip $$($1_INCLUDE_FILES))) \ ohair@478: -src "$$(subst $$(SPACE),$$(PATH_SEP),$$(strip $$($1_SRC)))" erikj@458: ohair@478: # Prepend the source/bin path to the filter expressions. ohair@478: ifneq ($$($1_INCLUDES),) ohair@478: $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES)))) ohair@478: $1_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS)) ohair@478: endif ohair@478: ifneq ($$($1_EXCLUDES),) ohair@478: $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES)))) ohair@478: $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS)) ohair@478: endif ohair@425: ohair@478: # Find all files to be copied from source to bin. ohair@478: ifneq (,$$($1_COPY)) ohair@478: # Search for all files to be copied. ohair@494: $1_ALL_COPIES := $$(filter $$(addprefix %,$$($1_COPY)),$$($1_ALL_SRCS)) ohair@478: # Copy these explicitly ohair@478: $1_ALL_COPIES += $$($1_COPY_FILES) ohair@478: # Copy must also respect filters. ohair@478: ifneq (,$$($1_INCLUDES)) ohair@478: $1_ALL_COPIES := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_COPIES)) ohair@478: endif ohair@478: ifneq (,$$($1_EXCLUDES)) ohair@478: $1_ALL_COPIES := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_COPIES)) ohair@478: endif ohair@478: ifneq (,$$($1_EXCLUDE_FILES)) ohair@478: $1_ALL_COPIES := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_COPIES)) ohair@478: endif ohair@478: # All files below META-INF are always copied. ohair@494: $1_ALL_COPIES += $$(filter $$(addsuffix /META-INF%,$$($1_SRC)),$$($1_ALL_SRCS)) ohair@478: ifneq (,$$($1_ALL_COPIES)) ohair@478: # Yep, there are files to be copied! ohair@478: $1_ALL_COPY_TARGETS:= ohair@478: $$(foreach i,$$($1_ALL_COPIES),$$(eval $$(call add_file_to_copy,$1,$$i))) ohair@478: # Now we can depend on $$($1_ALL_COPY_TARGETS) to copy all files! ohair@478: endif ohair@425: endif ohair@478: ohair@478: # Find all property files to be copied and cleaned from source to bin. ohair@478: ifneq (,$$($1_CLEAN)) ohair@478: # Search for all files to be copied. ohair@494: $1_ALL_CLEANS := $$(filter $$(addprefix %,$$($1_CLEAN)),$$($1_ALL_SRCS)) ohair@478: # Copy and clean must also respect filters. ohair@478: ifneq (,$$($1_INCLUDES)) ohair@478: $1_ALL_CLEANS := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_CLEANS)) ohair@478: endif ohair@478: ifneq (,$$($1_EXCLUDES)) ohair@478: $1_ALL_CLEANS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_CLEANS)) ohair@478: endif ohair@478: ifneq (,$$($1_EXCLUDE_FILES)) ohair@478: $1_ALL_CLEANS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_CLEANS)) ohair@478: endif ohair@478: ifneq (,$$($1_ALL_CLEANS)) ohair@478: # Yep, there are files to be copied and cleaned! ohair@478: $1_ALL_COPY_CLEAN_TARGETS:= ohair@478: $$(foreach i,$$($1_ALL_CLEANS),$$(eval $$(call add_file_to_copy_and_clean,$1,$$i))) ohair@478: # Now we can depend on $$($1_ALL_COPY_CLEAN_TARGETS) to copy all files! ohair@478: endif ohair@425: endif 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: 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@478: ifeq ($$($1_DISABLE_SJAVAC)x$$(ENABLE_SJAVAC),xyes) ohair@494: ifneq (,$$($1_HEADERS)) ohair@494: $1_HEADERS_ARG := -h $$($1_HEADERS) ohair@494: endif ohair@494: ohair@478: # Using sjavac to compile. ohair@478: $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_BIN)/javac_state ohair@425: ohrstrom@607: # Create SJAVAC variable form JAVAC variable. Expects $1_JAVAC to be ohrstrom@607: # "bootclasspathprepend -cp .../javac.jar com.sun.tools.javac.Main" ohrstrom@607: # and javac is simply replaced with sjavac. ohrstrom@607: $1_SJAVAC:=$$(subst com.sun.tools.javac.Main,com.sun.tools.sjavac.Main,$$($1_JAVAC)) ohair@494: ohair@494: # Set the $1_REMOTE to spawn a background javac server. erikj@502: $1_REMOTE:=--server:portfile=$$($1_SJAVAC_PORTFILE),id=$1,sjavac=$$(subst $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_SJAVAC)))) ohair@494: ohair@478: $$($1_BIN)/javac_state: $$($1_SRCS) $$($1_DEPENDS) ohair@478: $(MKDIR) -p $$(@D) ohair@478: $$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.batch.tmp) ohair@478: $(ECHO) Compiling $1 erikj@502: ($$($1_JVM) $$($1_SJAVAC) \ erikj@502: $$($1_REMOTE) \ erikj@635: -j $(JOBS) \ ohair@494: --permit-unidentified-artifacts \ ohair@494: --permit-sources-without-package \ ohair@494: --compare-found-sources $$($1_BIN)/_the.batch.tmp \ erikj@673: --log=$(LOG_LEVEL) \ erikj@502: $$($1_SJAVAC_ARGS) \ ohair@478: $$($1_FLAGS) \ erikj@502: $$($1_HEADERS_ARG) \ erikj@502: -d $$($1_BIN) && \ erikj@502: $(MV) $$($1_BIN)/_the.batch.tmp $$($1_BIN)/_the.batch) ohair@478: else ohair@478: # Using plain javac to batch compile everything. ohair@478: $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_BIN)/_the.batch ohair@425: ohair@494: # When buliding in batch, put headers in a temp dir to filter out those that actually ohair@494: # changed before copying them to the real header dir. ohair@494: ifneq (,$$($1_HEADERS)) ohair@494: $1_HEADERS_ARG := -h $$($1_HEADERS).tmp ohair@494: ohair@494: $$($1_HEADERS)/_the.headers: $$($1_BIN)/_the.batch ohair@494: $(MKDIR) -p $$(@D) ohair@494: for f in `ls $$($1_HEADERS).tmp`; do \ ohair@494: if [ ! -f "$$($1_HEADERS)/$$$$f" ] || [ "`$(DIFF) $$($1_HEADERS)/$$$$f $$($1_HEADERS).tmp/$$$$f`" != "" ]; then \ ohair@494: $(CP) -f $$($1_HEADERS).tmp/$$$$f $$($1_HEADERS)/$$$$f; \ ohair@494: fi; \ ohair@494: done ohair@494: $(RM) -r $$($1_HEADERS).tmp ohair@494: $(TOUCH) $$@ ohair@494: ohair@494: $1 += $$($1_HEADERS)/_the.headers ohair@494: endif ohair@494: ohair@478: # When not using sjavac, pass along all sources to javac using an @file. ohair@478: $$($1_BIN)/_the.batch: $$($1_SRCS) $$($1_DEPENDS) ohair@478: $(MKDIR) -p $$(@D) ohair@478: $(RM) $$($1_BIN)/_the.batch $$($1_BIN)/_the.batch.tmp ohair@478: $$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.batch.tmp) ohair@478: $(ECHO) Compiling `$(WC) $$($1_BIN)/_the.batch.tmp | $(TR) -s ' ' | $(CUT) -f 2 -d ' '` files for $1 ohair@478: ($$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) \ ohair@478: -implicit:none -sourcepath "$$($1_SRCROOTSC)" \ ohair@478: -d $$($1_BIN) $$($1_HEADERS_ARG) @$$($1_BIN)/_the.batch.tmp && \ ohair@478: $(MV) $$($1_BIN)/_the.batch.tmp $$($1_BIN)/_the.batch) ohair@494: ohair@425: endif ohair@425: ohair@478: # Check if a jar file was specified, then setup the rules for the jar. ohair@478: ifneq (,$$($1_JAR)) ohair@478: # If no suffixes was explicitly set for this jar file. ohair@478: # Use class and the cleaned/copied properties file suffixes as the default ohair@478: # for the types of files to be put into the jar. ohair@478: ifeq (,$$($1_SUFFIXES)) ohair@478: $1_SUFFIXES:=.class $$($1_CLEAN) $$($1_COPY) ohair@478: endif ohair@425: ohair@478: $$(eval $$(call SetupArchive,ARCHIVE_$1,$$($1),\ ohair@478: SRCS:=$$($1_BIN),\ ohair@478: SUFFIXES:=$$($1_SUFFIXES),\ ohair@478: EXCLUDE:=$$($1_EXCLUDES),\ ohair@478: INCLUDES:=$$($1_INCLUDES),\ ohair@478: EXTRA_FILES:=$$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS),\ ohair@478: JAR:=$$($1_JAR),\ ohair@478: JARMAIN:=$$($1_JARMAIN),\ ohair@478: MANIFEST:=$$($1_MANIFEST),\ ohair@478: EXTRA_MANIFEST_ATTR:=$$($1_EXTRA_MANIFEST_ATTR),\ ohair@478: JARINDEX:=$$($1_JARINDEX),\ ohair@478: HEADERS:=$$($1_HEADERS),\ ohair@478: SETUP:=$$($1_SETUP))) ohair@478: endif ohair@478: ohair@478: # Check if a srczip was specified, then setup the rules for the srczip. ohair@478: ifneq (,$$($1_SRCZIP)) ohair@478: $$(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@478: endif ohair@425: ohair@425: endef