1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/common/makefiles/JavaCompilation.gmk Tue Apr 10 08:18:28 2012 -0700 1.3 @@ -0,0 +1,887 @@ 1.4 +# 1.5 +# Copyright (c) 2011, 2012, 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 +# The complexity of this makefile is not the fault of make, but the fault 1.30 +# of javac and javah. The basic problems are: 1.31 +# 1.32 +# 1) Compiling a single Java source file unpredictably generates anything 1.33 +# between zero (0!) and an infinite number of .class files! 1.34 +# 2) There is no hint, for which classes javah needs to be run, 1.35 +# and it happily generates .h files for classes with no native methods. 1.36 +# 3) javac and javah do not cleanup anything, for example if an internal 1.37 +# class (potentially with native methods) is removed from a Java source file. 1.38 +# 1.39 +# This makefile is a tribute to GNU make. And yes, it was harder to write than it is 1.40 +# to read. The include/excludes of directories and files are only a temporary measure 1.41 +# to work around the messy jdk sources that put platform specific code in src/share/classes. 1.42 +# 1.43 +# We should move most of the functionality of this makefile into a 1.44 +# smart javac/javah/javadoc/jar combo tool. sjavac ? 1.45 +# 1.46 +# I.e. 1) It always generates a single output, a zip-file from a number of source roots. 1.47 +# The zip file contains information that enable incremental builds with full 1.48 +# dependency tracking between packages. 1.49 +# 2) It automatically generates the right .h files. 1.50 +# 3) It keeps its house clean. 1.51 +# *) Generates intermediate files to be used for javadoc generation later. 1.52 +# and does all the other useful things that this makefile does, such as: 1.53 +# use all cores for compilation, reuse the running JVM for all compilations, 1.54 +# and has pubapi dependency tracking to minimize the number of files 1.55 +# that need to be recompiled during an incremental build. 1.56 +# 1.57 +# A zip file, or several zip files combined, can then be converted to a .jar file, or to a .jmod file. 1.58 +# 1.59 +# This would make this makefile much much simpler. I.e. make can be used 1.60 +# for its real purpose, track dependencies and trigger a recompile if a 1.61 +# dependency has changed. 1.62 +# 1.63 +# When you read this source. Remember that $(sort ...) has the side effect 1.64 +# of removing duplicates. It is actually this side effect that is 1.65 +# desired whenever sort is used below! 1.66 + 1.67 +ifeq (,$(_MAKEBASE_GMK)) 1.68 + $(error You must include MakeBase.gmk prior to including JavaCompilation.gmk) 1.69 +endif 1.70 + 1.71 +FALSE_FIND_PATTERN:=-name FILE_NAME_THAT_DOESNT_EXIST 1.72 + 1.73 +# If compilation of java package fails, then the public api file for that 1.74 +# package will not be genereated. We add this fallback rule to generate 1.75 +# an empty pubapi file. 1.76 +%.api: 1.77 + if test ! -f $@; then $(MKDIR) -p $(@D); $(TOUCH) $@; fi 1.78 + 1.79 +define SetupJavaCompiler 1.80 + # param 1 is for example BOOT_JAVAC or NEW_JAVAC 1.81 + # This is the name later used to decide which java compiler to use. 1.82 + # param 2-9 are named args. 1.83 + # JVM:=The jvm used to run the javac/javah command 1.84 + # JAVAC:=The javac jar and bootstrap classpath changes, or just bin/javac if JVM is left out 1.85 + # JAVAH:=The javah jar and bootstrap classpath changes, or just bin/javah if JVM is left out 1.86 + # FLAGS:=Flags to be supplied to javac 1.87 + # MODE:=SINGLE_THREADED_BATCH (primarily for old javac) or MULTI_CORE_CONCURRENT 1.88 + # only for MULTI_CORE_CONCURRENT are the options below relevant: 1.89 + # SERVER_DIR:=Use a javac server (-XDserver) and store the server related files here 1.90 + # SERVER_JVM:=Use this JVM for the server. Defaults to the JVM above. 1.91 + # USE_DEPS:=true means use -XDdeps,-XDpubapi and -XDnativeapi to track java dependencies 1.92 + $(if $2,$1_$(strip $2)) 1.93 + $(if $3,$1_$(strip $3)) 1.94 + $(if $4,$1_$(strip $4)) 1.95 + $(if $5,$1_$(strip $5)) 1.96 + $(if $6,$1_$(strip $6)) 1.97 + $(if $7,$1_$(strip $7)) 1.98 + $(if $8,$1_$(strip $8)) 1.99 + $(if $9,$1_$(strip $9)) 1.100 + 1.101 + ifeq ($$($1_MODE),MULTI_CORE_CONCURRENT) 1.102 + ifneq (,$$($1_SERVER_DIR)) 1.103 + # A javac server has been requested. 1.104 + # The port file contains the tcp/ip on which the server listens 1.105 + # and the cookie necessary to talk to the server. 1.106 + $1_JAVAC_PORTFILE:=$$($1_SERVER_DIR)/$1.port 1.107 + ifeq ($$($1_SERVER_JVM),) 1.108 + # You can use a different JVM to run the background javac server. 1.109 + # But if not set, it defaults to the same JVM that is used to start 1.110 + # the javac command. 1.111 + $1_SERVER_JVM:=$$($1_JVM) 1.112 + endif 1.113 + # Set the $1_REMOTE to spawn a background javac server. 1.114 + $1_REMOTE:=-XDserver:portfile=$$($1_JAVAC_PORTFILE),poolsize=$(JAVAC_SERVER_CORES),javac=$$(subst $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_JAVAC)))) 1.115 + endif 1.116 + endif 1.117 +endef 1.118 + 1.119 +define SetupArchive 1.120 + # param 1 is for example ARCHIVE_MYPACKAGE 1.121 + # param 2 are the dependecies 1.122 + # param 3,4,5,6,7,8,9 are named args. 1.123 + # SRCS:=List of directories in where to find files to add to archive 1.124 + # SUFFIXES:=File suffixes to include in jar 1.125 + # INCLUDES:=List of directories/packages in SRCS that should be included 1.126 + # EXCLUDES:=List of directories/packages in SRCS that should be excluded 1.127 + # EXCLUDE_FILES:=List of files in SRCS that should be excluded 1.128 + # EXTRA_FILES:=List of files in SRCS that should be included regardless of suffix match. 1.129 + # JAR:=Jar file to create 1.130 + # MANIFEST:=Optional manifest file template. 1.131 + # JARMAIN:=Optional main class to add to manifest 1.132 + # SETUP:=The Java(h) compiler setup, needed to run javah. 1.133 + # HEADERS:=Directory to put headers in 1.134 + # SKIP_METAINF:=Set to prevent contents of an META-INF directory to be automatically 1.135 + # added to the archive. 1.136 + # EXTRA_MANIFEST_ATTR:=Extra attribute to add to manifest. 1.137 + $(if $3,$1_$(strip $3)) 1.138 + $(if $4,$1_$(strip $4)) 1.139 + $(if $5,$1_$(strip $5)) 1.140 + $(if $6,$1_$(strip $6)) 1.141 + $(if $7,$1_$(strip $7)) 1.142 + $(if $8,$1_$(strip $8)) 1.143 + $(if $9,$1_$(strip $9)) 1.144 + $(if $(10),$1_$(strip $(10))) 1.145 + $(if $(11),$1_$(strip $(11))) 1.146 + $(if $(12),$1_$(strip $(12))) 1.147 + $(if $(13),$1_$(strip $(13))) 1.148 + $(if $(14),$1_$(strip $(14))) 1.149 + 1.150 + $1_JVM := $$($$($1_SETUP)_JVM) 1.151 + $1_JAVAH := $$($$($1_SETUP)_JAVAH) 1.152 + $1_JARMAIN:=$(strip $$($1_JARMAIN)) 1.153 + $1_JARNAME:=$$(notdir $$($1_JAR)) 1.154 + $1_MANIFEST_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_manifest 1.155 + $1_DELETESS_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletess 1.156 + $1_DELETES_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletes 1.157 + $1_PUBAPI_NOTIFICATIONS_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_pubapi_notifications 1.158 + $1_NATIVEAPI_NOTIFICATIONS_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_native_notifications 1.159 + $1_NATIVEAPI_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_native 1.160 + $1_BIN:=$$(dir $$($1_JAR)) 1.161 + ifeq (,$$($1_SUFFIXES)) 1.162 + # No suffix was set, default to classes. 1.163 + $1_SUFFIXES:=.class 1.164 + endif 1.165 + # Convert suffixes to a find expression 1.166 + $1_FIND_PATTERNS:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_SUFFIXES)) 1.167 + ifneq (,$$($1_INCLUDES)) 1.168 + $1_GREP_INCLUDES:=| $(GREP) $$(foreach src,$$($1_SRCS),$$(addprefix -e$(SPACE)$$(src)/,$$($1_INCLUDES))) 1.169 + endif 1.170 + ifneq (,$$($1_EXCLUDES)$$($1_EXCLUDE_FILES)) 1.171 + $1_GREP_EXCLUDES:=| $(GREP) -v $$(foreach src,$$($1_SRCS),$$(addprefix -e$(SPACE)$$(src)/,$$($1_EXCLUDES) $$($1_EXCLUDE_FILES))) 1.172 + endif 1.173 + 1.174 + # Utility macros, to make the shell script receipt somewhat easier to dechipher. 1.175 + 1.176 + # The capture contents macro finds all files (matching the patterns, typically 1.177 + # .class and .prp) that are newer than the jar-file, ie the new content to be put into the jar. 1.178 + $1_CAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS),(($(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) -a -newer $$@ $$($1_GREP_INCLUDES) $$($1_GREP_EXCLUDES) && $(ECHO) $$($1_EXTRA_FILES)) | $(SED) 's|$$(src)/||g' > $$(src)/_the.$$($1_JARNAME)_contents) && ) 1.179 + # The capture metainf macro finds all files below the META-INF directory that are newer than the jar-file. 1.180 + ifeq (,$$($1_SKIP_METAINF)) 1.181 + $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 ) && ) 1.182 + endif 1.183 + # The capture deletes macro finds all deleted files and concatenates them. The resulting file 1.184 + # tells us what to remove from the jar-file. 1.185 + $1_CAPTURE_DELETES=$$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.deleted -newer $$@ -exec $(SED) 's|$$(src)||g' \{\} >> $$($1_DELETES_FILE) \;) &&) 1.186 + # The capture pubapi notifications scans for pubapi change notifications. If such notifications are 1.187 + # found, then we will build the classes leading up to the jar again, to take into account the new timestamps 1.188 + # on the changed pubapi files. 1.189 + $1_CAPTURE_PUBAPI_NOTIFICATIONS=$$(foreach src,$$($1_SRCS),\ 1.190 + (cd $$(src) && \ 1.191 + $(FIND) . -name _the.package.api.notify -exec dirname \{\} \; >> $$($1_PUBAPI_NOTIFICATIONS_FILE) ; \ 1.192 + true) &&) 1.193 + # The capture nativeapi macro scans for native api change notificiations. If such notifications are 1.194 + # found, then we will run javah on the changed classes. It also collects all classes with native methods 1.195 + # to be used to find out which classes no longer has native methods, to trigger deletion of those .h files. 1.196 + $1_CAPTURE_NATIVEAPI=$$(foreach src,$$($1_SRCS),\ 1.197 + (cd $$(src) && \ 1.198 + $(FIND) . -name _the.package.native.notify | $(SED) 's/package.native.notify/package.native/' | \ 1.199 + $(XARGS) $(CAT) | $(GREP) '^TYPE ' | $(SED) 's/.*TYPE //' >> $$($1_NATIVEAPI_NOTIFICATIONS_FILE) ; \ 1.200 + $(FIND) . -name _the.package.native -exec $(CAT) \{\} \; | $(SED) -n 's/^TYPE //p' >> $$($1_NATIVEAPI_FILE) ; \ 1.201 + true) &&) 1.202 + # The update contents macro updates the jar file with the previously capture contents. 1.203 + $1_UPDATE_CONTENTS=$$(foreach src,$$($1_SRCS),\ 1.204 + (cd $$(src) && \ 1.205 + if [ -s _the.$$($1_JARNAME)_contents ]; then \ 1.206 + $(ECHO) " updating" `$(WC) -l _the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'` files && \ 1.207 + $(JAR) uf $$@ @_the.$$($1_JARNAME)_contents; \ 1.208 + fi) &&) 1.209 + # The s-variants of the above macros are used when the jar is created from scratch. 1.210 + $1_SCAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS),\ 1.211 + (($(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) $$($1_GREP_INCLUDES) $$($1_GREP_EXCLUDES) && $(ECHO) $$($1_EXTRA_FILES)) | $(SED) 's|$$(src)/||g' > $$(src)/_the.$$($1_JARNAME)_contents) && ) 1.212 + ifeq (,$$($1_SKIP_METAINF)) 1.213 + $1_SCAPTURE_METAINF=$$(foreach src,$$($1_SRCS),\ 1.214 + ($(FIND) $$(src)/META-INF -type f 2> /dev/null | $(SED) 's|$$(src)/||g' >> $$(src)/_the.$$($1_JARNAME)_contents) && ) 1.215 + endif 1.216 + $1_SUPDATE_CONTENTS=$$(foreach src,$$($1_SRCS),\ 1.217 + (cd $$(src) && $(JAR) uf $$@ @$$(src)/_the.$$($1_JARNAME)_contents) &&) 1.218 + # The TOUCH macro is used to make sure all timestamps are identical for package files and the pubapi files. 1.219 + # If we do not do this, we get random recompilations, the next time we run make, since the order of package building is random, 1.220 + # ie independent of package --dependes on-> public api of another package. This is of course 1.221 + # due to the fact that Java source often (always?) has circular dependencies. (Thus there is no correct order 1.222 + # to compile packages, and we can just as well do them in a random order. Which we do.) 1.223 + $1_TOUCH_API_FILES=$$(foreach src,$$($1_SRCS),\ 1.224 + ($(FIND) $$(src) -name _the.package.api -exec $(TOUCH) -r $$($1_JAR) \{\} \; ; true) && \ 1.225 + ($(FIND) $$(src) -name _the.package -exec $(TOUCH) -r $$($1_JAR) \{\} \; ; true) &&) 1.226 + # Use a slightly shorter name for logging, but with enough path to identify this jar. 1.227 + $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_JAR)) 1.228 + # Here is the rule that creates/updates the jar file. 1.229 + $$($1_JAR) : $2 1.230 + $(MKDIR) -p $$($1_BIN) 1.231 + if [ -n "$$($1_MANIFEST)" ]; then \ 1.232 + $(SED) -e "s#@@RELEASE@@#$(RELEASE)#" \ 1.233 + -e "s#@@COMPANY_NAME@@#$(COMPANY_NAME)#" $$($1_MANIFEST) > $$($1_MANIFEST_FILE); \ 1.234 + else \ 1.235 + $(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE); \ 1.236 + fi 1.237 + $(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE) 1.238 + if [ -n "$$($1_EXTRA_MANIFEST_ATTR)" ]; then \ 1.239 + $(ECHO) "$$($1_EXTRA_MANIFEST_ATTR)" >> $$($1_MANIFEST_FILE); \ 1.240 + fi 1.241 + +if [ -s $$@ ]; then \ 1.242 + $(RM) -r $$($1_PUBAPI_NOTIFICATIONS_FILE) && \ 1.243 + $$($1_CAPTURE_PUBAPI_NOTIFICATIONS) \ 1.244 + if [ -s $$($1_PUBAPI_NOTIFICATIONS_FILE) ]; then \ 1.245 + $(ECHO) Public api change detected in: && \ 1.246 + $(CAT) $$($1_PUBAPI_NOTIFICATIONS_FILE) | $(TR) '/' '.' | $(SED) 's|^..||g' | $(SED) 's|\.$$$$||g' | $(AWK) '{print " "$$$$1}' && \ 1.247 + $$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.api.notify $(FIND_DELETE); true) &&) \ 1.248 + $(MAKE) -f $(word 1,$(MAKEFILE_LIST)) $$($1_JAR) ; \ 1.249 + else \ 1.250 + $(ECHO) Modifying $$($1_NAME) && \ 1.251 + $$($1_CAPTURE_CONTENTS) \ 1.252 + $$($1_CAPTURE_METAINF) \ 1.253 + $(RM) $$($1_DELETES_FILE) && \ 1.254 + $$($1_CAPTURE_DELETES) \ 1.255 + $(CAT) $$($1_DELETES_FILE) > $$($1_DELETESS_FILE) && \ 1.256 + if [ -s $$($1_DELETESS_FILE) ]; then \ 1.257 + $(ECHO) " deleting" `$(WC) -l $$($1_DELETESS_FILE) | $(AWK) '{ print $$$$1 }'` files && \ 1.258 + $(ZIP) -q -d $$@ `$(CAT) $$($1_DELETESS_FILE)` ; \ 1.259 + fi && \ 1.260 + $$($1_UPDATE_CONTENTS) true && \ 1.261 + $$($1_TOUCH_API_FILES) true && \ 1.262 + $(RM) -r $$($1_NATIVEAPI_NOTIFICATIONS_FILE) $$($1_NATIVEAPI_FILE) && \ 1.263 + $$($1_CAPTURE_NATIVEAPI) true && \ 1.264 + if [ "x$$($1_JAVAH)" != "x" ] && [ -s $$($1_NATIVEAPI_NOTIFICATIONS_FILE) ]; then \ 1.265 + $(ECHO) Native api change detected in: && $(CAT) $$($1_NATIVEAPI_NOTIFICATIONS_FILE) && \ 1.266 + $$($1_JVM) $$($1_JAVAH) "-Xbootclasspath/p:$$($1_JAR)" -d $$($1_HEADERS) @$$($1_NATIVEAPI_NOTIFICATIONS_FILE) ; \ 1.267 + fi && \ 1.268 + $(TOUCH) $$($1_NATIVEAPI_FILE)_prev ; \ 1.269 + ($(GREP) -xvf $$($1_NATIVEAPI_FILE) $$($1_NATIVEAPI_FILE)_prev > $$($1_NATIVEAPI_FILE)_deleted; true) && \ 1.270 + $(CP) $$($1_NATIVEAPI_FILE) $$($1_NATIVEAPI_FILE)_prev && \ 1.271 + if [ -s $$($1_NATIVEAPI_FILE)_deleted ]; then \ 1.272 + $(ECHO) Native methods dropped from classes: && $(CAT) $$($1_NATIVEAPI_FILE)_deleted && \ 1.273 + $(RM) `$(CAT) $$($1_NATIVEAPI_FILE)_deleted | $(SED) -e 's|\.|_|g' -e 's|.*|$$($1_HEADERS)/&.h $$($1_HEADERS)/&_*|'` ; \ 1.274 + fi && \ 1.275 + $$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.api.notify $(FIND_DELETE); true) &&) true ; \ 1.276 + fi ; \ 1.277 + else \ 1.278 + $(ECHO) Creating $$($1_NAME) && $(JAR) cfm $$@ $$($1_MANIFEST_FILE) && \ 1.279 + $$($1_SCAPTURE_CONTENTS) \ 1.280 + $$($1_SCAPTURE_METAINF) \ 1.281 + $$($1_SUPDATE_CONTENTS) \ 1.282 + $$($1_TOUCH_API_FILES) true && \ 1.283 + $(RM) -r $$($1_NATIVEAPI_NOTIFICATIONS_FILE) $$($1_NATIVEAPI_FILE) && \ 1.284 + $$($1_CAPTURE_NATIVEAPI) true && \ 1.285 + if [ "x$$($1_JAVAH)" != "x" ] && [ -s $$($1_NATIVEAPI_FILE) ]; then \ 1.286 + $(ECHO) Generating native api headers for `$(CAT) $$($1_NATIVEAPI_FILE) | $(WC) -l` classes && \ 1.287 + $(RM) $$($1_HEADERS)/*.h && \ 1.288 + $$($1_JVM) $$($1_JAVAH) "-Xbootclasspath/p:$$($1_JAR)" -d $$($1_HEADERS) @$$($1_NATIVEAPI_FILE) && \ 1.289 + $(CP) $$($1_NATIVEAPI_FILE) $$($1_NATIVEAPI_FILE)_prev ; \ 1.290 + fi && \ 1.291 + $$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name "*.notify" $(FIND_DELETE); true) &&) true ; \ 1.292 + fi; 1.293 + 1.294 +endef 1.295 + 1.296 +define append_to 1.297 + $(ECHO) "$1" >> $2 1.298 +endef 1.299 + 1.300 +define SetupZipArchive 1.301 + # param 1 is for example ZIP_MYSOURCE 1.302 + # param 2,3,4,5,6,7,8,9 are named args. 1.303 + # SRC,ZIP,INCLUDES,EXCLUDES,EXCLUDE_FILES 1.304 + $(if $2,$1_$(strip $2)) 1.305 + $(if $3,$1_$(strip $3)) 1.306 + $(if $4,$1_$(strip $4)) 1.307 + $(if $5,$1_$(strip $5)) 1.308 + $(if $6,$1_$(strip $6)) 1.309 + $(if $7,$1_$(strip $7)) 1.310 + $(if $8,$1_$(strip $8)) 1.311 + $(if $9,$1_$(strip $9)) 1.312 + 1.313 + # Find all files in the source tree. 1.314 + $1_ALL_SRCS := $$(foreach i,$$($1_SRC), $$(shell $(FIND) $$i -type f -a ! -name "_the.*")) 1.315 + 1.316 + ifneq ($$($1_INCLUDES),) 1.317 + $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES)))) 1.318 + $1_ZIP_INCLUDES := $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_INCLUDES))) 1.319 + $1_ALL_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_SRCS)) 1.320 + endif 1.321 + ifneq ($$($1_EXCLUDES),) 1.322 + $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES)))) 1.323 + $1_ZIP_EXCLUDES := $$(addprefix -x$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_EXCLUDES))) 1.324 + $1_ALL_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS)) 1.325 + endif 1.326 + 1.327 + # Use a slightly shorter name for logging, but with enough path to identify this zip. 1.328 + $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_ZIP)) 1.329 + 1.330 + # Now $1_ALL_SRCS should contain all sources that are going to be put into the zip. 1.331 + # I.e. the zip -i and -x options should match the filtering done in the makefile. 1.332 + # Explicitly excluded files can be given with absolute path. The patsubst solution 1.333 + # isn't perfect but the likelyhood of an absolute path to match something in a src 1.334 + # dir is very small. 1.335 + $$($1_ZIP) : $$($1_ALL_SRCS) 1.336 + $(MKDIR) -p $$(@D) 1.337 + $(ECHO) Updating $$($1_NAME) 1.338 + $$(foreach i,$$($1_SRC),(cd $$i && $(ZIP) -qru $$@ . $$($1_ZIP_INCLUDES) $$($1_ZIP_EXCLUDES) -x \*_the.\* $$(addprefix -x$(SPACE),$$(patsubst $$i/%,%,$$($1_EXCLUDE_FILES)))) ;) true 1.339 + $(TOUCH) $$@ 1.340 +endef 1.341 + 1.342 +define add_file_to_copy 1.343 + # param 1 = BUILD_MYPACKAGE 1.344 + # parma 2 = The source file to copy. 1.345 + $2_TARGET:=$2 1.346 + # Remove the source prefix. 1.347 + $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET))) 1.348 + # Now we can setup the depency that will trigger the copying. 1.349 + $$($1_BIN)$$($2_TARGET) : $2 1.350 + $(MKDIR) -p $$(@D) 1.351 + $(CP) $$< $$@ 1.352 + $(CHMOD) -f ug+w $$@ 1.353 + 1.354 + # And do not forget this target 1.355 + $1_ALL_COPY_TARGETS += $$($1_BIN)$$($2_TARGET) 1.356 +endef 1.357 + 1.358 + 1.359 +# This macro is used only for properties files that are to be 1.360 +# copied over to the classes directory in cleaned form: 1.361 +# Previously this was inconsistently done in different repositories. 1.362 +# This is the new clean standard. 1.363 +define add_file_to_copy_and_clean 1.364 + # param 1 = BUILD_MYPACKAGE 1.365 + # parma 2 = The source file to copy and clean. 1.366 + $2_TARGET:=$2 1.367 + # Remove the source prefix. 1.368 + $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET))) 1.369 + # Now we can setup the depency that will trigger the copying. 1.370 + $$($1_BIN)$$($2_TARGET) : $2 1.371 + $(MKDIR) -p $$(@D) 1.372 + $(ECHO) Cleaning $$($2_TARGET) 1.373 + $(CAT) $$< | $(SED) -e 's/\([^\\]\):/\1\\:/g' -e 's/\([^\\]\)=/\1\\=/g' -e 's/#.*/#/g' \ 1.374 + | $(SED) \ 1.375 +-e 's/\\u0020/\x20/g' \ 1.376 +-e 's/\\u003A/\x3A/g' \ 1.377 +-e 's/\\u006B/\x6B/g' \ 1.378 +-e 's/\\u0075/\x75/g' \ 1.379 +-e 's/\\u00A0/\xA0/g' \ 1.380 +-e 's/\\u00A3/\xA3/g' \ 1.381 +-e 's/\\u00B0/\xB0/g' \ 1.382 +-e 's/\\u00B7/\xB7/g' \ 1.383 +-e 's/\\u00BA/\xBA/g' \ 1.384 +-e 's/\\u00BF/\xBF/g' \ 1.385 +-e 's/\\u00C0/\xC0/g' \ 1.386 +-e 's/\\u00C1/\xC1/g' \ 1.387 +-e 's/\\u00C2/\xC2/g' \ 1.388 +-e 's/\\u00C4/\xC4/g' \ 1.389 +-e 's/\\u00C5/\xC5/g' \ 1.390 +-e 's/\\u00C8/\xC8/g' \ 1.391 +-e 's/\\u00C9/\xC9/g' \ 1.392 +-e 's/\\u00CA/\xCA/g' \ 1.393 +-e 's/\\u00CD/\xCD/g' \ 1.394 +-e 's/\\u00CE/\xCE/g' \ 1.395 +-e 's/\\u00D3/\xD3/g' \ 1.396 +-e 's/\\u00D4/\xD4/g' \ 1.397 +-e 's/\\u00D6/\xD6/g' \ 1.398 +-e 's/\\u00DA/\xDA/g' \ 1.399 +-e 's/\\u00DC/\xDC/g' \ 1.400 +-e 's/\\u00DD/\xDD/g' \ 1.401 +-e 's/\\u00DF/\xDF/g' \ 1.402 +-e 's/\\u00E0/\xE0/g' \ 1.403 +-e 's/\\u00E1/\xE1/g' \ 1.404 +-e 's/\\u00E2/\xE2/g' \ 1.405 +-e 's/\\u00E3/\xE3/g' \ 1.406 +-e 's/\\u00E4/\xE4/g' \ 1.407 +-e 's/\\u00E5/\xE5/g' \ 1.408 +-e 's/\\u00E6/\xE6/g' \ 1.409 +-e 's/\\u00E7/\xE7/g' \ 1.410 +-e 's/\\u00E8/\xE8/g' \ 1.411 +-e 's/\\u00E9/\xE9/g' \ 1.412 +-e 's/\\u00EA/\xEA/g' \ 1.413 +-e 's/\\u00EB/\xEB/g' \ 1.414 +-e 's/\\u00EC/\xEC/g' \ 1.415 +-e 's/\\u00ED/\xED/g' \ 1.416 +-e 's/\\u00EE/\xEE/g' \ 1.417 +-e 's/\\u00EF/\xEF/g' \ 1.418 +-e 's/\\u00F1/\xF1/g' \ 1.419 +-e 's/\\u00F2/\xF2/g' \ 1.420 +-e 's/\\u00F3/\xF3/g' \ 1.421 +-e 's/\\u00F4/\xF4/g' \ 1.422 +-e 's/\\u00F5/\xF5/g' \ 1.423 +-e 's/\\u00F6/\xF6/g' \ 1.424 +-e 's/\\u00F9/\xF9/g' \ 1.425 +-e 's/\\u00FA/\xFA/g' \ 1.426 +-e 's/\\u00FC/\xFC/g' \ 1.427 +-e 's/\\u0020/\x20/g' \ 1.428 +-e 's/\\u003f/\x3f/g' \ 1.429 +-e 's/\\u006f/\x6f/g' \ 1.430 +-e 's/\\u0075/\x75/g' \ 1.431 +-e 's/\\u00a0/\xa0/g' \ 1.432 +-e 's/\\u00a3/\xa3/g' \ 1.433 +-e 's/\\u00b0/\xb0/g' \ 1.434 +-e 's/\\u00ba/\xba/g' \ 1.435 +-e 's/\\u00bf/\xbf/g' \ 1.436 +-e 's/\\u00c1/\xc1/g' \ 1.437 +-e 's/\\u00c4/\xc4/g' \ 1.438 +-e 's/\\u00c5/\xc5/g' \ 1.439 +-e 's/\\u00c8/\xc8/g' \ 1.440 +-e 's/\\u00c9/\xc9/g' \ 1.441 +-e 's/\\u00ca/\xca/g' \ 1.442 +-e 's/\\u00cd/\xcd/g' \ 1.443 +-e 's/\\u00d6/\xd6/g' \ 1.444 +-e 's/\\u00dc/\xdc/g' \ 1.445 +-e 's/\\u00dd/\xdd/g' \ 1.446 +-e 's/\\u00df/\xdf/g' \ 1.447 +-e 's/\\u00e0/\xe0/g' \ 1.448 +-e 's/\\u00e1/\xe1/g' \ 1.449 +-e 's/\\u00e2/\xe2/g' \ 1.450 +-e 's/\\u00e3/\xe3/g' \ 1.451 +-e 's/\\u00e4/\xe4/g' \ 1.452 +-e 's/\\u00e5/\xe5/g' \ 1.453 +-e 's/\\u00e7/\xe7/g' \ 1.454 +-e 's/\\u00e8/\xe8/g' \ 1.455 +-e 's/\\u00e9/\xe9/g' \ 1.456 +-e 's/\\u00ea/\xea/g' \ 1.457 +-e 's/\\u00eb/\xeb/g' \ 1.458 +-e 's/\\u00ec/\xec/g' \ 1.459 +-e 's/\\u00ed/\xed/g' \ 1.460 +-e 's/\\u00ee/\xee/g' \ 1.461 +-e 's/\\u00ef/\xef/g' \ 1.462 +-e 's/\\u00f0/\xf0/g' \ 1.463 +-e 's/\\u00f1/\xf1/g' \ 1.464 +-e 's/\\u00f2/\xf2/g' \ 1.465 +-e 's/\\u00f3/\xf3/g' \ 1.466 +-e 's/\\u00f4/\xf4/g' \ 1.467 +-e 's/\\u00f5/\xf5/g' \ 1.468 +-e 's/\\u00f6/\xf6/g' \ 1.469 +-e 's/\\u00f7/\xf7/g' \ 1.470 +-e 's/\\u00f8/\xf8/g' \ 1.471 +-e 's/\\u00f9/\xf9/g' \ 1.472 +-e 's/\\u00fa/\xfa/g' \ 1.473 +-e 's/\\u00fc/\xfc/g' \ 1.474 +-e 's/\\u00ff/\xff/g' \ 1.475 + | $(SED) -e '/^#/d' -e '/^$$$$/d' \ 1.476 + -e :a -e '/\\$$$$/N; s/\\\n//; ta' \ 1.477 + -e 's/^[ \t]*//;s/[ \t]*$$$$//' \ 1.478 + -e 's/\\=/=/' | LANG=C sort > $$@ 1.479 + $(CHMOD) -f ug+w $$@ 1.480 + 1.481 + # And do not forget this target 1.482 + $1_ALL_COPY_CLEAN_TARGETS += $$($1_BIN)$$($2_TARGET) 1.483 +endef 1.484 + 1.485 +define add_java_package 1.486 + # param 1 = BUILD_MYPACKAGE 1.487 + # param 2 = the package target file (_the.package) 1.488 + # param 3 = src roots, all of them, separated with space 1.489 + # param 4 = bin root 1.490 + # param 5 = include these dependecies 1.491 + # param 6 = not used 1.492 + # param 7 = if non-empty, then use -Xdeps and -Xpubapi 1.493 + # param 8 = xremote configuration, or empty. 1.494 + # param 9 = javac command 1.495 + # param 10 = javac flags 1.496 + # param 11 = exclude these files! 1.497 + # param 12 = only include these files! 1.498 + # param 13 = javah command 1.499 + # param 14 = override src roots to be passed into -sourcepath, ugly ugly ugly, do not use this! 1.500 + # it is only here to workaround ugly things in the source code in the jdk that ought 1.501 + # to be fixed instead! 1.502 + ifdef $2_USED_BY 1.503 + $$(error Attempting to add the package $2 from $3 which is already added with sources from $$($2_USED_BY)) 1.504 + endif 1.505 + $2_USED_BY:=$3 1.506 + # Remove the _the.package file to get the target bin dir for the classes in this package. 1.507 + $2_PACKAGE_BDIR:=$(dir $2) 1.508 + # The source roots separated with a path separator (: or ; depending on os) 1.509 + # (The patsubst is necessary to trim away unnecessary spaces.) 1.510 + ifneq ($(14),) 1.511 + $2_SRCROOTSC:=$(subst $(SPACE),$(PATH_SEP),$(strip $(patsubst %,%,$(14)))) 1.512 + else 1.513 + $2_SRCROOTSC:=$(subst $(SPACE),$(PATH_SEP),$(strip $(patsubst %,%,$3))) 1.514 + endif 1.515 + # Suffix the package path to the src roots, to get a list of all possible source locations 1.516 + # for this package. 1.517 + $2_PACKAGE_SDIRS:=$$(foreach i,$3,$$(subst $4,$$i,$$($2_PACKAGE_BDIR))) 1.518 + # Use wildcard in all potential source locations to find the actual sources. 1.519 + $2_PACKAGE_SRCS:=$$(filter-out $(11),$$(wildcard $$(addsuffix *.java,$$($2_PACKAGE_SDIRS)))) 1.520 + ifneq ($(12),) 1.521 + # Filter on include file filter if set. 1.522 + $2_PACKAGE_SRCS:=$$(filter $(12),$$($2_PACKAGE_SRCS)) 1.523 + endif 1.524 + # Generate a proper package name from the file name. 1.525 + $2_PACKAGE:=$(patsubst .%.,%,$(subst /,.,$(subst $4,,$(dir $2)))) 1.526 + # Use a javac server for this package? 1.527 + $2_REMOTE:=$8 1.528 + 1.529 + # Include previously generated information about what classes are output by this package 1.530 + # and what sources were used for the compile. 1.531 + -include $$($2_PACKAGE_BDIR)_the.package.d 1.532 + 1.533 + # Include the notify, file, that exists if the package has been compiled during a previous make round. 1.534 + # I.e. we are now dealing with a compile triggered by a pubapi change. 1.535 + -include $$($2_PACKAGE_BDIR)_the.package.notify 1.536 + 1.537 + # If the notify file existed, then $$($2_NOTIFIED) will be equal to true. 1.538 + # Use this information to block dependency tracking for this package. 1.539 + # This is necessary to cut the circular dependency chains that are so common in Java sources. 1.540 + 1.541 + ifneq ($$($2_NOTIFIED),true) 1.542 + # No need to block, since this package has not yet been recompiled. 1.543 + # Thus include previously generated dependency information. (if it exists) 1.544 + -include $$($2_PACKAGE_BDIR)_the.package.dddd 1.545 +# else 1.546 +# $$(info WAS NOTIFIED $2) 1.547 + endif 1.548 + 1.549 + # Should we create proper dependencies between packages? 1.550 + ifneq ($7,) 1.551 + # The flag: -XDpubapi:file=foo,package=mypack,notify writes a file foo that contains a 1.552 + # database of the public api of the classes supplied on the command line and are 1.553 + # inside the package mypack. If foo already exists, javac will only write to foo, 1.554 + # if there is a change in the pubapi. I.e. we can use the timestamp of this file 1.555 + # for triggering dependencies. "notify" means create a "file" suffixed with notify 1.556 + # if the pubapi really changed. 1.557 + $2_PUBAPI=-XDpubapi=file=$$($2_PACKAGE_BDIR)_the.package.api,notify,package=$$($2_PACKAGE) 1.558 + # The flag: -XDnativeapi:file=foo,package=mypack,notify works similar to pubabi, but 1.559 + # instead tracks native methods. This file can be used to trigger dependencies for 1.560 + # native compilations. 1.561 + $2_NATIVEAPI=-XDnativeapi=file=$$($2_PACKAGE_BDIR)_the.package.native,notify,package=$$($2_PACKAGE) 1.562 + # The flag -XDdeps:file=foo.deps,groupon=package writes a foo.deps file containing packages dependencies: 1.563 + # java.net : java.io java.lang 1.564 + # I.e. the classes in .net depend on the public apis of java.io and java.lang 1.565 + # The dependencies can be grouped on classes instead (groupon=class) 1.566 + # java.net.Bar : java.io.Socket java.lang.String 1.567 + $2_DEPS:=-XDdeps=file=$$($2_PACKAGE_BDIR)_the.package.deps,groupon=package 1.568 + # The next command rewrites the deps output from javac into a proper makefile dependency. 1.569 + # The dependencies are always to an .api file generated by the pubapi option above. 1.570 + # This is necessary since java package dependencies are almost always circular. 1.571 + $2_APPEND_DEPS:=($(CAT) $$($2_PACKAGE_BDIR)_the.package.deps | $(TR) '.' '/' | $(AWK) '{ print "$4/" $$$$3 }' | sort > $$($2_PACKAGE_BDIR)_the.package.ddd && $(GREP) -f $$($2_PACKAGE_BDIR)_the.package.ddd $5 | $(AWK) '{ print "$(dir $2)_the.package : " $$$$1 "_the.package.api" }' > $$($2_PACKAGE_BDIR)_the.package.dddd ; true) 1.572 + else 1.573 + # If not using dependencies, use $2 as fallback to trigger regeneration of javah header files. 1.574 + # This will generate a surplus of header files, but this does not hurt compilation. 1.575 + $2_NATIVEAPICHANGE_TRIGGER:=$2 1.576 + $2_FETCH_NATIVEAPICHANGE_CLASSES:=$(CAT) $$($2_PACKAGE_BDIR)_the.package.now|$(GREP) -v '\$$$$'|$(SED) -e 's|$4/||g'|$(SED) 's|.class||g'| $(TR) '/' '.' 1.577 + endif 1.578 + 1.579 + # The _the.package file is dependent on the java files inside the package. 1.580 + # Fill the _the.package file with a list of the java files and compile them 1.581 + # to class files. 1.582 + $2 : $$($2_PACKAGE_SRCS) 1.583 + $(MKDIR) -p $$($2_PACKAGE_BDIR) 1.584 + $(RM) $2.tmp 1.585 + $$(call ListPathsSafely,$2_PACKAGE_SRCS,\n, >> $2.tmp) 1.586 + $(ECHO) $$($2_PACKAGE_BDIR)*.class | $(GREP) -v \*.class | $(TR) ' ' '\n' > $$($2_PACKAGE_BDIR)_the.package.prev 1.587 + $(RM) $$($2_PACKAGE_BDIR)*.class $$($2_PACKAGE_BDIR)*.notify $$($2_PACKAGE_BDIR)*.deleted 1.588 + $(ECHO) Compiling `$(WC) $2.tmp | $(TR) -s ' ' | $(CUT) -f 2 -d ' '` files in package $(patsubst $4/%/,%,$(dir $2.tmp)) 1.589 + $9 $$($2_REMOTE) $$($2_DEPS) $$($2_PUBAPI) $$($2_NATIVEAPI) $(10) -implicit:none -sourcepath "$$($2_SRCROOTSC)" -d $4 @$2.tmp 1.590 + $(ECHO) $$($2_PACKAGE_BDIR)*.class | $(GREP) -v \*.class | $(TR) ' ' '\n' > $$($2_PACKAGE_BDIR)_the.package.now 1.591 + ($(GREP) -xvf $$($2_PACKAGE_BDIR)_the.package.now $$($2_PACKAGE_BDIR)_the.package.prev > $$($2_PACKAGE_BDIR)_the.package.deleted;true) 1.592 + $(ECHO) $1_CLASSES += `$(CAT) $$($2_PACKAGE_BDIR)_the.package.now` | \ 1.593 + $(SED) 's/\$$$$/\$$$$\$$$$/g' > $$($2_PACKAGE_BDIR)_the.package.d 1.594 + $(ECHO) $1_JAVAS += $$($2_PACKAGE_SRCS) >> $$($2_PACKAGE_BDIR)_the.package.d 1.595 + $(ECHO) $2_NOTIFIED:=true > $$($2_PACKAGE_BDIR)_the.package.notify 1.596 + $$($2_APPEND_DEPS) 1.597 + $$($2_COPY_FILES) 1.598 + $(MV) -f $2.tmp $2 1.599 +endef 1.600 + 1.601 +define remove_string 1.602 + $2 := $$(subst $1,,$$($2)) 1.603 +endef 1.604 + 1.605 +define replace_space_with_pathsep 1.606 + $1:=$(subst $(SPACE),$(PATH_SEP),$(strip $(patsubst %,%,$2))) 1.607 +endef 1.608 + 1.609 +define SetupJavaCompilation 1.610 + # param 1 is for example BUILD_MYPACKAGE 1.611 + # param 2,3,4,5,6,7,8 are named args. 1.612 + # SETUP:=must point to a previously setup java compiler, for example: SETUP:=BOOTJAVAC 1.613 + # JVM:=path to ..bin/java 1.614 + # ADD_JAVAC_FLAGS:=javac flags to append to the default ones. 1.615 + # SRC:=one or more directories to search for sources 1.616 + # BIN:=store classes here 1.617 + # INCLUDES:=myapp.foo means will only compile java files in myapp.foo or any of its sub-packages. 1.618 + # EXCLUDES:=myapp.foo means will do not compile java files in myapp.foo or any of its sub-packages. 1.619 + # COPY:=.prp means copy all prp files to the corresponding package in BIN. 1.620 + # CLEAN:=.properties means copy and clean all properties file to the corresponding package in BIN. 1.621 + # COPY_FILES:=myapp/foo/setting.txt means copy this file over to the package myapp/foo 1.622 + # SRCZIP:=Create a src.zip based on the found sources and copied files. 1.623 + # INCLUDE_FILES:="com/sun/SolarisFoobar.java" means only compile this file! 1.624 + # EXCLUDE_FILES:="com/sun/SolarisFoobar.java" means do not compile this particular file! 1.625 + # "SolarisFoobar.java" means do not compile SolarisFoobar, wherever it is found. 1.626 + # JAVAC_SOURCE_PATH_UGLY_OVERRIDE:=Don't use this. This forces an explicit -sourcepath to javac. 1.627 + # Its only here until we cleanup some nasty source code pasta in the jdk. 1.628 + # HEADERS:=path to directory where all generated c-headers are written. 1.629 + $(if $2,$1_$(strip $2)) 1.630 + $(if $3,$1_$(strip $3)) 1.631 + $(if $4,$1_$(strip $4)) 1.632 + $(if $5,$1_$(strip $5)) 1.633 + $(if $6,$1_$(strip $6)) 1.634 + $(if $7,$1_$(strip $7)) 1.635 + $(if $8,$1_$(strip $8)) 1.636 + $(if $9,$1_$(strip $9)) 1.637 + $(if $(10),$1_$(strip $(10))) 1.638 + $(if $(11),$1_$(strip $(11))) 1.639 + $(if $(12),$1_$(strip $(12))) 1.640 + $(if $(13),$1_$(strip $(13))) 1.641 + $(if $(14),$1_$(strip $(14))) 1.642 + 1.643 +# Extract the info from the java compiler setup. 1.644 +$1_MODE := $$($$($1_SETUP)_MODE) 1.645 +ifneq (SINGLE_THREADED_BATCH,$$($1_MODE)) 1.646 + ifneq (MULTI_CORE_CONCURRENT,$$($1_MODE)) 1.647 + $$(error The Java compilation $1 refers to a non-existant java compiler setup $$($1_SETUP)) 1.648 + endif 1.649 +endif 1.650 +$1_USE_DEPS := $$($$($1_SETUP)_USE_DEPS) 1.651 +$1_REMOTE := $$($$($1_SETUP)_REMOTE) 1.652 +$1_JVM := $$($$($1_SETUP)_JVM) 1.653 +$1_JAVAC := $$($$($1_SETUP)_JAVAC) 1.654 +$1_JAVAH := $$($$($1_SETUP)_JAVAH) 1.655 +$1_FLAGS := $$($$($1_SETUP)_FLAGS) $(JAVAC_FLAGS) $$($1_ADD_JAVAC_FLAGS) 1.656 +ifeq (,$$($1_HEADERS)) 1.657 + $1_HEADERS := $$($1_BIN) 1.658 +endif 1.659 + 1.660 +# Handle addons and overrides. 1.661 +$1_SRC:=$$(call ADD_SRCS,$$($1_SRC)) 1.662 +# Make sure the dirs exist. 1.663 +$$(shell $(MKDIR) -p $$($1_SRC) $$($1_BIN)) 1.664 +# Find all files in the source trees. 1.665 +$1_ALL_SRCS := $$(filter-out $(OVR_SRCS),$$(foreach i,$$($1_SRC),$$(shell $(FIND) $$i -type f))) 1.666 +# Extract the java files. 1.667 +ifneq ($$($1_EXCLUDE_FILES),) 1.668 + $1_EXCLUDE_FILES_PATTERN:=$$(addprefix %,$$($1_EXCLUDE_FILES)) 1.669 +endif 1.670 +$1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$(filter %.java,$$($1_ALL_SRCS))) 1.671 +ifneq ($$($1_INCLUDE_FILES),) 1.672 + $1_INCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES))) 1.673 + $1_SRCS := $$(filter $$($1_INCLUDE_FILES), $$($1_SRCS)) 1.674 +endif 1.675 +$1_PKGS := $$(sort $$(dir $$($1_SRCS))) 1.676 +# Remove the source root from each found path. 1.677 +$$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$1_PKGS))) 1.678 +$1_PKGS := $$(sort $$($1_PKGS)) 1.679 +# There can be only a single bin dir root, no need to foreach over the roots. 1.680 +$1_BINS := $$(shell $(FIND) $$($1_BIN) -name "*.class") 1.681 + 1.682 +# Now we have a list of all java files to compile: $$($1_SRCS) 1.683 +# and we have a list of all existing class files: $$($1_BINS) 1.684 + 1.685 +# Prepend the source/bin path to the filter expressions. 1.686 +ifneq ($$($1_INCLUDES),) 1.687 + $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES)))) 1.688 + $1_PKG_INCLUDES := $$(addprefix /,$$(addsuffix /%,$$($1_INCLUDES))) 1.689 + $1_BIN_INCLUDES := $$(addprefix $$($1_BIN)/,$$(addsuffix /%,$$($1_INCLUDES))) 1.690 + $1_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS)) 1.691 + $1_PKGS := $$(filter $$($1_PKG_INCLUDES),$$($1_PKGS)) 1.692 + $1_BINS := $$(filter $$($1_BIN_INCLUDES),$$($1_BINS)) 1.693 +endif 1.694 +ifneq ($$($1_EXCLUDES),) 1.695 + $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES)))) 1.696 + $1_PKG_EXCLUDES := $$(addprefix /,$$(addsuffix /%,$$($1_EXCLUDES))) 1.697 + $1_BIN_EXCLUDES := $$(addprefix $$($1_BIN)/,$$(addsuffix /%,$$($1_EXCLUDES))) 1.698 + $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS)) 1.699 + $1_PKGS := $$(filter-out $$($1_PKG_EXCLUDES),$$($1_PKGS)) 1.700 + $1_BINS := $$(filter-out $$($1_BIN_EXCLUDES),$$($1_BINS)) 1.701 +endif 1.702 + 1.703 +# Find all files to be copied from source to bin. 1.704 +ifneq (,$$($1_COPY)) 1.705 + # Rewrite list of patterns into a find statement. 1.706 + $1_COPY_PATTERN:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_COPY)) 1.707 + # Search for all files to be copied. 1.708 + $1_ALL_COPIES := $$(foreach i,$$($1_SRC), $$(shell $(FIND) $$i \( $$($1_COPY_PATTERN) \) -a -type f)) 1.709 + # Copy these explicitly 1.710 + $1_ALL_COPIES += $$($1_COPY_FILES) 1.711 + # Copy must also respect filters. 1.712 + ifneq (,$$($1_INCLUDES)) 1.713 + $1_ALL_COPIES := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_COPIES)) 1.714 + endif 1.715 + ifneq (,$$($1_EXCLUDES)) 1.716 + $1_ALL_COPIES := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_COPIES)) 1.717 + endif 1.718 + ifneq (,$$($1_EXCLUDE_FILES)) 1.719 + $1_ALL_COPIES := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_COPIES)) 1.720 + endif 1.721 + # All files below META-INF are always copied. 1.722 + $1_ALL_COPIES += $$(foreach i,$$($1_SRC), $$(shell $(FIND) $$i/META-INF -type f 2> /dev/null)) 1.723 + ifneq (,$$($1_ALL_COPIES)) 1.724 + # Yep, there are files to be copied! 1.725 + $1_ALL_COPY_TARGETS:= 1.726 + $$(foreach i,$$($1_ALL_COPIES),$$(eval $$(call add_file_to_copy,$1,$$i))) 1.727 + # Now we can depend on $$($1_ALL_COPY_TARGETS) to copy all files! 1.728 + endif 1.729 +endif 1.730 + 1.731 +# Find all property files to be copied and cleaned from source to bin. 1.732 +ifneq (,$$($1_CLEAN)) 1.733 + # Rewrite list of patterns into a find statement. 1.734 + $1_CLEAN_PATTERN:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_CLEAN)) 1.735 + # Search for all files to be copied. 1.736 + $1_ALL_CLEANS := $$(foreach i,$$($1_SRC), $$(shell $(FIND) $$i \( $$($1_CLEAN_PATTERN) \) -a -type f)) 1.737 + # Copy and clean must also respect filters. 1.738 + ifneq (,$$($1_INCLUDES)) 1.739 + $1_ALL_CLEANS := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_CLEANS)) 1.740 + endif 1.741 + ifneq (,$$($1_EXCLUDES)) 1.742 + $1_ALL_CLEANS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_CLEANS)) 1.743 + endif 1.744 + ifneq (,$$($1_EXCLUDE_FILES)) 1.745 + $1_ALL_CLEANS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_CLEANS)) 1.746 + endif 1.747 + ifneq (,$$($1_ALL_CLEANS)) 1.748 + # Yep, there are files to be copied and cleaned! 1.749 + $1_ALL_COPY_CLEAN_TARGETS:= 1.750 + $$(foreach i,$$($1_ALL_CLEANS),$$(eval $$(call add_file_to_copy_and_clean,$1,$$i))) 1.751 + # Now we can depend on $$($1_ALL_COPY_CLEAN_TARGETS) to copy all files! 1.752 + endif 1.753 +endif 1.754 + 1.755 +# Find all the directories that contain java sources, each directory 1.756 +# corresponds to a package because we expect the source 1.757 +# code to be organized in this standardized way! 1.758 +$1_SDIRS := $$(sort $$(dir $$($1_SRCS))) 1.759 +# Now prefix each package with the bin root. 1.760 +$1_BDIRS := $$(foreach i,$$($1_PKGS),$$(addprefix $$($1_BIN),$$i)) 1.761 +# Now create a list of the packages that are about to compile. This list is 1.762 +# later used to filter out dependencies that point outside of this set. 1.763 +$$(shell $(RM) $$($1_BIN)/_the.list_of_packages) 1.764 +$$(eval $$(call ListPathsSafelyNow,$1_BDIRS,\n, >> $$($1_BIN)/_the.list_of_packages)) 1.765 + 1.766 +ifeq ($$($1_MODE),SINGLE_THREADED_BATCH) 1.767 + # Ok, we will feed all the found java files into a single javac invocation. 1.768 + # There can be no dependency checking, nor incremental builds. It is 1.769 + # the best we can do with the old javac. If the javac supports a javac server 1.770 + # then we can use the javac server. 1.771 + 1.772 + # We can depend on this target file to trigger a regeneration of all the sources 1.773 + $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_BIN)/_the.batch 1.774 + 1.775 + # Prep the source paths. 1.776 + ifneq ($$($1_JAVAC_SOURCE_PATH_UGLY_OVERRIDE),) 1.777 + $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_JAVAC_SOURCE_PATH_UGLY_OVERRIDE))) 1.778 + else 1.779 + $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_SRC))) 1.780 + endif 1.781 + 1.782 + # Create a sed expression to remove the source roots and to replace / with . 1.783 + # and remove .java at the end. 1.784 + $1_REWRITE_INTO_CLASSES:=$$(foreach i,$$($1_SRC),-e 's|$$i/||g') -e 's|/|.|g' -e 's|.java$$$$||g' 1.785 + 1.786 + # Here is the batch rules that depends on all the sources. 1.787 + $$($1_BIN)/_the.batch: $$($1_SRCS) 1.788 + $(MKDIR) -p $$(@D) 1.789 + $(RM) $$($1_BIN)/_the.batch $$($1_BIN)/_the.batch.tmp 1.790 + $$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.batch.tmp) 1.791 + $(ECHO) Compiling `$(WC) $$($1_BIN)/_the.batch.tmp | $(TR) -s ' ' | $(CUT) -f 2 -d ' '` files in batch $1 1.792 + ($$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) -implicit:none -sourcepath "$$($1_SRCROOTSC)" -d $$($1_BIN) @$$($1_BIN)/_the.batch.tmp && \ 1.793 + $$(if $$($1_JAVAH),\ 1.794 + $(CAT) $$($1_BIN)/_the.batch.tmp | $(XARGS) $(GREP) -E "[[:space:]]native[[:space:]]|@GenerateNativeHeader" |\ 1.795 + $(GREP) -v '*' | $(GREP) -v '//' | $(CUT) -f 1 -d ':' | $(SORT) -u |\ 1.796 + $(SED) $$($1_REWRITE_INTO_CLASSES) > $$($1_BIN)/_the.batch.natives && \ 1.797 + if test -s $$($1_BIN)/_the.batch.natives; then \ 1.798 + $$($1_JVM) $$($1_JAVAH) "-Xbootclasspath/p:$$($1_BIN)" -d $$($1_HEADERS) @$$($1_BIN)/_the.batch.natives ; \ 1.799 + fi &&) \ 1.800 + $(MV) $$($1_BIN)/_the.batch.tmp $$($1_BIN)/_the.batch) 1.801 +else 1.802 + # Ok, we have a modern javac server running! 1.803 + # Since a single Java file can generate zero to an infinity number of .class files 1.804 + # the exact number and names of the .class files will only be known after the compile. 1.805 + # Thus after the compile, a list of the generated classes will be stored in _the.package.d 1.806 + # which is included by the makefile during the next compile. These .d files will 1.807 + # add the generated class names to the BUILD_MYPACKAGE_CLASSES variable and used java file names 1.808 + # to the BUILD_MYPACKAGE_JAVAS variable. 1.809 + $1_CLASSES := 1.810 + $1_JAVAS := 1.811 + # Create a file in each package that represents the package dependency. 1.812 + # This file (_the.package) will also contain a list of the source files 1.813 + # to be compiled for this package. 1.814 + $1 := $$(sort $$(patsubst %,%_the.package,$$($1_BDIRS))) 1.815 + # Now call add_java_package for each package to create the dependencies. 1.816 + $$(foreach p,$$($1),$$(eval $$(call add_java_package,$1,$$p,$$($1_SRC),$$($1_BIN),$$($1_BIN)/_the.list_of_packages,NOTUSED,$$($1_USE_DEPS),$$($1_REMOTE),$$($1_JVM) $$($1_JAVAC),$$($1_FLAGS),$$($1_EXCLUDE_FILES_PATTERN) $(OVR_SRCS),$$($1_INCLUDE_FILES),$$($1_JVM) $$($1_JAVAH),$$($1_JAVAC_SOURCE_PATH_UGLY_OVERRIDE)))) 1.817 + # All dependencies are setup, now we only need to depend on $1 (aka $(BUILD_MYPACKAGE)) 1.818 + # and they will automatically be built! 1.819 + 1.820 + # Now add on any files to copy targets 1.821 + $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1) 1.822 + # Remove the set of found classes from the set of all previously known classes 1.823 + # and the remainder is the set of missing classes. 1.824 + $1_MISSING_CLASSES:=$$(filter-out $$($1_BINS),$$($1_CLASSES)) 1.825 + $1_PKGS_MISSING_CLASSES:=$$(sort $$(dir $$($1_MISSING_CLASSES))) 1.826 + # Remove the set of found java files from the set of all previously known java files 1.827 + # the remainder is Java files that have gone missing. 1.828 + $1_MISSING_JAVAS:=$$(filter-out $$($1_SRCS),$$($1_JAVAS)) 1.829 + $1_PKGS_MISSING_JAVAS:=$$(sort $$(dir $$($1_MISSING_JAVAS))) 1.830 + # Remove each source root from the found paths. 1.831 + $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$1_PKGS_MISSING_JAVAS))) 1.832 + # Finally remove duplicates and prefix with the binary path instead. 1.833 + $1_PKGS_MISSING_JAVAS:= $$(addprefix $$($1_BIN),$$(sort $$($1_PKGS_MISSING_JAVAS))) 1.834 + 1.835 + # Remove the set of all theoretical classes from the set of found classes. 1.836 + # the remainder is the set of superfluous classes. 1.837 + $1_SUPERFLUOUS_CLASSES:=$$(sort $$(filter-out $$($1_CLASSES),$$($1_BINS))) 1.838 + $1_PKGS_SUPERFLUOUS_CLASSES:=$$(sort $$(dir $$($1_SUPERFLUOUS_CLASSES))) 1.839 + 1.840 + # Now delete the _the.package files inside the problematic dirs. 1.841 + # This will force a rebuild of these packages! 1.842 + $1_FOO:=$$(sort $$($1_PKGS_MISSING_CLASSES) \ 1.843 + $$($1_PKGS_SUPERFLUOUS_CLASSES) \ 1.844 + $$($1_PKGS_MISSING_JAVAS)) 1.845 +# ifneq (,$$($1_FOO)) 1.846 +# $$(info MESSED UP PACKAGES $$($1_FOO)) 1.847 +# endif 1.848 + 1.849 + $$(shell $(RM) $$(addsuffix _the.package,$$(sort $$($1_PKGS_MISSING_CLASSES) \ 1.850 + $$($1_PKGS_SUPERFLUOUS_CLASSES) \ 1.851 + $$($1_PKGS_MISSING_JAVAS)))) 1.852 + 1.853 + # Normal makefile dependencies based on timestamps will detect the normal use case 1.854 + # when Java files are simply added or modified. 1.855 +endif 1.856 + 1.857 +ifneq (,$$($1_JAR)) 1.858 + 1.859 + ifeq (,$$($1_SUFFIXES)) 1.860 + $1_SUFFIXES:=.class $$($1_CLEAN) $$($1_COPY) 1.861 + endif 1.862 + 1.863 + # A jar file was specified. Set it up. 1.864 + $$(eval $$(call SetupArchive,ARCHIVE_$1,$$($1),\ 1.865 + SRCS:=$$($1_BIN),\ 1.866 + SUFFIXES:=$$($1_SUFFIXES),\ 1.867 + EXCLUDE:=$$($1_EXCLUDES),\ 1.868 + INCLUDES:=$$($1_INCLUDES),\ 1.869 + EXTRA_FILES:=$$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS),\ 1.870 + JAR:=$$($1_JAR),\ 1.871 + JARMAIN:=$$($1_JARMAIN),\ 1.872 + MANIFEST:=$$($1_MANIFEST),\ 1.873 + EXTRA_MANIFEST_ATTR:=$$($1_EXTRA_MANIFEST_ATTR),\ 1.874 + HEADERS:=$$($1_HEADERS),\ 1.875 + SETUP:=$$($1_SETUP))) 1.876 +endif 1.877 + 1.878 +ifneq (,$$($1_SRCZIP)) 1.879 + # A srczip file was specified. Set it up. 1.880 + $$(eval $$(call SetupZipArchive,ARCHIVE_$1,\ 1.881 + SRC:=$$($1_SRC),\ 1.882 + ZIP:=$$($1_SRCZIP),\ 1.883 + INCLUDES:=$$($1_INCLUDES),\ 1.884 + EXCLUDES:=$$($1_EXCLUDES),\ 1.885 + EXCLUDE_FILES:=$$($1_EXCLUDE_FILES))) 1.886 +endif 1.887 + 1.888 +endef 1.889 + 1.890 +