aoqi@0: # aoqi@0: # Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: # aoqi@0: # This code is free software; you can redistribute it and/or modify it aoqi@0: # under the terms of the GNU General Public License version 2 only, as aoqi@0: # published by the Free Software Foundation. Oracle designates this aoqi@0: # particular file as subject to the "Classpath" exception as provided aoqi@0: # by Oracle in the LICENSE file that accompanied this code. aoqi@0: # aoqi@0: # This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: # version 2 for more details (a copy is included in the LICENSE file that aoqi@0: # accompanied this code). aoqi@0: # aoqi@0: # You should have received a copy of the GNU General Public License version aoqi@0: # 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: # aoqi@0: # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: # or visit www.oracle.com if you need additional information or have any aoqi@0: # questions. aoqi@0: # aoqi@0: aoqi@0: # This makefile is much simpler now that it can use the smart javac wrapper aoqi@0: # for dependency tracking between java packages and incremental compiles. aoqi@0: # It could be even more simple if we added support for incremental jar updates aoqi@0: # directly from the smart javac wrapper. aoqi@0: aoqi@0: # Cleaning/copying properties here is not a good solution. The properties aoqi@0: # should be cleaned/copied by a annotation processor in sjavac. aoqi@0: aoqi@0: # When you read this source. Remember that $(sort ...) has the side effect aoqi@0: # of removing duplicates. It is actually this side effect that is aoqi@0: # desired whenever sort is used below! aoqi@0: aoqi@0: ifeq (,$(_MAKEBASE_GMK)) aoqi@0: $(error You must include MakeBase.gmk prior to including JavaCompilation.gmk) aoqi@0: endif aoqi@0: aoqi@0: FALSE_FIND_PATTERN:=-name FILE_NAME_THAT_DOESNT_EXIST aoqi@0: aoqi@0: define SetupJavaCompiler aoqi@0: # param 1 is for example GENERATE_OLD_BYTECODE or GENERATE_NEW_JDKBYTECODE aoqi@0: # This is the name of the compiler setup. aoqi@0: # param 2-9 are named args. aoqi@0: # JVM:=The jvm used to run the javac/javah command aoqi@0: # JAVAC:=The javac jar and bootstrap classpath changes, or just bin/javac if JVM is left out aoqi@0: # FLAGS:=Flags to be supplied to javac aoqi@0: # SERVER_DIR:=Use a javac server (-XDserver) and store the server related files here aoqi@0: # SERVER_JVM:=Use this JVM for the server. Defaults to the JVM above. aoqi@0: $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE)) aoqi@0: $(call LogSetupMacroEntry,SetupJavaCompiler($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)) aoqi@0: $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompiler, please update JavaCompilation.gmk)) aoqi@0: aoqi@0: # The port file contains the tcp/ip on which the server listens aoqi@0: # and the cookie necessary to talk to the server. aoqi@0: $1_SJAVAC_PORTFILE:=$$($1_SERVER_DIR)/server.port aoqi@0: # You can use a different JVM to run the background javac server. aoqi@0: ifeq ($$($1_SERVER_JVM),) aoqi@0: # It defaults to the same JVM that is used to start the javac command. aoqi@0: $1_SERVER_JVM:=$$($1_JVM) aoqi@0: endif aoqi@0: endef aoqi@0: aoqi@0: define SetupArchive aoqi@0: # param 1 is for example ARCHIVE_MYPACKAGE aoqi@0: # param 2 are the dependecies aoqi@0: # param 3,4,5,6,7,8,9 are named args. aoqi@0: # SRCS:=List of directories in where to find files to add to archive aoqi@0: # SUFFIXES:=File suffixes to include in jar aoqi@0: # INCLUDES:=List of directories/packages in SRCS that should be included aoqi@0: # EXCLUDES:=List of directories/packages in SRCS that should be excluded aoqi@0: # EXCLUDE_FILES:=List of files in SRCS that should be excluded aoqi@0: # EXTRA_FILES:=List of files in SRCS that should be included regardless of suffix match. aoqi@0: # JAR:=Jar file to create aoqi@0: # MANIFEST:=Optional manifest file template. aoqi@0: # JARMAIN:=Optional main class to add to manifest aoqi@0: # JARINDEX:=true means generate the index in the jar file. aoqi@0: # SKIP_METAINF:=Set to prevent contents of an META-INF directory to be automatically aoqi@0: # added to the archive. aoqi@0: # EXTRA_MANIFEST_ATTR:=Extra attribute to add to manifest. aoqi@0: # CHECK_COMPRESS_JAR Check the COMPRESS_JAR variable aoqi@0: aoqi@0: # NOTE: $2 is dependencies, not a named argument! aoqi@0: $(foreach i,3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE)) aoqi@0: $(call LogSetupMacroEntry,SetupArchive($1),,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)) aoqi@0: $(if $(findstring $(LOG_LEVEL),trace), $(info *[2] = $(strip $2))) aoqi@0: $(if $(16),$(error Internal makefile error: Too many arguments to SetupArchive, please update JavaCompilation.gmk)) aoqi@0: aoqi@0: $1_JARMAIN:=$(strip $$($1_JARMAIN)) aoqi@0: $1_JARNAME:=$$(notdir $$($1_JAR)) aoqi@0: $1_MANIFEST_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_manifest aoqi@0: $1_DELETESS_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletess aoqi@0: $1_DELETES_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletes aoqi@0: $1_BIN:=$$(dir $$($1_JAR)) aoqi@0: aoqi@0: ifeq (,$$($1_SUFFIXES)) aoqi@0: # No suffix was set, default to classes. aoqi@0: $1_SUFFIXES:=.class aoqi@0: endif aoqi@0: # Convert suffixes to a find expression aoqi@0: $1_FIND_PATTERNS:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_SUFFIXES)) aoqi@0: # On windows, a lot of includes/excludes risk making the command line too long, so aoqi@0: # writing the grep patterns to files. aoqi@0: ifneq (,$$($1_INCLUDES)) aoqi@0: $1_GREP_INCLUDE_PATTERNS:=$$(foreach src,$$($1_SRCS), \ aoqi@0: $$(addprefix $$(src)/,$$($1_INCLUDES))) aoqi@0: # If there are a lot of include patterns, output to file to shorten command lines aoqi@0: ifeq ($$(word 20,$$($1_GREP_INCLUDE_PATTERNS)),) aoqi@0: $1_GREP_INCLUDES:=| $(GREP) $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_INCLUDE_PATTERNS)) aoqi@0: else aoqi@0: $1_GREP_INCLUDE_OUTPUT:=$(RM) $$($1_BIN)/_the.$$($1_JARNAME)_include $$(NEWLINE) \ aoqi@0: $$(call ListPathsSafely,$1_GREP_INCLUDE_PATTERNS,\n, \ aoqi@0: >> $$($1_BIN)/_the.$$($1_JARNAME)_include) aoqi@0: $1_GREP_INCLUDES:=| $(GREP) -f $$($1_BIN)/_the.$$($1_JARNAME)_include aoqi@0: endif aoqi@0: endif aoqi@0: ifneq (,$$($1_EXCLUDES)$$($1_EXCLUDE_FILES)) aoqi@0: $1_GREP_EXCLUDE_PATTERNS:=$$(foreach src,$$($1_SRCS),$$(addprefix $$(src)/, \ aoqi@0: $$($1_EXCLUDES) $$($1_EXCLUDE_FILES))) aoqi@0: # If there are a lot of include patterns, output to file to shorten command lines aoqi@0: ifeq ($$(word 20,$$($1_GREP_EXCLUDE_PATTERNS)),) aoqi@0: $1_GREP_EXCLUDES:=| $(GREP) -v $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_EXCLUDE_PATTERNS)) aoqi@0: else aoqi@0: $1_GREP_EXCLUDE_OUTPUT=$(RM) $$($1_BIN)/_the.$$($1_JARNAME)_exclude $$(NEWLINE) \ aoqi@0: $$(call ListPathsSafely,$1_GREP_EXCLUDE_PATTERNS,\n, \ aoqi@0: >> $$($1_BIN)/_the.$$($1_JARNAME)_exclude) aoqi@0: $1_GREP_EXCLUDES:=| $(GREP) -v -f $$($1_BIN)/_the.$$($1_JARNAME)_exclude aoqi@0: endif aoqi@0: endif aoqi@0: aoqi@0: # Check if this jar needs to have its index generated. aoqi@0: ifneq (,$$($1_JARINDEX)) aoqi@0: $1_JARINDEX = (cd $$(dir $$@) && $(JAR) -i $$(notdir $$@)) aoqi@0: else aoqi@0: $1_JARINDEX = true aoqi@0: endif aoqi@0: # When this macro is run in the same makefile as the java compilation, dependencies are aoqi@0: # transfered in make variables. When the macro is run in a different makefile than the aoqi@0: # java compilation, the dependencies need to be found in the filesystem. aoqi@0: ifneq (,$2) aoqi@0: $1_DEPS:=$2 aoqi@0: else aoqi@0: $1_DEPS:=$$(filter $$(addprefix %,$$($1_SUFFIXES)), \ aoqi@0: $$(call CacheFind,$$($1_SRCS))) aoqi@0: ifneq (,$$($1_GREP_INCLUDE_PATTERNS)) aoqi@0: $1_DEPS:=$$(filter $$(addsuffix %,$$($1_GREP_INCLUDE_PATTERNS)),$$($1_DEPS)) aoqi@0: endif aoqi@0: ifneq (,$$($1_GREP_EXCLUDE_PATTERNS)) aoqi@0: $1_DEPS:=$$(filter-out $$(addsuffix %,$$($1_GREP_EXCLUDE_PATTERNS)),$$($1_DEPS)) aoqi@0: endif aoqi@0: # The subst of \ is needed because $ has to be escaped with \ in EXTRA_FILES for the command aoqi@0: # lines, but not here for use in make dependencies. aoqi@0: $1_DEPS+=$$(subst \,,$$(foreach src,$$($1_SRCS),$$(addprefix $$(src)/,$$($1_EXTRA_FILES)))) aoqi@0: ifeq (,$$($1_SKIP_METAINF)) aoqi@0: $1_DEPS+=$$(call CacheFind,$$(wildcard $$(addsuffix /META-INF,$$($1_SRCS)))) aoqi@0: endif aoqi@0: endif aoqi@0: aoqi@0: # Utility macros, to make the shell script receipt somewhat easier to decipher. aoqi@0: aoqi@0: # The capture contents macro finds all files (matching the patterns, typically aoqi@0: # .class and .prp) that are newer than the jar-file, ie the new content to be put into the jar. aoqi@0: # NOTICE: please leave the parentheses space separated otherwise the AIX build will break! aoqi@0: $1_CAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS), \ aoqi@0: ( ( $(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) -a -newer $$@ $$($1_GREP_INCLUDES) \ aoqi@0: $$($1_GREP_EXCLUDES) | $(SED) 's|$$(src)/||g' && \ aoqi@0: $(ECHO) $$(subst $$(src)/,,$$($1_EXTRA_FILES) ) ) > \ aoqi@0: $$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE) ) aoqi@0: # The capture metainf macro finds all files below the META-INF directory that are newer than the jar-file. aoqi@0: ifeq (,$$($1_SKIP_METAINF)) aoqi@0: $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)) aoqi@0: endif aoqi@0: # The capture deletes macro finds all deleted files and concatenates them. The resulting file aoqi@0: # tells us what to remove from the jar-file. aoqi@0: $1_CAPTURE_DELETES=$$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.deleted -newer $$@ -exec $(SED) 's|$$(src)||g' \{\} >> $$($1_DELETES_FILE) \;) $$(NEWLINE)) aoqi@0: # The update contents macro updates the jar file with the previously capture contents. aoqi@0: # Use 'wc -w' to see if the contents file is empty. aoqi@0: $1_UPDATE_CONTENTS=$$(foreach src,$$($1_SRCS), \ aoqi@0: (cd $$(src) && \ aoqi@0: if [ "`$(WC) -w _the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'`" -gt "0" ]; then \ aoqi@0: $(ECHO) " updating" `$(WC) -l _the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'` files && \ aoqi@0: $(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @_the.$$($1_JARNAME)_contents; \ aoqi@0: fi) $$(NEWLINE)) aoqi@0: # The s-variants of the above macros are used when the jar is created from scratch. aoqi@0: # NOTICE: please leave the parentheses space separated otherwise the AIX build will break! aoqi@0: $1_SCAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS), \ aoqi@0: ( ( $(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) $$($1_GREP_INCLUDES) \ aoqi@0: $$($1_GREP_EXCLUDES) | $(SED) 's|$$(src)/||g' && \ aoqi@0: $$(subst $$(src)/,,$(ECHO) $$($1_EXTRA_FILES) ) ) > \ aoqi@0: $$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE) ) aoqi@0: aoqi@0: ifeq (,$$($1_SKIP_METAINF)) aoqi@0: $1_SCAPTURE_METAINF=$$(foreach src,$$($1_SRCS), \ aoqi@0: ($(FIND) $$(src)/META-INF -type f 2> /dev/null | $(SED) 's|$$(src)/||g' >> \ aoqi@0: $$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE)) aoqi@0: endif aoqi@0: $1_SUPDATE_CONTENTS=$$(foreach src,$$($1_SRCS), \ aoqi@0: (cd $$(src) && $(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @$$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE)) aoqi@0: aoqi@0: # Use a slightly shorter name for logging, but with enough path to identify this jar. aoqi@0: $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_JAR)) aoqi@0: aoqi@0: ifneq (,$$($1_CHECK_COMPRESS_JAR)) aoqi@0: $1_JAR_CREATE_OPTIONS := c0fm aoqi@0: $1_JAR_UPDATE_OPTIONS := u0f aoqi@0: ifeq ($(COMPRESS_JARS), true) aoqi@0: $1_JAR_CREATE_OPTIONS := cfm aoqi@0: $1_JAR_UPDATE_OPTIONS := uf aoqi@0: endif aoqi@0: else aoqi@0: $1_JAR_CREATE_OPTIONS := cfm aoqi@0: $1_JAR_UPDATE_OPTIONS := uf aoqi@0: endif aoqi@0: aoqi@0: # Here is the rule that creates/updates the jar file. aoqi@0: $$($1_JAR) : $$($1_DEPS) aoqi@0: $(MKDIR) -p $$($1_BIN) aoqi@0: $$($1_GREP_INCLUDE_OUTPUT) aoqi@0: $$($1_GREP_EXCLUDE_OUTPUT) aoqi@0: $$(if $$($1_MANIFEST), \ aoqi@0: $(SED) -e "s#@@RELEASE@@#$(RELEASE)#" \ aoqi@0: -e "s#@@COMPANY_NAME@@#$(COMPANY_NAME)#" $$($1_MANIFEST) > $$($1_MANIFEST_FILE) \ aoqi@0: , \ aoqi@0: $(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE)) aoqi@0: $$(if $$($1_JARMAIN),$(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE)) aoqi@0: $$(if $$($1_EXTRA_MANIFEST_ATTR),$(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE)) aoqi@0: $$(if $$(wildcard $$@), \ aoqi@0: $(ECHO) Modifying $$($1_NAME) $$(NEWLINE) \ aoqi@0: $$($1_CAPTURE_CONTENTS) \ aoqi@0: $$($1_CAPTURE_METAINF) \ aoqi@0: $(RM) $$($1_DELETES_FILE) $$(NEWLINE) \ aoqi@0: $$($1_CAPTURE_DELETES) \ aoqi@0: $(CAT) $$($1_DELETES_FILE) > $$($1_DELETESS_FILE) $$(NEWLINE) \ aoqi@0: if [ -s $$($1_DELETESS_FILE) ]; then \ aoqi@0: $(ECHO) " deleting" `$(WC) -l $$($1_DELETESS_FILE) | $(AWK) '{ print $$$$1 }'` files && \ aoqi@0: $(ZIP) -q -d $$@ `$(CAT) $$($1_DELETESS_FILE)` ; \ aoqi@0: fi $$(NEWLINE) \ aoqi@0: $$($1_UPDATE_CONTENTS) true $$(NEWLINE) \ aoqi@0: $$($1_JARINDEX) && true \ aoqi@0: , \ aoqi@0: $(ECHO) Creating $$($1_NAME) && $(JAR) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) $$(NEWLINE) \ aoqi@0: $$($1_SCAPTURE_CONTENTS) \ aoqi@0: $$($1_SCAPTURE_METAINF) \ aoqi@0: $$($1_SUPDATE_CONTENTS) \ aoqi@0: $$($1_JARINDEX) && true ) aoqi@0: aoqi@0: endef aoqi@0: aoqi@0: define SetupZipArchive aoqi@0: # param 1 is for example ZIP_MYSOURCE aoqi@0: # param 2,3,4,5,6,7,8,9 are named args. aoqi@0: # SRC,ZIP,INCLUDES,INCLUDE_FILES,EXCLUDES,EXCLUDE_FILES,SUFFIXES,EXTRA_DEPS aoqi@0: $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE)) aoqi@0: $(call LogSetupMacroEntry,SetupZipArchive($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)) aoqi@0: $(if $(16),$(error Internal makefile error: Too many arguments to SetupZipArchive, please update JavaCompilation.gmk)) aoqi@0: aoqi@0: # To avoid running find over too large sets of files, which causes make to crash aoqi@0: # on some configurations (cygwin), use INCLUDES and INCLUDE_FILES to build a set aoqi@0: # of directories to run find in, if available. aoqi@0: ifneq ($$($1_INCLUDES)$$($1_INCLUDE_FILES),) aoqi@0: $1_FIND_LIST := $$(wildcard $$(foreach i,$$($1_SRC), \ aoqi@0: $$(addprefix $$i/,$$($1_INCLUDES) $$($1_INCLUDE_FILES)))) aoqi@0: else aoqi@0: $1_FIND_LIST := $$($1_SRC) aoqi@0: endif aoqi@0: aoqi@0: # Find all files in the source tree. aoqi@0: $1_ALL_SRCS := $$(call not-containing,_the.,$$(call CacheFind,$$($1_FIND_LIST))) aoqi@0: aoqi@0: # Filter on suffixes if set aoqi@0: ifneq ($$($1_SUFFIXES),) aoqi@0: $1_ALL_SRCS := $$(filter $$(addprefix %, $$($1_SUFFIXES)), $$($1_ALL_SRCS)) aoqi@0: endif aoqi@0: aoqi@0: ifneq ($$($1_INCLUDES),) aoqi@0: ifneq ($$($1_SUFFIXES),) aoqi@0: $1_ZIP_INCLUDES := $$(foreach s,$$($1_SUFFIXES), \ aoqi@0: $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$$s$(DQUOTE),$$($1_INCLUDES)))) aoqi@0: else aoqi@0: $1_ZIP_INCLUDES := $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_INCLUDES))) aoqi@0: endif aoqi@0: endif aoqi@0: ifneq ($$($1_INCLUDE_FILES),) aoqi@0: $1_ZIP_INCLUDES += $$(addprefix -i$(SPACE),$$($1_INCLUDE_FILES)) aoqi@0: endif aoqi@0: ifneq ($$($1_EXCLUDES),) aoqi@0: $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES)))) aoqi@0: $1_ZIP_EXCLUDES := $$(addprefix -x$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_EXCLUDES))) aoqi@0: $1_ALL_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_SRCS)) aoqi@0: endif aoqi@0: aoqi@0: # Use a slightly shorter name for logging, but with enough path to identify this zip. aoqi@0: $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_ZIP)) aoqi@0: aoqi@0: # Now $1_ALL_SRCS should contain all sources that are going to be put into the zip. aoqi@0: # I.e. the zip -i and -x options should match the filtering done in the makefile. aoqi@0: # Explicitly excluded files can be given with absolute path. The patsubst solution aoqi@0: # isn't perfect but the likelyhood of an absolute path to match something in a src aoqi@0: # dir is very small. aoqi@0: # If zip has nothing to do, it returns 12 and would fail the build. Check for 12 aoqi@0: # and only fail if it's not. aoqi@0: $$($1_ZIP) : $$($1_ALL_SRCS) $$($1_EXTRA_DEPS) aoqi@0: $(MKDIR) -p $$(@D) aoqi@0: $(ECHO) Updating $$($1_NAME) aoqi@0: $$(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 aoqi@0: $(TOUCH) $$@ aoqi@0: endef aoqi@0: aoqi@0: define add_file_to_copy aoqi@0: # param 1 = BUILD_MYPACKAGE aoqi@0: # parma 2 = The source file to copy. aoqi@0: $2_TARGET:=$2 aoqi@0: # Remove the source prefix. aoqi@0: $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET))) aoqi@0: # Now we can setup the depency that will trigger the copying. aoqi@0: $$($1_BIN)$$($2_TARGET) : $2 aoqi@0: $(MKDIR) -p $$(@D) aoqi@0: $(CP) $$< $$@ aoqi@0: $(CHMOD) -f ug+w $$@ aoqi@0: aoqi@0: # And do not forget this target aoqi@0: $1_ALL_COPY_TARGETS += $$($1_BIN)$$($2_TARGET) aoqi@0: endef aoqi@0: aoqi@0: aoqi@0: # This macro is used only for properties files that are to be aoqi@0: # copied over to the classes directory in cleaned form: aoqi@0: # Previously this was inconsistently done in different repositories. aoqi@0: # This is the new clean standard. Though it is to be superseded by aoqi@0: # a standard annotation processor from with sjavac. aoqi@0: define add_file_to_copy_and_clean aoqi@0: # param 1 = BUILD_MYPACKAGE aoqi@0: # parma 2 = The source file to copy and clean. aoqi@0: $2_TARGET:=$2 aoqi@0: # Remove the source prefix. aoqi@0: $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET))) aoqi@0: # Now we can setup the depency that will trigger the copying. aoqi@0: $$($1_BIN)$$($2_TARGET) : $2 aoqi@0: $(MKDIR) -p $$(@D) aoqi@0: $(CAT) $$< | $(SED) -e 's/\([^\\]\):/\1\\:/g' -e 's/\([^\\]\)=/\1\\=/g' -e 's/#.*/#/g' \ aoqi@0: | $(SED) -f "$(SRC_ROOT)/make/common/support/unicode2x.sed" \ aoqi@0: | $(SED) -e '/^#/d' -e '/^$$$$/d' \ aoqi@0: -e :a -e '/\\$$$$/N; s/\\\n//; ta' \ aoqi@0: -e 's/^[ \t]*//;s/[ \t]*$$$$//' \ aoqi@0: -e 's/\\=/=/' | LANG=C $(SORT) > $$@ aoqi@0: $(CHMOD) -f ug+w $$@ aoqi@0: aoqi@0: # And do not forget this target aoqi@0: $1_ALL_COPY_CLEAN_TARGETS += $$($1_BIN)$$($2_TARGET) aoqi@0: endef aoqi@0: aoqi@0: define remove_string aoqi@0: $2 := $$(subst $1,,$$($2)) aoqi@0: endef aoqi@0: aoqi@0: define replace_space_with_pathsep aoqi@0: $1:=$(subst $(SPACE),$(PATH_SEP),$(strip $(patsubst %,%,$2))) aoqi@0: endef aoqi@0: aoqi@0: define SetupJavaCompilation aoqi@0: # param 1 is for example BUILD_MYPACKAGE aoqi@0: # param 2,3,4,5,6,7,8 are named args. aoqi@0: # SETUP:=must point to a previously setup java compiler, for example: SETUP:=BOOTJAVAC aoqi@0: # JVM:=path to ..bin/java aoqi@0: # ADD_JAVAC_FLAGS:=javac flags to append to the default ones. aoqi@0: # SRC:=one or more directories to search for sources aoqi@0: # BIN:=store classes here aoqi@0: # INCLUDES:=myapp.foo means will only compile java files in myapp.foo or any of its sub-packages. aoqi@0: # EXCLUDES:=myapp.foo means will do not compile java files in myapp.foo or any of its sub-packages. aoqi@0: # COPY:=.prp means copy all prp files to the corresponding package in BIN. aoqi@0: # CLEAN:=.properties means copy and clean all properties file to the corresponding package in BIN. aoqi@0: # COPY_FILES:=myapp/foo/setting.txt means copy this file over to the package myapp/foo aoqi@0: # SRCZIP:=Create a src.zip based on the found sources and copied files. aoqi@0: # INCLUDE_FILES:="com/sun/SolarisFoobar.java" means only compile this file! aoqi@0: # EXCLUDE_FILES:="com/sun/SolarisFoobar.java" means do not compile this particular file! aoqi@0: # "SolarisFoobar.java" means do not compile SolarisFoobar, wherever it is found. aoqi@0: # JAVAC_SOURCE_PATH_OVERRIDE:=This forces an explicit -sourcepath to javac instead of the complete aoqi@0: # source roots from SRC. This is sometimes needed when compiling specific subsets of the source. aoqi@0: # HEADERS:=path to directory where all generated c-headers are written. aoqi@0: # DEPENDS:=Extra dependecy aoqi@0: $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE)) aoqi@0: $(call LogSetupMacroEntry,SetupJavaCompilation($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)) aoqi@0: $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompilation, please update JavaCompilation.gmk)) aoqi@0: aoqi@0: # Extract the info from the java compiler setup. aoqi@0: $1_JVM := $$($$($1_SETUP)_JVM) aoqi@0: $1_JAVAC := $$($$($1_SETUP)_JAVAC) aoqi@0: $1_FLAGS := $$($$($1_SETUP)_FLAGS) $(JAVAC_FLAGS) $$($1_ADD_JAVAC_FLAGS) aoqi@0: ifeq ($$($1_JAVAC),) aoqi@0: $$(error The Java compilation $1 refers to a non-existant java compiler setup $$($1_SETUP)) aoqi@0: endif aoqi@0: $1_SJAVAC_PORTFILE := $$($$($1_SETUP)_SJAVAC_PORTFILE) aoqi@0: $1_SERVER_JVM := $$($$($1_SETUP)_SERVER_JVM) aoqi@0: aoqi@0: # Handle addons and overrides. aoqi@0: $1_SRC:=$$(call ADD_SRCS,$$($1_SRC)) aoqi@0: # Make sure the dirs exist. aoqi@0: $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupJavaCompilation $1 contains missing directory $$d))) aoqi@0: $$(eval $$(call MakeDir,$$($1_BIN))) aoqi@0: # Find all files in the source trees. aoqi@0: $1_ALL_SRCS += $$(filter-out $(OVR_SRCS),$$(call CacheFind,$$($1_SRC))) aoqi@0: # Extract the java files. aoqi@0: ifneq ($$($1_EXCLUDE_FILES),) aoqi@0: $1_EXCLUDE_FILES_PATTERN:=$$(addprefix %,$$($1_EXCLUDE_FILES)) aoqi@0: endif aoqi@0: $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$(filter %.java,$$($1_ALL_SRCS))) aoqi@0: ifneq ($$($1_INCLUDE_FILES),) aoqi@0: $1_INCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES))) aoqi@0: $1_SRCS := $$(filter $$($1_INCLUDE_FILES), $$($1_SRCS)) aoqi@0: endif aoqi@0: aoqi@0: # Now we have a list of all java files to compile: $$($1_SRCS) aoqi@0: aoqi@0: # Create the corresponding smart javac wrapper command line. aoqi@0: $1_SJAVAC_ARGS:=$$(addprefix -x ,$$(addsuffix .*,$$(subst /,.,$$($1_EXCLUDES)))) \ aoqi@0: $$(addprefix -i ,$$(addsuffix .*,$$(subst /,.,$$($1_INCLUDES)))) \ aoqi@0: $$(addprefix -xf *,$$(strip $$($1_EXCLUDE_FILES))) \ aoqi@0: $$(addprefix -if *,$$(strip $$($1_INCLUDE_FILES))) \ aoqi@0: -src "$$(subst $$(SPACE),$$(PATH_SEP),$$(strip $$($1_SRC)))" aoqi@0: aoqi@0: # Prepend the source/bin path to the filter expressions. aoqi@0: ifneq ($$($1_INCLUDES),) aoqi@0: $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES)))) aoqi@0: $1_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS)) aoqi@0: endif aoqi@0: ifneq ($$($1_EXCLUDES),) aoqi@0: $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES)))) aoqi@0: $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS)) aoqi@0: endif aoqi@0: aoqi@0: # Find all files to be copied from source to bin. aoqi@0: ifneq (,$$($1_COPY)) aoqi@0: # Search for all files to be copied. aoqi@0: $1_ALL_COPIES := $$(filter $$(addprefix %,$$($1_COPY)),$$($1_ALL_SRCS)) aoqi@0: # Copy these explicitly aoqi@0: $1_ALL_COPIES += $$($1_COPY_FILES) aoqi@0: # Copy must also respect filters. aoqi@0: ifneq (,$$($1_INCLUDES)) aoqi@0: $1_ALL_COPIES := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_COPIES)) aoqi@0: endif aoqi@0: ifneq (,$$($1_EXCLUDES)) aoqi@0: $1_ALL_COPIES := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_COPIES)) aoqi@0: endif aoqi@0: ifneq (,$$($1_EXCLUDE_FILES)) aoqi@0: $1_ALL_COPIES := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_COPIES)) aoqi@0: endif aoqi@0: # All files below META-INF are always copied. aoqi@0: $1_ALL_COPIES += $$(filter $$(addsuffix /META-INF%,$$($1_SRC)),$$($1_ALL_SRCS)) aoqi@0: ifneq (,$$($1_ALL_COPIES)) aoqi@0: # Yep, there are files to be copied! aoqi@0: $1_ALL_COPY_TARGETS:= aoqi@0: $$(foreach i,$$($1_ALL_COPIES),$$(eval $$(call add_file_to_copy,$1,$$i))) aoqi@0: # Now we can depend on $$($1_ALL_COPY_TARGETS) to copy all files! aoqi@0: endif aoqi@0: endif aoqi@0: aoqi@0: # Find all property files to be copied and cleaned from source to bin. aoqi@0: ifneq (,$$($1_CLEAN)) aoqi@0: # Search for all files to be copied. aoqi@0: $1_ALL_CLEANS := $$(filter $$(addprefix %,$$($1_CLEAN)),$$($1_ALL_SRCS)) aoqi@0: # Copy and clean must also respect filters. aoqi@0: ifneq (,$$($1_INCLUDES)) aoqi@0: $1_ALL_CLEANS := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_CLEANS)) aoqi@0: endif aoqi@0: ifneq (,$$($1_EXCLUDES)) aoqi@0: $1_ALL_CLEANS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_CLEANS)) aoqi@0: endif aoqi@0: ifneq (,$$($1_EXCLUDE_FILES)) aoqi@0: $1_ALL_CLEANS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_CLEANS)) aoqi@0: endif aoqi@0: ifneq (,$$($1_ALL_CLEANS)) aoqi@0: # Yep, there are files to be copied and cleaned! aoqi@0: $1_ALL_COPY_CLEAN_TARGETS:= aoqi@0: $$(foreach i,$$($1_ALL_CLEANS),$$(eval $$(call add_file_to_copy_and_clean,$1,$$i))) aoqi@0: # Now we can depend on $$($1_ALL_COPY_CLEAN_TARGETS) to copy all files! aoqi@0: endif aoqi@0: endif aoqi@0: aoqi@0: # Prep the source paths. aoqi@0: ifneq ($$($1_JAVAC_SOURCE_PATH_OVERRIDE),) aoqi@0: $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_JAVAC_SOURCE_PATH_OVERRIDE))) aoqi@0: else aoqi@0: $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_SRC))) aoqi@0: endif aoqi@0: aoqi@0: # Create a sed expression to remove the source roots and to replace / with . aoqi@0: # and remove .java at the end. aoqi@0: $1_REWRITE_INTO_CLASSES:=$$(foreach i,$$($1_SRC),-e 's|$$i/||g') -e 's|/|.|g' -e 's|.java$$$$||g' aoqi@0: aoqi@0: ifeq ($$($1_DISABLE_SJAVAC)x$$(ENABLE_SJAVAC),xyes) aoqi@0: ifneq (,$$($1_HEADERS)) aoqi@0: $1_HEADERS_ARG := -h $$($1_HEADERS) aoqi@0: endif aoqi@0: aoqi@0: # Using sjavac to compile. aoqi@0: $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_BIN)/javac_state aoqi@0: aoqi@0: # Create SJAVAC variable form JAVAC variable. Expects $1_JAVAC to be aoqi@0: # "bootclasspathprepend -cp .../javac.jar com.sun.tools.javac.Main" aoqi@0: # and javac is simply replaced with sjavac. aoqi@0: $1_SJAVAC:=$$(subst com.sun.tools.javac.Main,com.sun.tools.sjavac.Main,$$($1_JAVAC)) aoqi@0: aoqi@0: # Set the $1_REMOTE to spawn a background javac server. aoqi@0: $1_REMOTE:=--server:portfile=$$($1_SJAVAC_PORTFILE),id=$1,sjavac=$$(subst $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_SJAVAC)))) aoqi@0: aoqi@0: $$($1_BIN)/javac_state: $$($1_SRCS) $$($1_DEPENDS) aoqi@0: $(MKDIR) -p $$(@D) aoqi@0: $$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.$1_batch.tmp) aoqi@0: $(ECHO) Compiling $1 aoqi@0: ($$($1_JVM) $$($1_SJAVAC) \ aoqi@0: $$($1_REMOTE) \ aoqi@0: -j $(JOBS) \ aoqi@0: --permit-unidentified-artifacts \ aoqi@0: --permit-sources-without-package \ aoqi@0: --compare-found-sources $$($1_BIN)/_the.$1_batch.tmp \ aoqi@0: --log=$(LOG_LEVEL) \ aoqi@0: $$($1_SJAVAC_ARGS) \ aoqi@0: $$($1_FLAGS) \ aoqi@0: $$($1_HEADERS_ARG) \ aoqi@0: -d $$($1_BIN) && \ aoqi@0: $(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch) aoqi@0: else aoqi@0: # Using plain javac to batch compile everything. aoqi@0: $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_BIN)/_the.$1_batch aoqi@0: aoqi@0: # When building in batch, put headers in a temp dir to filter out those that actually aoqi@0: # changed before copying them to the real header dir. aoqi@0: ifneq (,$$($1_HEADERS)) aoqi@0: $1_HEADERS_ARG := -h $$($1_HEADERS).$1.tmp aoqi@0: aoqi@0: $$($1_HEADERS)/_the.$1_headers: $$($1_BIN)/_the.$1_batch aoqi@0: $(MKDIR) -p $$(@D) aoqi@0: for f in `ls $$($1_HEADERS).$1.tmp`; do \ aoqi@0: if [ ! -f "$$($1_HEADERS)/$$$$f" ] || [ "`$(DIFF) $$($1_HEADERS)/$$$$f $$($1_HEADERS).$1.tmp/$$$$f`" != "" ]; then \ aoqi@0: $(CP) -f $$($1_HEADERS).$1.tmp/$$$$f $$($1_HEADERS)/$$$$f; \ aoqi@0: fi; \ aoqi@0: done aoqi@0: $(RM) -r $$($1_HEADERS).$1.tmp aoqi@0: $(TOUCH) $$@ aoqi@0: aoqi@0: $1 += $$($1_HEADERS)/_the.$1_headers aoqi@0: endif aoqi@0: aoqi@0: # When not using sjavac, pass along all sources to javac using an @file. aoqi@0: $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS) aoqi@0: $(MKDIR) -p $$(@D) aoqi@0: $(RM) $$($1_BIN)/_the.$1_batch $$($1_BIN)/_the.$1_batch.tmp aoqi@0: $$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.$1_batch.tmp) aoqi@0: $(ECHO) Compiling `$(WC) $$($1_BIN)/_the.$1_batch.tmp | $(TR) -s ' ' | $(CUT) -f 2 -d ' '` files for $1 aoqi@0: ($$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) \ aoqi@0: -implicit:none -sourcepath "$$($1_SRCROOTSC)" \ aoqi@0: -d $$($1_BIN) $$($1_HEADERS_ARG) @$$($1_BIN)/_the.$1_batch.tmp && \ aoqi@0: $(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch) aoqi@0: aoqi@0: endif aoqi@0: aoqi@0: # Check if a jar file was specified, then setup the rules for the jar. aoqi@0: ifneq (,$$($1_JAR)) aoqi@0: # If no suffixes was explicitly set for this jar file. aoqi@0: # Use class and the cleaned/copied properties file suffixes as the default aoqi@0: # for the types of files to be put into the jar. aoqi@0: ifeq (,$$($1_SUFFIXES)) aoqi@0: $1_SUFFIXES:=.class $$($1_CLEAN) $$($1_COPY) aoqi@0: endif aoqi@0: aoqi@0: $$(eval $$(call SetupArchive,ARCHIVE_$1,$$($1), \ aoqi@0: SRCS:=$$($1_BIN), \ aoqi@0: SUFFIXES:=$$($1_SUFFIXES), \ aoqi@0: EXCLUDE:=$$($1_EXCLUDES), \ aoqi@0: INCLUDES:=$$($1_INCLUDES), \ aoqi@0: EXTRA_FILES:=$$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS), \ aoqi@0: JAR:=$$($1_JAR), \ aoqi@0: JARMAIN:=$$($1_JARMAIN), \ aoqi@0: MANIFEST:=$$($1_MANIFEST), \ aoqi@0: EXTRA_MANIFEST_ATTR:=$$($1_EXTRA_MANIFEST_ATTR), \ aoqi@0: JARINDEX:=$$($1_JARINDEX), \ aoqi@0: HEADERS:=$$($1_HEADERS), \ aoqi@0: SETUP:=$$($1_SETUP))) aoqi@0: endif aoqi@0: aoqi@0: # Check if a srczip was specified, then setup the rules for the srczip. aoqi@0: ifneq (,$$($1_SRCZIP)) aoqi@0: $$(eval $$(call SetupZipArchive,ARCHIVE_$1, \ aoqi@0: SRC:=$$($1_SRC), \ aoqi@0: ZIP:=$$($1_SRCZIP), \ aoqi@0: INCLUDES:=$$($1_INCLUDES), \ aoqi@0: EXCLUDES:=$$($1_EXCLUDES), \ aoqi@0: EXCLUDE_FILES:=$$($1_EXCLUDE_FILES))) aoqi@0: endif aoqi@0: aoqi@0: endef