1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/make/common/JavaCompilation.gmk Thu Dec 05 15:12:22 2013 -0800 1.3 @@ -0,0 +1,594 @@ 1.4 +# 1.5 +# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 +# 1.8 +# This code is free software; you can redistribute it and/or modify it 1.9 +# under the terms of the GNU General Public License version 2 only, as 1.10 +# published by the Free Software Foundation. Oracle designates this 1.11 +# particular file as subject to the "Classpath" exception as provided 1.12 +# by Oracle in the LICENSE file that accompanied this code. 1.13 +# 1.14 +# This code is distributed in the hope that it will be useful, but WITHOUT 1.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 +# version 2 for more details (a copy is included in the LICENSE file that 1.18 +# accompanied this code). 1.19 +# 1.20 +# You should have received a copy of the GNU General Public License version 1.21 +# 2 along with this work; if not, write to the Free Software Foundation, 1.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 +# 1.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 +# or visit www.oracle.com if you need additional information or have any 1.26 +# questions. 1.27 +# 1.28 + 1.29 +# This makefile is much simpler now that it can use the smart javac wrapper 1.30 +# for dependency tracking between java packages and incremental compiles. 1.31 +# It could be even more simple if we added support for incremental jar updates 1.32 +# directly from the smart javac wrapper. 1.33 + 1.34 +# Cleaning/copying properties here is not a good solution. The properties 1.35 +# should be cleaned/copied by a annotation processor in sjavac. 1.36 + 1.37 +# When you read this source. Remember that $(sort ...) has the side effect 1.38 +# of removing duplicates. It is actually this side effect that is 1.39 +# desired whenever sort is used below! 1.40 + 1.41 +ifeq (,$(_MAKEBASE_GMK)) 1.42 + $(error You must include MakeBase.gmk prior to including JavaCompilation.gmk) 1.43 +endif 1.44 + 1.45 +FALSE_FIND_PATTERN:=-name FILE_NAME_THAT_DOESNT_EXIST 1.46 + 1.47 +define SetupJavaCompiler 1.48 + # param 1 is for example GENERATE_OLD_BYTECODE or GENERATE_NEW_JDKBYTECODE 1.49 + # This is the name of the compiler setup. 1.50 + # param 2-9 are named args. 1.51 + # JVM:=The jvm used to run the javac/javah command 1.52 + # JAVAC:=The javac jar and bootstrap classpath changes, or just bin/javac if JVM is left out 1.53 + # FLAGS:=Flags to be supplied to javac 1.54 + # SERVER_DIR:=Use a javac server (-XDserver) and store the server related files here 1.55 + # SERVER_JVM:=Use this JVM for the server. Defaults to the JVM above. 1.56 + $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE)) 1.57 + $(call LogSetupMacroEntry,SetupJavaCompiler($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)) 1.58 + $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompiler, please update JavaCompilation.gmk)) 1.59 + 1.60 + # The port file contains the tcp/ip on which the server listens 1.61 + # and the cookie necessary to talk to the server. 1.62 + $1_SJAVAC_PORTFILE:=$$($1_SERVER_DIR)/server.port 1.63 + # You can use a different JVM to run the background javac server. 1.64 + ifeq ($$($1_SERVER_JVM),) 1.65 + # It defaults to the same JVM that is used to start the javac command. 1.66 + $1_SERVER_JVM:=$$($1_JVM) 1.67 + endif 1.68 +endef 1.69 + 1.70 +define SetupArchive 1.71 + # param 1 is for example ARCHIVE_MYPACKAGE 1.72 + # param 2 are the dependecies 1.73 + # param 3,4,5,6,7,8,9 are named args. 1.74 + # SRCS:=List of directories in where to find files to add to archive 1.75 + # SUFFIXES:=File suffixes to include in jar 1.76 + # INCLUDES:=List of directories/packages in SRCS that should be included 1.77 + # EXCLUDES:=List of directories/packages in SRCS that should be excluded 1.78 + # EXCLUDE_FILES:=List of files in SRCS that should be excluded 1.79 + # EXTRA_FILES:=List of files in SRCS that should be included regardless of suffix match. 1.80 + # JAR:=Jar file to create 1.81 + # MANIFEST:=Optional manifest file template. 1.82 + # JARMAIN:=Optional main class to add to manifest 1.83 + # JARINDEX:=true means generate the index in the jar file. 1.84 + # SKIP_METAINF:=Set to prevent contents of an META-INF directory to be automatically 1.85 + # added to the archive. 1.86 + # EXTRA_MANIFEST_ATTR:=Extra attribute to add to manifest. 1.87 + # CHECK_COMPRESS_JAR Check the COMPRESS_JAR variable 1.88 + 1.89 + # NOTE: $2 is dependencies, not a named argument! 1.90 + $(foreach i,3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE)) 1.91 + $(call LogSetupMacroEntry,SetupArchive($1),<dependencies>,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)) 1.92 + $(if $(findstring $(LOG_LEVEL),trace), $(info *[2] <dependencies> = $(strip $2))) 1.93 + $(if $(16),$(error Internal makefile error: Too many arguments to SetupArchive, please update JavaCompilation.gmk)) 1.94 + 1.95 + $1_JARMAIN:=$(strip $$($1_JARMAIN)) 1.96 + $1_JARNAME:=$$(notdir $$($1_JAR)) 1.97 + $1_MANIFEST_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_manifest 1.98 + $1_DELETESS_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletess 1.99 + $1_DELETES_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletes 1.100 + $1_BIN:=$$(dir $$($1_JAR)) 1.101 + 1.102 + ifeq (,$$($1_SUFFIXES)) 1.103 + # No suffix was set, default to classes. 1.104 + $1_SUFFIXES:=.class 1.105 + endif 1.106 + # Convert suffixes to a find expression 1.107 + $1_FIND_PATTERNS:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_SUFFIXES)) 1.108 + # On windows, a lot of includes/excludes risk making the command line too long, so 1.109 + # writing the grep patterns to files. 1.110 + ifneq (,$$($1_INCLUDES)) 1.111 + $1_GREP_INCLUDE_PATTERNS:=$$(foreach src,$$($1_SRCS), \ 1.112 + $$(addprefix $$(src)/,$$($1_INCLUDES))) 1.113 + # If there are a lot of include patterns, output to file to shorten command lines 1.114 + ifeq ($$(word 20,$$($1_GREP_INCLUDE_PATTERNS)),) 1.115 + $1_GREP_INCLUDES:=| $(GREP) $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_INCLUDE_PATTERNS)) 1.116 + else 1.117 + $1_GREP_INCLUDE_OUTPUT:=$(RM) $$($1_BIN)/_the.$$($1_JARNAME)_include $$(NEWLINE) \ 1.118 + $$(call ListPathsSafely,$1_GREP_INCLUDE_PATTERNS,\n, \ 1.119 + >> $$($1_BIN)/_the.$$($1_JARNAME)_include) 1.120 + $1_GREP_INCLUDES:=| $(GREP) -f $$($1_BIN)/_the.$$($1_JARNAME)_include 1.121 + endif 1.122 + endif 1.123 + ifneq (,$$($1_EXCLUDES)$$($1_EXCLUDE_FILES)) 1.124 + $1_GREP_EXCLUDE_PATTERNS:=$$(foreach src,$$($1_SRCS),$$(addprefix $$(src)/, \ 1.125 + $$($1_EXCLUDES) $$($1_EXCLUDE_FILES))) 1.126 + # If there are a lot of include patterns, output to file to shorten command lines 1.127 + ifeq ($$(word 20,$$($1_GREP_EXCLUDE_PATTERNS)),) 1.128 + $1_GREP_EXCLUDES:=| $(GREP) -v $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_EXCLUDE_PATTERNS)) 1.129 + else 1.130 + $1_GREP_EXCLUDE_OUTPUT=$(RM) $$($1_BIN)/_the.$$($1_JARNAME)_exclude $$(NEWLINE) \ 1.131 + $$(call ListPathsSafely,$1_GREP_EXCLUDE_PATTERNS,\n, \ 1.132 + >> $$($1_BIN)/_the.$$($1_JARNAME)_exclude) 1.133 + $1_GREP_EXCLUDES:=| $(GREP) -v -f $$($1_BIN)/_the.$$($1_JARNAME)_exclude 1.134 + endif 1.135 + endif 1.136 + 1.137 + # Check if this jar needs to have its index generated. 1.138 + ifneq (,$$($1_JARINDEX)) 1.139 + $1_JARINDEX = (cd $$(dir $$@) && $(JAR) -i $$(notdir $$@)) 1.140 + else 1.141 + $1_JARINDEX = true 1.142 + endif 1.143 + # When this macro is run in the same makefile as the java compilation, dependencies are 1.144 + # transfered in make variables. When the macro is run in a different makefile than the 1.145 + # java compilation, the dependencies need to be found in the filesystem. 1.146 + ifneq (,$2) 1.147 + $1_DEPS:=$2 1.148 + else 1.149 + $1_DEPS:=$$(filter $$(addprefix %,$$($1_SUFFIXES)), \ 1.150 + $$(call CacheFind,$$($1_SRCS))) 1.151 + ifneq (,$$($1_GREP_INCLUDE_PATTERNS)) 1.152 + $1_DEPS:=$$(filter $$(addsuffix %,$$($1_GREP_INCLUDE_PATTERNS)),$$($1_DEPS)) 1.153 + endif 1.154 + ifneq (,$$($1_GREP_EXCLUDE_PATTERNS)) 1.155 + $1_DEPS:=$$(filter-out $$(addsuffix %,$$($1_GREP_EXCLUDE_PATTERNS)),$$($1_DEPS)) 1.156 + endif 1.157 + # The subst of \ is needed because $ has to be escaped with \ in EXTRA_FILES for the command 1.158 + # lines, but not here for use in make dependencies. 1.159 + $1_DEPS+=$$(subst \,,$$(foreach src,$$($1_SRCS),$$(addprefix $$(src)/,$$($1_EXTRA_FILES)))) 1.160 + ifeq (,$$($1_SKIP_METAINF)) 1.161 + $1_DEPS+=$$(call CacheFind,$$(wildcard $$(addsuffix /META-INF,$$($1_SRCS)))) 1.162 + endif 1.163 + endif 1.164 + 1.165 + # Utility macros, to make the shell script receipt somewhat easier to decipher. 1.166 + 1.167 + # The capture contents macro finds all files (matching the patterns, typically 1.168 + # .class and .prp) that are newer than the jar-file, ie the new content to be put into the jar. 1.169 + # NOTICE: please leave the parentheses space separated otherwise the AIX build will break! 1.170 + $1_CAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS), \ 1.171 + ( ( $(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) -a -newer $$@ $$($1_GREP_INCLUDES) \ 1.172 + $$($1_GREP_EXCLUDES) | $(SED) 's|$$(src)/||g' && \ 1.173 + $(ECHO) $$(subst $$(src)/,,$$($1_EXTRA_FILES) ) ) > \ 1.174 + $$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE) ) 1.175 + # The capture metainf macro finds all files below the META-INF directory that are newer than the jar-file. 1.176 + ifeq (,$$($1_SKIP_METAINF)) 1.177 + $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)) 1.178 + endif 1.179 + # The capture deletes macro finds all deleted files and concatenates them. The resulting file 1.180 + # tells us what to remove from the jar-file. 1.181 + $1_CAPTURE_DELETES=$$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.deleted -newer $$@ -exec $(SED) 's|$$(src)||g' \{\} >> $$($1_DELETES_FILE) \;) $$(NEWLINE)) 1.182 + # The update contents macro updates the jar file with the previously capture contents. 1.183 + # Use 'wc -w' to see if the contents file is empty. 1.184 + $1_UPDATE_CONTENTS=$$(foreach src,$$($1_SRCS), \ 1.185 + (cd $$(src) && \ 1.186 + if [ "`$(WC) -w _the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'`" -gt "0" ]; then \ 1.187 + $(ECHO) " updating" `$(WC) -l _the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'` files && \ 1.188 + $(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @_the.$$($1_JARNAME)_contents; \ 1.189 + fi) $$(NEWLINE)) 1.190 + # The s-variants of the above macros are used when the jar is created from scratch. 1.191 + # NOTICE: please leave the parentheses space separated otherwise the AIX build will break! 1.192 + $1_SCAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS), \ 1.193 + ( ( $(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) $$($1_GREP_INCLUDES) \ 1.194 + $$($1_GREP_EXCLUDES) | $(SED) 's|$$(src)/||g' && \ 1.195 + $$(subst $$(src)/,,$(ECHO) $$($1_EXTRA_FILES) ) ) > \ 1.196 + $$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE) ) 1.197 + 1.198 + ifeq (,$$($1_SKIP_METAINF)) 1.199 + $1_SCAPTURE_METAINF=$$(foreach src,$$($1_SRCS), \ 1.200 + ($(FIND) $$(src)/META-INF -type f 2> /dev/null | $(SED) 's|$$(src)/||g' >> \ 1.201 + $$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE)) 1.202 + endif 1.203 + $1_SUPDATE_CONTENTS=$$(foreach src,$$($1_SRCS), \ 1.204 + (cd $$(src) && $(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @$$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE)) 1.205 + 1.206 + # Use a slightly shorter name for logging, but with enough path to identify this jar. 1.207 + $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_JAR)) 1.208 + 1.209 + ifneq (,$$($1_CHECK_COMPRESS_JAR)) 1.210 + $1_JAR_CREATE_OPTIONS := c0fm 1.211 + $1_JAR_UPDATE_OPTIONS := u0f 1.212 + ifeq ($(COMPRESS_JARS), true) 1.213 + $1_JAR_CREATE_OPTIONS := cfm 1.214 + $1_JAR_UPDATE_OPTIONS := uf 1.215 + endif 1.216 + else 1.217 + $1_JAR_CREATE_OPTIONS := cfm 1.218 + $1_JAR_UPDATE_OPTIONS := uf 1.219 + endif 1.220 + 1.221 + # Here is the rule that creates/updates the jar file. 1.222 + $$($1_JAR) : $$($1_DEPS) 1.223 + $(MKDIR) -p $$($1_BIN) 1.224 + $$($1_GREP_INCLUDE_OUTPUT) 1.225 + $$($1_GREP_EXCLUDE_OUTPUT) 1.226 + $$(if $$($1_MANIFEST), \ 1.227 + $(SED) -e "s#@@RELEASE@@#$(RELEASE)#" \ 1.228 + -e "s#@@COMPANY_NAME@@#$(COMPANY_NAME)#" $$($1_MANIFEST) > $$($1_MANIFEST_FILE) \ 1.229 + , \ 1.230 + $(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE)) 1.231 + $$(if $$($1_JARMAIN),$(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE)) 1.232 + $$(if $$($1_EXTRA_MANIFEST_ATTR),$(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE)) 1.233 + $$(if $$(wildcard $$@), \ 1.234 + $(ECHO) Modifying $$($1_NAME) $$(NEWLINE) \ 1.235 + $$($1_CAPTURE_CONTENTS) \ 1.236 + $$($1_CAPTURE_METAINF) \ 1.237 + $(RM) $$($1_DELETES_FILE) $$(NEWLINE) \ 1.238 + $$($1_CAPTURE_DELETES) \ 1.239 + $(CAT) $$($1_DELETES_FILE) > $$($1_DELETESS_FILE) $$(NEWLINE) \ 1.240 + if [ -s $$($1_DELETESS_FILE) ]; then \ 1.241 + $(ECHO) " deleting" `$(WC) -l $$($1_DELETESS_FILE) | $(AWK) '{ print $$$$1 }'` files && \ 1.242 + $(ZIP) -q -d $$@ `$(CAT) $$($1_DELETESS_FILE)` ; \ 1.243 + fi $$(NEWLINE) \ 1.244 + $$($1_UPDATE_CONTENTS) true $$(NEWLINE) \ 1.245 + $$($1_JARINDEX) && true \ 1.246 + , \ 1.247 + $(ECHO) Creating $$($1_NAME) && $(JAR) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) $$(NEWLINE) \ 1.248 + $$($1_SCAPTURE_CONTENTS) \ 1.249 + $$($1_SCAPTURE_METAINF) \ 1.250 + $$($1_SUPDATE_CONTENTS) \ 1.251 + $$($1_JARINDEX) && true ) 1.252 + 1.253 +endef 1.254 + 1.255 +define SetupZipArchive 1.256 + # param 1 is for example ZIP_MYSOURCE 1.257 + # param 2,3,4,5,6,7,8,9 are named args. 1.258 + # SRC,ZIP,INCLUDES,INCLUDE_FILES,EXCLUDES,EXCLUDE_FILES,SUFFIXES,EXTRA_DEPS 1.259 + $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE)) 1.260 + $(call LogSetupMacroEntry,SetupZipArchive($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)) 1.261 + $(if $(16),$(error Internal makefile error: Too many arguments to SetupZipArchive, please update JavaCompilation.gmk)) 1.262 + 1.263 + # To avoid running find over too large sets of files, which causes make to crash 1.264 + # on some configurations (cygwin), use INCLUDES and INCLUDE_FILES to build a set 1.265 + # of directories to run find in, if available. 1.266 + ifneq ($$($1_INCLUDES)$$($1_INCLUDE_FILES),) 1.267 + $1_FIND_LIST := $$(wildcard $$(foreach i,$$($1_SRC), \ 1.268 + $$(addprefix $$i/,$$($1_INCLUDES) $$($1_INCLUDE_FILES)))) 1.269 + else 1.270 + $1_FIND_LIST := $$($1_SRC) 1.271 + endif 1.272 + 1.273 + # Find all files in the source tree. 1.274 + $1_ALL_SRCS := $$(call not-containing,_the.,$$(call CacheFind,$$($1_FIND_LIST))) 1.275 + 1.276 + # Filter on suffixes if set 1.277 + ifneq ($$($1_SUFFIXES),) 1.278 + $1_ALL_SRCS := $$(filter $$(addprefix %, $$($1_SUFFIXES)), $$($1_ALL_SRCS)) 1.279 + endif 1.280 + 1.281 + ifneq ($$($1_INCLUDES),) 1.282 + ifneq ($$($1_SUFFIXES),) 1.283 + $1_ZIP_INCLUDES := $$(foreach s,$$($1_SUFFIXES), \ 1.284 + $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$$s$(DQUOTE),$$($1_INCLUDES)))) 1.285 + else 1.286 + $1_ZIP_INCLUDES := $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_INCLUDES))) 1.287 + endif 1.288 + endif 1.289 + ifneq ($$($1_INCLUDE_FILES),) 1.290 + $1_ZIP_INCLUDES += $$(addprefix -i$(SPACE),$$($1_INCLUDE_FILES)) 1.291 + endif 1.292 + ifneq ($$($1_EXCLUDES),) 1.293 + $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES)))) 1.294 + $1_ZIP_EXCLUDES := $$(addprefix -x$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_EXCLUDES))) 1.295 + $1_ALL_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_SRCS)) 1.296 + endif 1.297 + 1.298 + # Use a slightly shorter name for logging, but with enough path to identify this zip. 1.299 + $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_ZIP)) 1.300 + 1.301 + # Now $1_ALL_SRCS should contain all sources that are going to be put into the zip. 1.302 + # I.e. the zip -i and -x options should match the filtering done in the makefile. 1.303 + # Explicitly excluded files can be given with absolute path. The patsubst solution 1.304 + # isn't perfect but the likelyhood of an absolute path to match something in a src 1.305 + # dir is very small. 1.306 + # If zip has nothing to do, it returns 12 and would fail the build. Check for 12 1.307 + # and only fail if it's not. 1.308 + $$($1_ZIP) : $$($1_ALL_SRCS) $$($1_EXTRA_DEPS) 1.309 + $(MKDIR) -p $$(@D) 1.310 + $(ECHO) Updating $$($1_NAME) 1.311 + $$(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 1.312 + $(TOUCH) $$@ 1.313 +endef 1.314 + 1.315 +define add_file_to_copy 1.316 + # param 1 = BUILD_MYPACKAGE 1.317 + # parma 2 = The source file to copy. 1.318 + $2_TARGET:=$2 1.319 + # Remove the source prefix. 1.320 + $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET))) 1.321 + # Now we can setup the depency that will trigger the copying. 1.322 + $$($1_BIN)$$($2_TARGET) : $2 1.323 + $(MKDIR) -p $$(@D) 1.324 + $(CP) $$< $$@ 1.325 + $(CHMOD) -f ug+w $$@ 1.326 + 1.327 + # And do not forget this target 1.328 + $1_ALL_COPY_TARGETS += $$($1_BIN)$$($2_TARGET) 1.329 +endef 1.330 + 1.331 + 1.332 +# This macro is used only for properties files that are to be 1.333 +# copied over to the classes directory in cleaned form: 1.334 +# Previously this was inconsistently done in different repositories. 1.335 +# This is the new clean standard. Though it is to be superseded by 1.336 +# a standard annotation processor from with sjavac. 1.337 +define add_file_to_copy_and_clean 1.338 + # param 1 = BUILD_MYPACKAGE 1.339 + # parma 2 = The source file to copy and clean. 1.340 + $2_TARGET:=$2 1.341 + # Remove the source prefix. 1.342 + $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET))) 1.343 + # Now we can setup the depency that will trigger the copying. 1.344 + $$($1_BIN)$$($2_TARGET) : $2 1.345 + $(MKDIR) -p $$(@D) 1.346 + $(CAT) $$< | $(SED) -e 's/\([^\\]\):/\1\\:/g' -e 's/\([^\\]\)=/\1\\=/g' -e 's/#.*/#/g' \ 1.347 + | $(SED) -f "$(SRC_ROOT)/make/common/support/unicode2x.sed" \ 1.348 + | $(SED) -e '/^#/d' -e '/^$$$$/d' \ 1.349 + -e :a -e '/\\$$$$/N; s/\\\n//; ta' \ 1.350 + -e 's/^[ \t]*//;s/[ \t]*$$$$//' \ 1.351 + -e 's/\\=/=/' | LANG=C $(SORT) > $$@ 1.352 + $(CHMOD) -f ug+w $$@ 1.353 + 1.354 + # And do not forget this target 1.355 + $1_ALL_COPY_CLEAN_TARGETS += $$($1_BIN)$$($2_TARGET) 1.356 +endef 1.357 + 1.358 +define remove_string 1.359 + $2 := $$(subst $1,,$$($2)) 1.360 +endef 1.361 + 1.362 +define replace_space_with_pathsep 1.363 + $1:=$(subst $(SPACE),$(PATH_SEP),$(strip $(patsubst %,%,$2))) 1.364 +endef 1.365 + 1.366 +define SetupJavaCompilation 1.367 + # param 1 is for example BUILD_MYPACKAGE 1.368 + # param 2,3,4,5,6,7,8 are named args. 1.369 + # SETUP:=must point to a previously setup java compiler, for example: SETUP:=BOOTJAVAC 1.370 + # JVM:=path to ..bin/java 1.371 + # ADD_JAVAC_FLAGS:=javac flags to append to the default ones. 1.372 + # SRC:=one or more directories to search for sources 1.373 + # BIN:=store classes here 1.374 + # INCLUDES:=myapp.foo means will only compile java files in myapp.foo or any of its sub-packages. 1.375 + # EXCLUDES:=myapp.foo means will do not compile java files in myapp.foo or any of its sub-packages. 1.376 + # COPY:=.prp means copy all prp files to the corresponding package in BIN. 1.377 + # CLEAN:=.properties means copy and clean all properties file to the corresponding package in BIN. 1.378 + # COPY_FILES:=myapp/foo/setting.txt means copy this file over to the package myapp/foo 1.379 + # SRCZIP:=Create a src.zip based on the found sources and copied files. 1.380 + # INCLUDE_FILES:="com/sun/SolarisFoobar.java" means only compile this file! 1.381 + # EXCLUDE_FILES:="com/sun/SolarisFoobar.java" means do not compile this particular file! 1.382 + # "SolarisFoobar.java" means do not compile SolarisFoobar, wherever it is found. 1.383 + # JAVAC_SOURCE_PATH_OVERRIDE:=This forces an explicit -sourcepath to javac instead of the complete 1.384 + # source roots from SRC. This is sometimes needed when compiling specific subsets of the source. 1.385 + # HEADERS:=path to directory where all generated c-headers are written. 1.386 + # DEPENDS:=Extra dependecy 1.387 + $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE)) 1.388 + $(call LogSetupMacroEntry,SetupJavaCompilation($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)) 1.389 + $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompilation, please update JavaCompilation.gmk)) 1.390 + 1.391 + # Extract the info from the java compiler setup. 1.392 + $1_JVM := $$($$($1_SETUP)_JVM) 1.393 + $1_JAVAC := $$($$($1_SETUP)_JAVAC) 1.394 + $1_FLAGS := $$($$($1_SETUP)_FLAGS) $(JAVAC_FLAGS) $$($1_ADD_JAVAC_FLAGS) 1.395 + ifeq ($$($1_JAVAC),) 1.396 + $$(error The Java compilation $1 refers to a non-existant java compiler setup $$($1_SETUP)) 1.397 + endif 1.398 + $1_SJAVAC_PORTFILE := $$($$($1_SETUP)_SJAVAC_PORTFILE) 1.399 + $1_SERVER_JVM := $$($$($1_SETUP)_SERVER_JVM) 1.400 + 1.401 + # Handle addons and overrides. 1.402 + $1_SRC:=$$(call ADD_SRCS,$$($1_SRC)) 1.403 + # Make sure the dirs exist. 1.404 + $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupJavaCompilation $1 contains missing directory $$d))) 1.405 + $$(eval $$(call MakeDir,$$($1_BIN))) 1.406 + # Find all files in the source trees. 1.407 + $1_ALL_SRCS += $$(filter-out $(OVR_SRCS),$$(call CacheFind,$$($1_SRC))) 1.408 + # Extract the java files. 1.409 + ifneq ($$($1_EXCLUDE_FILES),) 1.410 + $1_EXCLUDE_FILES_PATTERN:=$$(addprefix %,$$($1_EXCLUDE_FILES)) 1.411 + endif 1.412 + $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$(filter %.java,$$($1_ALL_SRCS))) 1.413 + ifneq ($$($1_INCLUDE_FILES),) 1.414 + $1_INCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES))) 1.415 + $1_SRCS := $$(filter $$($1_INCLUDE_FILES), $$($1_SRCS)) 1.416 + endif 1.417 + 1.418 + # Now we have a list of all java files to compile: $$($1_SRCS) 1.419 + 1.420 + # Create the corresponding smart javac wrapper command line. 1.421 + $1_SJAVAC_ARGS:=$$(addprefix -x ,$$(addsuffix .*,$$(subst /,.,$$($1_EXCLUDES)))) \ 1.422 + $$(addprefix -i ,$$(addsuffix .*,$$(subst /,.,$$($1_INCLUDES)))) \ 1.423 + $$(addprefix -xf *,$$(strip $$($1_EXCLUDE_FILES))) \ 1.424 + $$(addprefix -if *,$$(strip $$($1_INCLUDE_FILES))) \ 1.425 + -src "$$(subst $$(SPACE),$$(PATH_SEP),$$(strip $$($1_SRC)))" 1.426 + 1.427 + # Prepend the source/bin path to the filter expressions. 1.428 + ifneq ($$($1_INCLUDES),) 1.429 + $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES)))) 1.430 + $1_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS)) 1.431 + endif 1.432 + ifneq ($$($1_EXCLUDES),) 1.433 + $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES)))) 1.434 + $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS)) 1.435 + endif 1.436 + 1.437 + # Find all files to be copied from source to bin. 1.438 + ifneq (,$$($1_COPY)) 1.439 + # Search for all files to be copied. 1.440 + $1_ALL_COPIES := $$(filter $$(addprefix %,$$($1_COPY)),$$($1_ALL_SRCS)) 1.441 + # Copy these explicitly 1.442 + $1_ALL_COPIES += $$($1_COPY_FILES) 1.443 + # Copy must also respect filters. 1.444 + ifneq (,$$($1_INCLUDES)) 1.445 + $1_ALL_COPIES := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_COPIES)) 1.446 + endif 1.447 + ifneq (,$$($1_EXCLUDES)) 1.448 + $1_ALL_COPIES := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_COPIES)) 1.449 + endif 1.450 + ifneq (,$$($1_EXCLUDE_FILES)) 1.451 + $1_ALL_COPIES := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_COPIES)) 1.452 + endif 1.453 + # All files below META-INF are always copied. 1.454 + $1_ALL_COPIES += $$(filter $$(addsuffix /META-INF%,$$($1_SRC)),$$($1_ALL_SRCS)) 1.455 + ifneq (,$$($1_ALL_COPIES)) 1.456 + # Yep, there are files to be copied! 1.457 + $1_ALL_COPY_TARGETS:= 1.458 + $$(foreach i,$$($1_ALL_COPIES),$$(eval $$(call add_file_to_copy,$1,$$i))) 1.459 + # Now we can depend on $$($1_ALL_COPY_TARGETS) to copy all files! 1.460 + endif 1.461 + endif 1.462 + 1.463 + # Find all property files to be copied and cleaned from source to bin. 1.464 + ifneq (,$$($1_CLEAN)) 1.465 + # Search for all files to be copied. 1.466 + $1_ALL_CLEANS := $$(filter $$(addprefix %,$$($1_CLEAN)),$$($1_ALL_SRCS)) 1.467 + # Copy and clean must also respect filters. 1.468 + ifneq (,$$($1_INCLUDES)) 1.469 + $1_ALL_CLEANS := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_CLEANS)) 1.470 + endif 1.471 + ifneq (,$$($1_EXCLUDES)) 1.472 + $1_ALL_CLEANS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_CLEANS)) 1.473 + endif 1.474 + ifneq (,$$($1_EXCLUDE_FILES)) 1.475 + $1_ALL_CLEANS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_CLEANS)) 1.476 + endif 1.477 + ifneq (,$$($1_ALL_CLEANS)) 1.478 + # Yep, there are files to be copied and cleaned! 1.479 + $1_ALL_COPY_CLEAN_TARGETS:= 1.480 + $$(foreach i,$$($1_ALL_CLEANS),$$(eval $$(call add_file_to_copy_and_clean,$1,$$i))) 1.481 + # Now we can depend on $$($1_ALL_COPY_CLEAN_TARGETS) to copy all files! 1.482 + endif 1.483 + endif 1.484 + 1.485 + # Prep the source paths. 1.486 + ifneq ($$($1_JAVAC_SOURCE_PATH_OVERRIDE),) 1.487 + $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_JAVAC_SOURCE_PATH_OVERRIDE))) 1.488 + else 1.489 + $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_SRC))) 1.490 + endif 1.491 + 1.492 + # Create a sed expression to remove the source roots and to replace / with . 1.493 + # and remove .java at the end. 1.494 + $1_REWRITE_INTO_CLASSES:=$$(foreach i,$$($1_SRC),-e 's|$$i/||g') -e 's|/|.|g' -e 's|.java$$$$||g' 1.495 + 1.496 + ifeq ($$($1_DISABLE_SJAVAC)x$$(ENABLE_SJAVAC),xyes) 1.497 + ifneq (,$$($1_HEADERS)) 1.498 + $1_HEADERS_ARG := -h $$($1_HEADERS) 1.499 + endif 1.500 + 1.501 + # Using sjavac to compile. 1.502 + $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_BIN)/javac_state 1.503 + 1.504 + # Create SJAVAC variable form JAVAC variable. Expects $1_JAVAC to be 1.505 + # "bootclasspathprepend -cp .../javac.jar com.sun.tools.javac.Main" 1.506 + # and javac is simply replaced with sjavac. 1.507 + $1_SJAVAC:=$$(subst com.sun.tools.javac.Main,com.sun.tools.sjavac.Main,$$($1_JAVAC)) 1.508 + 1.509 + # Set the $1_REMOTE to spawn a background javac server. 1.510 + $1_REMOTE:=--server:portfile=$$($1_SJAVAC_PORTFILE),id=$1,sjavac=$$(subst $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_SJAVAC)))) 1.511 + 1.512 + $$($1_BIN)/javac_state: $$($1_SRCS) $$($1_DEPENDS) 1.513 + $(MKDIR) -p $$(@D) 1.514 + $$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.$1_batch.tmp) 1.515 + $(ECHO) Compiling $1 1.516 + ($$($1_JVM) $$($1_SJAVAC) \ 1.517 + $$($1_REMOTE) \ 1.518 + -j $(JOBS) \ 1.519 + --permit-unidentified-artifacts \ 1.520 + --permit-sources-without-package \ 1.521 + --compare-found-sources $$($1_BIN)/_the.$1_batch.tmp \ 1.522 + --log=$(LOG_LEVEL) \ 1.523 + $$($1_SJAVAC_ARGS) \ 1.524 + $$($1_FLAGS) \ 1.525 + $$($1_HEADERS_ARG) \ 1.526 + -d $$($1_BIN) && \ 1.527 + $(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch) 1.528 + else 1.529 + # Using plain javac to batch compile everything. 1.530 + $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_BIN)/_the.$1_batch 1.531 + 1.532 + # When building in batch, put headers in a temp dir to filter out those that actually 1.533 + # changed before copying them to the real header dir. 1.534 + ifneq (,$$($1_HEADERS)) 1.535 + $1_HEADERS_ARG := -h $$($1_HEADERS).tmp 1.536 + 1.537 + $$($1_HEADERS)/_the.$1_headers: $$($1_BIN)/_the.$1_batch 1.538 + $(MKDIR) -p $$(@D) 1.539 + for f in `ls $$($1_HEADERS).tmp`; do \ 1.540 + if [ ! -f "$$($1_HEADERS)/$$$$f" ] || [ "`$(DIFF) $$($1_HEADERS)/$$$$f $$($1_HEADERS).tmp/$$$$f`" != "" ]; then \ 1.541 + $(CP) -f $$($1_HEADERS).tmp/$$$$f $$($1_HEADERS)/$$$$f; \ 1.542 + fi; \ 1.543 + done 1.544 + $(RM) -r $$($1_HEADERS).tmp 1.545 + $(TOUCH) $$@ 1.546 + 1.547 + $1 += $$($1_HEADERS)/_the.$1_headers 1.548 + endif 1.549 + 1.550 + # When not using sjavac, pass along all sources to javac using an @file. 1.551 + $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS) 1.552 + $(MKDIR) -p $$(@D) 1.553 + $(RM) $$($1_BIN)/_the.$1_batch $$($1_BIN)/_the.$1_batch.tmp 1.554 + $$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.$1_batch.tmp) 1.555 + $(ECHO) Compiling `$(WC) $$($1_BIN)/_the.$1_batch.tmp | $(TR) -s ' ' | $(CUT) -f 2 -d ' '` files for $1 1.556 + ($$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) \ 1.557 + -implicit:none -sourcepath "$$($1_SRCROOTSC)" \ 1.558 + -d $$($1_BIN) $$($1_HEADERS_ARG) @$$($1_BIN)/_the.$1_batch.tmp && \ 1.559 + $(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch) 1.560 + 1.561 + endif 1.562 + 1.563 + # Check if a jar file was specified, then setup the rules for the jar. 1.564 + ifneq (,$$($1_JAR)) 1.565 + # If no suffixes was explicitly set for this jar file. 1.566 + # Use class and the cleaned/copied properties file suffixes as the default 1.567 + # for the types of files to be put into the jar. 1.568 + ifeq (,$$($1_SUFFIXES)) 1.569 + $1_SUFFIXES:=.class $$($1_CLEAN) $$($1_COPY) 1.570 + endif 1.571 + 1.572 + $$(eval $$(call SetupArchive,ARCHIVE_$1,$$($1), \ 1.573 + SRCS:=$$($1_BIN), \ 1.574 + SUFFIXES:=$$($1_SUFFIXES), \ 1.575 + EXCLUDE:=$$($1_EXCLUDES), \ 1.576 + INCLUDES:=$$($1_INCLUDES), \ 1.577 + EXTRA_FILES:=$$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS), \ 1.578 + JAR:=$$($1_JAR), \ 1.579 + JARMAIN:=$$($1_JARMAIN), \ 1.580 + MANIFEST:=$$($1_MANIFEST), \ 1.581 + EXTRA_MANIFEST_ATTR:=$$($1_EXTRA_MANIFEST_ATTR), \ 1.582 + JARINDEX:=$$($1_JARINDEX), \ 1.583 + HEADERS:=$$($1_HEADERS), \ 1.584 + SETUP:=$$($1_SETUP))) 1.585 + endif 1.586 + 1.587 + # Check if a srczip was specified, then setup the rules for the srczip. 1.588 + ifneq (,$$($1_SRCZIP)) 1.589 + $$(eval $$(call SetupZipArchive,ARCHIVE_$1, \ 1.590 + SRC:=$$($1_SRC), \ 1.591 + ZIP:=$$($1_SRCZIP), \ 1.592 + INCLUDES:=$$($1_INCLUDES), \ 1.593 + EXCLUDES:=$$($1_EXCLUDES), \ 1.594 + EXCLUDE_FILES:=$$($1_EXCLUDE_FILES))) 1.595 + endif 1.596 + 1.597 +endef