JavaCompilation.gmk revision 1305:a6e8bde6a87e
1233294Sstas#
2102644Snectar# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
355682Smarkm# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4142403Snectar#
5233294Sstas# This code is free software; you can redistribute it and/or modify it
6233294Sstas# under the terms of the GNU General Public License version 2 only, as
755682Smarkm# published by the Free Software Foundation.  Oracle designates this
855682Smarkm# particular file as subject to the "Classpath" exception as provided
955682Smarkm# by Oracle in the LICENSE file that accompanied this code.
1055682Smarkm#
1155682Smarkm# This code is distributed in the hope that it will be useful, but WITHOUT
1255682Smarkm# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1355682Smarkm# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1455682Smarkm# version 2 for more details (a copy is included in the LICENSE file that
1555682Smarkm# accompanied this code).
1690926Snectar#
1790926Snectar# You should have received a copy of the GNU General Public License version
18233294Sstas# 2 along with this work; if not, write to the Free Software Foundation,
1990926Snectar# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20233294Sstas#
2190926Snectar# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22233294Sstas# or visit www.oracle.com if you need additional information or have any
2355682Smarkm# questions.
24142403Snectar#
25142403Snectar
2655682Smarkm# This makefile is much simpler now that it can use the smart javac wrapper
2755682Smarkm# for dependency tracking between java packages and incremental compiles.
28233294Sstas# It could be even more simple if we added support for incremental jar updates
2955682Smarkm# directly from the smart javac wrapper.
30233294Sstas
31102644Snectar# Cleaning/copying properties here is not a good solution. The properties
32102644Snectar# should be cleaned/copied by a annotation processor in sjavac.
33102644Snectar
34127808Snectar# When you read this source. Remember that $(sort ...) has the side effect
3590926Snectar# of removing duplicates. It is actually this side effect that is
36127808Snectar# desired whenever sort is used below!
3755682Smarkm
3855682Smarkmifndef _JAVA_COMPILATION_GMK
3955682Smarkm_JAVA_COMPILATION_GMK := 1
4055682Smarkm
4155682Smarkmifeq (,$(_MAKEBASE_GMK))
4255682Smarkm  $(error You must include MakeBase.gmk prior to including JavaCompilation.gmk)
43178825Sdfrendif
4455682Smarkm
45178825Sdfr# Java compilation needs SetupZipArchive if we're generating a source zip.
46142403Snectarinclude ZipArchive.gmk
47142403Snectar
48178825SdfrFALSE_FIND_PATTERN:=-name FILE_NAME_THAT_DOESNT_EXIST
49178825Sdfr
50178825Sdfr# Setup make rules for defining a Java compiler, which is needed to compile
51178825Sdfr# Java code. This rule generates no output.
52178825Sdfr#
53178825Sdfr# Parameter 1 is the name of the compiler definition. This name needs to be
54178825Sdfr# passed to SetupJavaCompilation. This name is used as variable prefix.
55178825Sdfr#
56178825Sdfr# Remaining parameters are named arguments. These include:
57178825Sdfr#   JVM:=The jvm used to run the javac/javah command
58178825Sdfr#   JAVAC:=The javac jar and bootstrap classpath changes, or just bin/javac if JVM is left out
59178825Sdfr#   FLAGS:=Flags to be supplied to javac
60142403Snectar#   SERVER_DIR:=Use a javac server (-XDserver) and store the server related files here
61233294Sstas#   SERVER_JVM:=Use this JVM for the server. Defaults to the JVM above.
62233294Sstasdefine SetupJavaCompiler
63233294Sstas  $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompiler, please update JavaCompilation.gmk))
64233294Sstas  $(call EvalDebugWrapper,$(strip $1),$(call SetupJavaCompilerInner,$(strip $1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)))
65233294Sstasendef
66233294Sstas
67142403Snectardefine SetupJavaCompilerInner
68233294Sstas  $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE))
69233294Sstas  $(call LogSetupMacroEntry,SetupJavaCompiler($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
70233294Sstas  $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompiler, please update JavaCompilation.gmk))
71233294Sstas
72233294Sstas  # The port file contains the tcp/ip on which the server listens
73233294Sstas  # and the cookie necessary to talk to the server.
74233294Sstas  $1_SJAVAC_PORTFILE:=$$($1_SERVER_DIR)/server.port
75233294Sstas  # You can use a different JVM to run the background javac server.
76233294Sstas  ifeq ($$($1_SERVER_JVM),)
77233294Sstas    # It defaults to the same JVM that is used to start the javac command.
78233294Sstas    $1_SERVER_JVM:=$$($1_JVM)
79142403Snectar  endif
80142403Snectarendef
81142403Snectar
82233294Sstas# Setup make rules for creating a jar archive.
83142403Snectar#
84142403Snectar# Parameter 1 is the name of the rule. This name is used as variable prefix,
85142403Snectar# and the targets generated are listed in a variable by that name.
86142403Snectar#
87142403Snectar# Remaining parameters are named arguments. These include:
88142403Snectar#   SRCS:=List of directories in where to find files to add to archive
89142403Snectar#   SUFFIXES:=File suffixes to include in jar
90142403Snectar#   INCLUDES:=List of directories/packages in SRCS that should be included
91142403Snectar#   EXCLUDES:=List of directories/packages in SRCS that should be excluded
92142403Snectar#   EXCLUDE_FILES:=List of files in SRCS that should be excluded
93142403Snectar#   EXTRA_FILES:=List of files in SRCS that should be included regardless of suffix match.
94142403Snectar#   JAR:=Jar file to create
95142403Snectar#   MANIFEST:=Optional manifest file template.
96142403Snectar#   JARMAIN:=Optional main class to add to manifest
97233294Sstas#   JARINDEX:=true means generate the index in the jar file.
98142403Snectar#   SKIP_METAINF:=Set to prevent contents of an META-INF directory to be automatically
99142403Snectar#       added to the archive.
100142403Snectar#   EXTRA_MANIFEST_ATTR:=Extra attribute to add to manifest.
101142403Snectar#   CHECK_COMPRESS_JAR Check the COMPRESS_JAR variable
102178825Sdfrdefine SetupArchive
103142403Snectar  $(if $(16),$(error Internal makefile error: Too many arguments to SetupArchive, please update JavaCompilation.gmk))
104142403Snectar  $(call EvalDebugWrapper,$(strip $1),$(call SetupArchiveInner,$(strip $1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)))
105142403Snectarendef
106142403Snectar
107142403Snectardefine SetupArchiveInner
108142403Snectar  # NOTE: $2 is dependencies, not a named argument!
109142403Snectar  $(foreach i,3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE))
110142403Snectar  $(call LogSetupMacroEntry,SetupArchive($1),<dependencies>,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
111233294Sstas  $(if $(findstring $(LOG_LEVEL),trace), $(info *[2] <dependencies> = $(strip $2)))
112233294Sstas  $(if $(16),$(error Internal makefile error: Too many arguments to SetupArchive, please update JavaCompilation.gmk))
113233294Sstas
114233294Sstas  $1_JARMAIN:=$(strip $$($1_JARMAIN))
115233294Sstas  $1_JARNAME:=$$(notdir $$($1_JAR))
116233294Sstas  $1_MANIFEST_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_manifest
117178825Sdfr  $1_DELETESS_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletess
118178825Sdfr  $1_DELETES_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletes
119178825Sdfr  $1_BIN:=$$(dir $$($1_JAR))
120178825Sdfr
121178825Sdfr  ifeq (,$$($1_SUFFIXES))
122178825Sdfr    # No suffix was set, default to classes.
123178825Sdfr    $1_SUFFIXES:=.class
124233294Sstas  endif
125142403Snectar  # Convert suffixes to a find expression
126142403Snectar  $1_FIND_PATTERNS:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_SUFFIXES))
127178825Sdfr  # On windows, a lot of includes/excludes risk making the command line too long, so
128142403Snectar  # writing the grep patterns to files.
129142403Snectar  # Grep returns 1 if nothing is matched. Do not fail the build for this.
130233294Sstas  ifneq (,$$($1_INCLUDES))
131178825Sdfr    $1_GREP_INCLUDE_PATTERNS:=$$(call EscapeDollar, \
132178825Sdfr        $$(foreach src,$$($1_SRCS), $$(addprefix $$(src)/,$$($1_INCLUDES))))
133178825Sdfr    # If there are a lot of include patterns, output to file to shorten command lines
134178825Sdfr    ifeq ($$(word 20,$$($1_GREP_INCLUDE_PATTERNS)),)
135178825Sdfr      $1_GREP_INCLUDES:=| ( $(GREP) $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_INCLUDE_PATTERNS)) \
136233294Sstas          || test "$$$$?" = "1" )
137233294Sstas    else
138233294Sstas      $1_GREP_INCLUDE_OUTPUT:=$(RM) $$($1_BIN)/_the.$$($1_JARNAME)_include $$(NEWLINE) \
139233294Sstas          $$(call ListPathsSafely,$1_GREP_INCLUDE_PATTERNS,\n, \
140233294Sstas          >> $$($1_BIN)/_the.$$($1_JARNAME)_include)
141233294Sstas      $1_GREP_INCLUDES:=| ( $(GREP) -f $$($1_BIN)/_the.$$($1_JARNAME)_include \
142233294Sstas          || test "$$$$?" = "1" )
143233294Sstas    endif
144233294Sstas  endif
145233294Sstas  ifneq (,$$($1_EXCLUDES)$$($1_EXCLUDE_FILES))
146233294Sstas    $1_GREP_EXCLUDE_PATTERNS:=$$(call EscapeDollar, \
147233294Sstas        $$(foreach src,$$($1_SRCS),$$(addprefix $$(src)/, \
148233294Sstas        $$($1_EXCLUDES) $$($1_EXCLUDE_FILES))))
149233294Sstas    # If there are a lot of include patterns, output to file to shorten command lines
150233294Sstas    ifeq ($$(word 20,$$($1_GREP_EXCLUDE_PATTERNS)),)
151233294Sstas      $1_GREP_EXCLUDES:=| ( $(GREP) -v $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_EXCLUDE_PATTERNS)) \
152178825Sdfr          || test "$$$$?" = "1" )
153178825Sdfr    else
154178825Sdfr      $1_GREP_EXCLUDE_OUTPUT=$(RM) $$($1_BIN)/_the.$$($1_JARNAME)_exclude $$(NEWLINE) \
155142403Snectar          $$(call ListPathsSafely,$1_GREP_EXCLUDE_PATTERNS,\n, \
156233294Sstas          >> $$($1_BIN)/_the.$$($1_JARNAME)_exclude)
157233294Sstas      $1_GREP_EXCLUDES:=| ( $(GREP) -v -f $$($1_BIN)/_the.$$($1_JARNAME)_exclude \
158233294Sstas          || test "$$$$?" = "1" )
159233294Sstas    endif
160233294Sstas  endif
161178825Sdfr
162178825Sdfr  # Check if this jar needs to have its index generated.
163178825Sdfr  ifneq (,$$($1_JARINDEX))
164233294Sstas    $1_JARINDEX = (cd $$(dir $$@) && $(JAR) -i $$(notdir $$@))
165233294Sstas  else
166233294Sstas    $1_JARINDEX = true
167233294Sstas  endif
168233294Sstas  # When this macro is run in the same makefile as the java compilation, dependencies are
169233294Sstas  # transfered in make variables. When the macro is run in a different makefile than the
170178825Sdfr  # java compilation, the dependencies need to be found in the filesystem.
171178825Sdfr  ifneq (,$2)
172178825Sdfr    $1_DEPS:=$2
173233294Sstas  else
174233294Sstas    # Add all source roots to the find cache since we are likely going to run find
175178825Sdfr    # on these more than once. The cache will only be updated if necessary.
176178825Sdfr    $$(eval $$(call FillCacheFind, $$($1_FIND_LIST)))
177178825Sdfr    $1_DEPS:=$$(filter $$(addprefix %,$$($1_SUFFIXES)), \
178178825Sdfr        $$(call CacheFind,$$($1_SRCS)))
179178825Sdfr    ifneq (,$$($1_GREP_INCLUDE_PATTERNS))
180178825Sdfr      $1_DEPS:=$$(filter $$(addsuffix %,$$($1_GREP_INCLUDE_PATTERNS)),$$($1_DEPS))
181178825Sdfr    endif
182178825Sdfr    ifneq (,$$($1_GREP_EXCLUDE_PATTERNS))
183178825Sdfr      $1_DEPS:=$$(filter-out $$(addsuffix %,$$($1_GREP_EXCLUDE_PATTERNS)),$$($1_DEPS))
184178825Sdfr    endif
185178825Sdfr    # Look for EXTRA_FILES in all SRCS dirs and as absolute paths.
186178825Sdfr    $1_DEPS+=$$(wildcard $$(foreach src, $$($1_SRCS), \
187233294Sstas        $$(addprefix $$(src)/, $$($1_EXTRA_FILES))) $$($1_EXTRA_FILES))
188178825Sdfr    ifeq (,$$($1_SKIP_METAINF))
189178825Sdfr      $1_DEPS+=$$(call CacheFind,$$(wildcard $$(addsuffix /META-INF,$$($1_SRCS))))
190178825Sdfr    endif
191178825Sdfr  endif
192178825Sdfr  # The dependency list should never be empty
193233294Sstas  ifeq ($$(strip $$($1_DEPS)), )
194233294Sstas    $$(warning No dependencies found for $1)
195233294Sstas  endif
196178825Sdfr
197233294Sstas  # Utility macros, to make the shell script receipt somewhat easier to decipher.
198142403Snectar
199178825Sdfr  # Capture extra files is the same for both CAPTURE_CONTENTS and SCAPTURE_CONTENTS so
200178825Sdfr  # only define it once to avoid duplication.
201178825Sdfr  # The list of extra files might be long, so need to use ListPathsSafely to print
202142403Snectar  # them out to a separte file. Then process the contents of that file to rewrite
203142403Snectar  # into -C <dir> <file> lines.
204233294Sstas  # The EXTRA_FILES_RESOLVED varible must be set in the macro so that it's evaluated
205142403Snectar  # in the recipe when the files are guaranteed to exist.
206178825Sdfr  $1_CAPTURE_EXTRA_FILES=\
207178825Sdfr      $(RM) $$($1_BIN)/_the.$$($1_JARNAME)_contents.extra $$(NEWLINE) \
208178825Sdfr      $$(eval $1_EXTRA_FILES_RESOLVED:=$$(call DoubleDollar, $$(call DoubleDollar, \
209233294Sstas          $$(wildcard $$(foreach src, $$($1_SRCS), \
210142403Snectar          $$(addprefix $$(src)/, $$($1_EXTRA_FILES))) $$($1_EXTRA_FILES))))) \
211142403Snectar      $$(if $$($1_EXTRA_FILES_RESOLVED), \
212142403Snectar        $$(call ListPathsSafely,$1_EXTRA_FILES_RESOLVED,\n, \
213142403Snectar            >> $$($1_BIN)/_the.$$($1_JARNAME)_contents.extra) $$(NEWLINE) \
214233294Sstas        $(SED) $$(foreach src,$$($1_SRCS), -e 's|$$(src)/|-C $$(src) |g') \
215142403Snectar            $$($1_BIN)/_the.$$($1_JARNAME)_contents.extra \
216142403Snectar            >> $$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE))
217142403Snectar
218233294Sstas  # The capture contents macro finds all files (matching the patterns, typically
219233294Sstas  # .class and .prp) that are newer than the jar-file, ie the new content to be put into the jar.
220233294Sstas  # NOTICE: please leave the parentheses space separated otherwise the AIX build will break!
221233294Sstas  $1_CAPTURE_CONTENTS=\
222233294Sstas      $(RM) $$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE) \
223178825Sdfr      $$(foreach src,$$($1_SRCS), \
224178825Sdfr        $(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) -a -newer $$@ $$($1_GREP_INCLUDES) \
225178825Sdfr          $$($1_GREP_EXCLUDES) | $(SED) 's|$$(src)/|-C $$(src) |g' \
226233294Sstas        >> $$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE)) \
227233294Sstas      $$($1_CAPTURE_EXTRA_FILES)
228142403Snectar
229142403Snectar  # The capture metainf macro finds all files below the META-INF directory that are newer than the jar-file.
230142403Snectar  # Find returns non zero if the META-INF dir does not exist, ignore this.
231142403Snectar  ifeq (,$$($1_SKIP_METAINF))
232142403Snectar    $1_CAPTURE_METAINF =$$(foreach src,$$($1_SRCS), \
233233294Sstas        ( ( $(FIND) $$(src)/META-INF -type f -a -newer $$@ 2> /dev/null || true ) \
234142403Snectar            | $(SED) 's|$$(src)/|-C $$(src) |g' >> \
235142403Snectar        $$($1_BIN)/_the.$$($1_JARNAME)_contents ) $$(NEWLINE) )
236142403Snectar  endif
237142403Snectar  # The capture deletes macro finds all deleted files and concatenates them. The resulting file
238142403Snectar  # tells us what to remove from the jar-file.
239233294Sstas  $1_CAPTURE_DELETES=$$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.deleted -newer $$@ \
240178825Sdfr      -exec $(SED) 's|$$(src)||g' \{\} >> $$($1_DELETES_FILE) \;) $$(NEWLINE))
241178825Sdfr  # The update contents macro updates the jar file with the previously capture contents.
242178825Sdfr  # Use 'wc -w' to see if the contents file is empty.
243178825Sdfr  $1_UPDATE_CONTENTS=\
244178825Sdfr      if [ "`$(WC) -l $$($1_BIN)/_the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'`" -gt "0" ]; then \
245178825Sdfr        $(ECHO) "  updating" `$(WC) -l $$($1_BIN)/_the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'` files && \
246178825Sdfr        $(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @$$($1_BIN)/_the.$$($1_JARNAME)_contents; \
247233294Sstas      fi $$(NEWLINE)
248178825Sdfr  # The s-variants of the above macros are used when the jar is created from scratch.
249178825Sdfr  # NOTICE: please leave the parentheses space separated otherwise the AIX build will break!
250178825Sdfr  $1_SCAPTURE_CONTENTS=\
251233294Sstas      $(RM) $$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE) \
252233294Sstas      $$(foreach src,$$($1_SRCS), \
253233294Sstas        $(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) $$($1_GREP_INCLUDES) \
254233294Sstas            $$($1_GREP_EXCLUDES) | $(SED) 's|$$(src)/|-C $$(src) |g' \
255142403Snectar            >> $$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE)) \
256142403Snectar      $$($1_CAPTURE_EXTRA_FILES)
257233294Sstas
258178825Sdfr  # Find returns non zero if the META-INF dir does not exist, ignore this.
259178825Sdfr  ifeq (,$$($1_SKIP_METAINF))
260178825Sdfr    $1_SCAPTURE_METAINF=$$(foreach src,$$($1_SRCS), \
261178825Sdfr        ( ( $(FIND) $$(src)/META-INF -type f 2> /dev/null || true ) \
262142403Snectar            | $(SED) 's|$$(src)/|-C $$(src) |g' >> \
263233294Sstas        $$($1_BIN)/_the.$$($1_JARNAME)_contents) $$(NEWLINE) )
264178825Sdfr  endif
265178825Sdfr  $1_SUPDATE_CONTENTS=$(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @$$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE)
266178825Sdfr
267178825Sdfr  # Use a slightly shorter name for logging, but with enough path to identify this jar.
268178825Sdfr  $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_JAR))
269178825Sdfr
270233294Sstas  ifneq (,$$($1_CHECK_COMPRESS_JAR))
271233294Sstas    $1_JAR_CREATE_OPTIONS := c0fm
272233294Sstas    $1_JAR_UPDATE_OPTIONS := u0f
273233294Sstas    ifeq ($(COMPRESS_JARS), true)
274233294Sstas      $1_JAR_CREATE_OPTIONS := cfm
275233294Sstas      $1_JAR_UPDATE_OPTIONS := uf
276233294Sstas    endif
277233294Sstas  else
278233294Sstas    $1_JAR_CREATE_OPTIONS := cfm
279233294Sstas    $1_JAR_UPDATE_OPTIONS := uf
280142403Snectar  endif
281142403Snectar
282178825Sdfr  # Include all variables of significance in the vardeps file
283178825Sdfr  $1_VARDEPS := $(JAR) $$($1_JAR_CREATE_OPTIONS) $$($1_MANIFEST) $(RELEASE) $(COMPANY_NAME) \
284178825Sdfr      $$($1_JARMAIN) $$($1_EXTRA_MANIFEST_ATTR)
285142403Snectar  $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$(dir $$($1_JAR))_the.$$($1_JARNAME).vardeps)
286178825Sdfr
287178825Sdfr  # Here is the rule that creates/updates the jar file.
288178825Sdfr  $$($1_JAR) : $$($1_DEPS) $$($1_MANIFEST) $$($1_VARDEPS_FILE)
289142403Snectar	$(MKDIR) -p $$($1_BIN)
290142403Snectar	$$($1_GREP_INCLUDE_OUTPUT)
291233294Sstas	$$($1_GREP_EXCLUDE_OUTPUT)
292233294Sstas        # If the vardeps file is part of the newer prereq list, it means that
293233294Sstas        # either the jar file does not exist, or we need to recreate it from
294233294Sstas        # from scratch anyway since a simple update will not catch all the 
295233294Sstas        # potential changes.
296178825Sdfr	$$(if $$(filter $$($1_VARDEPS_FILE) $$($1_MANIFEST), $$?), \
297178825Sdfr	  $$(if $$($1_MANIFEST), \
298233294Sstas	    $(SED) -e "s#@@RELEASE@@#$(RELEASE)#" \
299233294Sstas	        -e "s#@@COMPANY_NAME@@#$(COMPANY_NAME)#" $$($1_MANIFEST) > $$($1_MANIFEST_FILE) $$(NEWLINE) \
300233294Sstas	  , \
301233294Sstas	    $(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE) $$(NEWLINE)) \
302233294Sstas	  $$(if $$($1_JARMAIN), \
303142403Snectar	    $(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE) $$(NEWLINE)) \
304142403Snectar	  $$(if $$($1_EXTRA_MANIFEST_ATTR), \
305178825Sdfr	    $(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE) $$(NEWLINE)) \
306142403Snectar	  $(ECHO) Creating $$($1_NAME) $$(NEWLINE) \
307178825Sdfr	  $(JAR) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) $$(NEWLINE) \
308178825Sdfr	  $$($1_SCAPTURE_CONTENTS) \
309178825Sdfr	  $$($1_SCAPTURE_METAINF) \
310142403Snectar	  $$($1_SUPDATE_CONTENTS) \
311142403Snectar	  $$($1_JARINDEX) && true \
312233294Sstas	, \
313233294Sstas	  $(ECHO) Modifying $$($1_NAME) $$(NEWLINE) \
314142403Snectar	  $$($1_CAPTURE_CONTENTS) \
315127808Snectar	  $$($1_CAPTURE_METAINF) \
31655682Smarkm	  $(RM) $$($1_DELETES_FILE) $$(NEWLINE) \
31772445Sassar	  $$($1_CAPTURE_DELETES) \
318127808Snectar	  $(CAT) $$($1_DELETES_FILE) > $$($1_DELETESS_FILE) $$(NEWLINE) \
319233294Sstas	  if [ -s $$($1_DELETESS_FILE) ]; then \
320233294Sstas	    $(ECHO) "  deleting" `$(WC) -l $$($1_DELETESS_FILE) | $(AWK) '{ print $$$$1 }'` files && \
321127808Snectar	    $(ZIP) -q -d $$@ `$(CAT) $$($1_DELETESS_FILE)` ; \
322127808Snectar	  fi $$(NEWLINE) \
323127808Snectar	  $$($1_UPDATE_CONTENTS) true $$(NEWLINE) \
32455682Smarkm	  $$($1_JARINDEX) && true )
32555682Smarkm
326233294Sstas  # Add jar to target list
327233294Sstas  $1 += $$($1_JAR)
32855682Smarkmendef
32955682Smarkm
33055682Smarkm    $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES))))
331233294Sstas  ifneq ($$($1_EXCLUDE_FILES),)
332127808Snectar    # Cannot precompute ZIP_EXCLUDE_FILES as it is dependent on which src root is being
33390926Snectar    # zipped at the moment.
33472445Sassar    $1_SRC_EXCLUDE_FILES := $$(addprefix %, $$($1_EXCLUDE_FILES)) $$($1_EXCLUDE_FILES)
335233294Sstas    $1_ALL_SRCS := $$(filter-out $$($1_SRC_EXCLUDE_FILES), $$($1_ALL_SRCS))
336127808Snectar  endif
337233294Sstasdefine add_file_to_copy
33855682Smarkm  # param 1 = BUILD_MYPACKAGE
339127808Snectar  # parma 2 = The source file to copy.
340233294Sstas  $2_TARGET:=$2
34190926Snectar  # Remove the source prefix.
342178825Sdfr  $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET)))
343178825Sdfr  # To allow for automatic overrides, do not create a rule for a target file that
34472445Sassar  # already has one
345233294Sstas  ifeq ($$(findstring $$($2_TARGET), $$($1_COPY_LIST)), )
346233294Sstas    $1_COPY_LIST += $$($2_TARGET)
347233294Sstas    # Now we can setup the depency that will trigger the copying.
348127808Snectar    $$($1_BIN)$$($2_TARGET) : $2
349127808Snectar	$(MKDIR) -p $$(@D)
350127808Snectar	$(CP) $$< $$@
351127808Snectar	$(CHMOD) -f ug+w $$@
352127808Snectar
353233294Sstas    # And do not forget this target
354178825Sdfr    $1_ALL_COPY_TARGETS += $$($1_BIN)$$($2_TARGET)
35555682Smarkm  endif
35672445Sassarendef
357178825Sdfr
358127808Snectar
359127808Snectar# This macro is used only for properties files that are to be
360233294Sstas# copied over to the classes directory in cleaned form:
361233294Sstas# Previously this was inconsistently done in different repositories.
362127808Snectar# This is the new clean standard. Though it is to be superseded by
363127808Snectar# a standard annotation processor from with sjavac.
364233294Sstas#
365178825Sdfr# The sed expression does this:
366127808Snectar# 1. Add a backslash before any :, = or ! that do not have a backslash already.
367127808Snectar# 2. Apply the file unicode2x.sed which does a whole bunch of \u00XX to \xXX
368127808Snectar#    conversions.
36990926Snectar# 3. Delete all lines starting with #.
370233294Sstas# 4. Delete empty lines.
371127808Snectar# 5. Append lines ending with \ with the next line.
372178825Sdfr# 6. Remove leading and trailing white space. Note that tabs must be explicit
37355682Smarkm#    as sed on macosx does not understand '\t'.
374102644Snectar# 7. Replace the first \= with just =.
375102644Snectar# 8. Finally it's all sorted to create a stable output.
376178825Sdfr#
377127808Snectar# It is assumed that = is the character used for separating names and values.
378127808Snectardefine add_file_to_clean
37955682Smarkm  # param 1 = BUILD_MYPACKAGE
38055682Smarkm  # parma 2 = The source file to copy and clean.
38190926Snectar  $2_TARGET:=$2
382127808Snectar  # Remove the source prefix.
383127808Snectar  $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET)))
384127808Snectar  # Now we can setup the depency that will trigger the copying.
385127808Snectar  $$($1_BIN)$$($2_TARGET) : $2
386127808Snectar	$(MKDIR) -p $$(@D)
38790926Snectar	export LC_ALL=C ; $(CAT) $$< \
38890926Snectar	    | $(SED) -e 's/\([^\\]\):/\1\\:/g' -e 's/\([^\\]\)=/\1\\=/g' \
38990926Snectar	        -e 's/\([^\\]\)!/\1\\!/g' -e 's/#.*/#/g' \
390127808Snectar	    | $(SED) -f "$(SRC_ROOT)/make/common/support/unicode2x.sed" \
391127808Snectar	    | $(SED) -e '/^#/d' -e '/^$$$$/d' \
392127808Snectar	        -e :a -e '/\\$$$$/N; s/\\\n//; ta' \
393127808Snectar	        -e 's/^[ 	]*//;s/[ 	]*$$$$//' \
394233294Sstas	        -e 's/\\=/=/' \
395127808Snectar	    | $(SORT) > $$@
396127808Snectar	$(CHMOD) -f ug+w $$@
397233294Sstas
398178825Sdfr  # And do not forget this target
399127808Snectar  $1_ALL_COPY_CLEAN_TARGETS += $$($1_BIN)$$($2_TARGET)
400127808Snectarendef
401127808Snectar
402127808Snectardefine remove_string
403127808Snectar  $2 := $$(subst $1,,$$($2))
404127808Snectarendef
405127808Snectar
406127808Snectar# Setup make rules for compiling Java source code to class files and/or a
407178825Sdfr# resulting jar file.
408178825Sdfr#
409178825Sdfr# Parameter 1 is the name of the rule. This name is used as variable prefix,
410178825Sdfr# and the targets generated are listed in a variable by that name.
411127808Snectar#
412127808Snectar# Remaining parameters are named arguments. These include:
41355682Smarkm#   SETUP:=must point to a previously setup java compiler, for example: SETUP:=BOOTJAVAC
414127808Snectar#   JVM:=path to ..bin/java
415233294Sstas#   ADD_JAVAC_FLAGS:=javac flags to append to the default ones.
416233294Sstas#   SRC:=one or more directories to search for sources
417127808Snectar#   BIN:=store classes here
418127808Snectar#   INCLUDES:=myapp.foo means will only compile java files in myapp.foo or any of its sub-packages.
419127808Snectar#   EXCLUDES:=myapp.foo means will do not compile java files in myapp.foo or any of its sub-packages.
420127808Snectar#   COPY:=.prp means copy all prp files to the corresponding package in BIN.
421127808Snectar#   COPY_FILES:=myapp/foo/setting.txt means copy this file over to the package myapp/foo
42255682Smarkm#   CLEAN:=.properties means copy and clean all properties file to the corresponding package in BIN.
423127808Snectar#   CLEAN_FILES:=myapp/foo/setting.txt means clean this file over to the package myapp/foo
424127808Snectar#   SRCZIP:=Create a src.zip based on the found sources and copied files.
425178825Sdfr#   INCLUDE_FILES:="com/sun/SolarisFoobar.java" means only compile this file!
426127808Snectar#   EXCLUDE_FILES:="com/sun/SolarisFoobar.java" means do not compile this particular file!
427127808Snectar#       "SolarisFoobar.java" means do not compile SolarisFoobar, wherever it is found.
42855682Smarkm#   HEADERS:=path to directory where all generated c-headers are written.
42955682Smarkm#   DEPENDS:=Extra dependecy
430127808Snectar#   DISABLE_SJAVAC:=Explicitly disable the use of sjavac for this compilation unit.
431127808Snectardefine SetupJavaCompilation
432233294Sstas  $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompilation, please update JavaCompilation.gmk))
433127808Snectar  $(call EvalDebugWrapper,$(strip $1),$(call SetupJavaCompilationInner,$(strip $1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15)))
434127808Snectarendef
435233294Sstas
43655682Smarkmdefine SetupJavaCompilationInner
43755682Smarkm  $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE))
438120945Snectar  $(call LogSetupMacroEntry,SetupJavaCompilation($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
439127808Snectar  $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompilation, please update JavaCompilation.gmk))
440233294Sstas
441178825Sdfr  # Extract the info from the java compiler setup.
442233294Sstas  $1_JVM := $$($$($1_SETUP)_JVM)
443233294Sstas  $1_JAVAC := $$($$($1_SETUP)_JAVAC)
444233294Sstas  $1_FLAGS := $$($$($1_SETUP)_FLAGS) $(JAVAC_FLAGS) $$($1_ADD_JAVAC_FLAGS)
44555682Smarkm  ifeq ($$($1_JAVAC),)
446233294Sstas    $$(error The Java compilation $1 refers to a non-existant java compiler setup $$($1_SETUP))
447127808Snectar  endif
448233294Sstas  $1_SJAVAC_PORTFILE := $$($$($1_SETUP)_SJAVAC_PORTFILE)
449233294Sstas  $1_SERVER_JVM := $$($$($1_SETUP)_SERVER_JVM)
45055682Smarkm
451127808Snectar  # Handle addons and overrides.
452127808Snectar  $1_SRC:=$$(call ADD_SRCS,$$($1_SRC))
453127808Snectar  # Make sure the dirs exist.
454127808Snectar  $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupJavaCompilation $1 contains missing directory $$d)))
455233294Sstas  $$(call MakeDir,$$($1_BIN))
456127808Snectar  # Add all source roots to the find cache since we are likely going to run find
457127808Snectar  # on these more than once. The cache will only be updated if necessary.
458233294Sstas  $$(eval $$(call FillCacheFind,$$($1_SRC)))
459233294Sstas  # Find all files in the source trees. Preserve order of source roots for overrides to
460233294Sstas  # work correctly. CacheFind does not preserve order so need to call it for each root.
461233294Sstas  $1_ALL_SRCS += $$(filter-out $(OVR_SRCS),$$(foreach s,$$($1_SRC),$$(call CacheFind,$$(s))))
46255682Smarkm  # Extract the java files.
463233294Sstas  ifneq ($$($1_EXCLUDE_FILES),)
464127808Snectar    $1_EXCLUDE_FILES_PATTERN:=$$(addprefix %,$$($1_EXCLUDE_FILES))
465127808Snectar  endif
466233294Sstas  $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$(filter %.java,$$($1_ALL_SRCS)))
467233294Sstas  ifneq ($$($1_INCLUDE_FILES),)
468102644Snectar    $1_INCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES)))
46955682Smarkm    $1_SRCS := $$(filter $$($1_INCLUDE_FILES), $$($1_SRCS))
470178825Sdfr  endif
47155682Smarkm
47255682Smarkm  # Now we have a list of all java files to compile: $$($1_SRCS)
47355682Smarkm
474178825Sdfr  # Create the corresponding smart javac wrapper command line.
47590926Snectar  $1_SJAVAC_ARGS:=$$(addprefix -x ,$$(addsuffix /*,$$($1_EXCLUDES))) \
47690926Snectar      $$(addprefix -i ,$$(addsuffix /*,$$($1_INCLUDES))) \
47790926Snectar      $$(addprefix -xf *,$$(strip $$($1_EXCLUDE_FILES))) \
47890926Snectar      $$(addprefix -if *,$$(strip $$($1_INCLUDE_FILES))) \
47955682Smarkm      -src "$$(subst $$(SPACE),$$(PATH_SEP),$$(strip $$($1_SRC)))"
480178825Sdfr
481178825Sdfr  # Prepend the source/bin path to the filter expressions.
482178825Sdfr  ifneq ($$($1_INCLUDES),)
483178825Sdfr    $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES))))
484178825Sdfr    $1_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS))
485233294Sstas  endif
486127808Snectar  ifneq ($$($1_EXCLUDES),)
487233294Sstas    $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES))))
488233294Sstas    $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS))
489127808Snectar  endif
490233294Sstas
491178825Sdfr  # All files below META-INF are always copied.
492178825Sdfr  $1_ALL_COPIES := $$(filter $$(addsuffix /META-INF%,$$($1_SRC)),$$($1_ALL_SRCS))
493127808Snectar  # Find all files to be copied from source to bin.
494127808Snectar  ifneq (,$$($1_COPY)$$($1_COPY_FILES))
495127808Snectar    # Search for all files to be copied.
496127808Snectar    $1_ALL_COPIES += $$(filter $$(addprefix %,$$($1_COPY)),$$($1_ALL_SRCS))
497127808Snectar    # Copy these explicitly
498127808Snectar    $1_ALL_COPIES += $$($1_COPY_FILES)
499178825Sdfr  endif
500127808Snectar  # Copy must also respect filters.
501178825Sdfr  ifneq (,$$($1_INCLUDES))
502178825Sdfr    $1_ALL_COPIES := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_COPIES))
503102644Snectar  endif
504102644Snectar  ifneq (,$$($1_EXCLUDES))
505102644Snectar    $1_ALL_COPIES := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_COPIES))
506178825Sdfr  endif
507127808Snectar  ifneq (,$$($1_EXCLUDE_FILES))
508127808Snectar    $1_ALL_COPIES := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_COPIES))
509127808Snectar  endif
510127808Snectar  ifneq (,$$($1_ALL_COPIES))
511127808Snectar    # Yep, there are files to be copied!
512127808Snectar    $1_ALL_COPY_TARGETS:=
513178825Sdfr        $$(foreach i,$$($1_ALL_COPIES),$$(eval $$(call add_file_to_copy,$1,$$i)))
514127808Snectar    # Now we can depend on $$($1_ALL_COPY_TARGETS) to copy all files!
515127808Snectar  endif
51672445Sassar
517127808Snectar  # Find all property files to be copied and cleaned from source to bin.
518127808Snectar  ifneq (,$$($1_CLEAN)$$($1_CLEAN_FILES))
519178825Sdfr    # Search for all files to be copied.
520127808Snectar    $1_ALL_CLEANS := $$(filter $$(addprefix %,$$($1_CLEAN)),$$($1_ALL_SRCS))
521127808Snectar    # Clean these explicitly
522142403Snectar    $1_ALL_CLEANS += $$($1_CLEAN_FILES)
523127808Snectar    # Copy and clean must also respect filters.
524178825Sdfr    ifneq (,$$($1_INCLUDES))
525127808Snectar      $1_ALL_CLEANS := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_CLEANS))
526127808Snectar    endif
527178825Sdfr    ifneq (,$$($1_EXCLUDES))
528127808Snectar      $1_ALL_CLEANS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_CLEANS))
529127808Snectar    endif
530178825Sdfr    ifneq (,$$($1_EXCLUDE_FILES))
531233294Sstas      $1_ALL_CLEANS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_CLEANS))
532127808Snectar    endif
533127808Snectar    ifneq (,$$($1_ALL_CLEANS))
534233294Sstas      # Yep, there are files to be copied and cleaned!
535178825Sdfr      $1_ALL_COPY_CLEAN_TARGETS:=
536178825Sdfr          $$(foreach i,$$($1_ALL_CLEANS),$$(eval $$(call add_file_to_clean,$1,$$i)))
537233294Sstas      # Now we can depend on $$($1_ALL_COPY_CLEAN_TARGETS) to copy all files!
538233294Sstas    endif
539233294Sstas  endif
540233294Sstas
541102644Snectar  # Create a sed expression to remove the source roots and to replace / with .
54290926Snectar  # and remove .java at the end.
54390926Snectar  $1_REWRITE_INTO_CLASSES:=$$(foreach i,$$($1_SRC),-e 's|$$i/||g') -e 's|/|.|g' -e 's|.java$$$$||g'
54490926Snectar
545233294Sstas  ifeq ($$($1_DISABLE_SJAVAC)x$$(ENABLE_SJAVAC),xyes)
54690926Snectar    ifneq (,$$($1_HEADERS))
54790926Snectar      $1_HEADERS_ARG := -h $$($1_HEADERS)
54890926Snectar    endif
54990926Snectar
55090926Snectar    # Using sjavac to compile.
55190926Snectar    $1_COMPILE_TARGETS := $$($1_BIN)/_the.$1_batch
552233294Sstas
55390926Snectar    # Create SJAVAC variable form JAVAC variable. Expects $1_JAVAC to be
554120945Snectar    # "bootclasspathprepend -cp .../javac.jar com.sun.tools.javac.Main"
55590926Snectar    # and javac is simply replaced with sjavac.
55690926Snectar    $1_SJAVAC:=$$(subst com.sun.tools.javac.Main,com.sun.tools.sjavac.Main,$$($1_JAVAC))
55790926Snectar
55890926Snectar    # Set the $1_REMOTE to spawn a background javac server.
559233294Sstas    $1_REMOTE:=--server:portfile=$$($1_SJAVAC_PORTFILE),id=$1,sjavac=$$(subst \
56090926Snectar        $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_SJAVAC))))
56172445Sassar
562178825Sdfr    $1_VARDEPS := $$($1_JVM) $$($1_SJAVAC) $$($1_SJAVAC_ARGS) $$($1_FLAGS) \
563233294Sstas        $$($1_HEADERS_ARG) $$($1_BIN)
56472445Sassar    $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$($1_BIN)/_the.$1.vardeps)
565233294Sstas
566178825Sdfr    $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS) $$($1_VARDEPS_FILE)
56772445Sassar	$(MKDIR) -p $$(@D) $$(dir $$($1_SJAVAC_PORTFILE))
568233294Sstas        # As a workaround for sjavac not tracking api changed from the classpath, force full
56990926Snectar        # recompile if an external dependency, which is something other than a source
570102644Snectar        # change, triggered this compilation.
571233294Sstas	$$(if $$(filter-out $$($1_SRCS), $$?), $(FIND) $$(@D) -name "*.class" $(FIND_DELETE))
572178825Sdfr	$$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.$1_batch.tmp)
573103423Snectar	$(ECHO) Compiling $1
574103423Snectar	($$($1_JVM) $$($1_SJAVAC) \
575178825Sdfr	    $$($1_REMOTE) \
576233294Sstas	    -j 1 \
577178825Sdfr	    --permit-unidentified-artifacts \
578178825Sdfr	    --permit-sources-without-package \
579102644Snectar	    --compare-found-sources $$($1_BIN)/_the.$1_batch.tmp \
580178825Sdfr	    --log=$(LOG_LEVEL) \
581233294Sstas	    $$($1_SJAVAC_ARGS) \
582102644Snectar	    $$($1_FLAGS) \
58390926Snectar	    $$($1_HEADERS_ARG) \
584233294Sstas	    -d $$($1_BIN) && \
585233294Sstas	$(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch)
586233294Sstas        # Create a pubapi file that only changes when the pubapi changes. Dependent
587178825Sdfr        # compilations can use this file to only get recompiled when pubapi has changed.
588233294Sstas        # Grep returns 1 if no matching lines are found. Do not fail for this.
589233294Sstas	$(GREP) -e "^I" $$($1_BIN)/javac_state > $$($1_BIN)/_the.$1_pubapi.tmp \
590178825Sdfr	    || test "$$$$?" = "1"
591178825Sdfr	if [ ! -f $$($1_BIN)/_the.$1_pubapi ] \
592178825Sdfr	    || [ "`$(DIFF) $$($1_BIN)/_the.$1_pubapi $$($1_BIN)/_the.$1_pubapi.tmp`" != "" ]; then \
593178825Sdfr	  $(MV) $$($1_BIN)/_the.$1_pubapi.tmp $$($1_BIN)/_the.$1_pubapi; \
594233294Sstas	fi
595233294Sstas
596233294Sstas  else
597233294Sstas    # Using plain javac to batch compile everything.
598233294Sstas    $1_COMPILE_TARGETS := $$($1_BIN)/_the.$1_batch
599233294Sstas
60072445Sassar    # When building in batch, put headers in a temp dir to filter out those that actually
60172445Sassar    # changed before copying them to the real header dir.
60272445Sassar    ifneq (,$$($1_HEADERS))
603178825Sdfr      $1_HEADERS_ARG := -h $$($1_HEADERS).$1.tmp
60472445Sassar
605233294Sstas      $$($1_HEADERS)/_the.$1_headers: $$($1_BIN)/_the.$1_batch
606127808Snectar		$(MKDIR) -p $$(@D)
60755682Smarkm		if [ -d "$$($1_HEADERS).$1.tmp" ]; then \
608233294Sstas		  for f in `ls $$($1_HEADERS).$1.tmp`; do \
609233294Sstas		    if [ ! -f "$$($1_HEADERS)/$$$$f" ] \
610142403Snectar		        || [ "`$(DIFF) $$($1_HEADERS)/$$$$f $$($1_HEADERS).$1.tmp/$$$$f`" != "" ]; then \
61172445Sassar		    $(CP) -f $$($1_HEADERS).$1.tmp/$$$$f $$($1_HEADERS)/$$$$f; \
612142403Snectar		  fi; \
61372445Sassar		  done; \
614127808Snectar		fi
61572445Sassar		$(RM) -r $$($1_HEADERS).$1.tmp
616127808Snectar		$(TOUCH) $$@
61772445Sassar
618233294Sstas      $1_HEADER_TARGETS := $$($1_HEADERS)/_the.$1_headers
619233294Sstas    endif
620142403Snectar
62172445Sassar    $1_VARDEPS := $$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) $$($1_BIN) $$($1_HEADERS_ARG)
622233294Sstas    $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$($1_BIN)/_the.$1.vardeps)
623178825Sdfr
624178825Sdfr    # When not using sjavac, pass along all sources to javac using an @file.
625233294Sstas    $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS) $$($1_VARDEPS_FILE)
626178825Sdfr	$(MKDIR) -p $$(@D)
627178825Sdfr	$(RM) $$($1_BIN)/_the.$1_batch $$($1_BIN)/_the.$1_batch.tmp
628178825Sdfr	$$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.$1_batch.tmp)
629178825Sdfr	$(ECHO) Compiling `$(WC) $$($1_BIN)/_the.$1_batch.tmp | $(TR) -s ' ' | $(CUT) -f 2 -d ' '` files for $1
630178825Sdfr	($$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) \
631233294Sstas	    -implicit:none \
632178825Sdfr	    -d $$($1_BIN) $$($1_HEADERS_ARG) @$$($1_BIN)/_the.$1_batch.tmp && \
633233294Sstas	$(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch)
634178825Sdfr
635178825Sdfr  endif
636178825Sdfr
637178825Sdfr  # Add all targets to main variable
638233294Sstas  $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_COMPILE_TARGETS) \
639233294Sstas      $$($1_HEADER_TARGETS)
64055682Smarkm
64190926Snectar  # Check if a jar file was specified, then setup the rules for the jar.
64290926Snectar  ifneq (,$$($1_JAR))
64355682Smarkm    # If no suffixes was explicitly set for this jar file.
64455682Smarkm    # Use class and the cleaned/copied properties file suffixes as the default
645233294Sstas    # for the types of files to be put into the jar.
646142403Snectar    ifeq (,$$($1_SUFFIXES))
647142403Snectar      $1_SUFFIXES:=.class $$($1_CLEAN) $$($1_COPY)
648142403Snectar    endif
649142403Snectar
650233294Sstas    $$(eval $$(call SetupArchive,ARCHIVE_$1,$$($1), \
651233294Sstas        SRCS:=$$($1_BIN), \
652142403Snectar        SUFFIXES:=$$($1_SUFFIXES), \
653142403Snectar        EXCLUDE:=$$($1_EXCLUDES), \
654142403Snectar        INCLUDES:=$$($1_INCLUDES), \
655233294Sstas        EXTRA_FILES:=$$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS), \
656233294Sstas        JAR:=$$($1_JAR), \
657233294Sstas        JARMAIN:=$$($1_JARMAIN), \
658142403Snectar        MANIFEST:=$$($1_MANIFEST), \
659142403Snectar        EXTRA_MANIFEST_ATTR:=$$($1_EXTRA_MANIFEST_ATTR), \
660142403Snectar        JARINDEX:=$$($1_JARINDEX), \
661142403Snectar        HEADERS:=$$($1_HEADERS), \
662142403Snectar        SETUP:=$$($1_SETUP)))
663142403Snectar
664142403Snectar    # Add jar to target list
665142403Snectar    $1 += $$($1_JAR)
666142403Snectar  endif
667142403Snectar
668142403Snectar  # Check if a srczip was specified, then setup the rules for the srczip.
669142403Snectar  ifneq (,$$($1_SRCZIP))
670142403Snectar    $$(eval $$(call SetupZipArchive,ARCHIVE_$1, \
671142403Snectar        SRC:=$$($1_SRC), \
672142403Snectar        ZIP:=$$($1_SRCZIP), \
673142403Snectar        INCLUDES:=$$($1_INCLUDES), \
674142403Snectar        EXCLUDES:=$$($1_EXCLUDES), \
675233294Sstas        EXCLUDE_FILES:=$$($1_EXCLUDE_FILES)))
67655682Smarkm
67755682Smarkm    # Add zip to target list
678178825Sdfr    $1 += $$($1_SRCZIP)
679233294Sstas  endif
680233294Sstasendef
68155682Smarkm
682233294Sstas# Use this macro to find the correct target to depend on when the original
68355682Smarkm# SetupJavaCompilation is declared in a different makefile, to avoid having
684233294Sstas# to declare and evaluate it again.
685233294Sstas# param 1 is for example BUILD_MYPACKAGE
686233294Sstas# param 2 is the output directory (BIN)
687233294Sstasdefine SetupJavaCompilationCompileTarget
688233294Sstas  $(if $(findstring yes, $(ENABLE_SJAVAC)), $(strip $2)/_the.$(strip $1)_pubapi, \
68955682Smarkm      $(strip $2)/_the.$(strip $1)_batch)
69055682Smarkmendef
69155682Smarkm
692233294Sstasendif # _JAVA_COMPILATION_GMK
693233294Sstas