1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/make/common/JavaCompilation.gmk Thu Nov 14 10:53:23 2013 +0100 1.3 @@ -0,0 +1,592 @@ 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 + $1_CAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS), \ 1.170 + (($(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) -a -newer $$@ $$($1_GREP_INCLUDES) \ 1.171 + $$($1_GREP_EXCLUDES) | $(SED) 's|$$(src)/||g' && \ 1.172 + $(ECHO) $$(subst $$(src)/,,$$($1_EXTRA_FILES))) > \ 1.173 + $$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE)) 1.174 + # The capture metainf macro finds all files below the META-INF directory that are newer than the jar-file. 1.175 + ifeq (,$$($1_SKIP_METAINF)) 1.176 + $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.177 + endif 1.178 + # The capture deletes macro finds all deleted files and concatenates them. The resulting file 1.179 + # tells us what to remove from the jar-file. 1.180 + $1_CAPTURE_DELETES=$$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.deleted -newer $$@ -exec $(SED) 's|$$(src)||g' \{\} >> $$($1_DELETES_FILE) \;) $$(NEWLINE)) 1.181 + # The update contents macro updates the jar file with the previously capture contents. 1.182 + # xargs is used to trim the whitespace from the contents file, to see if it is empty. 1.183 + $1_UPDATE_CONTENTS=$$(foreach src,$$($1_SRCS), \ 1.184 + (cd $$(src) && \ 1.185 + if [ -n "`$(CAT) _the.$$($1_JARNAME)_contents | $(XARGS)`" ]; then \ 1.186 + $(ECHO) " updating" `$(WC) -l _the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'` files && \ 1.187 + $(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @_the.$$($1_JARNAME)_contents; \ 1.188 + fi) $$(NEWLINE)) 1.189 + # The s-variants of the above macros are used when the jar is created from scratch. 1.190 + $1_SCAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS), \ 1.191 + (($(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) $$($1_GREP_INCLUDES) \ 1.192 + $$($1_GREP_EXCLUDES) | $(SED) 's|$$(src)/||g' && \ 1.193 + $$(subst $$(src)/,,$(ECHO) $$($1_EXTRA_FILES))) > \ 1.194 + $$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE)) 1.195 + 1.196 + ifeq (,$$($1_SKIP_METAINF)) 1.197 + $1_SCAPTURE_METAINF=$$(foreach src,$$($1_SRCS), \ 1.198 + ($(FIND) $$(src)/META-INF -type f 2> /dev/null | $(SED) 's|$$(src)/||g' >> \ 1.199 + $$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE)) 1.200 + endif 1.201 + $1_SUPDATE_CONTENTS=$$(foreach src,$$($1_SRCS), \ 1.202 + (cd $$(src) && $(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @$$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE)) 1.203 + 1.204 + # Use a slightly shorter name for logging, but with enough path to identify this jar. 1.205 + $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_JAR)) 1.206 + 1.207 + ifneq (,$$($1_CHECK_COMPRESS_JAR)) 1.208 + $1_JAR_CREATE_OPTIONS := c0fm 1.209 + $1_JAR_UPDATE_OPTIONS := u0f 1.210 + ifeq ($(COMPRESS_JARS), true) 1.211 + $1_JAR_CREATE_OPTIONS := cfm 1.212 + $1_JAR_UPDATE_OPTIONS := uf 1.213 + endif 1.214 + else 1.215 + $1_JAR_CREATE_OPTIONS := cfm 1.216 + $1_JAR_UPDATE_OPTIONS := uf 1.217 + endif 1.218 + 1.219 + # Here is the rule that creates/updates the jar file. 1.220 + $$($1_JAR) : $$($1_DEPS) 1.221 + $(MKDIR) -p $$($1_BIN) 1.222 + $$($1_GREP_INCLUDE_OUTPUT) 1.223 + $$($1_GREP_EXCLUDE_OUTPUT) 1.224 + $$(if $$($1_MANIFEST), \ 1.225 + $(SED) -e "s#@@RELEASE@@#$(RELEASE)#" \ 1.226 + -e "s#@@COMPANY_NAME@@#$(COMPANY_NAME)#" $$($1_MANIFEST) > $$($1_MANIFEST_FILE) \ 1.227 + , \ 1.228 + $(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE)) 1.229 + $$(if $$($1_JARMAIN),$(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE)) 1.230 + $$(if $$($1_EXTRA_MANIFEST_ATTR),$(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE)) 1.231 + $$(if $$(wildcard $$@), \ 1.232 + $(ECHO) Modifying $$($1_NAME) $$(NEWLINE) \ 1.233 + $$($1_CAPTURE_CONTENTS) \ 1.234 + $$($1_CAPTURE_METAINF) \ 1.235 + $(RM) $$($1_DELETES_FILE) $$(NEWLINE) \ 1.236 + $$($1_CAPTURE_DELETES) \ 1.237 + $(CAT) $$($1_DELETES_FILE) > $$($1_DELETESS_FILE) $$(NEWLINE) \ 1.238 + if [ -s $$($1_DELETESS_FILE) ]; then \ 1.239 + $(ECHO) " deleting" `$(WC) -l $$($1_DELETESS_FILE) | $(AWK) '{ print $$$$1 }'` files && \ 1.240 + $(ZIP) -q -d $$@ `$(CAT) $$($1_DELETESS_FILE)` ; \ 1.241 + fi $$(NEWLINE) \ 1.242 + $$($1_UPDATE_CONTENTS) true $$(NEWLINE) \ 1.243 + $$($1_JARINDEX) && true \ 1.244 + , \ 1.245 + $(ECHO) Creating $$($1_NAME) && $(JAR) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) $$(NEWLINE) \ 1.246 + $$($1_SCAPTURE_CONTENTS) \ 1.247 + $$($1_SCAPTURE_METAINF) \ 1.248 + $$($1_SUPDATE_CONTENTS) \ 1.249 + $$($1_JARINDEX) && true ) 1.250 + 1.251 +endef 1.252 + 1.253 +define SetupZipArchive 1.254 + # param 1 is for example ZIP_MYSOURCE 1.255 + # param 2,3,4,5,6,7,8,9 are named args. 1.256 + # SRC,ZIP,INCLUDES,INCLUDE_FILES,EXCLUDES,EXCLUDE_FILES,SUFFIXES,EXTRA_DEPS 1.257 + $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE)) 1.258 + $(call LogSetupMacroEntry,SetupZipArchive($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)) 1.259 + $(if $(16),$(error Internal makefile error: Too many arguments to SetupZipArchive, please update JavaCompilation.gmk)) 1.260 + 1.261 + # To avoid running find over too large sets of files, which causes make to crash 1.262 + # on some configurations (cygwin), use INCLUDES and INCLUDE_FILES to build a set 1.263 + # of directories to run find in, if available. 1.264 + ifneq ($$($1_INCLUDES)$$($1_INCLUDE_FILES),) 1.265 + $1_FIND_LIST := $$(wildcard $$(foreach i,$$($1_SRC), \ 1.266 + $$(addprefix $$i/,$$($1_INCLUDES) $$($1_INCLUDE_FILES)))) 1.267 + else 1.268 + $1_FIND_LIST := $$($1_SRC) 1.269 + endif 1.270 + 1.271 + # Find all files in the source tree. 1.272 + $1_ALL_SRCS := $$(call not-containing,_the.,$$(call CacheFind,$$($1_FIND_LIST))) 1.273 + 1.274 + # Filter on suffixes if set 1.275 + ifneq ($$($1_SUFFIXES),) 1.276 + $1_ALL_SRCS := $$(filter $$(addprefix %, $$($1_SUFFIXES)), $$($1_ALL_SRCS)) 1.277 + endif 1.278 + 1.279 + ifneq ($$($1_INCLUDES),) 1.280 + ifneq ($$($1_SUFFIXES),) 1.281 + $1_ZIP_INCLUDES := $$(foreach s,$$($1_SUFFIXES), \ 1.282 + $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$$s$(DQUOTE),$$($1_INCLUDES)))) 1.283 + else 1.284 + $1_ZIP_INCLUDES := $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_INCLUDES))) 1.285 + endif 1.286 + endif 1.287 + ifneq ($$($1_INCLUDE_FILES),) 1.288 + $1_ZIP_INCLUDES += $$(addprefix -i$(SPACE),$$($1_INCLUDE_FILES)) 1.289 + endif 1.290 + ifneq ($$($1_EXCLUDES),) 1.291 + $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES)))) 1.292 + $1_ZIP_EXCLUDES := $$(addprefix -x$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_EXCLUDES))) 1.293 + $1_ALL_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_SRCS)) 1.294 + endif 1.295 + 1.296 + # Use a slightly shorter name for logging, but with enough path to identify this zip. 1.297 + $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_ZIP)) 1.298 + 1.299 + # Now $1_ALL_SRCS should contain all sources that are going to be put into the zip. 1.300 + # I.e. the zip -i and -x options should match the filtering done in the makefile. 1.301 + # Explicitly excluded files can be given with absolute path. The patsubst solution 1.302 + # isn't perfect but the likelyhood of an absolute path to match something in a src 1.303 + # dir is very small. 1.304 + # If zip has nothing to do, it returns 12 and would fail the build. Check for 12 1.305 + # and only fail if it's not. 1.306 + $$($1_ZIP) : $$($1_ALL_SRCS) $$($1_EXTRA_DEPS) 1.307 + $(MKDIR) -p $$(@D) 1.308 + $(ECHO) Updating $$($1_NAME) 1.309 + $$(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.310 + $(TOUCH) $$@ 1.311 +endef 1.312 + 1.313 +define add_file_to_copy 1.314 + # param 1 = BUILD_MYPACKAGE 1.315 + # parma 2 = The source file to copy. 1.316 + $2_TARGET:=$2 1.317 + # Remove the source prefix. 1.318 + $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET))) 1.319 + # Now we can setup the depency that will trigger the copying. 1.320 + $$($1_BIN)$$($2_TARGET) : $2 1.321 + $(MKDIR) -p $$(@D) 1.322 + $(CP) $$< $$@ 1.323 + $(CHMOD) -f ug+w $$@ 1.324 + 1.325 + # And do not forget this target 1.326 + $1_ALL_COPY_TARGETS += $$($1_BIN)$$($2_TARGET) 1.327 +endef 1.328 + 1.329 + 1.330 +# This macro is used only for properties files that are to be 1.331 +# copied over to the classes directory in cleaned form: 1.332 +# Previously this was inconsistently done in different repositories. 1.333 +# This is the new clean standard. Though it is to be superseded by 1.334 +# a standard annotation processor from with sjavac. 1.335 +define add_file_to_copy_and_clean 1.336 + # param 1 = BUILD_MYPACKAGE 1.337 + # parma 2 = The source file to copy and clean. 1.338 + $2_TARGET:=$2 1.339 + # Remove the source prefix. 1.340 + $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET))) 1.341 + # Now we can setup the depency that will trigger the copying. 1.342 + $$($1_BIN)$$($2_TARGET) : $2 1.343 + $(MKDIR) -p $$(@D) 1.344 + $(CAT) $$< | $(SED) -e 's/\([^\\]\):/\1\\:/g' -e 's/\([^\\]\)=/\1\\=/g' -e 's/#.*/#/g' \ 1.345 + | $(SED) -f "$(SRC_ROOT)/make/common/support/unicode2x.sed" \ 1.346 + | $(SED) -e '/^#/d' -e '/^$$$$/d' \ 1.347 + -e :a -e '/\\$$$$/N; s/\\\n//; ta' \ 1.348 + -e 's/^[ \t]*//;s/[ \t]*$$$$//' \ 1.349 + -e 's/\\=/=/' | LANG=C $(SORT) > $$@ 1.350 + $(CHMOD) -f ug+w $$@ 1.351 + 1.352 + # And do not forget this target 1.353 + $1_ALL_COPY_CLEAN_TARGETS += $$($1_BIN)$$($2_TARGET) 1.354 +endef 1.355 + 1.356 +define remove_string 1.357 + $2 := $$(subst $1,,$$($2)) 1.358 +endef 1.359 + 1.360 +define replace_space_with_pathsep 1.361 + $1:=$(subst $(SPACE),$(PATH_SEP),$(strip $(patsubst %,%,$2))) 1.362 +endef 1.363 + 1.364 +define SetupJavaCompilation 1.365 + # param 1 is for example BUILD_MYPACKAGE 1.366 + # param 2,3,4,5,6,7,8 are named args. 1.367 + # SETUP:=must point to a previously setup java compiler, for example: SETUP:=BOOTJAVAC 1.368 + # JVM:=path to ..bin/java 1.369 + # ADD_JAVAC_FLAGS:=javac flags to append to the default ones. 1.370 + # SRC:=one or more directories to search for sources 1.371 + # BIN:=store classes here 1.372 + # INCLUDES:=myapp.foo means will only compile java files in myapp.foo or any of its sub-packages. 1.373 + # EXCLUDES:=myapp.foo means will do not compile java files in myapp.foo or any of its sub-packages. 1.374 + # COPY:=.prp means copy all prp files to the corresponding package in BIN. 1.375 + # CLEAN:=.properties means copy and clean all properties file to the corresponding package in BIN. 1.376 + # COPY_FILES:=myapp/foo/setting.txt means copy this file over to the package myapp/foo 1.377 + # SRCZIP:=Create a src.zip based on the found sources and copied files. 1.378 + # INCLUDE_FILES:="com/sun/SolarisFoobar.java" means only compile this file! 1.379 + # EXCLUDE_FILES:="com/sun/SolarisFoobar.java" means do not compile this particular file! 1.380 + # "SolarisFoobar.java" means do not compile SolarisFoobar, wherever it is found. 1.381 + # JAVAC_SOURCE_PATH_OVERRIDE:=This forces an explicit -sourcepath to javac instead of the complete 1.382 + # source roots from SRC. This is sometimes needed when compiling specific subsets of the source. 1.383 + # HEADERS:=path to directory where all generated c-headers are written. 1.384 + # DEPENDS:=Extra dependecy 1.385 + $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE)) 1.386 + $(call LogSetupMacroEntry,SetupJavaCompilation($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)) 1.387 + $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompilation, please update JavaCompilation.gmk)) 1.388 + 1.389 + # Extract the info from the java compiler setup. 1.390 + $1_JVM := $$($$($1_SETUP)_JVM) 1.391 + $1_JAVAC := $$($$($1_SETUP)_JAVAC) 1.392 + $1_FLAGS := $$($$($1_SETUP)_FLAGS) $(JAVAC_FLAGS) $$($1_ADD_JAVAC_FLAGS) 1.393 + ifeq ($$($1_JAVAC),) 1.394 + $$(error The Java compilation $1 refers to a non-existant java compiler setup $$($1_SETUP)) 1.395 + endif 1.396 + $1_SJAVAC_PORTFILE := $$($$($1_SETUP)_SJAVAC_PORTFILE) 1.397 + $1_SERVER_JVM := $$($$($1_SETUP)_SERVER_JVM) 1.398 + 1.399 + # Handle addons and overrides. 1.400 + $1_SRC:=$$(call ADD_SRCS,$$($1_SRC)) 1.401 + # Make sure the dirs exist. 1.402 + $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupJavaCompilation $1 contains missing directory $$d))) 1.403 + $$(eval $$(call MakeDir,$$($1_BIN))) 1.404 + # Find all files in the source trees. 1.405 + $1_ALL_SRCS += $$(filter-out $(OVR_SRCS),$$(call CacheFind,$$($1_SRC))) 1.406 + # Extract the java files. 1.407 + ifneq ($$($1_EXCLUDE_FILES),) 1.408 + $1_EXCLUDE_FILES_PATTERN:=$$(addprefix %,$$($1_EXCLUDE_FILES)) 1.409 + endif 1.410 + $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$(filter %.java,$$($1_ALL_SRCS))) 1.411 + ifneq ($$($1_INCLUDE_FILES),) 1.412 + $1_INCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES))) 1.413 + $1_SRCS := $$(filter $$($1_INCLUDE_FILES), $$($1_SRCS)) 1.414 + endif 1.415 + 1.416 + # Now we have a list of all java files to compile: $$($1_SRCS) 1.417 + 1.418 + # Create the corresponding smart javac wrapper command line. 1.419 + $1_SJAVAC_ARGS:=$$(addprefix -x ,$$(addsuffix .*,$$(subst /,.,$$($1_EXCLUDES)))) \ 1.420 + $$(addprefix -i ,$$(addsuffix .*,$$(subst /,.,$$($1_INCLUDES)))) \ 1.421 + $$(addprefix -xf *,$$(strip $$($1_EXCLUDE_FILES))) \ 1.422 + $$(addprefix -if *,$$(strip $$($1_INCLUDE_FILES))) \ 1.423 + -src "$$(subst $$(SPACE),$$(PATH_SEP),$$(strip $$($1_SRC)))" 1.424 + 1.425 + # Prepend the source/bin path to the filter expressions. 1.426 + ifneq ($$($1_INCLUDES),) 1.427 + $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES)))) 1.428 + $1_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS)) 1.429 + endif 1.430 + ifneq ($$($1_EXCLUDES),) 1.431 + $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES)))) 1.432 + $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS)) 1.433 + endif 1.434 + 1.435 + # Find all files to be copied from source to bin. 1.436 + ifneq (,$$($1_COPY)) 1.437 + # Search for all files to be copied. 1.438 + $1_ALL_COPIES := $$(filter $$(addprefix %,$$($1_COPY)),$$($1_ALL_SRCS)) 1.439 + # Copy these explicitly 1.440 + $1_ALL_COPIES += $$($1_COPY_FILES) 1.441 + # Copy must also respect filters. 1.442 + ifneq (,$$($1_INCLUDES)) 1.443 + $1_ALL_COPIES := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_COPIES)) 1.444 + endif 1.445 + ifneq (,$$($1_EXCLUDES)) 1.446 + $1_ALL_COPIES := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_COPIES)) 1.447 + endif 1.448 + ifneq (,$$($1_EXCLUDE_FILES)) 1.449 + $1_ALL_COPIES := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_COPIES)) 1.450 + endif 1.451 + # All files below META-INF are always copied. 1.452 + $1_ALL_COPIES += $$(filter $$(addsuffix /META-INF%,$$($1_SRC)),$$($1_ALL_SRCS)) 1.453 + ifneq (,$$($1_ALL_COPIES)) 1.454 + # Yep, there are files to be copied! 1.455 + $1_ALL_COPY_TARGETS:= 1.456 + $$(foreach i,$$($1_ALL_COPIES),$$(eval $$(call add_file_to_copy,$1,$$i))) 1.457 + # Now we can depend on $$($1_ALL_COPY_TARGETS) to copy all files! 1.458 + endif 1.459 + endif 1.460 + 1.461 + # Find all property files to be copied and cleaned from source to bin. 1.462 + ifneq (,$$($1_CLEAN)) 1.463 + # Search for all files to be copied. 1.464 + $1_ALL_CLEANS := $$(filter $$(addprefix %,$$($1_CLEAN)),$$($1_ALL_SRCS)) 1.465 + # Copy and clean must also respect filters. 1.466 + ifneq (,$$($1_INCLUDES)) 1.467 + $1_ALL_CLEANS := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_CLEANS)) 1.468 + endif 1.469 + ifneq (,$$($1_EXCLUDES)) 1.470 + $1_ALL_CLEANS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_CLEANS)) 1.471 + endif 1.472 + ifneq (,$$($1_EXCLUDE_FILES)) 1.473 + $1_ALL_CLEANS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_CLEANS)) 1.474 + endif 1.475 + ifneq (,$$($1_ALL_CLEANS)) 1.476 + # Yep, there are files to be copied and cleaned! 1.477 + $1_ALL_COPY_CLEAN_TARGETS:= 1.478 + $$(foreach i,$$($1_ALL_CLEANS),$$(eval $$(call add_file_to_copy_and_clean,$1,$$i))) 1.479 + # Now we can depend on $$($1_ALL_COPY_CLEAN_TARGETS) to copy all files! 1.480 + endif 1.481 + endif 1.482 + 1.483 + # Prep the source paths. 1.484 + ifneq ($$($1_JAVAC_SOURCE_PATH_OVERRIDE),) 1.485 + $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_JAVAC_SOURCE_PATH_OVERRIDE))) 1.486 + else 1.487 + $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_SRC))) 1.488 + endif 1.489 + 1.490 + # Create a sed expression to remove the source roots and to replace / with . 1.491 + # and remove .java at the end. 1.492 + $1_REWRITE_INTO_CLASSES:=$$(foreach i,$$($1_SRC),-e 's|$$i/||g') -e 's|/|.|g' -e 's|.java$$$$||g' 1.493 + 1.494 + ifeq ($$($1_DISABLE_SJAVAC)x$$(ENABLE_SJAVAC),xyes) 1.495 + ifneq (,$$($1_HEADERS)) 1.496 + $1_HEADERS_ARG := -h $$($1_HEADERS) 1.497 + endif 1.498 + 1.499 + # Using sjavac to compile. 1.500 + $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_BIN)/javac_state 1.501 + 1.502 + # Create SJAVAC variable form JAVAC variable. Expects $1_JAVAC to be 1.503 + # "bootclasspathprepend -cp .../javac.jar com.sun.tools.javac.Main" 1.504 + # and javac is simply replaced with sjavac. 1.505 + $1_SJAVAC:=$$(subst com.sun.tools.javac.Main,com.sun.tools.sjavac.Main,$$($1_JAVAC)) 1.506 + 1.507 + # Set the $1_REMOTE to spawn a background javac server. 1.508 + $1_REMOTE:=--server:portfile=$$($1_SJAVAC_PORTFILE),id=$1,sjavac=$$(subst $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_SJAVAC)))) 1.509 + 1.510 + $$($1_BIN)/javac_state: $$($1_SRCS) $$($1_DEPENDS) 1.511 + $(MKDIR) -p $$(@D) 1.512 + $$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.$1_batch.tmp) 1.513 + $(ECHO) Compiling $1 1.514 + ($$($1_JVM) $$($1_SJAVAC) \ 1.515 + $$($1_REMOTE) \ 1.516 + -j $(JOBS) \ 1.517 + --permit-unidentified-artifacts \ 1.518 + --permit-sources-without-package \ 1.519 + --compare-found-sources $$($1_BIN)/_the.$1_batch.tmp \ 1.520 + --log=$(LOG_LEVEL) \ 1.521 + $$($1_SJAVAC_ARGS) \ 1.522 + $$($1_FLAGS) \ 1.523 + $$($1_HEADERS_ARG) \ 1.524 + -d $$($1_BIN) && \ 1.525 + $(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch) 1.526 + else 1.527 + # Using plain javac to batch compile everything. 1.528 + $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_BIN)/_the.$1_batch 1.529 + 1.530 + # When building in batch, put headers in a temp dir to filter out those that actually 1.531 + # changed before copying them to the real header dir. 1.532 + ifneq (,$$($1_HEADERS)) 1.533 + $1_HEADERS_ARG := -h $$($1_HEADERS).tmp 1.534 + 1.535 + $$($1_HEADERS)/_the.$1_headers: $$($1_BIN)/_the.$1_batch 1.536 + $(MKDIR) -p $$(@D) 1.537 + for f in `ls $$($1_HEADERS).tmp`; do \ 1.538 + if [ ! -f "$$($1_HEADERS)/$$$$f" ] || [ "`$(DIFF) $$($1_HEADERS)/$$$$f $$($1_HEADERS).tmp/$$$$f`" != "" ]; then \ 1.539 + $(CP) -f $$($1_HEADERS).tmp/$$$$f $$($1_HEADERS)/$$$$f; \ 1.540 + fi; \ 1.541 + done 1.542 + $(RM) -r $$($1_HEADERS).tmp 1.543 + $(TOUCH) $$@ 1.544 + 1.545 + $1 += $$($1_HEADERS)/_the.$1_headers 1.546 + endif 1.547 + 1.548 + # When not using sjavac, pass along all sources to javac using an @file. 1.549 + $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS) 1.550 + $(MKDIR) -p $$(@D) 1.551 + $(RM) $$($1_BIN)/_the.$1_batch $$($1_BIN)/_the.$1_batch.tmp 1.552 + $$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.$1_batch.tmp) 1.553 + $(ECHO) Compiling `$(WC) $$($1_BIN)/_the.$1_batch.tmp | $(TR) -s ' ' | $(CUT) -f 2 -d ' '` files for $1 1.554 + ($$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) \ 1.555 + -implicit:none -sourcepath "$$($1_SRCROOTSC)" \ 1.556 + -d $$($1_BIN) $$($1_HEADERS_ARG) @$$($1_BIN)/_the.$1_batch.tmp && \ 1.557 + $(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch) 1.558 + 1.559 + endif 1.560 + 1.561 + # Check if a jar file was specified, then setup the rules for the jar. 1.562 + ifneq (,$$($1_JAR)) 1.563 + # If no suffixes was explicitly set for this jar file. 1.564 + # Use class and the cleaned/copied properties file suffixes as the default 1.565 + # for the types of files to be put into the jar. 1.566 + ifeq (,$$($1_SUFFIXES)) 1.567 + $1_SUFFIXES:=.class $$($1_CLEAN) $$($1_COPY) 1.568 + endif 1.569 + 1.570 + $$(eval $$(call SetupArchive,ARCHIVE_$1,$$($1), \ 1.571 + SRCS:=$$($1_BIN), \ 1.572 + SUFFIXES:=$$($1_SUFFIXES), \ 1.573 + EXCLUDE:=$$($1_EXCLUDES), \ 1.574 + INCLUDES:=$$($1_INCLUDES), \ 1.575 + EXTRA_FILES:=$$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS), \ 1.576 + JAR:=$$($1_JAR), \ 1.577 + JARMAIN:=$$($1_JARMAIN), \ 1.578 + MANIFEST:=$$($1_MANIFEST), \ 1.579 + EXTRA_MANIFEST_ATTR:=$$($1_EXTRA_MANIFEST_ATTR), \ 1.580 + JARINDEX:=$$($1_JARINDEX), \ 1.581 + HEADERS:=$$($1_HEADERS), \ 1.582 + SETUP:=$$($1_SETUP))) 1.583 + endif 1.584 + 1.585 + # Check if a srczip was specified, then setup the rules for the srczip. 1.586 + ifneq (,$$($1_SRCZIP)) 1.587 + $$(eval $$(call SetupZipArchive,ARCHIVE_$1, \ 1.588 + SRC:=$$($1_SRC), \ 1.589 + ZIP:=$$($1_SRCZIP), \ 1.590 + INCLUDES:=$$($1_INCLUDES), \ 1.591 + EXCLUDES:=$$($1_EXCLUDES), \ 1.592 + EXCLUDE_FILES:=$$($1_EXCLUDE_FILES))) 1.593 + endif 1.594 + 1.595 +endef