annotate make/common/JavaCompilation.gmk @ 1858:4a8a7397e3f0

8147086: Excluding of copy files broken after JDK-8144226 Reviewed-by: ihse
author erikj
date Thu, 14 Jan 2016 13:50:40 +0100
parents 4b01ea6c12c3
children 0dd4e511e076
rev   line source
ohair@423 1 #
ihse@1494 2 # Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
ohair@423 3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@423 4 #
ohair@423 5 # This code is free software; you can redistribute it and/or modify it
ohair@423 6 # under the terms of the GNU General Public License version 2 only, as
ohair@423 7 # published by the Free Software Foundation. Oracle designates this
ohair@423 8 # particular file as subject to the "Classpath" exception as provided
ohair@423 9 # by Oracle in the LICENSE file that accompanied this code.
ohair@423 10 #
ohair@423 11 # This code is distributed in the hope that it will be useful, but WITHOUT
ohair@423 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@423 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@423 14 # version 2 for more details (a copy is included in the LICENSE file that
ohair@423 15 # accompanied this code).
ohair@423 16 #
ohair@423 17 # You should have received a copy of the GNU General Public License version
ohair@423 18 # 2 along with this work; if not, write to the Free Software Foundation,
ohair@423 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@423 20 #
ohair@423 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@423 22 # or visit www.oracle.com if you need additional information or have any
ohair@423 23 # questions.
ohair@423 24 #
ohair@423 25
ohair@423 26 # When you read this source. Remember that $(sort ...) has the side effect
ohair@423 27 # of removing duplicates. It is actually this side effect that is
ohair@423 28 # desired whenever sort is used below!
ohair@423 29
chegar@1120 30 ifndef _JAVA_COMPILATION_GMK
chegar@1120 31 _JAVA_COMPILATION_GMK := 1
chegar@1120 32
ihse@837 33 ifeq (,$(_MAKEBASE_GMK))
ihse@837 34 $(error You must include MakeBase.gmk prior to including JavaCompilation.gmk)
ohair@423 35 endif
ohair@423 36
ihse@1726 37 # Java compilation needs SetupJarArchive and/or SetupZipArchive, if we're
ihse@1726 38 # generating a jar file or a source zip.
ihse@1726 39 include JarArchive.gmk
ihse@1233 40 include ZipArchive.gmk
ihse@1233 41
ihse@1233 42 # Setup make rules for defining a Java compiler, which is needed to compile
ihse@1233 43 # Java code. This rule generates no output.
ihse@1233 44 #
ihse@1233 45 # Parameter 1 is the name of the compiler definition. This name needs to be
ihse@1233 46 # passed to SetupJavaCompilation. This name is used as variable prefix.
ihse@1233 47 #
ihse@1233 48 # Remaining parameters are named arguments. These include:
ihse@1233 49 # JVM:=The jvm used to run the javac/javah command
ihse@1233 50 # JAVAC:=The javac jar and bootstrap classpath changes, or just bin/javac if JVM is left out
ihse@1233 51 # FLAGS:=Flags to be supplied to javac
ihse@1233 52 # SERVER_DIR:=Use a javac server (-XDserver) and store the server related files here
ihse@1233 53 # SERVER_JVM:=Use this JVM for the server. Defaults to the JVM above.
erikj@1705 54 # DISABLE_SJAVAC:=Set to true if this setup does not support sjavac
erikj@1379 55 SetupJavaCompiler = $(NamedParamsMacroTemplate)
erikj@1379 56 define SetupJavaCompilerBody
ihse@837 57 # The port file contains the tcp/ip on which the server listens
ihse@837 58 # and the cookie necessary to talk to the server.
ihse@837 59 $1_SJAVAC_PORTFILE:=$$($1_SERVER_DIR)/server.port
ihse@837 60 # You can use a different JVM to run the background javac server.
ihse@837 61 ifeq ($$($1_SERVER_JVM),)
ihse@837 62 # It defaults to the same JVM that is used to start the javac command.
ihse@837 63 $1_SERVER_JVM:=$$($1_JVM)
ihse@837 64 endif
ohair@423 65 endef
ohair@423 66
ohair@423 67 define add_file_to_copy
ihse@837 68 # param 1 = BUILD_MYPACKAGE
ihse@837 69 # parma 2 = The source file to copy.
ihse@837 70 $2_TARGET:=$2
ihse@837 71 # Remove the source prefix.
ihse@837 72 $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET)))
chegar@1120 73 # To allow for automatic overrides, do not create a rule for a target file that
chegar@1120 74 # already has one
erikj@1476 75 ifneq ($$($1_COPY_$$($2_TARGET)), 1)
erikj@1476 76 $1_COPY_$$($2_TARGET) := 1
erikj@1790 77 # Now we can setup the dependency that will trigger the copying.
chegar@1120 78 $$($1_BIN)$$($2_TARGET) : $2
ohair@423 79 $(MKDIR) -p $$(@D)
ohair@423 80 $(CP) $$< $$@
ohair@423 81 $(CHMOD) -f ug+w $$@
ohair@423 82
chegar@1120 83 # And do not forget this target
chegar@1120 84 $1_ALL_COPY_TARGETS += $$($1_BIN)$$($2_TARGET)
chegar@1120 85 endif
ohair@423 86 endef
ohair@423 87
ohair@423 88 # This macro is used only for properties files that are to be
ohair@423 89 # copied over to the classes directory in cleaned form:
ohair@423 90 # Previously this was inconsistently done in different repositories.
ohair@476 91 # This is the new clean standard. Though it is to be superseded by
ohair@476 92 # a standard annotation processor from with sjavac.
erikj@989 93 #
erikj@1325 94 # An empty echo ensures that the input to sed always ends with a newline.
erikj@1325 95 # Certain implementations (e.g. Solaris) will skip the last line without
erikj@1325 96 # it.
erikj@1325 97 #
erikj@989 98 # The sed expression does this:
erikj@989 99 # 1. Add a backslash before any :, = or ! that do not have a backslash already.
ihse@1236 100 # 2. Apply the file unicode2x.sed which does a whole bunch of \u00XX to \xXX
erikj@989 101 # conversions.
erikj@989 102 # 3. Delete all lines starting with #.
erikj@989 103 # 4. Delete empty lines.
erikj@989 104 # 5. Append lines ending with \ with the next line.
erikj@1036 105 # 6. Remove leading and trailing white space. Note that tabs must be explicit
erikj@1036 106 # as sed on macosx does not understand '\t'.
erikj@989 107 # 7. Replace the first \= with just =.
erikj@989 108 # 8. Finally it's all sorted to create a stable output.
ihse@1236 109 #
erikj@989 110 # It is assumed that = is the character used for separating names and values.
erikj@989 111 define add_file_to_clean
ihse@837 112 # param 1 = BUILD_MYPACKAGE
ihse@837 113 # parma 2 = The source file to copy and clean.
ihse@837 114 $2_TARGET:=$2
ihse@837 115 # Remove the source prefix.
ihse@837 116 $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET)))
ihse@837 117 # Now we can setup the depency that will trigger the copying.
erikj@1476 118 # To allow for automatic overrides, do not create a rule for a target file that
erikj@1476 119 # already has one
erikj@1476 120 ifneq ($$($1_CLEAN_$$($2_TARGET)), 1)
erikj@1476 121 $1_CLEAN_$$($2_TARGET) := 1
erikj@1476 122 $$($1_BIN)$$($1_MODULE_SUBDIR)$$($2_TARGET) : $2
ohair@423 123 $(MKDIR) -p $$(@D)
erikj@1325 124 export LC_ALL=C ; ( $(CAT) $$< && $(ECHO) "" ) \
erikj@1232 125 | $(SED) -e 's/\([^\\]\):/\1\\:/g' -e 's/\([^\\]\)=/\1\\=/g' \
sla@1385 126 -e 's/\([^\\]\)!/\1\\!/g' -e 's/^[ ]*#.*/#/g' \
ihse@910 127 | $(SED) -f "$(SRC_ROOT)/make/common/support/unicode2x.sed" \
ihse@837 128 | $(SED) -e '/^#/d' -e '/^$$$$/d' \
ihse@837 129 -e :a -e '/\\$$$$/N; s/\\\n//; ta' \
erikj@1036 130 -e 's/^[ ]*//;s/[ ]*$$$$//' \
erikj@1232 131 -e 's/\\=/=/' \
erikj@1232 132 | $(SORT) > $$@
ohair@423 133 $(CHMOD) -f ug+w $$@
ohair@423 134
erikj@1476 135 # And do not forget this target
erikj@1476 136 $1_ALL_COPY_CLEAN_TARGETS += $$($1_BIN)$$($2_TARGET)
erikj@1476 137 endif
ohair@423 138 endef
ohair@423 139
ohair@423 140 define remove_string
ihse@837 141 $2 := $$(subst $1,,$$($2))
ohair@423 142 endef
ohair@423 143
ihse@1233 144 # Setup make rules for compiling Java source code to class files and/or a
ihse@1233 145 # resulting jar file.
ihse@1233 146 #
ihse@1233 147 # Parameter 1 is the name of the rule. This name is used as variable prefix,
ihse@1233 148 # and the targets generated are listed in a variable by that name.
ihse@1233 149 #
ihse@1233 150 # Remaining parameters are named arguments. These include:
ihse@1233 151 # SETUP:=must point to a previously setup java compiler, for example: SETUP:=BOOTJAVAC
ihse@1233 152 # JVM:=path to ..bin/java
ihse@1233 153 # ADD_JAVAC_FLAGS:=javac flags to append to the default ones.
erikj@1476 154 # SRC:=one or more directories to search for sources. The order of the source roots
erikj@1476 155 # is significant. The first found file of a certain name has priority.
ihse@1233 156 # BIN:=store classes here
ihse@1627 157 # CLASSPATH:=a list of additional entries to set as classpath to javac
ihse@1233 158 # INCLUDES:=myapp.foo means will only compile java files in myapp.foo or any of its sub-packages.
ihse@1233 159 # EXCLUDES:=myapp.foo means will do not compile java files in myapp.foo or any of its sub-packages.
ihse@1233 160 # COPY:=.prp means copy all prp files to the corresponding package in BIN.
ihse@1233 161 # COPY_FILES:=myapp/foo/setting.txt means copy this file over to the package myapp/foo
ihse@1233 162 # CLEAN:=.properties means copy and clean all properties file to the corresponding package in BIN.
ihse@1233 163 # CLEAN_FILES:=myapp/foo/setting.txt means clean this file over to the package myapp/foo
ihse@1233 164 # SRCZIP:=Create a src.zip based on the found sources and copied files.
ihse@1233 165 # INCLUDE_FILES:="com/sun/SolarisFoobar.java" means only compile this file!
ihse@1233 166 # EXCLUDE_FILES:="com/sun/SolarisFoobar.java" means do not compile this particular file!
ihse@1233 167 # "SolarisFoobar.java" means do not compile SolarisFoobar, wherever it is found.
ihse@1233 168 # HEADERS:=path to directory where all generated c-headers are written.
ihse@1233 169 # DEPENDS:=Extra dependecy
ihse@1233 170 # DISABLE_SJAVAC:=Explicitly disable the use of sjavac for this compilation unit.
ihse@1656 171 # KEEP_DUPS:=Do not remove duplicate file names from different source roots.
erikj@1379 172 SetupJavaCompilation = $(NamedParamsMacroTemplate)
erikj@1379 173 define SetupJavaCompilationBody
ohair@423 174
ihse@1327 175 # Verify arguments
ihse@1327 176 ifeq ($$($1_BIN),)
ihse@1327 177 $$(error Must specify BIN (in $1))
ihse@1327 178 endif
ihse@1327 179
ihse@837 180 # Extract the info from the java compiler setup.
ihse@837 181 $1_JVM := $$($$($1_SETUP)_JVM)
ihse@837 182 $1_JAVAC := $$($$($1_SETUP)_JAVAC)
ihse@837 183 $1_FLAGS := $$($$($1_SETUP)_FLAGS) $(JAVAC_FLAGS) $$($1_ADD_JAVAC_FLAGS)
ihse@1627 184 ifneq ($$($1_CLASSPATH), )
ihse@1627 185 $1_FLAGS += -cp $$(call PathList, $$($1_CLASSPATH))
ihse@1627 186 endif
ihse@837 187 ifeq ($$($1_JAVAC),)
ihse@837 188 $$(error The Java compilation $1 refers to a non-existant java compiler setup $$($1_SETUP))
ihse@837 189 endif
ihse@837 190 $1_SJAVAC_PORTFILE := $$($$($1_SETUP)_SJAVAC_PORTFILE)
ihse@837 191 $1_SERVER_JVM := $$($$($1_SETUP)_SERVER_JVM)
erikj@1705 192 $1_DISABLE_SJAVAC := $$($$($1_SETUP)_DISABLE_SJAVAC)
ihse@837 193
ihse@837 194 # Make sure the dirs exist.
erikj@1476 195 $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupJavaCompilation $1 contains missing directory >$$d<)))
erikj@1299 196 $$(call MakeDir,$$($1_BIN))
ihse@1236 197 # Add all source roots to the find cache since we are likely going to run find
erikj@997 198 # on these more than once. The cache will only be updated if necessary.
erikj@997 199 $$(eval $$(call FillCacheFind,$$($1_SRC)))
ihse@1730 200 # Find all files in the source trees. Preserve order of source roots so that
ihse@1730 201 # the first version in case of multiple instances of the same file is selected.
ihse@1730 202 # CacheFind does not preserve order so need to call it for each root.
ihse@1730 203 $1_ALL_SRCS += $$(foreach s, $$($1_SRC), $$(call CacheFind, $$(s)))
ihse@837 204 # Extract the java files.
alundblad@1855 205 $1_SRCS := $$(filter %.java, $$($1_ALL_SRCS))
alundblad@1855 206
alundblad@1855 207 # Translate include/exclude into patterns
alundblad@1855 208 ifneq ($$($1_EXCLUDE_FILES), )
alundblad@1855 209 $1_EXCLUDE_PATTERN := $$(addprefix %, $$($1_EXCLUDE_FILES))
ihse@837 210 endif
alundblad@1855 211 ifneq ($$($1_INCLUDE_FILES), )
alundblad@1855 212 $1_INCLUDE_PATTERN := $$(foreach i, $$($1_SRC), $$(addprefix $$i/, $$($1_INCLUDE_FILES)))
alundblad@1855 213 endif
alundblad@1855 214 ifneq ($$($1_EXCLUDES), )
alundblad@1855 215 $1_EXCLUDE_PATTERN += $$(foreach i, $$($1_SRC), $$(addprefix $$i/, $$(addsuffix /%, $$($1_EXCLUDES))))
alundblad@1855 216 endif
alundblad@1855 217 ifneq ($$($1_INCLUDES), )
alundblad@1855 218 $1_INCLUDE_PATTERN += $$(foreach i, $$($1_SRC), $$(addprefix $$i/, $$(addsuffix /%, $$($1_INCLUDES))))
ihse@837 219 endif
ihse@837 220
alundblad@1855 221 # Apply include/exclude patterns to java sources
alundblad@1855 222 ifneq ($$($1_EXCLUDE_PATTERN), )
alundblad@1855 223 $1_SRCS := $$(filter-out $$($1_EXCLUDE_PATTERN), $$($1_SRCS))
ihse@837 224 endif
alundblad@1855 225 ifneq ($$($1_INCLUDE_PATTERN), )
alundblad@1855 226 $1_SRCS := $$(filter $$($1_INCLUDE_PATTERN), $$($1_SRCS))
ihse@837 227 endif
ihse@837 228
ihse@1656 229 ifneq ($$($1_KEEP_DUPS), true)
ihse@1656 230 # Remove duplicate source files by keeping the first found of each duplicate.
ihse@1656 231 # This allows for automatic overrides with custom or platform specific versions
ihse@1656 232 # source files.
ihse@1656 233 #
ihse@1656 234 # For the smart javac wrapper case, add each removed file to an extra exclude
ihse@1656 235 # file list to prevent sjavac from finding duplicate sources.
ihse@1656 236 $1_SRCS := $$(strip $$(foreach s, $$($1_SRCS), \
ihse@1656 237 $$(eval relative_src := $$(call remove-prefixes, $$($1_SRC), $$(s))) \
ihse@1656 238 $$(if $$($1_$$(relative_src)), \
ihse@1656 239 $$(eval $1_SJAVAC_EXCLUDE_FILES += $$(s)), \
ihse@1656 240 $$(eval $1_$$(relative_src) := 1) $$(s))))
ihse@1656 241 endif
erikj@1476 242
ihse@1656 243 ifeq ($$(strip $$($1_SRCS)), )
ihse@1656 244 $$(error No source files found for $1)
ihse@1656 245 endif
ihse@1656 246
ihse@1656 247 $1_SAFE_NAME := $$(strip $$(subst /,_, $1))
ihse@1656 248
ihse@1656 249 # Create the corresponding smart javac wrapper command line.
alundblad@1855 250 $1_SJAVAC_ARGS:=$$(addprefix -x ,$$(addsuffix /**,$$($1_EXCLUDES))) \
alundblad@1855 251 $$(addprefix -i ,$$(addsuffix /**,$$($1_INCLUDES))) \
alundblad@1855 252 $$(addprefix -x **,$$(strip $$($1_EXCLUDE_FILES) $$($1_SJAVAC_EXCLUDE_FILES))) \
alundblad@1855 253 $$(addprefix -i **,$$(strip $$($1_INCLUDE_FILES))) \
ihse@1627 254 -src $$(call PathList, $$($1_SRC))
erikj@1476 255
chegar@1120 256 # All files below META-INF are always copied.
chegar@1120 257 $1_ALL_COPIES := $$(filter $$(addsuffix /META-INF%,$$($1_SRC)),$$($1_ALL_SRCS))
ihse@837 258 # Find all files to be copied from source to bin.
erikj@989 259 ifneq (,$$($1_COPY)$$($1_COPY_FILES))
ihse@837 260 # Search for all files to be copied.
chegar@1120 261 $1_ALL_COPIES += $$(filter $$(addprefix %,$$($1_COPY)),$$($1_ALL_SRCS))
ihse@837 262 # Copy these explicitly
ihse@837 263 $1_ALL_COPIES += $$($1_COPY_FILES)
erikj@989 264 endif
erikj@1300 265 # Copy must also respect filters.
alundblad@1855 266 ifneq (,$$($1_INCLUDE_PATTERN))
alundblad@1855 267 $1_ALL_COPIES := $$(filter $$($1_INCLUDE_PATTERN),$$($1_ALL_COPIES))
erikj@1300 268 endif
alundblad@1855 269 ifneq (,$$($1_EXCLUDE_PATTERN))
erikj@1858 270 $1_ALL_COPIES := $$(filter-out $$($1_EXCLUDE_PATTERN),$$($1_ALL_COPIES))
erikj@1300 271 endif
erikj@1300 272 ifneq (,$$($1_ALL_COPIES))
erikj@1300 273 # Yep, there are files to be copied!
erikj@1300 274 $1_ALL_COPY_TARGETS:=
erikj@1300 275 $$(foreach i,$$($1_ALL_COPIES),$$(eval $$(call add_file_to_copy,$1,$$i)))
erikj@1300 276 # Now we can depend on $$($1_ALL_COPY_TARGETS) to copy all files!
erikj@1300 277 endif
ohair@423 278
ihse@837 279 # Find all property files to be copied and cleaned from source to bin.
erikj@989 280 ifneq (,$$($1_CLEAN)$$($1_CLEAN_FILES))
ihse@837 281 # Search for all files to be copied.
ihse@837 282 $1_ALL_CLEANS := $$(filter $$(addprefix %,$$($1_CLEAN)),$$($1_ALL_SRCS))
erikj@989 283 # Clean these explicitly
erikj@989 284 $1_ALL_CLEANS += $$($1_CLEAN_FILES)
ihse@837 285 # Copy and clean must also respect filters.
alundblad@1855 286 ifneq (,$$($1_INCLUDE_PATTERN))
alundblad@1855 287 $1_ALL_CLEANS := $$(filter $$($1_INCLUDE_PATTERN),$$($1_ALL_CLEANS))
ohair@476 288 endif
alundblad@1855 289 ifneq (,$$($1_EXCLUDE_PATTERN))
alundblad@1855 290 $1_ALL_CLEANS := $$(filter-out $$($1_EXCLUDE_PATTERN),$$($1_ALL_CLEANS))
ihse@837 291 endif
ihse@837 292 ifneq (,$$($1_ALL_CLEANS))
ihse@837 293 # Yep, there are files to be copied and cleaned!
ihse@837 294 $1_ALL_COPY_CLEAN_TARGETS:=
erikj@989 295 $$(foreach i,$$($1_ALL_CLEANS),$$(eval $$(call add_file_to_clean,$1,$$i)))
ihse@837 296 # Now we can depend on $$($1_ALL_COPY_CLEAN_TARGETS) to copy all files!
ihse@837 297 endif
ihse@837 298 endif
ihse@837 299
ihse@837 300 # Create a sed expression to remove the source roots and to replace / with .
ihse@837 301 # and remove .java at the end.
ihse@837 302 $1_REWRITE_INTO_CLASSES:=$$(foreach i,$$($1_SRC),-e 's|$$i/||g') -e 's|/|.|g' -e 's|.java$$$$||g'
ihse@837 303
erikj@1705 304 # Create SJAVAC variable from JAVAC variable. Expects $1_JAVAC to be
erikj@1705 305 # "bootclasspathprepend -cp .../javac.jar com.sun.tools.javac.Main"
erikj@1705 306 # and javac is simply replaced with sjavac.
erikj@1705 307 $1_SJAVAC:=$$(subst com.sun.tools.javac.Main,com.sun.tools.sjavac.Main,$$($1_JAVAC))
erikj@1705 308
erikj@1705 309 # Set the $1_REMOTE to spawn a background javac server.
erikj@1705 310 $1_REMOTE:=--server:portfile=$$($1_SJAVAC_PORTFILE),id=$1,sjavac=$$(subst \
erikj@1705 311 $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_SJAVAC))))
erikj@1705 312
erikj@1790 313 $1_COMPILE_TARGET := $$($1_BIN)/_the.$1_batch
erikj@1790 314
ihse@837 315 ifeq ($$($1_DISABLE_SJAVAC)x$$(ENABLE_SJAVAC),xyes)
erikj@1790 316 # Using sjavac to compile.
erikj@1790 317
ihse@837 318 ifneq (,$$($1_HEADERS))
ihse@837 319 $1_HEADERS_ARG := -h $$($1_HEADERS)
ohair@476 320 endif
ohair@423 321
erikj@1299 322 $1_VARDEPS := $$($1_JVM) $$($1_SJAVAC) $$($1_SJAVAC_ARGS) $$($1_FLAGS) \
ihse@1656 323 $$($1_HEADERS_ARG) $$($1_BIN) $$($1_EXCLUDES) $$($1_INCLUDES) \
ihse@1656 324 $$($1_EXCLUDE_FILES) $$($1_INCLUDE_FILES)
erikj@1299 325 $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$($1_BIN)/_the.$1.vardeps)
erikj@1299 326
erikj@1790 327 $$($1_COMPILE_TARGET): $$($1_SRCS) $$($1_DEPENDS) $$($1_VARDEPS_FILE)
erikj@1293 328 $(MKDIR) -p $$(@D) $$(dir $$($1_SJAVAC_PORTFILE))
erikj@1790 329 $$(eval $$(call ListPathsSafely,$1_SRCS, $$@.tmp))
ihse@837 330 $(ECHO) Compiling $1
ihse@1656 331 $(call LogFailures, $$($1_BIN)/_the.$$($1_SAFE_NAME)_batch.log, $$($1_SAFE_NAME), \
ihse@1623 332 $$($1_JVM) $$($1_SJAVAC) \
ihse@1623 333 $$($1_REMOTE) \
ihse@1623 334 -j 1 \
ihse@1623 335 --permit-unidentified-artifacts \
ihse@1623 336 --permit-sources-without-package \
erikj@1790 337 --compare-found-sources $$@.tmp \
ihse@1623 338 --log=$(LOG_LEVEL) \
alundblad@1653 339 --state-dir=$$($1_BIN) \
ihse@1623 340 $$($1_SJAVAC_ARGS) \
ihse@1623 341 $$($1_FLAGS) \
ihse@1623 342 $$($1_HEADERS_ARG) \
ihse@1623 343 -d $$($1_BIN)) && \
erikj@1790 344 $(MV) $$@.tmp $$@
erikj@1144 345 # Create a pubapi file that only changes when the pubapi changes. Dependent
erikj@1144 346 # compilations can use this file to only get recompiled when pubapi has changed.
erikj@1144 347 # Grep returns 1 if no matching lines are found. Do not fail for this.
erikj@1144 348 $(GREP) -e "^I" $$($1_BIN)/javac_state > $$($1_BIN)/_the.$1_pubapi.tmp \
erikj@1144 349 || test "$$$$?" = "1"
erikj@1144 350 if [ ! -f $$($1_BIN)/_the.$1_pubapi ] \
erikj@1144 351 || [ "`$(DIFF) $$($1_BIN)/_the.$1_pubapi $$($1_BIN)/_the.$1_pubapi.tmp`" != "" ]; then \
erikj@1144 352 $(MV) $$($1_BIN)/_the.$1_pubapi.tmp $$($1_BIN)/_the.$1_pubapi; \
erikj@1144 353 fi
erikj@1144 354
ihse@837 355 else
ihse@837 356 # Using plain javac to batch compile everything.
ohair@476 357
ihse@837 358 # When building in batch, put headers in a temp dir to filter out those that actually
ihse@837 359 # changed before copying them to the real header dir.
ihse@837 360 ifneq (,$$($1_HEADERS))
erikj@960 361 $1_HEADERS_ARG := -h $$($1_HEADERS).$1.tmp
ohair@423 362
erikj@1790 363 $$($1_HEADERS)/_the.$1_headers: $$($1_COMPILE_TARGET)
ohair@492 364 $(MKDIR) -p $$(@D)
chegar@1120 365 if [ -d "$$($1_HEADERS).$1.tmp" ]; then \
chegar@1120 366 for f in `ls $$($1_HEADERS).$1.tmp`; do \
chegar@1120 367 if [ ! -f "$$($1_HEADERS)/$$$$f" ] \
chegar@1120 368 || [ "`$(DIFF) $$($1_HEADERS)/$$$$f $$($1_HEADERS).$1.tmp/$$$$f`" != "" ]; then \
erikj@960 369 $(CP) -f $$($1_HEADERS).$1.tmp/$$$$f $$($1_HEADERS)/$$$$f; \
ohair@492 370 fi; \
chegar@1120 371 done; \
chegar@1120 372 fi
erikj@960 373 $(RM) -r $$($1_HEADERS).$1.tmp
ohair@492 374 $(TOUCH) $$@
ohair@492 375
chegar@1120 376 $1_HEADER_TARGETS := $$($1_HEADERS)/_the.$1_headers
ohair@423 377 endif
ohair@423 378
ihse@1656 379 $1_VARDEPS := $$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) $$($1_BIN) \
ihse@1656 380 $$($1_HEADERS_ARG) $$($1_EXCLUDES) $$($1_INCLUDES) \
ihse@1656 381 $$($1_EXCLUDE_FILES) $$($1_INCLUDE_FILES)
erikj@1299 382 $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$($1_BIN)/_the.$1.vardeps)
erikj@1299 383
erikj@1705 384 ifeq ($$($1_DISABLE_SJAVAC)x$(ENABLE_JAVAC_SERVER), xyes)
erikj@1705 385 $1_JAVAC_CMD := $$($1_SJAVAC) $$($1_REMOTE)
erikj@1705 386 else
erikj@1705 387 $1_JAVAC_CMD := $$($1_JAVAC)
erikj@1705 388 endif
erikj@1705 389
ihse@837 390 # When not using sjavac, pass along all sources to javac using an @file.
erikj@1790 391 $$($1_COMPILE_TARGET): $$($1_SRCS) $$($1_DEPENDS) $$($1_VARDEPS_FILE)
ihse@837 392 $(MKDIR) -p $$(@D)
erikj@1790 393 $$(eval $$(call ListPathsSafely,$1_SRCS, $$@.tmp))
erikj@1790 394 $(ECHO) Compiling `$(WC) $$@.tmp | $(TR) -s ' ' | $(CUT) -f 2 -d ' '` files for $1
ihse@1656 395 $(call LogFailures, $$($1_BIN)/_the.$$($1_SAFE_NAME)_batch.log, $$($1_SAFE_NAME), \
erikj@1705 396 $$($1_JVM) $$($1_JAVAC_CMD) $$($1_FLAGS) \
ihse@1623 397 -implicit:none \
erikj@1790 398 -d $$($1_BIN) $$($1_HEADERS_ARG) @$$@.tmp) && \
erikj@1790 399 $(MV) $$@.tmp $$@
ihse@837 400 endif
ihse@837 401
chegar@1120 402 # Add all targets to main variable
erikj@1790 403 $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_COMPILE_TARGET) \
chegar@1120 404 $$($1_HEADER_TARGETS)
chegar@1120 405
ihse@837 406 # Check if a jar file was specified, then setup the rules for the jar.
ihse@837 407 ifneq (,$$($1_JAR))
ihse@837 408 # If no suffixes was explicitly set for this jar file.
ihse@837 409 # Use class and the cleaned/copied properties file suffixes as the default
ihse@837 410 # for the types of files to be put into the jar.
ihse@837 411 ifeq (,$$($1_SUFFIXES))
ihse@837 412 $1_SUFFIXES:=.class $$($1_CLEAN) $$($1_COPY)
ohair@476 413 endif
ohair@476 414
ihse@1726 415 $$(eval $$(call SetupJarArchive, ARCHIVE_$1, \
erikj@1379 416 DEPENDENCIES:=$$($1), \
ihse@837 417 SRCS:=$$($1_BIN), \
ihse@837 418 SUFFIXES:=$$($1_SUFFIXES), \
ihse@837 419 EXCLUDE:=$$($1_EXCLUDES), \
ihse@837 420 INCLUDES:=$$($1_INCLUDES), \
ihse@837 421 EXTRA_FILES:=$$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS), \
ihse@837 422 JAR:=$$($1_JAR), \
ihse@837 423 JARMAIN:=$$($1_JARMAIN), \
ihse@837 424 MANIFEST:=$$($1_MANIFEST), \
ihse@837 425 EXTRA_MANIFEST_ATTR:=$$($1_EXTRA_MANIFEST_ATTR), \
ihse@837 426 JARINDEX:=$$($1_JARINDEX), \
ihse@837 427 HEADERS:=$$($1_HEADERS), \
ihse@1726 428 SETUP:=$$($1_SETUP), \
ihse@1726 429 ))
erikj@959 430
erikj@959 431 # Add jar to target list
erikj@959 432 $1 += $$($1_JAR)
ihse@837 433 endif
ihse@837 434
ihse@837 435 # Check if a srczip was specified, then setup the rules for the srczip.
ihse@837 436 ifneq (,$$($1_SRCZIP))
ihse@1725 437 $$(eval $$(call SetupZipArchive, ZIP_ARCHIVE_$1, \
ihse@837 438 SRC:=$$($1_SRC), \
ihse@837 439 ZIP:=$$($1_SRCZIP), \
ihse@837 440 INCLUDES:=$$($1_INCLUDES), \
ihse@837 441 EXCLUDES:=$$($1_EXCLUDES), \
ihse@837 442 EXCLUDE_FILES:=$$($1_EXCLUDE_FILES)))
erikj@959 443
erikj@959 444 # Add zip to target list
erikj@959 445 $1 += $$($1_SRCZIP)
ihse@837 446 endif
ohair@423 447 endef
chegar@1120 448
chegar@1120 449 # Use this macro to find the correct target to depend on when the original
chegar@1120 450 # SetupJavaCompilation is declared in a different makefile, to avoid having
chegar@1120 451 # to declare and evaluate it again.
chegar@1120 452 # param 1 is for example BUILD_MYPACKAGE
chegar@1120 453 # param 2 is the output directory (BIN)
chegar@1120 454 define SetupJavaCompilationCompileTarget
erikj@1144 455 $(if $(findstring yes, $(ENABLE_SJAVAC)), $(strip $2)/_the.$(strip $1)_pubapi, \
chegar@1120 456 $(strip $2)/_the.$(strip $1)_batch)
chegar@1120 457 endef
erikj@1299 458
erikj@1299 459 endif # _JAVA_COMPILATION_GMK