JavaCompilation.gmk revision 1730:a36dc737a448
1194612Sed# 2194612Sed# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. 3194612Sed# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4194612Sed# 5194612Sed# This code is free software; you can redistribute it and/or modify it 6194612Sed# under the terms of the GNU General Public License version 2 only, as 7194612Sed# published by the Free Software Foundation. Oracle designates this 8194612Sed# particular file as subject to the "Classpath" exception as provided 9194612Sed# by Oracle in the LICENSE file that accompanied this code. 10194612Sed# 11194612Sed# This code is distributed in the hope that it will be useful, but WITHOUT 12194612Sed# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13194612Sed# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14194612Sed# version 2 for more details (a copy is included in the LICENSE file that 15194612Sed# accompanied this code). 16249423Sdim# 17249423Sdim# You should have received a copy of the GNU General Public License version 18249423Sdim# 2 along with this work; if not, write to the Free Software Foundation, 19218893Sdim# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20249423Sdim# 21194612Sed# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22194612Sed# or visit www.oracle.com if you need additional information or have any 23218893Sdim# questions. 24194612Sed# 25194612Sed 26249423Sdim# When you read this source. Remember that $(sort ...) has the side effect 27249423Sdim# of removing duplicates. It is actually this side effect that is 28198090Srdivacky# desired whenever sort is used below! 29198090Srdivacky 30198090Srdivackyifndef _JAVA_COMPILATION_GMK 31198090Srdivacky_JAVA_COMPILATION_GMK := 1 32198090Srdivacky 33198090Srdivackyifeq (,$(_MAKEBASE_GMK)) 34198090Srdivacky $(error You must include MakeBase.gmk prior to including JavaCompilation.gmk) 35198090Srdivackyendif 36198090Srdivacky 37198090Srdivacky# Java compilation needs SetupJarArchive and/or SetupZipArchive, if we're 38198090Srdivacky# generating a jar file or a source zip. 39198090Srdivackyinclude JarArchive.gmk 40198090Srdivackyinclude ZipArchive.gmk 41194612Sed 42198090Srdivacky# Setup make rules for defining a Java compiler, which is needed to compile 43198090Srdivacky# Java code. This rule generates no output. 44198090Srdivacky# 45203954Srdivacky# Parameter 1 is the name of the compiler definition. This name needs to be 46194612Sed# passed to SetupJavaCompilation. This name is used as variable prefix. 47194612Sed# 48194612Sed# Remaining parameters are named arguments. These include: 49194612Sed# JVM:=The jvm used to run the javac/javah command 50194612Sed# JAVAC:=The javac jar and bootstrap classpath changes, or just bin/javac if JVM is left out 51194612Sed# FLAGS:=Flags to be supplied to javac 52194612Sed# SERVER_DIR:=Use a javac server (-XDserver) and store the server related files here 53194612Sed# SERVER_JVM:=Use this JVM for the server. Defaults to the JVM above. 54194612Sed# DISABLE_SJAVAC:=Set to true if this setup does not support sjavac 55263508SdimSetupJavaCompiler = $(NamedParamsMacroTemplate) 56263508Sdimdefine SetupJavaCompilerBody 57263508Sdim # The port file contains the tcp/ip on which the server listens 58218893Sdim # and the cookie necessary to talk to the server. 59223017Sdim $1_SJAVAC_PORTFILE:=$$($1_SERVER_DIR)/server.port 60223017Sdim # You can use a different JVM to run the background javac server. 61203954Srdivacky ifeq ($$($1_SERVER_JVM),) 62194612Sed # It defaults to the same JVM that is used to start the javac command. 63194612Sed $1_SERVER_JVM:=$$($1_JVM) 64223017Sdim endif 65223017Sdimendef 66194612Sed 67203954Srdivackydefine add_file_to_copy 68263508Sdim # param 1 = BUILD_MYPACKAGE 69194612Sed # parma 2 = The source file to copy. 70218893Sdim $2_TARGET:=$2 71194612Sed # Remove the source prefix. 72194612Sed $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET))) 73194612Sed # To allow for automatic overrides, do not create a rule for a target file that 74194612Sed # already has one 75194612Sed ifneq ($$($1_COPY_$$($2_TARGET)), 1) 76194612Sed $1_COPY_$$($2_TARGET) := 1 77194612Sed # Now we can setup the depency that will trigger the copying. 78194612Sed $$($1_BIN)$$($2_TARGET) : $2 79194612Sed $(MKDIR) -p $$(@D) 80194612Sed $(CP) $$< $$@ 81194612Sed $(CHMOD) -f ug+w $$@ 82194612Sed 83194612Sed # And do not forget this target 84194612Sed $1_ALL_COPY_TARGETS += $$($1_BIN)$$($2_TARGET) 85194612Sed endif 86239462Sdimendef 87239462Sdim 88239462Sdim# This macro is used only for properties files that are to be 89239462Sdim# copied over to the classes directory in cleaned form: 90194612Sed# Previously this was inconsistently done in different repositories. 91194612Sed# This is the new clean standard. Though it is to be superseded by 92203954Srdivacky# a standard annotation processor from with sjavac. 93194612Sed# 94203954Srdivacky# An empty echo ensures that the input to sed always ends with a newline. 95194612Sed# Certain implementations (e.g. Solaris) will skip the last line without 96194612Sed# it. 97194612Sed# 98203954Srdivacky# The sed expression does this: 99239462Sdim# 1. Add a backslash before any :, = or ! that do not have a backslash already. 100239462Sdim# 2. Apply the file unicode2x.sed which does a whole bunch of \u00XX to \xXX 101194612Sed# conversions. 102198090Srdivacky# 3. Delete all lines starting with #. 103198090Srdivacky# 4. Delete empty lines. 104198090Srdivacky# 5. Append lines ending with \ with the next line. 105198090Srdivacky# 6. Remove leading and trailing white space. Note that tabs must be explicit 106203954Srdivacky# as sed on macosx does not understand '\t'. 107198090Srdivacky# 7. Replace the first \= with just =. 108198090Srdivacky# 8. Finally it's all sorted to create a stable output. 109198090Srdivacky# 110198090Srdivacky# It is assumed that = is the character used for separating names and values. 111198090Srdivackydefine add_file_to_clean 112198090Srdivacky # param 1 = BUILD_MYPACKAGE 113198090Srdivacky # parma 2 = The source file to copy and clean. 114194612Sed $2_TARGET:=$2 115194612Sed # Remove the source prefix. 116203954Srdivacky $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET))) 117198090Srdivacky # Now we can setup the depency that will trigger the copying. 118198090Srdivacky # To allow for automatic overrides, do not create a rule for a target file that 119198090Srdivacky # already has one 120203954Srdivacky ifneq ($$($1_CLEAN_$$($2_TARGET)), 1) 121198090Srdivacky $1_CLEAN_$$($2_TARGET) := 1 122198090Srdivacky $$($1_BIN)$$($1_MODULE_SUBDIR)$$($2_TARGET) : $2 123198090Srdivacky $(MKDIR) -p $$(@D) 124198090Srdivacky export LC_ALL=C ; ( $(CAT) $$< && $(ECHO) "" ) \ 125198090Srdivacky | $(SED) -e 's/\([^\\]\):/\1\\:/g' -e 's/\([^\\]\)=/\1\\=/g' \ 126239462Sdim -e 's/\([^\\]\)!/\1\\!/g' -e 's/^[ ]*#.*/#/g' \ 127239462Sdim | $(SED) -f "$(SRC_ROOT)/make/common/support/unicode2x.sed" \ 128239462Sdim | $(SED) -e '/^#/d' -e '/^$$$$/d' \ 129239462Sdim -e :a -e '/\\$$$$/N; s/\\\n//; ta' \ 130194612Sed -e 's/^[ ]*//;s/[ ]*$$$$//' \ 131194612Sed -e 's/\\=/=/' \ 132195340Sed | $(SORT) > $$@ 133194612Sed $(CHMOD) -f ug+w $$@ 134203954Srdivacky 135194612Sed # And do not forget this target 136194612Sed $1_ALL_COPY_CLEAN_TARGETS += $$($1_BIN)$$($2_TARGET) 137194612Sed endif 138195340Sedendef 139203954Srdivacky 140195340Seddefine remove_string 141195340Sed $2 := $$(subst $1,,$$($2)) 142195340Sedendef 143194612Sed 144194612Sed# Setup make rules for compiling Java source code to class files and/or a 145194612Sed# resulting jar file. 146195340Sed# 147195340Sed# Parameter 1 is the name of the rule. This name is used as variable prefix, 148195340Sed# and the targets generated are listed in a variable by that name. 149195340Sed# 150195340Sed# Remaining parameters are named arguments. These include: 151234353Sdim# SETUP:=must point to a previously setup java compiler, for example: SETUP:=BOOTJAVAC 152234353Sdim# JVM:=path to ..bin/java 153249423Sdim# ADD_JAVAC_FLAGS:=javac flags to append to the default ones. 154249423Sdim# SRC:=one or more directories to search for sources. The order of the source roots 155203954Srdivacky# is significant. The first found file of a certain name has priority. 156194612Sed# BIN:=store classes here 157239462Sdim# CLASSPATH:=a list of additional entries to set as classpath to javac 158239462Sdim# INCLUDES:=myapp.foo means will only compile java files in myapp.foo or any of its sub-packages. 159239462Sdim# EXCLUDES:=myapp.foo means will do not compile java files in myapp.foo or any of its sub-packages. 160239462Sdim# COPY:=.prp means copy all prp files to the corresponding package in BIN. 161239462Sdim# COPY_FILES:=myapp/foo/setting.txt means copy this file over to the package myapp/foo 162239462Sdim# CLEAN:=.properties means copy and clean all properties file to the corresponding package in BIN. 163239462Sdim# CLEAN_FILES:=myapp/foo/setting.txt means clean this file over to the package myapp/foo 164239462Sdim# SRCZIP:=Create a src.zip based on the found sources and copied files. 165239462Sdim# INCLUDE_FILES:="com/sun/SolarisFoobar.java" means only compile this file! 166203954Srdivacky# EXCLUDE_FILES:="com/sun/SolarisFoobar.java" means do not compile this particular file! 167239462Sdim# "SolarisFoobar.java" means do not compile SolarisFoobar, wherever it is found. 168239462Sdim# HEADERS:=path to directory where all generated c-headers are written. 169239462Sdim# DEPENDS:=Extra dependecy 170239462Sdim# DISABLE_SJAVAC:=Explicitly disable the use of sjavac for this compilation unit. 171239462Sdim# KEEP_DUPS:=Do not remove duplicate file names from different source roots. 172239462SdimSetupJavaCompilation = $(NamedParamsMacroTemplate) 173239462Sdimdefine SetupJavaCompilationBody 174239462Sdim 175239462Sdim # Verify arguments 176199989Srdivacky ifeq ($$($1_BIN),) 177239462Sdim $$(error Must specify BIN (in $1)) 178239462Sdim endif 179239462Sdim 180239462Sdim # Extract the info from the java compiler setup. 181239462Sdim $1_JVM := $$($$($1_SETUP)_JVM) 182239462Sdim $1_JAVAC := $$($$($1_SETUP)_JAVAC) 183199989Srdivacky $1_FLAGS := $$($$($1_SETUP)_FLAGS) $(JAVAC_FLAGS) $$($1_ADD_JAVAC_FLAGS) 184239462Sdim ifneq ($$($1_CLASSPATH), ) 185239462Sdim $1_FLAGS += -cp $$(call PathList, $$($1_CLASSPATH)) 186239462Sdim endif 187239462Sdim ifeq ($$($1_JAVAC),) 188239462Sdim $$(error The Java compilation $1 refers to a non-existant java compiler setup $$($1_SETUP)) 189239462Sdim endif 190239462Sdim $1_SJAVAC_PORTFILE := $$($$($1_SETUP)_SJAVAC_PORTFILE) 191239462Sdim $1_SERVER_JVM := $$($$($1_SETUP)_SERVER_JVM) 192239462Sdim $1_DISABLE_SJAVAC := $$($$($1_SETUP)_DISABLE_SJAVAC) 193239462Sdim 194239462Sdim # Make sure the dirs exist. 195239462Sdim $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupJavaCompilation $1 contains missing directory >$$d<))) 196239462Sdim $$(call MakeDir,$$($1_BIN)) 197239462Sdim # Add all source roots to the find cache since we are likely going to run find 198239462Sdim # on these more than once. The cache will only be updated if necessary. 199239462Sdim $$(eval $$(call FillCacheFind,$$($1_SRC))) 200239462Sdim # Find all files in the source trees. Preserve order of source roots so that 201249423Sdim # the first version in case of multiple instances of the same file is selected. 202239462Sdim # CacheFind does not preserve order so need to call it for each root. 203239462Sdim $1_ALL_SRCS += $$(foreach s, $$($1_SRC), $$(call CacheFind, $$(s))) 204239462Sdim # Extract the java files. 205234353Sdim ifneq ($$($1_EXCLUDE_FILES),) 206239462Sdim $1_EXCLUDE_FILES_PATTERN:=$$(addprefix %,$$($1_EXCLUDE_FILES)) 207239462Sdim endif 208234353Sdim $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$(filter %.java,$$($1_ALL_SRCS))) 209239462Sdim ifneq ($$($1_INCLUDE_FILES),) 210239462Sdim $1_INCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES))) 211249423Sdim $1_SRCS := $$(filter $$($1_INCLUDE_FILES), $$($1_SRCS)) 212194612Sed endif 213195340Sed 214263508Sdim # Prepend the source/bin path to the filter expressions. 215263508Sdim ifneq ($$($1_INCLUDES),) 216234982Sdim $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES)))) 217249423Sdim $1_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS)) 218249423Sdim endif 219234353Sdim ifneq ($$($1_EXCLUDES),) 220206274Srdivacky $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES)))) 221206274Srdivacky $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS)) 222234353Sdim endif 223206274Srdivacky 224206274Srdivacky ifneq ($$($1_KEEP_DUPS), true) 225218893Sdim # Remove duplicate source files by keeping the first found of each duplicate. 226239462Sdim # This allows for automatic overrides with custom or platform specific versions 227239462Sdim # source files. 228239462Sdim # 229239462Sdim # For the smart javac wrapper case, add each removed file to an extra exclude 230239462Sdim # file list to prevent sjavac from finding duplicate sources. 231195340Sed $1_SRCS := $$(strip $$(foreach s, $$($1_SRCS), \ 232234982Sdim $$(eval relative_src := $$(call remove-prefixes, $$($1_SRC), $$(s))) \ 233195340Sed $$(if $$($1_$$(relative_src)), \ 234195340Sed $$(eval $1_SJAVAC_EXCLUDE_FILES += $$(s)), \ 235263508Sdim $$(eval $1_$$(relative_src) := 1) $$(s)))) 236263508Sdim endif 237263508Sdim 238263508Sdim ifeq ($$(strip $$($1_SRCS)), ) 239263508Sdim $$(error No source files found for $1) 240263508Sdim endif 241195340Sed 242195340Sed $1_SAFE_NAME := $$(strip $$(subst /,_, $1)) 243195340Sed 244195340Sed # Create the corresponding smart javac wrapper command line. 245249423Sdim $1_SJAVAC_ARGS:=$$(addprefix -x ,$$(addsuffix /*,$$($1_EXCLUDES))) \ 246234353Sdim $$(addprefix -i ,$$(addsuffix /*,$$($1_INCLUDES))) \ 247249423Sdim $$(addprefix -xf *,$$(strip $$($1_EXCLUDE_FILES) $$($1_SJAVAC_EXCLUDE_FILES))) \ 248249423Sdim $$(addprefix -if *,$$(strip $$($1_INCLUDE_FILES))) \ 249249423Sdim -src $$(call PathList, $$($1_SRC)) 250234353Sdim 251249423Sdim # All files below META-INF are always copied. 252249423Sdim $1_ALL_COPIES := $$(filter $$(addsuffix /META-INF%,$$($1_SRC)),$$($1_ALL_SRCS)) 253249423Sdim # Find all files to be copied from source to bin. 254234353Sdim ifneq (,$$($1_COPY)$$($1_COPY_FILES)) 255234353Sdim # Search for all files to be copied. 256249423Sdim $1_ALL_COPIES += $$(filter $$(addprefix %,$$($1_COPY)),$$($1_ALL_SRCS)) 257249423Sdim # Copy these explicitly 258249423Sdim $1_ALL_COPIES += $$($1_COPY_FILES) 259249423Sdim endif 260234353Sdim # Copy must also respect filters. 261249423Sdim ifneq (,$$($1_INCLUDES)) 262249423Sdim $1_ALL_COPIES := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_COPIES)) 263249423Sdim endif 264249423Sdim ifneq (,$$($1_EXCLUDES)) 265249423Sdim $1_ALL_COPIES := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_COPIES)) 266249423Sdim endif 267249423Sdim ifneq (,$$($1_EXCLUDE_FILES)) 268249423Sdim $1_ALL_COPIES := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_COPIES)) 269249423Sdim endif 270249423Sdim ifneq (,$$($1_ALL_COPIES)) 271249423Sdim # Yep, there are files to be copied! 272249423Sdim $1_ALL_COPY_TARGETS:= 273249423Sdim $$(foreach i,$$($1_ALL_COPIES),$$(eval $$(call add_file_to_copy,$1,$$i))) 274249423Sdim # Now we can depend on $$($1_ALL_COPY_TARGETS) to copy all files! 275249423Sdim endif 276249423Sdim 277249423Sdim # Find all property files to be copied and cleaned from source to bin. 278249423Sdim ifneq (,$$($1_CLEAN)$$($1_CLEAN_FILES)) 279249423Sdim # Search for all files to be copied. 280249423Sdim $1_ALL_CLEANS := $$(filter $$(addprefix %,$$($1_CLEAN)),$$($1_ALL_SRCS)) 281249423Sdim # Clean these explicitly 282249423Sdim $1_ALL_CLEANS += $$($1_CLEAN_FILES) 283249423Sdim # Copy and clean must also respect filters. 284249423Sdim ifneq (,$$($1_INCLUDES)) 285249423Sdim $1_ALL_CLEANS := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_CLEANS)) 286249423Sdim endif 287249423Sdim ifneq (,$$($1_EXCLUDES)) 288249423Sdim $1_ALL_CLEANS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_CLEANS)) 289249423Sdim endif 290249423Sdim ifneq (,$$($1_EXCLUDE_FILES)) 291249423Sdim $1_ALL_CLEANS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_CLEANS)) 292249423Sdim endif 293249423Sdim ifneq (,$$($1_ALL_CLEANS)) 294249423Sdim # Yep, there are files to be copied and cleaned! 295249423Sdim $1_ALL_COPY_CLEAN_TARGETS:= 296249423Sdim $$(foreach i,$$($1_ALL_CLEANS),$$(eval $$(call add_file_to_clean,$1,$$i))) 297249423Sdim # Now we can depend on $$($1_ALL_COPY_CLEAN_TARGETS) to copy all files! 298249423Sdim endif 299249423Sdim endif 300249423Sdim 301249423Sdim # Create a sed expression to remove the source roots and to replace / with . 302249423Sdim # and remove .java at the end. 303249423Sdim $1_REWRITE_INTO_CLASSES:=$$(foreach i,$$($1_SRC),-e 's|$$i/||g') -e 's|/|.|g' -e 's|.java$$$$||g' 304249423Sdim 305249423Sdim # Create SJAVAC variable from JAVAC variable. Expects $1_JAVAC to be 306249423Sdim # "bootclasspathprepend -cp .../javac.jar com.sun.tools.javac.Main" 307249423Sdim # and javac is simply replaced with sjavac. 308249423Sdim $1_SJAVAC:=$$(subst com.sun.tools.javac.Main,com.sun.tools.sjavac.Main,$$($1_JAVAC)) 309249423Sdim 310249423Sdim # Set the $1_REMOTE to spawn a background javac server. 311249423Sdim $1_REMOTE:=--server:portfile=$$($1_SJAVAC_PORTFILE),id=$1,sjavac=$$(subst \ 312249423Sdim $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_SJAVAC)))) 313249423Sdim 314249423Sdim ifeq ($$($1_DISABLE_SJAVAC)x$$(ENABLE_SJAVAC),xyes) 315249423Sdim ifneq (,$$($1_HEADERS)) 316249423Sdim $1_HEADERS_ARG := -h $$($1_HEADERS) 317249423Sdim endif 318249423Sdim 319249423Sdim # Using sjavac to compile. 320249423Sdim $1_COMPILE_TARGETS := $$($1_BIN)/_the.$1_batch 321249423Sdim 322249423Sdim $1_VARDEPS := $$($1_JVM) $$($1_SJAVAC) $$($1_SJAVAC_ARGS) $$($1_FLAGS) \ 323249423Sdim $$($1_HEADERS_ARG) $$($1_BIN) $$($1_EXCLUDES) $$($1_INCLUDES) \ 324249423Sdim $$($1_EXCLUDE_FILES) $$($1_INCLUDE_FILES) 325249423Sdim $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$($1_BIN)/_the.$1.vardeps) 326249423Sdim 327249423Sdim $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS) $$($1_VARDEPS_FILE) 328249423Sdim $(MKDIR) -p $$(@D) $$(dir $$($1_SJAVAC_PORTFILE)) 329249423Sdim $$(eval $$(call ListPathsSafely,$1_SRCS, $$($1_BIN)/_the.$1_batch.tmp)) 330249423Sdim $(ECHO) Compiling $1 331249423Sdim $(call LogFailures, $$($1_BIN)/_the.$$($1_SAFE_NAME)_batch.log, $$($1_SAFE_NAME), \ 332249423Sdim $$($1_JVM) $$($1_SJAVAC) \ 333249423Sdim $$($1_REMOTE) \ 334249423Sdim -j 1 \ 335249423Sdim --permit-unidentified-artifacts \ 336249423Sdim --permit-sources-without-package \ 337249423Sdim --compare-found-sources $$($1_BIN)/_the.$1_batch.tmp \ 338249423Sdim --log=$(LOG_LEVEL) \ 339249423Sdim --state-dir=$$($1_BIN) \ 340249423Sdim $$($1_SJAVAC_ARGS) \ 341249423Sdim $$($1_FLAGS) \ 342249423Sdim $$($1_HEADERS_ARG) \ 343249423Sdim -d $$($1_BIN)) && \ 344249423Sdim $(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch 345249423Sdim # Create a pubapi file that only changes when the pubapi changes. Dependent 346249423Sdim # compilations can use this file to only get recompiled when pubapi has changed. 347249423Sdim # Grep returns 1 if no matching lines are found. Do not fail for this. 348234982Sdim $(GREP) -e "^I" $$($1_BIN)/javac_state > $$($1_BIN)/_the.$1_pubapi.tmp \ 349234982Sdim || test "$$$$?" = "1" 350239462Sdim if [ ! -f $$($1_BIN)/_the.$1_pubapi ] \ 351239462Sdim || [ "`$(DIFF) $$($1_BIN)/_the.$1_pubapi $$($1_BIN)/_the.$1_pubapi.tmp`" != "" ]; then \ 352234982Sdim $(MV) $$($1_BIN)/_the.$1_pubapi.tmp $$($1_BIN)/_the.$1_pubapi; \ 353234982Sdim fi 354234982Sdim 355234982Sdim else 356195340Sed # Using plain javac to batch compile everything. 357195340Sed $1_COMPILE_TARGETS := $$($1_BIN)/_the.$1_batch 358195340Sed 359202878Srdivacky # When building in batch, put headers in a temp dir to filter out those that actually 360202878Srdivacky # changed before copying them to the real header dir. 361202878Srdivacky ifneq (,$$($1_HEADERS)) 362202878Srdivacky $1_HEADERS_ARG := -h $$($1_HEADERS).$1.tmp 363202878Srdivacky 364203954Srdivacky $$($1_HEADERS)/_the.$1_headers: $$($1_BIN)/_the.$1_batch 365202878Srdivacky $(MKDIR) -p $$(@D) 366202878Srdivacky if [ -d "$$($1_HEADERS).$1.tmp" ]; then \ 367202878Srdivacky for f in `ls $$($1_HEADERS).$1.tmp`; do \ 368202878Srdivacky if [ ! -f "$$($1_HEADERS)/$$$$f" ] \ 369202878Srdivacky || [ "`$(DIFF) $$($1_HEADERS)/$$$$f $$($1_HEADERS).$1.tmp/$$$$f`" != "" ]; then \ 370202878Srdivacky $(CP) -f $$($1_HEADERS).$1.tmp/$$$$f $$($1_HEADERS)/$$$$f; \ 371195340Sed fi; \ 372203954Srdivacky done; \ 373234353Sdim fi 374234982Sdim $(RM) -r $$($1_HEADERS).$1.tmp 375234982Sdim $(TOUCH) $$@ 376234982Sdim 377234982Sdim $1_HEADER_TARGETS := $$($1_HEADERS)/_the.$1_headers 378234982Sdim endif 379234982Sdim 380234982Sdim $1_VARDEPS := $$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) $$($1_BIN) \ 381234982Sdim $$($1_HEADERS_ARG) $$($1_EXCLUDES) $$($1_INCLUDES) \ 382234982Sdim $$($1_EXCLUDE_FILES) $$($1_INCLUDE_FILES) 383234982Sdim $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$($1_BIN)/_the.$1.vardeps) 384234982Sdim 385234982Sdim ifeq ($$($1_DISABLE_SJAVAC)x$(ENABLE_JAVAC_SERVER), xyes) 386234982Sdim $1_JAVAC_CMD := $$($1_SJAVAC) $$($1_REMOTE) 387234982Sdim else 388234982Sdim $1_JAVAC_CMD := $$($1_JAVAC) 389234353Sdim endif 390234982Sdim 391234982Sdim # When not using sjavac, pass along all sources to javac using an @file. 392234982Sdim $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS) $$($1_VARDEPS_FILE) 393234982Sdim $(MKDIR) -p $$(@D) 394234982Sdim $$(eval $$(call ListPathsSafely,$1_SRCS, $$($1_BIN)/_the.$1_batch.tmp)) 395234982Sdim $(ECHO) Compiling `$(WC) $$($1_BIN)/_the.$1_batch.tmp | $(TR) -s ' ' | $(CUT) -f 2 -d ' '` files for $1 396202878Srdivacky $(call LogFailures, $$($1_BIN)/_the.$$($1_SAFE_NAME)_batch.log, $$($1_SAFE_NAME), \ 397199989Srdivacky $$($1_JVM) $$($1_JAVAC_CMD) $$($1_FLAGS) \ 398234982Sdim -implicit:none \ 399234982Sdim -d $$($1_BIN) $$($1_HEADERS_ARG) @$$($1_BIN)/_the.$1_batch.tmp) && \ 400234982Sdim $(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch 401234353Sdim endif 402234353Sdim 403203954Srdivacky # Add all targets to main variable 404249423Sdim $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_COMPILE_TARGETS) \ 405249423Sdim $$($1_HEADER_TARGETS) 406249423Sdim 407249423Sdim # Check if a jar file was specified, then setup the rules for the jar. 408249423Sdim ifneq (,$$($1_JAR)) 409249423Sdim # If no suffixes was explicitly set for this jar file. 410249423Sdim # Use class and the cleaned/copied properties file suffixes as the default 411249423Sdim # for the types of files to be put into the jar. 412249423Sdim ifeq (,$$($1_SUFFIXES)) 413249423Sdim $1_SUFFIXES:=.class $$($1_CLEAN) $$($1_COPY) 414249423Sdim endif 415249423Sdim 416234353Sdim $$(eval $$(call SetupJarArchive, ARCHIVE_$1, \ 417249423Sdim DEPENDENCIES:=$$($1), \ 418234353Sdim SRCS:=$$($1_BIN), \ 419234353Sdim SUFFIXES:=$$($1_SUFFIXES), \ 420234353Sdim EXCLUDE:=$$($1_EXCLUDES), \ 421234353Sdim INCLUDES:=$$($1_INCLUDES), \ 422249423Sdim EXTRA_FILES:=$$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS), \ 423249423Sdim JAR:=$$($1_JAR), \ 424249423Sdim JARMAIN:=$$($1_JARMAIN), \ 425195340Sed MANIFEST:=$$($1_MANIFEST), \ 426249423Sdim EXTRA_MANIFEST_ATTR:=$$($1_EXTRA_MANIFEST_ATTR), \ 427249423Sdim JARINDEX:=$$($1_JARINDEX), \ 428249423Sdim HEADERS:=$$($1_HEADERS), \ 429249423Sdim SETUP:=$$($1_SETUP), \ 430249423Sdim )) 431249423Sdim 432249423Sdim # Add jar to target list 433249423Sdim $1 += $$($1_JAR) 434234353Sdim endif 435249423Sdim 436234353Sdim # Check if a srczip was specified, then setup the rules for the srczip. 437234353Sdim ifneq (,$$($1_SRCZIP)) 438249423Sdim $$(eval $$(call SetupZipArchive, ZIP_ARCHIVE_$1, \ 439234353Sdim SRC:=$$($1_SRC), \ 440234353Sdim ZIP:=$$($1_SRCZIP), \ 441234353Sdim INCLUDES:=$$($1_INCLUDES), \ 442234353Sdim EXCLUDES:=$$($1_EXCLUDES), \ 443234353Sdim EXCLUDE_FILES:=$$($1_EXCLUDE_FILES))) 444234353Sdim 445249423Sdim # Add zip to target list 446234353Sdim $1 += $$($1_SRCZIP) 447234982Sdim endif 448234982Sdimendef 449234982Sdim 450234353Sdim# Use this macro to find the correct target to depend on when the original 451234353Sdim# SetupJavaCompilation is declared in a different makefile, to avoid having 452234353Sdim# to declare and evaluate it again. 453234353Sdim# param 1 is for example BUILD_MYPACKAGE 454234353Sdim# param 2 is the output directory (BIN) 455234353Sdimdefine SetupJavaCompilationCompileTarget 456234353Sdim $(if $(findstring yes, $(ENABLE_SJAVAC)), $(strip $2)/_the.$(strip $1)_pubapi, \ 457234353Sdim $(strip $2)/_the.$(strip $1)_batch) 458234353Sdimendef 459234353Sdim 460234353Sdimendif # _JAVA_COMPILATION_GMK 461234353Sdim