1 # 2 # Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. 3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 # 5 # This code is free software; you can redistribute it and/or modify it 6 # under the terms of the GNU General Public License version 2 only, as 7 # published by the Free Software Foundation. Oracle designates this 8 # particular file as subject to the "Classpath" exception as provided 9 # by Oracle in the LICENSE file that accompanied this code. 10 # 11 # This code is distributed in the hope that it will be useful, but WITHOUT 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 # version 2 for more details (a copy is included in the LICENSE file that 15 # accompanied this code). 16 # 17 # You should have received a copy of the GNU General Public License version 18 # 2 along with this work; if not, write to the Free Software Foundation, 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 # 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 # or visit www.oracle.com if you need additional information or have any 23 # questions. 24 # 25 26 # The complexity of this makefile is not the fault of make, but the fault 27 # of javac and javah. The basic problems are: 28 # 29 # 1) Compiling a single Java source file unpredictably generates anything 30 # between zero (0!) and an infinite number of .class files! 31 # 2) There is no hint, for which classes javah needs to be run, 32 # and it happily generates .h files for classes with no native methods. 33 # 3) javac and javah do not cleanup anything, for example if an internal 34 # class (potentially with native methods) is removed from a Java source file. 35 # 36 # This makefile is a tribute to GNU make. And yes, it was harder to write than it is 37 # to read. The include/excludes of directories and files are only a temporary measure 38 # to work around the messy jdk sources that put platform specific code in src/share/classes. 39 # 40 # We should move most of the functionality of this makefile into a 41 # smart javac/javah/javadoc/jar combo tool. sjavac ? 42 # 43 # I.e. 1) It always generates a single output, a zip-file from a number of source roots. 44 # The zip file contains information that enable incremental builds with full 45 # dependency tracking between packages. 46 # 2) It automatically generates the right .h files. 47 # 3) It keeps its house clean. 48 # *) Generates intermediate files to be used for javadoc generation later. 49 # and does all the other useful things that this makefile does, such as: 50 # use all cores for compilation, reuse the running JVM for all compilations, 51 # and has pubapi dependency tracking to minimize the number of files 52 # that need to be recompiled during an incremental build. 53 # 54 # A zip file, or several zip files combined, can then be converted to a .jar file, or to a .jmod file. 55 # 56 # This would make this makefile much much simpler. I.e. make can be used 57 # for its real purpose, track dependencies and trigger a recompile if a 58 # dependency has changed. 59 # 60 # When you read this source. Remember that $(sort ...) has the side effect 61 # of removing duplicates. It is actually this side effect that is 62 # desired whenever sort is used below! 63 64 ifeq (,$(_MAKEBASE_GMK)) 65 $(error You must include MakeBase.gmk prior to including JavaCompilation.gmk) 66 endif 67 68 FALSE_FIND_PATTERN:=-name FILE_NAME_THAT_DOESNT_EXIST 69 70 # If compilation of java package fails, then the public api file for that 71 # package will not be genereated. We add this fallback rule to generate 72 # an empty pubapi file. 73 %.api: 74 if test ! -f $@; then $(MKDIR) -p $(@D); $(TOUCH) $@; fi 75 76 define SetupJavaCompiler 77 # param 1 is for example BOOT_JAVAC or NEW_JAVAC 78 # This is the name later used to decide which java compiler to use. 79 # param 2-9 are named args. 80 # JVM:=The jvm used to run the javac/javah command 81 # JAVAC:=The javac jar and bootstrap classpath changes, or just bin/javac if JVM is left out 82 # JAVAH:=The javah jar and bootstrap classpath changes, or just bin/javah if JVM is left out 83 # FLAGS:=Flags to be supplied to javac 84 # MODE:=SINGLE_THREADED_BATCH (primarily for old javac) or MULTI_CORE_CONCURRENT 85 # only for MULTI_CORE_CONCURRENT are the options below relevant: 86 # SERVER_DIR:=Use a javac server (-XDserver) and store the server related files here 87 # SERVER_JVM:=Use this JVM for the server. Defaults to the JVM above. 88 # USE_DEPS:=true means use -XDdeps,-XDpubapi and -XDnativeapi to track java dependencies 89 $(if $2,$1_$(strip $2)) 90 $(if $3,$1_$(strip $3)) 91 $(if $4,$1_$(strip $4)) 92 $(if $5,$1_$(strip $5)) 93 $(if $6,$1_$(strip $6)) 94 $(if $7,$1_$(strip $7)) 95 $(if $8,$1_$(strip $8)) 96 $(if $9,$1_$(strip $9)) 97 98 ifeq ($$($1_MODE),MULTI_CORE_CONCURRENT) 99 ifneq (,$$($1_SERVER_DIR)) 100 # A javac server has been requested. 101 # The port file contains the tcp/ip on which the server listens 102 # and the cookie necessary to talk to the server. 103 $1_JAVAC_PORTFILE:=$$($1_SERVER_DIR)/$1.port 104 ifeq ($$($1_SERVER_JVM),) 105 # You can use a different JVM to run the background javac server. 106 # But if not set, it defaults to the same JVM that is used to start 107 # the javac command. 108 $1_SERVER_JVM:=$$($1_JVM) 109 endif 110 # Set the $1_REMOTE to spawn a background javac server. 111 $1_REMOTE:=-XDserver:portfile=$$($1_JAVAC_PORTFILE),poolsize=$(JAVAC_SERVER_CORES),javac=$$(subst $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_JAVAC)))) 112 endif 113 endif 114 endef 115 116 define SetupArchive 117 # param 1 is for example ARCHIVE_MYPACKAGE 118 # param 2 are the dependecies 119 # param 3,4,5,6,7,8,9 are named args. 120 # SRCS:=List of directories in where to find files to add to archive 121 # SUFFIXES:=File suffixes to include in jar 122 # INCLUDES:=List of directories/packages in SRCS that should be included 123 # EXCLUDES:=List of directories/packages in SRCS that should be excluded 124 # EXCLUDE_FILES:=List of files in SRCS that should be excluded 125 # EXTRA_FILES:=List of files in SRCS that should be included regardless of suffix match. 126 # JAR:=Jar file to create 127 # MANIFEST:=Optional manifest file template. 128 # JARMAIN:=Optional main class to add to manifest 129 # SETUP:=The Java(h) compiler setup, needed to run javah. 130 # HEADERS:=Directory to put headers in 131 # SKIP_METAINF:=Set to prevent contents of an META-INF directory to be automatically 132 # added to the archive. 133 # EXTRA_MANIFEST_ATTR:=Extra attribute to add to manifest. 134 $(if $3,$1_$(strip $3)) 135 $(if $4,$1_$(strip $4)) 136 $(if $5,$1_$(strip $5)) 137 $(if $6,$1_$(strip $6)) 138 $(if $7,$1_$(strip $7)) 139 $(if $8,$1_$(strip $8)) 140 $(if $9,$1_$(strip $9)) 141 $(if $(10),$1_$(strip $(10))) 142 $(if $(11),$1_$(strip $(11))) 143 $(if $(12),$1_$(strip $(12))) 144 $(if $(13),$1_$(strip $(13))) 145 $(if $(14),$1_$(strip $(14))) 146 147 $1_JVM := $$($$($1_SETUP)_JVM) 148 $1_JAVAH := $$($$($1_SETUP)_JAVAH) 149 $1_JARMAIN:=$(strip $$($1_JARMAIN)) 150 $1_JARNAME:=$$(notdir $$($1_JAR)) 151 $1_MANIFEST_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_manifest 152 $1_DELETESS_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletess 153 $1_DELETES_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletes 154 $1_PUBAPI_NOTIFICATIONS_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_pubapi_notifications 155 $1_NATIVEAPI_NOTIFICATIONS_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_native_notifications 156 $1_NATIVEAPI_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_native 157 $1_BIN:=$$(dir $$($1_JAR)) 158 ifeq (,$$($1_SUFFIXES)) 159 # No suffix was set, default to classes. 160 $1_SUFFIXES:=.class 161 endif 162 # Convert suffixes to a find expression 163 $1_FIND_PATTERNS:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_SUFFIXES)) 164 ifneq (,$$($1_INCLUDES)) 165 $1_GREP_INCLUDES:=| $(GREP) $$(foreach src,$$($1_SRCS),$$(addprefix -e$(SPACE)$$(src)/,$$($1_INCLUDES))) 166 endif 167 ifneq (,$$($1_EXCLUDES)$$($1_EXCLUDE_FILES)) 168 $1_GREP_EXCLUDES:=| $(GREP) -v $$(foreach src,$$($1_SRCS),$$(addprefix -e$(SPACE)$$(src)/,$$($1_EXCLUDES) $$($1_EXCLUDE_FILES))) 169 endif 170 171 # Utility macros, to make the shell script receipt somewhat easier to dechipher. 172 173 # The capture contents macro finds all files (matching the patterns, typically 174 # .class and .prp) that are newer than the jar-file, ie the new content to be put into the jar. 175 $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) && ) 176 # The capture metainf macro finds all files below the META-INF directory that are newer than the jar-file. 177 ifeq (,$$($1_SKIP_METAINF)) 178 $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 ) && ) 179 endif 180 # The capture deletes macro finds all deleted files and concatenates them. The resulting file 181 # tells us what to remove from the jar-file. 182 $1_CAPTURE_DELETES=$$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.deleted -newer $$@ -exec $(SED) 's|$$(src)||g' \{\} >> $$($1_DELETES_FILE) \;) &&) 183 # The capture pubapi notifications scans for pubapi change notifications. If such notifications are 184 # found, then we will build the classes leading up to the jar again, to take into account the new timestamps 185 # on the changed pubapi files. 186 $1_CAPTURE_PUBAPI_NOTIFICATIONS=$$(foreach src,$$($1_SRCS),\ 187 (cd $$(src) && \ 188 $(FIND) . -name _the.package.api.notify -exec dirname \{\} \; >> $$($1_PUBAPI_NOTIFICATIONS_FILE) ; \ 189 true) &&) 190 # The capture nativeapi macro scans for native api change notificiations. If such notifications are 191 # found, then we will run javah on the changed classes. It also collects all classes with native methods 192 # to be used to find out which classes no longer has native methods, to trigger deletion of those .h files. 193 $1_CAPTURE_NATIVEAPI=$$(foreach src,$$($1_SRCS),\ 194 (cd $$(src) && \ 195 $(FIND) . -name _the.package.native.notify | $(SED) 's/package.native.notify/package.native/' | \ 196 $(XARGS) $(CAT) | $(GREP) '^TYPE ' | $(SED) 's/.*TYPE //' >> $$($1_NATIVEAPI_NOTIFICATIONS_FILE) ; \ 197 $(FIND) . -name _the.package.native -exec $(CAT) \{\} \; | $(SED) -n 's/^TYPE //p' >> $$($1_NATIVEAPI_FILE) ; \ 198 true) &&) 199 # The update contents macro updates the jar file with the previously capture contents. 200 $1_UPDATE_CONTENTS=$$(foreach src,$$($1_SRCS),\ 201 (cd $$(src) && \ 202 if [ -s _the.$$($1_JARNAME)_contents ]; then \ 203 $(ECHO) " updating" `$(WC) -l _the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'` files && \ 204 $(JAR) uf $$@ @_the.$$($1_JARNAME)_contents; \ 205 fi) &&) 206 # The s-variants of the above macros are used when the jar is created from scratch. 207 $1_SCAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS),\ 208 (($(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) && ) 209 ifeq (,$$($1_SKIP_METAINF)) 210 $1_SCAPTURE_METAINF=$$(foreach src,$$($1_SRCS),\ 211 ($(FIND) $$(src)/META-INF -type f 2> /dev/null | $(SED) 's|$$(src)/||g' >> $$(src)/_the.$$($1_JARNAME)_contents) && ) 212 endif 213 $1_SUPDATE_CONTENTS=$$(foreach src,$$($1_SRCS),\ 214 (cd $$(src) && $(JAR) uf $$@ @$$(src)/_the.$$($1_JARNAME)_contents) &&) 215 # The TOUCH macro is used to make sure all timestamps are identical for package files and the pubapi files. 216 # If we do not do this, we get random recompilations, the next time we run make, since the order of package building is random, 217 # ie independent of package --dependes on-> public api of another package. This is of course 218 # due to the fact that Java source often (always?) has circular dependencies. (Thus there is no correct order 219 # to compile packages, and we can just as well do them in a random order. Which we do.) 220 $1_TOUCH_API_FILES=$$(foreach src,$$($1_SRCS),\ 221 ($(FIND) $$(src) -name _the.package.api -exec $(TOUCH) -r $$($1_JAR) \{\} \; ; true) && \ 222 ($(FIND) $$(src) -name _the.package -exec $(TOUCH) -r $$($1_JAR) \{\} \; ; true) &&) 223 # Use a slightly shorter name for logging, but with enough path to identify this jar. 224 $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_JAR)) 225 # Here is the rule that creates/updates the jar file. 226 $$($1_JAR) : $2 227 $(MKDIR) -p $$($1_BIN) 228 if [ -n "$$($1_MANIFEST)" ]; then \ 229 $(SED) -e "s#@@RELEASE@@#$(RELEASE)#" \ 230 -e "s#@@COMPANY_NAME@@#$(COMPANY_NAME)#" $$($1_MANIFEST) > $$($1_MANIFEST_FILE); \ 231 else \ 232 $(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE); \ 233 fi 234 $(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE) 235 if [ -n "$$($1_EXTRA_MANIFEST_ATTR)" ]; then \ 236 $(ECHO) "$$($1_EXTRA_MANIFEST_ATTR)" >> $$($1_MANIFEST_FILE); \ 237 fi 238 +if [ -s $$@ ]; then \ 239 $(RM) -r $$($1_PUBAPI_NOTIFICATIONS_FILE) && \ 240 $$($1_CAPTURE_PUBAPI_NOTIFICATIONS) \ 241 if [ -s $$($1_PUBAPI_NOTIFICATIONS_FILE) ]; then \ 242 $(ECHO) Public api change detected in: && \ 243 $(CAT) $$($1_PUBAPI_NOTIFICATIONS_FILE) | $(TR) '/' '.' | $(SED) 's|^..||g' | $(SED) 's|\.$$$$||g' | $(AWK) '{print " "$$$$1}' && \ 244 $$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.api.notify $(FIND_DELETE); true) &&) \ 245 $(MAKE) -f $(word 1,$(MAKEFILE_LIST)) $$($1_JAR) ; \ 246 else \ 247 $(ECHO) Modifying $$($1_NAME) && \ 248 $$($1_CAPTURE_CONTENTS) \ 249 $$($1_CAPTURE_METAINF) \ 250 $(RM) $$($1_DELETES_FILE) && \ 251 $$($1_CAPTURE_DELETES) \ 252 $(CAT) $$($1_DELETES_FILE) > $$($1_DELETESS_FILE) && \ 253 if [ -s $$($1_DELETESS_FILE) ]; then \ 254 $(ECHO) " deleting" `$(WC) -l $$($1_DELETESS_FILE) | $(AWK) '{ print $$$$1 }'` files && \ 255 $(ZIP) -q -d $$@ `$(CAT) $$($1_DELETESS_FILE)` ; \ 256 fi && \ 257 $$($1_UPDATE_CONTENTS) true && \ 258 $$($1_TOUCH_API_FILES) true && \ 259 $(RM) -r $$($1_NATIVEAPI_NOTIFICATIONS_FILE) $$($1_NATIVEAPI_FILE) && \ 260 $$($1_CAPTURE_NATIVEAPI) true && \ 261 if [ "x$$($1_JAVAH)" != "x" ] && [ -s $$($1_NATIVEAPI_NOTIFICATIONS_FILE) ]; then \ 262 $(ECHO) Native api change detected in: && $(CAT) $$($1_NATIVEAPI_NOTIFICATIONS_FILE) && \ 263 $$($1_JVM) $$($1_JAVAH) "-Xbootclasspath/p:$$($1_JAR)" -d $$($1_HEADERS) @$$($1_NATIVEAPI_NOTIFICATIONS_FILE) ; \ 264 fi && \ 265 $(TOUCH) $$($1_NATIVEAPI_FILE)_prev ; \ 266 ($(GREP) -xvf $$($1_NATIVEAPI_FILE) $$($1_NATIVEAPI_FILE)_prev > $$($1_NATIVEAPI_FILE)_deleted; true) && \ 267 $(CP) $$($1_NATIVEAPI_FILE) $$($1_NATIVEAPI_FILE)_prev && \ 268 if [ -s $$($1_NATIVEAPI_FILE)_deleted ]; then \ 269 $(ECHO) Native methods dropped from classes: && $(CAT) $$($1_NATIVEAPI_FILE)_deleted && \ 270 $(RM) `$(CAT) $$($1_NATIVEAPI_FILE)_deleted | $(SED) -e 's|\.|_|g' -e 's|.*|$$($1_HEADERS)/&.h $$($1_HEADERS)/&_*|'` ; \ 271 fi && \ 272 $$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.api.notify $(FIND_DELETE); true) &&) true ; \ 273 fi ; \ 274 else \ 275 $(ECHO) Creating $$($1_NAME) && $(JAR) cfm $$@ $$($1_MANIFEST_FILE) && \ 276 $$($1_SCAPTURE_CONTENTS) \ 277 $$($1_SCAPTURE_METAINF) \ 278 $$($1_SUPDATE_CONTENTS) \ 279 $$($1_TOUCH_API_FILES) true && \ 280 $(RM) -r $$($1_NATIVEAPI_NOTIFICATIONS_FILE) $$($1_NATIVEAPI_FILE) && \ 281 $$($1_CAPTURE_NATIVEAPI) true && \ 282 if [ "x$$($1_JAVAH)" != "x" ] && [ -s $$($1_NATIVEAPI_FILE) ]; then \ 283 $(ECHO) Generating native api headers for `$(CAT) $$($1_NATIVEAPI_FILE) | $(WC) -l` classes && \ 284 $(RM) $$($1_HEADERS)/*.h && \ 285 $$($1_JVM) $$($1_JAVAH) "-Xbootclasspath/p:$$($1_JAR)" -d $$($1_HEADERS) @$$($1_NATIVEAPI_FILE) && \ 286 $(CP) $$($1_NATIVEAPI_FILE) $$($1_NATIVEAPI_FILE)_prev ; \ 287 fi && \ 288 $$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name "*.notify" $(FIND_DELETE); true) &&) true ; \ 289 fi; 290 291 endef 292 293 define append_to 294 $(ECHO) "$1" >> $2 295 endef 296 297 define SetupZipArchive 298 # param 1 is for example ZIP_MYSOURCE 299 # param 2,3,4,5,6,7,8,9 are named args. 300 # SRC,ZIP,INCLUDES,EXCLUDES,EXCLUDE_FILES 301 $(if $2,$1_$(strip $2)) 302 $(if $3,$1_$(strip $3)) 303 $(if $4,$1_$(strip $4)) 304 $(if $5,$1_$(strip $5)) 305 $(if $6,$1_$(strip $6)) 306 $(if $7,$1_$(strip $7)) 307 $(if $8,$1_$(strip $8)) 308 $(if $9,$1_$(strip $9)) 309 310 # Find all files in the source tree. 311 $1_ALL_SRCS := $$(foreach i,$$($1_SRC), $$(shell $(FIND) $$i -type f -a ! -name "_the.*")) 312 313 ifneq ($$($1_INCLUDES),) 314 $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES)))) 315 $1_ZIP_INCLUDES := $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_INCLUDES))) 316 $1_ALL_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_SRCS)) 317 endif 318 ifneq ($$($1_EXCLUDES),) 319 $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES)))) 320 $1_ZIP_EXCLUDES := $$(addprefix -x$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_EXCLUDES))) 321 $1_ALL_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS)) 322 endif 323 324 # Use a slightly shorter name for logging, but with enough path to identify this zip. 325 $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_ZIP)) 326 327 # Now $1_ALL_SRCS should contain all sources that are going to be put into the zip. 328 # I.e. the zip -i and -x options should match the filtering done in the makefile. 329 # Explicitly excluded files can be given with absolute path. The patsubst solution 330 # isn't perfect but the likelyhood of an absolute path to match something in a src 331 # dir is very small. 332 $$($1_ZIP) : $$($1_ALL_SRCS) 333 $(MKDIR) -p $$(@D) 334 $(ECHO) Updating $$($1_NAME) 335 $$(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 336 $(TOUCH) $$@ 337 endef 338 339 define add_file_to_copy 340 # param 1 = BUILD_MYPACKAGE 341 # parma 2 = The source file to copy. 342 $2_TARGET:=$2 343 # Remove the source prefix. 344 $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET))) 345 # Now we can setup the depency that will trigger the copying. 346 $$($1_BIN)$$($2_TARGET) : $2 347 $(MKDIR) -p $$(@D) 348 $(CP) $$< $$@ 349 $(CHMOD) -f ug+w $$@ 350 351 # And do not forget this target 352 $1_ALL_COPY_TARGETS += $$($1_BIN)$$($2_TARGET) 353 endef 354 355 356 # This macro is used only for properties files that are to be 357 # copied over to the classes directory in cleaned form: 358 # Previously this was inconsistently done in different repositories. 359 # This is the new clean standard. 360 define add_file_to_copy_and_clean 361 # param 1 = BUILD_MYPACKAGE 362 # parma 2 = The source file to copy and clean. 363 $2_TARGET:=$2 364 # Remove the source prefix. 365 $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET))) 366 # Now we can setup the depency that will trigger the copying. 367 $$($1_BIN)$$($2_TARGET) : $2 368 $(MKDIR) -p $$(@D) 369 $(ECHO) Cleaning $$($2_TARGET) 370 $(CAT) $$< | $(SED) -e 's/\([^\\]\):/\1\\:/g' -e 's/\([^\\]\)=/\1\\=/g' -e 's/#.*/#/g' \ 371 | $(SED) \ 372 -e 's/\\u0020/\x20/g' \ 373 -e 's/\\u003A/\x3A/g' \ 374 -e 's/\\u006B/\x6B/g' \ 375 -e 's/\\u0075/\x75/g' \ 376 -e 's/\\u00A0/\xA0/g' \ 377 -e 's/\\u00A3/\xA3/g' \ 378 -e 's/\\u00B0/\xB0/g' \ 379 -e 's/\\u00B7/\xB7/g' \ 380 -e 's/\\u00BA/\xBA/g' \ 381 -e 's/\\u00BF/\xBF/g' \ 382 -e 's/\\u00C0/\xC0/g' \ 383 -e 's/\\u00C1/\xC1/g' \ 384 -e 's/\\u00C2/\xC2/g' \ 385 -e 's/\\u00C4/\xC4/g' \ 386 -e 's/\\u00C5/\xC5/g' \ 387 -e 's/\\u00C8/\xC8/g' \ 388 -e 's/\\u00C9/\xC9/g' \ 389 -e 's/\\u00CA/\xCA/g' \ 390 -e 's/\\u00CD/\xCD/g' \ 391 -e 's/\\u00CE/\xCE/g' \ 392 -e 's/\\u00D3/\xD3/g' \ 393 -e 's/\\u00D4/\xD4/g' \ 394 -e 's/\\u00D6/\xD6/g' \ 395 -e 's/\\u00DA/\xDA/g' \ 396 -e 's/\\u00DC/\xDC/g' \ 397 -e 's/\\u00DD/\xDD/g' \ 398 -e 's/\\u00DF/\xDF/g' \ 399 -e 's/\\u00E0/\xE0/g' \ 400 -e 's/\\u00E1/\xE1/g' \ 401 -e 's/\\u00E2/\xE2/g' \ 402 -e 's/\\u00E3/\xE3/g' \ 403 -e 's/\\u00E4/\xE4/g' \ 404 -e 's/\\u00E5/\xE5/g' \ 405 -e 's/\\u00E6/\xE6/g' \ 406 -e 's/\\u00E7/\xE7/g' \ 407 -e 's/\\u00E8/\xE8/g' \ 408 -e 's/\\u00E9/\xE9/g' \ 409 -e 's/\\u00EA/\xEA/g' \ 410 -e 's/\\u00EB/\xEB/g' \ 411 -e 's/\\u00EC/\xEC/g' \ 412 -e 's/\\u00ED/\xED/g' \ 413 -e 's/\\u00EE/\xEE/g' \ 414 -e 's/\\u00EF/\xEF/g' \ 415 -e 's/\\u00F1/\xF1/g' \ 416 -e 's/\\u00F2/\xF2/g' \ 417 -e 's/\\u00F3/\xF3/g' \ 418 -e 's/\\u00F4/\xF4/g' \ 419 -e 's/\\u00F5/\xF5/g' \ 420 -e 's/\\u00F6/\xF6/g' \ 421 -e 's/\\u00F9/\xF9/g' \ 422 -e 's/\\u00FA/\xFA/g' \ 423 -e 's/\\u00FC/\xFC/g' \ 424 -e 's/\\u0020/\x20/g' \ 425 -e 's/\\u003f/\x3f/g' \ 426 -e 's/\\u006f/\x6f/g' \ 427 -e 's/\\u0075/\x75/g' \ 428 -e 's/\\u00a0/\xa0/g' \ 429 -e 's/\\u00a3/\xa3/g' \ 430 -e 's/\\u00b0/\xb0/g' \ 431 -e 's/\\u00ba/\xba/g' \ 432 -e 's/\\u00bf/\xbf/g' \ 433 -e 's/\\u00c1/\xc1/g' \ 434 -e 's/\\u00c4/\xc4/g' \ 435 -e 's/\\u00c5/\xc5/g' \ 436 -e 's/\\u00c8/\xc8/g' \ 437 -e 's/\\u00c9/\xc9/g' \ 438 -e 's/\\u00ca/\xca/g' \ 439 -e 's/\\u00cd/\xcd/g' \ 440 -e 's/\\u00d6/\xd6/g' \ 441 -e 's/\\u00dc/\xdc/g' \ 442 -e 's/\\u00dd/\xdd/g' \ 443 -e 's/\\u00df/\xdf/g' \ 444 -e 's/\\u00e0/\xe0/g' \ 445 -e 's/\\u00e1/\xe1/g' \ 446 -e 's/\\u00e2/\xe2/g' \ 447 -e 's/\\u00e3/\xe3/g' \ 448 -e 's/\\u00e4/\xe4/g' \ 449 -e 's/\\u00e5/\xe5/g' \ 450 -e 's/\\u00e7/\xe7/g' \ 451 -e 's/\\u00e8/\xe8/g' \ 452 -e 's/\\u00e9/\xe9/g' \ 453 -e 's/\\u00ea/\xea/g' \ 454 -e 's/\\u00eb/\xeb/g' \ 455 -e 's/\\u00ec/\xec/g' \ 456 -e 's/\\u00ed/\xed/g' \ 457 -e 's/\\u00ee/\xee/g' \ 458 -e 's/\\u00ef/\xef/g' \ 459 -e 's/\\u00f0/\xf0/g' \ 460 -e 's/\\u00f1/\xf1/g' \ 461 -e 's/\\u00f2/\xf2/g' \ 462 -e 's/\\u00f3/\xf3/g' \ 463 -e 's/\\u00f4/\xf4/g' \ 464 -e 's/\\u00f5/\xf5/g' \ 465 -e 's/\\u00f6/\xf6/g' \ 466 -e 's/\\u00f7/\xf7/g' \ 467 -e 's/\\u00f8/\xf8/g' \ 468 -e 's/\\u00f9/\xf9/g' \ 469 -e 's/\\u00fa/\xfa/g' \ 470 -e 's/\\u00fc/\xfc/g' \ 471 -e 's/\\u00ff/\xff/g' \ 472 | $(SED) -e '/^#/d' -e '/^$$$$/d' \ 473 -e :a -e '/\\$$$$/N; s/\\\n//; ta' \ 474 -e 's/^[ \t]*//;s/[ \t]*$$$$//' \ 475 -e 's/\\=/=/' | LANG=C sort > $$@ 476 $(CHMOD) -f ug+w $$@ 477 478 # And do not forget this target 479 $1_ALL_COPY_CLEAN_TARGETS += $$($1_BIN)$$($2_TARGET) 480 endef 481 482 define add_java_package 483 # param 1 = BUILD_MYPACKAGE 484 # param 2 = the package target file (_the.package) 485 # param 3 = src roots, all of them, separated with space 486 # param 4 = bin root 487 # param 5 = include these dependecies 488 # param 6 = not used 489 # param 7 = if non-empty, then use -Xdeps and -Xpubapi 490 # param 8 = xremote configuration, or empty. 491 # param 9 = javac command 492 # param 10 = javac flags 493 # param 11 = exclude these files! 494 # param 12 = only include these files! 495 # param 13 = javah command 496 # param 14 = override src roots to be passed into -sourcepath, ugly ugly ugly, do not use this! 497 # it is only here to workaround ugly things in the source code in the jdk that ought 498 # to be fixed instead! 499 ifdef $2_USED_BY 500 $$(error Attempting to add the package $2 from $3 which is already added with sources from $$($2_USED_BY)) 501 endif 502 $2_USED_BY:=$3 503 # Remove the _the.package file to get the target bin dir for the classes in this package. 504 $2_PACKAGE_BDIR:=$(dir $2) 505 # The source roots separated with a path separator (: or ; depending on os) 506 # (The patsubst is necessary to trim away unnecessary spaces.) 507 ifneq ($(14),) 508 $2_SRCROOTSC:=$(subst $(SPACE),$(PATH_SEP),$(strip $(patsubst %,%,$(14)))) 509 else 510 $2_SRCROOTSC:=$(subst $(SPACE),$(PATH_SEP),$(strip $(patsubst %,%,$3))) 511 endif 512 # Suffix the package path to the src roots, to get a list of all possible source locations 513 # for this package. 514 $2_PACKAGE_SDIRS:=$$(foreach i,$3,$$(subst $4,$$i,$$($2_PACKAGE_BDIR))) 515 # Use wildcard in all potential source locations to find the actual sources. 516 $2_PACKAGE_SRCS:=$$(filter-out $(11),$$(wildcard $$(addsuffix *.java,$$($2_PACKAGE_SDIRS)))) 517 ifneq ($(12),) 518 # Filter on include file filter if set. 519 $2_PACKAGE_SRCS:=$$(filter $(12),$$($2_PACKAGE_SRCS)) 520 endif 521 # Generate a proper package name from the file name. 522 $2_PACKAGE:=$(patsubst .%.,%,$(subst /,.,$(subst $4,,$(dir $2)))) 523 # Use a javac server for this package? 524 $2_REMOTE:=$8 525 526 # Include previously generated information about what classes are output by this package 527 # and what sources were used for the compile. 528 -include $$($2_PACKAGE_BDIR)_the.package.d 529 530 # Include the notify, file, that exists if the package has been compiled during a previous make round. 531 # I.e. we are now dealing with a compile triggered by a pubapi change. 532 -include $$($2_PACKAGE_BDIR)_the.package.notify 533 534 # If the notify file existed, then $$($2_NOTIFIED) will be equal to true. 535 # Use this information to block dependency tracking for this package. 536 # This is necessary to cut the circular dependency chains that are so common in Java sources. 537 538 ifneq ($$($2_NOTIFIED),true) 539 # No need to block, since this package has not yet been recompiled. 540 # Thus include previously generated dependency information. (if it exists) 541 -include $$($2_PACKAGE_BDIR)_the.package.dddd 542 # else 543 # $$(info WAS NOTIFIED $2) 544 endif 545 546 # Should we create proper dependencies between packages? 547 ifneq ($7,) 548 # The flag: -XDpubapi:file=foo,package=mypack,notify writes a file foo that contains a 549 # database of the public api of the classes supplied on the command line and are 550 # inside the package mypack. If foo already exists, javac will only write to foo, 551 # if there is a change in the pubapi. I.e. we can use the timestamp of this file 552 # for triggering dependencies. "notify" means create a "file" suffixed with notify 553 # if the pubapi really changed. 554 $2_PUBAPI=-XDpubapi=file=$$($2_PACKAGE_BDIR)_the.package.api,notify,package=$$($2_PACKAGE) 555 # The flag: -XDnativeapi:file=foo,package=mypack,notify works similar to pubabi, but 556 # instead tracks native methods. This file can be used to trigger dependencies for 557 # native compilations. 558 $2_NATIVEAPI=-XDnativeapi=file=$$($2_PACKAGE_BDIR)_the.package.native,notify,package=$$($2_PACKAGE) 559 # The flag -XDdeps:file=foo.deps,groupon=package writes a foo.deps file containing packages dependencies: 560 # java.net : java.io java.lang 561 # I.e. the classes in .net depend on the public apis of java.io and java.lang 562 # The dependencies can be grouped on classes instead (groupon=class) 563 # java.net.Bar : java.io.Socket java.lang.String 564 $2_DEPS:=-XDdeps=file=$$($2_PACKAGE_BDIR)_the.package.deps,groupon=package 565 # The next command rewrites the deps output from javac into a proper makefile dependency. 566 # The dependencies are always to an .api file generated by the pubapi option above. 567 # This is necessary since java package dependencies are almost always circular. 568 $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) 569 else 570 # If not using dependencies, use $2 as fallback to trigger regeneration of javah header files. 571 # This will generate a surplus of header files, but this does not hurt compilation. 572 $2_NATIVEAPICHANGE_TRIGGER:=$2 573 $2_FETCH_NATIVEAPICHANGE_CLASSES:=$(CAT) $$($2_PACKAGE_BDIR)_the.package.now|$(GREP) -v '\$$$$'|$(SED) -e 's|$4/||g'|$(SED) 's|.class||g'| $(TR) '/' '.' 574 endif 575 576 # The _the.package file is dependent on the java files inside the package. 577 # Fill the _the.package file with a list of the java files and compile them 578 # to class files. 579 $2 : $$($2_PACKAGE_SRCS) 580 $(MKDIR) -p $$($2_PACKAGE_BDIR) 581 $(RM) $2.tmp 582 $$(call ListPathsSafely,$2_PACKAGE_SRCS,\n, >> $2.tmp) 583 $(ECHO) $$($2_PACKAGE_BDIR)*.class | $(GREP) -v \*.class | $(TR) ' ' '\n' > $$($2_PACKAGE_BDIR)_the.package.prev 584 $(RM) $$($2_PACKAGE_BDIR)*.class $$($2_PACKAGE_BDIR)*.notify $$($2_PACKAGE_BDIR)*.deleted 585 $(ECHO) Compiling `$(WC) $2.tmp | $(TR) -s ' ' | $(CUT) -f 2 -d ' '` files in package $(patsubst $4/%/,%,$(dir $2.tmp)) 586 $9 $$($2_REMOTE) $$($2_DEPS) $$($2_PUBAPI) $$($2_NATIVEAPI) $(10) -implicit:none -sourcepath "$$($2_SRCROOTSC)" -d $4 @$2.tmp 587 $(ECHO) $$($2_PACKAGE_BDIR)*.class | $(GREP) -v \*.class | $(TR) ' ' '\n' > $$($2_PACKAGE_BDIR)_the.package.now 588 ($(GREP) -xvf $$($2_PACKAGE_BDIR)_the.package.now $$($2_PACKAGE_BDIR)_the.package.prev > $$($2_PACKAGE_BDIR)_the.package.deleted;true) 589 $(ECHO) $1_CLASSES += `$(CAT) $$($2_PACKAGE_BDIR)_the.package.now` | \ 590 $(SED) 's/\$$$$/\$$$$\$$$$/g' > $$($2_PACKAGE_BDIR)_the.package.d 591 $(ECHO) $1_JAVAS += $$($2_PACKAGE_SRCS) >> $$($2_PACKAGE_BDIR)_the.package.d 592 $(ECHO) $2_NOTIFIED:=true > $$($2_PACKAGE_BDIR)_the.package.notify 593 $$($2_APPEND_DEPS) 594 $$($2_COPY_FILES) 595 $(MV) -f $2.tmp $2 596 endef 597 598 define remove_string 599 $2 := $$(subst $1,,$$($2)) 600 endef 601 602 define replace_space_with_pathsep 603 $1:=$(subst $(SPACE),$(PATH_SEP),$(strip $(patsubst %,%,$2))) 604 endef 605 606 define SetupJavaCompilation 607 # param 1 is for example BUILD_MYPACKAGE 608 # param 2,3,4,5,6,7,8 are named args. 609 # SETUP:=must point to a previously setup java compiler, for example: SETUP:=BOOTJAVAC 610 # JVM:=path to ..bin/java 611 # ADD_JAVAC_FLAGS:=javac flags to append to the default ones. 612 # SRC:=one or more directories to search for sources 613 # BIN:=store classes here 614 # INCLUDES:=myapp.foo means will only compile java files in myapp.foo or any of its sub-packages. 615 # EXCLUDES:=myapp.foo means will do not compile java files in myapp.foo or any of its sub-packages. 616 # COPY:=.prp means copy all prp files to the corresponding package in BIN. 617 # CLEAN:=.properties means copy and clean all properties file to the corresponding package in BIN. 618 # COPY_FILES:=myapp/foo/setting.txt means copy this file over to the package myapp/foo 619 # SRCZIP:=Create a src.zip based on the found sources and copied files. 620 # INCLUDE_FILES:="com/sun/SolarisFoobar.java" means only compile this file! 621 # EXCLUDE_FILES:="com/sun/SolarisFoobar.java" means do not compile this particular file! 622 # "SolarisFoobar.java" means do not compile SolarisFoobar, wherever it is found. 623 # JAVAC_SOURCE_PATH_UGLY_OVERRIDE:=Don't use this. This forces an explicit -sourcepath to javac. 624 # Its only here until we cleanup some nasty source code pasta in the jdk. 625 # HEADERS:=path to directory where all generated c-headers are written. 626 $(if $2,$1_$(strip $2)) 627 $(if $3,$1_$(strip $3)) 628 $(if $4,$1_$(strip $4)) 629 $(if $5,$1_$(strip $5)) 630 $(if $6,$1_$(strip $6)) 631 $(if $7,$1_$(strip $7)) 632 $(if $8,$1_$(strip $8)) 633 $(if $9,$1_$(strip $9)) 634 $(if $(10),$1_$(strip $(10))) 635 $(if $(11),$1_$(strip $(11))) 636 $(if $(12),$1_$(strip $(12))) 637 $(if $(13),$1_$(strip $(13))) 638 $(if $(14),$1_$(strip $(14))) 639 640 # Extract the info from the java compiler setup. 641 $1_MODE := $$($$($1_SETUP)_MODE) 642 ifneq (SINGLE_THREADED_BATCH,$$($1_MODE)) 643 ifneq (MULTI_CORE_CONCURRENT,$$($1_MODE)) 644 $$(error The Java compilation $1 refers to a non-existant java compiler setup $$($1_SETUP)) 645 endif 646 endif 647 $1_USE_DEPS := $$($$($1_SETUP)_USE_DEPS) 648 $1_REMOTE := $$($$($1_SETUP)_REMOTE) 649 $1_JVM := $$($$($1_SETUP)_JVM) 650 $1_JAVAC := $$($$($1_SETUP)_JAVAC) 651 $1_JAVAH := $$($$($1_SETUP)_JAVAH) 652 $1_FLAGS := $$($$($1_SETUP)_FLAGS) $(JAVAC_FLAGS) $$($1_ADD_JAVAC_FLAGS) 653 ifeq (,$$($1_HEADERS)) 654 $1_HEADERS := $$($1_BIN) 655 endif 656 657 # Handle addons and overrides. 658 $1_SRC:=$$(call ADD_SRCS,$$($1_SRC)) 659 # Make sure the dirs exist. 660 $$(shell $(MKDIR) -p $$($1_SRC) $$($1_BIN)) 661 # Find all files in the source trees. 662 $1_ALL_SRCS := $$(filter-out $(OVR_SRCS),$$(foreach i,$$($1_SRC),$$(shell $(FIND) $$i -type f))) 663 # Extract the java files. 664 ifneq ($$($1_EXCLUDE_FILES),) 665 $1_EXCLUDE_FILES_PATTERN:=$$(addprefix %,$$($1_EXCLUDE_FILES)) 666 endif 667 $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$(filter %.java,$$($1_ALL_SRCS))) 668 ifneq ($$($1_INCLUDE_FILES),) 669 $1_INCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES))) 670 $1_SRCS := $$(filter $$($1_INCLUDE_FILES), $$($1_SRCS)) 671 endif 672 $1_PKGS := $$(sort $$(dir $$($1_SRCS))) 673 # Remove the source root from each found path. 674 $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$1_PKGS))) 675 $1_PKGS := $$(sort $$($1_PKGS)) 676 # There can be only a single bin dir root, no need to foreach over the roots. 677 $1_BINS := $$(shell $(FIND) $$($1_BIN) -name "*.class") 678 679 # Now we have a list of all java files to compile: $$($1_SRCS) 680 # and we have a list of all existing class files: $$($1_BINS) 681 682 # Prepend the source/bin path to the filter expressions. 683 ifneq ($$($1_INCLUDES),) 684 $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES)))) 685 $1_PKG_INCLUDES := $$(addprefix /,$$(addsuffix /%,$$($1_INCLUDES))) 686 $1_BIN_INCLUDES := $$(addprefix $$($1_BIN)/,$$(addsuffix /%,$$($1_INCLUDES))) 687 $1_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS)) 688 $1_PKGS := $$(filter $$($1_PKG_INCLUDES),$$($1_PKGS)) 689 $1_BINS := $$(filter $$($1_BIN_INCLUDES),$$($1_BINS)) 690 endif 691 ifneq ($$($1_EXCLUDES),) 692 $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES)))) 693 $1_PKG_EXCLUDES := $$(addprefix /,$$(addsuffix /%,$$($1_EXCLUDES))) 694 $1_BIN_EXCLUDES := $$(addprefix $$($1_BIN)/,$$(addsuffix /%,$$($1_EXCLUDES))) 695 $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS)) 696 $1_PKGS := $$(filter-out $$($1_PKG_EXCLUDES),$$($1_PKGS)) 697 $1_BINS := $$(filter-out $$($1_BIN_EXCLUDES),$$($1_BINS)) 698 endif 699 700 # Find all files to be copied from source to bin. 701 ifneq (,$$($1_COPY)) 702 # Rewrite list of patterns into a find statement. 703 $1_COPY_PATTERN:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_COPY)) 704 # Search for all files to be copied. 705 $1_ALL_COPIES := $$(foreach i,$$($1_SRC), $$(shell $(FIND) $$i \( $$($1_COPY_PATTERN) \) -a -type f)) 706 # Copy these explicitly 707 $1_ALL_COPIES += $$($1_COPY_FILES) 708 # Copy must also respect filters. 709 ifneq (,$$($1_INCLUDES)) 710 $1_ALL_COPIES := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_COPIES)) 711 endif 712 ifneq (,$$($1_EXCLUDES)) 713 $1_ALL_COPIES := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_COPIES)) 714 endif 715 ifneq (,$$($1_EXCLUDE_FILES)) 716 $1_ALL_COPIES := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_COPIES)) 717 endif 718 # All files below META-INF are always copied. 719 $1_ALL_COPIES += $$(foreach i,$$($1_SRC), $$(shell $(FIND) $$i/META-INF -type f 2> /dev/null)) 720 ifneq (,$$($1_ALL_COPIES)) 721 # Yep, there are files to be copied! 722 $1_ALL_COPY_TARGETS:= 723 $$(foreach i,$$($1_ALL_COPIES),$$(eval $$(call add_file_to_copy,$1,$$i))) 724 # Now we can depend on $$($1_ALL_COPY_TARGETS) to copy all files! 725 endif 726 endif 727 728 # Find all property files to be copied and cleaned from source to bin. 729 ifneq (,$$($1_CLEAN)) 730 # Rewrite list of patterns into a find statement. 731 $1_CLEAN_PATTERN:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_CLEAN)) 732 # Search for all files to be copied. 733 $1_ALL_CLEANS := $$(foreach i,$$($1_SRC), $$(shell $(FIND) $$i \( $$($1_CLEAN_PATTERN) \) -a -type f)) 734 # Copy and clean must also respect filters. 735 ifneq (,$$($1_INCLUDES)) 736 $1_ALL_CLEANS := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_CLEANS)) 737 endif 738 ifneq (,$$($1_EXCLUDES)) 739 $1_ALL_CLEANS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_CLEANS)) 740 endif 741 ifneq (,$$($1_EXCLUDE_FILES)) 742 $1_ALL_CLEANS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_CLEANS)) 743 endif 744 ifneq (,$$($1_ALL_CLEANS)) 745 # Yep, there are files to be copied and cleaned! 746 $1_ALL_COPY_CLEAN_TARGETS:= 747 $$(foreach i,$$($1_ALL_CLEANS),$$(eval $$(call add_file_to_copy_and_clean,$1,$$i))) 748 # Now we can depend on $$($1_ALL_COPY_CLEAN_TARGETS) to copy all files! 749 endif 750 endif 751 752 # Find all the directories that contain java sources, each directory 753 # corresponds to a package because we expect the source 754 # code to be organized in this standardized way! 755 $1_SDIRS := $$(sort $$(dir $$($1_SRCS))) 756 # Now prefix each package with the bin root. 757 $1_BDIRS := $$(foreach i,$$($1_PKGS),$$(addprefix $$($1_BIN),$$i)) 758 # Now create a list of the packages that are about to compile. This list is 759 # later used to filter out dependencies that point outside of this set. 760 $$(shell $(RM) $$($1_BIN)/_the.list_of_packages) 761 $$(eval $$(call ListPathsSafelyNow,$1_BDIRS,\n, >> $$($1_BIN)/_the.list_of_packages)) 762 763 ifeq ($$($1_MODE),SINGLE_THREADED_BATCH) 764 # Ok, we will feed all the found java files into a single javac invocation. 765 # There can be no dependency checking, nor incremental builds. It is 766 # the best we can do with the old javac. If the javac supports a javac server 767 # then we can use the javac server. 768 769 # We can depend on this target file to trigger a regeneration of all the sources 770 $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_BIN)/_the.batch 771 772 # Prep the source paths. 773 ifneq ($$($1_JAVAC_SOURCE_PATH_UGLY_OVERRIDE),) 774 $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_JAVAC_SOURCE_PATH_UGLY_OVERRIDE))) 775 else 776 $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_SRC))) 777 endif 778 779 # Create a sed expression to remove the source roots and to replace / with . 780 # and remove .java at the end. 781 $1_REWRITE_INTO_CLASSES:=$$(foreach i,$$($1_SRC),-e 's|$$i/||g') -e 's|/|.|g' -e 's|.java$$$$||g' 782 783 # Here is the batch rules that depends on all the sources. 784 $$($1_BIN)/_the.batch: $$($1_SRCS) 785 $(MKDIR) -p $$(@D) 786 $(RM) $$($1_BIN)/_the.batch $$($1_BIN)/_the.batch.tmp 787 $$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.batch.tmp) 788 $(ECHO) Compiling `$(WC) $$($1_BIN)/_the.batch.tmp | $(TR) -s ' ' | $(CUT) -f 2 -d ' '` files in batch $1 789 ($$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) -implicit:none -sourcepath "$$($1_SRCROOTSC)" -d $$($1_BIN) @$$($1_BIN)/_the.batch.tmp && \ 790 $$(if $$($1_JAVAH),\ 791 $(CAT) $$($1_BIN)/_the.batch.tmp | $(XARGS) $(GREP) -E "[[:space:]]native[[:space:]]|@GenerateNativeHeader" |\ 792 $(GREP) -v '*' | $(GREP) -v '//' | $(CUT) -f 1 -d ':' | $(SORT) -u |\ 793 $(SED) $$($1_REWRITE_INTO_CLASSES) > $$($1_BIN)/_the.batch.natives && \ 794 if test -s $$($1_BIN)/_the.batch.natives; then \ 795 $$($1_JVM) $$($1_JAVAH) "-Xbootclasspath/p:$$($1_BIN)" -d $$($1_HEADERS) @$$($1_BIN)/_the.batch.natives ; \ 796 fi &&) \ 797 $(MV) $$($1_BIN)/_the.batch.tmp $$($1_BIN)/_the.batch) 798 else 799 # Ok, we have a modern javac server running! 800 # Since a single Java file can generate zero to an infinity number of .class files 801 # the exact number and names of the .class files will only be known after the compile. 802 # Thus after the compile, a list of the generated classes will be stored in _the.package.d 803 # which is included by the makefile during the next compile. These .d files will 804 # add the generated class names to the BUILD_MYPACKAGE_CLASSES variable and used java file names 805 # to the BUILD_MYPACKAGE_JAVAS variable. 806 $1_CLASSES := 807 $1_JAVAS := 808 # Create a file in each package that represents the package dependency. 809 # This file (_the.package) will also contain a list of the source files 810 # to be compiled for this package. 811 $1 := $$(sort $$(patsubst %,%_the.package,$$($1_BDIRS))) 812 # Now call add_java_package for each package to create the dependencies. 813 $$(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)))) 814 # All dependencies are setup, now we only need to depend on $1 (aka $(BUILD_MYPACKAGE)) 815 # and they will automatically be built! 816 817 # Now add on any files to copy targets 818 $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1) 819 # Remove the set of found classes from the set of all previously known classes 820 # and the remainder is the set of missing classes. 821 $1_MISSING_CLASSES:=$$(filter-out $$($1_BINS),$$($1_CLASSES)) 822 $1_PKGS_MISSING_CLASSES:=$$(sort $$(dir $$($1_MISSING_CLASSES))) 823 # Remove the set of found java files from the set of all previously known java files 824 # the remainder is Java files that have gone missing. 825 $1_MISSING_JAVAS:=$$(filter-out $$($1_SRCS),$$($1_JAVAS)) 826 $1_PKGS_MISSING_JAVAS:=$$(sort $$(dir $$($1_MISSING_JAVAS))) 827 # Remove each source root from the found paths. 828 $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$1_PKGS_MISSING_JAVAS))) 829 # Finally remove duplicates and prefix with the binary path instead. 830 $1_PKGS_MISSING_JAVAS:= $$(addprefix $$($1_BIN),$$(sort $$($1_PKGS_MISSING_JAVAS))) 831 832 # Remove the set of all theoretical classes from the set of found classes. 833 # the remainder is the set of superfluous classes. 834 $1_SUPERFLUOUS_CLASSES:=$$(sort $$(filter-out $$($1_CLASSES),$$($1_BINS))) 835 $1_PKGS_SUPERFLUOUS_CLASSES:=$$(sort $$(dir $$($1_SUPERFLUOUS_CLASSES))) 836 837 # Now delete the _the.package files inside the problematic dirs. 838 # This will force a rebuild of these packages! 839 $1_FOO:=$$(sort $$($1_PKGS_MISSING_CLASSES) \ 840 $$($1_PKGS_SUPERFLUOUS_CLASSES) \ 841 $$($1_PKGS_MISSING_JAVAS)) 842 # ifneq (,$$($1_FOO)) 843 # $$(info MESSED UP PACKAGES $$($1_FOO)) 844 # endif 845 846 $$(shell $(RM) $$(addsuffix _the.package,$$(sort $$($1_PKGS_MISSING_CLASSES) \ 847 $$($1_PKGS_SUPERFLUOUS_CLASSES) \ 848 $$($1_PKGS_MISSING_JAVAS)))) 849 850 # Normal makefile dependencies based on timestamps will detect the normal use case 851 # when Java files are simply added or modified. 852 endif 853 854 ifneq (,$$($1_JAR)) 855 856 ifeq (,$$($1_SUFFIXES)) 857 $1_SUFFIXES:=.class $$($1_CLEAN) $$($1_COPY) 858 endif 859 860 # A jar file was specified. Set it up. 861 $$(eval $$(call SetupArchive,ARCHIVE_$1,$$($1),\ 862 SRCS:=$$($1_BIN),\ 863 SUFFIXES:=$$($1_SUFFIXES),\ 864 EXCLUDE:=$$($1_EXCLUDES),\ 865 INCLUDES:=$$($1_INCLUDES),\ 866 EXTRA_FILES:=$$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS),\ 867 JAR:=$$($1_JAR),\ 868 JARMAIN:=$$($1_JARMAIN),\ 869 MANIFEST:=$$($1_MANIFEST),\ 870 EXTRA_MANIFEST_ATTR:=$$($1_EXTRA_MANIFEST_ATTR),\ 871 HEADERS:=$$($1_HEADERS),\ 872 SETUP:=$$($1_SETUP))) 873 endif 874 875 ifneq (,$$($1_SRCZIP)) 876 # A srczip file was specified. Set it up. 877 $$(eval $$(call SetupZipArchive,ARCHIVE_$1,\ 878 SRC:=$$($1_SRC),\ 879 ZIP:=$$($1_SRCZIP),\ 880 INCLUDES:=$$($1_INCLUDES),\ 881 EXCLUDES:=$$($1_EXCLUDES),\ 882 EXCLUDE_FILES:=$$($1_EXCLUDE_FILES))) 883 endif 884 885 endef 886 887