JavaCompilation.gmk revision 1120:ba5645f2735b
1193323Sed#
2193323Sed# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
3193323Sed# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4193323Sed#
5193323Sed# This code is free software; you can redistribute it and/or modify it
6193323Sed# under the terms of the GNU General Public License version 2 only, as
7193323Sed# published by the Free Software Foundation.  Oracle designates this
8193323Sed# particular file as subject to the "Classpath" exception as provided
9193323Sed# by Oracle in the LICENSE file that accompanied this code.
10193323Sed#
11193323Sed# This code is distributed in the hope that it will be useful, but WITHOUT
12193323Sed# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13193323Sed# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14193323Sed# version 2 for more details (a copy is included in the LICENSE file that
15193323Sed# accompanied this code).
16193323Sed#
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,
19249423Sdim# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20239462Sdim#
21249423Sdim# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22249423Sdim# or visit www.oracle.com if you need additional information or have any
23249423Sdim# questions.
24249423Sdim#
25249423Sdim
26249423Sdim# This makefile is much simpler now that it can use the smart javac wrapper
27249423Sdim# for dependency tracking between java packages and incremental compiles.
28249423Sdim# It could be even more simple if we added support for incremental jar updates
29193323Sed# directly from the smart javac wrapper.
30234353Sdim
31234353Sdim# Cleaning/copying properties here is not a good solution. The properties
32212904Sdim# should be cleaned/copied by a annotation processor in sjavac.
33193323Sed
34193323Sed# When you read this source. Remember that $(sort ...) has the side effect
35193323Sed# of removing duplicates. It is actually this side effect that is
36193323Sed# desired whenever sort is used below!
37193323Sed
38210299Sedifndef _JAVA_COMPILATION_GMK
39203954Srdivacky_JAVA_COMPILATION_GMK := 1
40193323Sed
41198090Srdivackyifeq (,$(_MAKEBASE_GMK))
42193323Sed  $(error You must include MakeBase.gmk prior to including JavaCompilation.gmk)
43193323Sedendif
44193323Sed
45193323SedFALSE_FIND_PATTERN:=-name FILE_NAME_THAT_DOESNT_EXIST
46193323Sed
47193323Seddefine SetupJavaCompiler
48193323Sed  # param 1 is for example GENERATE_OLD_BYTECODE or GENERATE_NEW_JDKBYTECODE
49193323Sed  # This is the name of the compiler setup.
50193323Sed  # param 2-9 are named args.
51193323Sed  #   JVM:=The jvm used to run the javac/javah command
52193323Sed  #   JAVAC:=The javac jar and bootstrap classpath changes, or just bin/javac if JVM is left out
53210299Sed  #   FLAGS:=Flags to be supplied to javac
54193323Sed  #   SERVER_DIR:=Use a javac server (-XDserver) and store the server related files here
55193323Sed  #   SERVER_JVM:=Use this JVM for the server. Defaults to the JVM above.
56193323Sed  $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE))
57193323Sed  $(call LogSetupMacroEntry,SetupJavaCompiler($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
58193323Sed  $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompiler, please update JavaCompilation.gmk))
59193323Sed
60193323Sed  # The port file contains the tcp/ip on which the server listens
61193323Sed  # and the cookie necessary to talk to the server.
62193323Sed  $1_SJAVAC_PORTFILE:=$$($1_SERVER_DIR)/server.port
63193323Sed  # You can use a different JVM to run the background javac server.
64193323Sed  ifeq ($$($1_SERVER_JVM),)
65193323Sed    # It defaults to the same JVM that is used to start the javac command.
66193323Sed    $1_SERVER_JVM:=$$($1_JVM)
67193323Sed  endif
68193323Sedendef
69193323Sed
70193323Seddefine SetupArchive
71193323Sed  # param 1 is for example ARCHIVE_MYPACKAGE
72193323Sed  # param 2 are the dependecies
73193323Sed  # param 3,4,5,6,7,8,9 are named args.
74212904Sdim  #   SRCS:=List of directories in where to find files to add to archive
75193323Sed  #   SUFFIXES:=File suffixes to include in jar
76193323Sed  #   INCLUDES:=List of directories/packages in SRCS that should be included
77210299Sed  #   EXCLUDES:=List of directories/packages in SRCS that should be excluded
78212904Sdim  #   EXCLUDE_FILES:=List of files in SRCS that should be excluded
79198090Srdivacky  #   EXTRA_FILES:=List of files in SRCS that should be included regardless of suffix match.
80234353Sdim  #   JAR:=Jar file to create
81263508Sdim  #   MANIFEST:=Optional manifest file template.
82263508Sdim  #   JARMAIN:=Optional main class to add to manifest
83193323Sed  #   JARINDEX:=true means generate the index in the jar file.
84193323Sed  #   SKIP_METAINF:=Set to prevent contents of an META-INF directory to be automatically
85193323Sed  #       added to the archive.
86193323Sed  #   EXTRA_MANIFEST_ATTR:=Extra attribute to add to manifest.
87193323Sed  #   CHECK_COMPRESS_JAR Check the COMPRESS_JAR variable
88210299Sed
89193323Sed  # NOTE: $2 is dependencies, not a named argument!
90193323Sed  $(foreach i,3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE))
91251662Sdim  $(call LogSetupMacroEntry,SetupArchive($1),<dependencies>,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
92251662Sdim  $(if $(findstring $(LOG_LEVEL),trace), $(info *[2] <dependencies> = $(strip $2)))
93251662Sdim  $(if $(16),$(error Internal makefile error: Too many arguments to SetupArchive, please update JavaCompilation.gmk))
94251662Sdim
95251662Sdim  $1_JARMAIN:=$(strip $$($1_JARMAIN))
96251662Sdim  $1_JARNAME:=$$(notdir $$($1_JAR))
97251662Sdim  $1_MANIFEST_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_manifest
98251662Sdim  $1_DELETESS_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletess
99251662Sdim  $1_DELETES_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletes
100251662Sdim  $1_BIN:=$$(dir $$($1_JAR))
101251662Sdim
102193323Sed  ifeq (,$$($1_SUFFIXES))
103251662Sdim    # No suffix was set, default to classes.
104251662Sdim    $1_SUFFIXES:=.class
105251662Sdim  endif
106251662Sdim  # Convert suffixes to a find expression
107251662Sdim  $1_FIND_PATTERNS:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_SUFFIXES))
108251662Sdim  # On windows, a lot of includes/excludes risk making the command line too long, so
109251662Sdim  # writing the grep patterns to files.
110251662Sdim  ifneq (,$$($1_INCLUDES))
111193323Sed    $1_GREP_INCLUDE_PATTERNS:=$$(call EscapeDollar, \
112193323Sed        $$(foreach src,$$($1_SRCS), $$(addprefix $$(src)/,$$($1_INCLUDES))))
113193323Sed    # If there are a lot of include patterns, output to file to shorten command lines
114193323Sed    ifeq ($$(word 20,$$($1_GREP_INCLUDE_PATTERNS)),)
115193323Sed      $1_GREP_INCLUDES:=| $(GREP) $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_INCLUDE_PATTERNS))
116193323Sed    else
117193323Sed      $1_GREP_INCLUDE_OUTPUT:=$(RM) $$($1_BIN)/_the.$$($1_JARNAME)_include $$(NEWLINE) \
118193323Sed          $$(call ListPathsSafely,$1_GREP_INCLUDE_PATTERNS,\n, \
119193323Sed          >> $$($1_BIN)/_the.$$($1_JARNAME)_include)
120193323Sed      $1_GREP_INCLUDES:=| $(GREP) -f $$($1_BIN)/_the.$$($1_JARNAME)_include
121218893Sdim    endif
122193323Sed  endif
123234353Sdim  ifneq (,$$($1_EXCLUDES)$$($1_EXCLUDE_FILES))
124234353Sdim    $1_GREP_EXCLUDE_PATTERNS:=$$(call EscapeDollar, \
125234353Sdim        $$(foreach src,$$($1_SRCS),$$(addprefix $$(src)/, \
126234353Sdim        $$($1_EXCLUDES) $$($1_EXCLUDE_FILES))))
127234353Sdim    # If there are a lot of include patterns, output to file to shorten command lines
128234353Sdim    ifeq ($$(word 20,$$($1_GREP_EXCLUDE_PATTERNS)),)
129234353Sdim      $1_GREP_EXCLUDES:=| $(GREP) -v $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_EXCLUDE_PATTERNS))
130234353Sdim    else
131234353Sdim      $1_GREP_EXCLUDE_OUTPUT=$(RM) $$($1_BIN)/_the.$$($1_JARNAME)_exclude $$(NEWLINE) \
132234353Sdim          $$(call ListPathsSafely,$1_GREP_EXCLUDE_PATTERNS,\n, \
133234353Sdim          >> $$($1_BIN)/_the.$$($1_JARNAME)_exclude)
134234353Sdim      $1_GREP_EXCLUDES:=| $(GREP) -v -f $$($1_BIN)/_the.$$($1_JARNAME)_exclude
135234353Sdim    endif
136234353Sdim  endif
137234353Sdim
138234353Sdim  # Check if this jar needs to have its index generated.
139193323Sed  ifneq (,$$($1_JARINDEX))
140193323Sed    $1_JARINDEX = (cd $$(dir $$@) && $(JAR) -i $$(notdir $$@))
141193323Sed  else
142193323Sed    $1_JARINDEX = true
143193323Sed  endif
144210299Sed  # When this macro is run in the same makefile as the java compilation, dependencies are
145210299Sed  # transfered in make variables. When the macro is run in a different makefile than the
146193323Sed  # java compilation, the dependencies need to be found in the filesystem.
147193323Sed  ifneq (,$2)
148193323Sed    $1_DEPS:=$2
149218893Sdim  else
150234353Sdim    # Add all source roots to the find cache since we are likely going to run find 
151263508Sdim    # on these more than once. The cache will only be updated if necessary.
152193323Sed    $$(eval $$(call FillCacheFind, $$($1_FIND_LIST)))
153193323Sed    $1_DEPS:=$$(filter $$(addprefix %,$$($1_SUFFIXES)), \
154193323Sed        $$(call CacheFind,$$($1_SRCS)))
155193323Sed    ifneq (,$$($1_GREP_INCLUDE_PATTERNS))
156210299Sed      $1_DEPS:=$$(filter $$(addsuffix %,$$($1_GREP_INCLUDE_PATTERNS)),$$($1_DEPS))
157210299Sed    endif
158210299Sed    ifneq (,$$($1_GREP_EXCLUDE_PATTERNS))
159193323Sed      $1_DEPS:=$$(filter-out $$(addsuffix %,$$($1_GREP_EXCLUDE_PATTERNS)),$$($1_DEPS))
160193323Sed    endif
161193323Sed    # Look for EXTRA_FILES in all SRCS dirs and as absolute paths.
162218893Sdim    $1_DEPS+=$$(wildcard $$(foreach src, $$($1_SRCS), \
163212904Sdim        $$(addprefix $$(src)/, $$($1_EXTRA_FILES))) $$($1_EXTRA_FILES))
164193323Sed    ifeq (,$$($1_SKIP_METAINF))
165224145Sdim      $1_DEPS+=$$(call CacheFind,$$(wildcard $$(addsuffix /META-INF,$$($1_SRCS))))
166193323Sed    endif
167193323Sed  endif
168210299Sed  # The dependency list should never be empty
169193323Sed  ifeq ($$(strip $$($1_DEPS)), )
170193323Sed    $$(warning No dependencies found for $1)
171193323Sed  endif
172210299Sed
173193323Sed  # Utility macros, to make the shell script receipt somewhat easier to decipher.
174193323Sed
175193323Sed  # Capture extra files is the same for both CAPTURE_CONTENTS and SCAPTURE_CONTENTS so
176193323Sed  # only define it once to avoid duplication.
177193323Sed  # The list of extra files might be long, so need to use ListPathsSafely to print
178193323Sed  # them out to a separte file. Then process the contents of that file to rewrite
179193323Sed  # into -C <dir> <file> lines.
180193323Sed  # The EXTRA_FILES_RESOLVED varible must be set in the macro so that it's evaluated
181193323Sed  # in the recipe when the files are guaranteed to exist.
182193323Sed  $1_CAPTURE_EXTRA_FILES=\
183193323Sed      $(RM) $$($1_BIN)/_the.$$($1_JARNAME)_contents.extra $$(NEWLINE) \
184193323Sed      $$(eval $1_EXTRA_FILES_RESOLVED:=$$(call DoubleDollar, $$(call DoubleDollar, \
185193323Sed          $$(wildcard $$(foreach src, $$($1_SRCS), \
186210299Sed          $$(addprefix $$(src)/, $$($1_EXTRA_FILES))) $$($1_EXTRA_FILES))))) \
187193323Sed      $$(if $$($1_EXTRA_FILES_RESOLVED), \
188210299Sed        $$(call ListPathsSafely,$1_EXTRA_FILES_RESOLVED,\n, \
189193323Sed            >> $$($1_BIN)/_the.$$($1_JARNAME)_contents.extra) $$(NEWLINE) \
190193323Sed        $(SED) $$(foreach src,$$($1_SRCS), -e 's|$$(src)/|-C $$(src) |g') \
191198090Srdivacky            $$($1_BIN)/_the.$$($1_JARNAME)_contents.extra \
192212904Sdim            >> $$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE))
193193323Sed
194193323Sed  # The capture contents macro finds all files (matching the patterns, typically
195193323Sed  # .class and .prp) that are newer than the jar-file, ie the new content to be put into the jar.
196193323Sed  # NOTICE: please leave the parentheses space separated otherwise the AIX build will break!
197193323Sed  $1_CAPTURE_CONTENTS=\
198193323Sed      $(RM) $$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE) \
199193323Sed      $$(foreach src,$$($1_SRCS), \
200193323Sed        $(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) -a -newer $$@ $$($1_GREP_INCLUDES) \
201198892Srdivacky          $$($1_GREP_EXCLUDES) | $(SED) 's|$$(src)/|-C $$(src) |g' \
202193323Sed        >> $$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE)) \
203193323Sed      $$($1_CAPTURE_EXTRA_FILES)
204210299Sed
205212904Sdim  # The capture metainf macro finds all files below the META-INF directory that are newer than the jar-file.
206193323Sed  ifeq (,$$($1_SKIP_METAINF))
207193323Sed    $1_CAPTURE_METAINF =$$(foreach src,$$($1_SRCS), \
208243830Sdim        ( $(FIND) $$(src)/META-INF -type f -a -newer $$@ 2> /dev/null | $(SED) 's|$$(src)/|-C $$(src) |g' >> \
209193323Sed        $$($1_BIN)/_the.$$($1_JARNAME)_contents ) $$(NEWLINE) )
210193323Sed  endif
211210299Sed  # The capture deletes macro finds all deleted files and concatenates them. The resulting file
212212904Sdim  # tells us what to remove from the jar-file.
213193323Sed  $1_CAPTURE_DELETES=$$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.deleted -newer $$@ \
214193323Sed      -exec $(SED) 's|$$(src)||g' \{\} >> $$($1_DELETES_FILE) \;) $$(NEWLINE))
215243830Sdim  # The update contents macro updates the jar file with the previously capture contents.
216212904Sdim  # Use 'wc -w' to see if the contents file is empty.
217212904Sdim  $1_UPDATE_CONTENTS=\
218234353Sdim      if [ "`$(WC) -l $$($1_BIN)/_the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'`" -gt "0" ]; then \
219193323Sed        $(ECHO) "  updating" `$(WC) -l $$($1_BIN)/_the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'` files && \
220193323Sed        $(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @$$($1_BIN)/_the.$$($1_JARNAME)_contents; \
221193323Sed      fi $$(NEWLINE)
222193323Sed  # The s-variants of the above macros are used when the jar is created from scratch.
223193323Sed  # NOTICE: please leave the parentheses space separated otherwise the AIX build will break!
224193323Sed  $1_SCAPTURE_CONTENTS=\
225193323Sed      $(RM) $$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE) \
226193323Sed      $$(foreach src,$$($1_SRCS), \
227193323Sed        $(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) $$($1_GREP_INCLUDES) \
228193323Sed            $$($1_GREP_EXCLUDES) | $(SED) 's|$$(src)/|-C $$(src) |g' \
229193323Sed            >> $$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE)) \
230193323Sed      $$($1_CAPTURE_EXTRA_FILES)
231193323Sed
232234353Sdim  ifeq (,$$($1_SKIP_METAINF))
233193323Sed    $1_SCAPTURE_METAINF=$$(foreach src,$$($1_SRCS), \
234193323Sed        ( $(FIND) $$(src)/META-INF -type f 2> /dev/null | $(SED) 's|$$(src)/|-C $$(src) |g' >> \
235193323Sed        $$($1_BIN)/_the.$$($1_JARNAME)_contents) $$(NEWLINE) )
236193323Sed  endif
237193323Sed  $1_SUPDATE_CONTENTS=$(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @$$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE)
238193323Sed
239198090Srdivacky  # Use a slightly shorter name for logging, but with enough path to identify this jar.
240193323Sed  $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_JAR))
241193323Sed
242234353Sdim  ifneq (,$$($1_CHECK_COMPRESS_JAR))
243234353Sdim    $1_JAR_CREATE_OPTIONS := c0fm
244234353Sdim    $1_JAR_UPDATE_OPTIONS := u0f
245234353Sdim    ifeq ($(COMPRESS_JARS), true)
246234353Sdim      $1_JAR_CREATE_OPTIONS := cfm
247234353Sdim      $1_JAR_UPDATE_OPTIONS := uf
248234353Sdim    endif
249234353Sdim  else
250234353Sdim    $1_JAR_CREATE_OPTIONS := cfm
251234353Sdim    $1_JAR_UPDATE_OPTIONS := uf
252234353Sdim  endif
253234353Sdim
254234353Sdim  # Here is the rule that creates/updates the jar file.
255234353Sdim  $$($1_JAR) : $$($1_DEPS)
256234353Sdim	$(MKDIR) -p $$($1_BIN)
257234353Sdim	$$($1_GREP_INCLUDE_OUTPUT)
258193323Sed	$$($1_GREP_EXCLUDE_OUTPUT)
259193323Sed	$$(if $$($1_MANIFEST), \
260193323Sed	  $(SED) -e "s#@@RELEASE@@#$(RELEASE)#" \
261193323Sed	      -e "s#@@COMPANY_NAME@@#$(COMPANY_NAME)#" $$($1_MANIFEST) > $$($1_MANIFEST_FILE) \
262193323Sed	, \
263193323Sed	  $(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE))
264234353Sdim	$$(if $$($1_JARMAIN),$(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE))
265234353Sdim	$$(if $$($1_EXTRA_MANIFEST_ATTR),$(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE))
266234353Sdim	$$(if $$(wildcard $$@), \
267234353Sdim	  $(ECHO) Modifying $$($1_NAME) $$(NEWLINE) \
268234353Sdim	  $$($1_CAPTURE_CONTENTS) \
269234353Sdim	  $$($1_CAPTURE_METAINF) \
270234353Sdim	  $(RM) $$($1_DELETES_FILE) $$(NEWLINE) \
271234353Sdim	  $$($1_CAPTURE_DELETES) \
272234353Sdim	  $(CAT) $$($1_DELETES_FILE) > $$($1_DELETESS_FILE) $$(NEWLINE) \
273234353Sdim	  if [ -s $$($1_DELETESS_FILE) ]; then \
274234353Sdim	    $(ECHO) "  deleting" `$(WC) -l $$($1_DELETESS_FILE) | $(AWK) '{ print $$$$1 }'` files && \
275234353Sdim	    $(ZIP) -q -d $$@ `$(CAT) $$($1_DELETESS_FILE)` ; \
276234353Sdim	  fi $$(NEWLINE) \
277234353Sdim	  $$($1_UPDATE_CONTENTS) true $$(NEWLINE) \
278234353Sdim	  $$($1_JARINDEX) && true \
279234353Sdim	, \
280234353Sdim	  $(ECHO) Creating $$($1_NAME) && $(JAR) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) $$(NEWLINE) \
281234353Sdim	  $$($1_SCAPTURE_CONTENTS) \
282234353Sdim	  $$($1_SCAPTURE_METAINF) \
283234353Sdim	  $$($1_SUPDATE_CONTENTS) \
284234353Sdim	  $$($1_JARINDEX) && true )
285193323Sed
286193323Sed  # Add jar to target list
287193323Sed  $1 += $$($1_JAR)
288193323Sedendef
289234353Sdim
290193323Seddefine SetupZipArchive
291193323Sed  # param 1 is for example ZIP_MYSOURCE
292193323Sed  # param 2,3,4,5,6,7,8,9 are named args.
293193323Sed  #   SRC,ZIP,INCLUDES,INCLUDE_FILES,EXCLUDES,EXCLUDE_FILES,SUFFIXES,EXTRA_DEPS
294193323Sed  $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE))
295193323Sed  $(call LogSetupMacroEntry,SetupZipArchive($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
296193323Sed  $(if $(16),$(error Internal makefile error: Too many arguments to SetupZipArchive, please update JavaCompilation.gmk))
297193323Sed
298193323Sed  # To avoid running find over too large sets of files, which causes make to crash
299193323Sed  # on some configurations (cygwin), use INCLUDES and INCLUDE_FILES to build a set
300193323Sed  # of directories to run find in, if available.
301193323Sed  ifneq ($$($1_INCLUDES)$$($1_INCLUDE_FILES),)
302193323Sed    $1_FIND_LIST := $$(wildcard $$(foreach i,$$($1_SRC), \
303193323Sed        $$(addprefix $$i/,$$($1_INCLUDES) $$($1_INCLUDE_FILES))))
304193323Sed  else
305193323Sed    $1_FIND_LIST := $$($1_SRC)
306193323Sed  endif
307193323Sed
308218893Sdim  # Find all files in the source tree.
309218893Sdim  $1_ALL_SRCS := $$(call not-containing,_the.,$$(call CacheFind,$$($1_FIND_LIST)))
310218893Sdim
311218893Sdim  # Filter on suffixes if set
312193323Sed  ifneq ($$($1_SUFFIXES),)
313193323Sed    $1_ALL_SRCS := $$(filter $$(addprefix %, $$($1_SUFFIXES)), $$($1_ALL_SRCS))
314193323Sed  endif
315193323Sed
316210299Sed  ifneq ($$($1_INCLUDES),)
317193323Sed    ifneq ($$($1_SUFFIXES),)
318193323Sed      $1_ZIP_INCLUDES := $$(foreach s,$$($1_SUFFIXES), \
319193323Sed          $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$$s$(DQUOTE),$$($1_INCLUDES))))
320193323Sed    else
321193323Sed      $1_ZIP_INCLUDES := $$(addprefix -i$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_INCLUDES)))
322193323Sed    endif
323193323Sed  endif
324218893Sdim  ifneq ($$($1_INCLUDE_FILES),)
325218893Sdim    $1_ZIP_INCLUDES += $$(addprefix -i$(SPACE),$$($1_INCLUDE_FILES))
326218893Sdim  endif
327218893Sdim  ifneq ($$($1_EXCLUDES),)
328193323Sed    $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES))))
329234353Sdim    $1_ZIP_EXCLUDES := $$(addprefix -x$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_EXCLUDES)))
330234353Sdim    $1_ALL_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_SRCS))
331210299Sed  endif
332193323Sed
333193323Sed  # Use a slightly shorter name for logging, but with enough path to identify this zip.
334193323Sed  $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_ZIP))
335193323Sed
336193323Sed  # Now $1_ALL_SRCS should contain all sources that are going to be put into the zip.
337193323Sed  # I.e. the zip -i and -x options should match the filtering done in the makefile.
338193323Sed  # Explicitly excluded files can be given with absolute path. The patsubst solution
339193323Sed  # isn't perfect but the likelyhood of an absolute path to match something in a src
340193323Sed  # dir is very small.
341193323Sed  # If zip has nothing to do, it returns 12 and would fail the build. Check for 12
342210299Sed  # and only fail if it's not.
343193323Sed  $$($1_ZIP) : $$($1_ALL_SRCS) $$($1_EXTRA_DEPS)
344193323Sed	$(MKDIR) -p $$(@D)
345193323Sed	$(ECHO) Updating $$($1_NAME)
346193323Sed	$$(foreach i,$$($1_SRC),(cd $$i && $(ZIP) -qru $$@ . $$($1_ZIP_INCLUDES) $$($1_ZIP_EXCLUDES) -x \*_the.\* $$(addprefix -x$(SPACE),$$(patsubst $$i/%,%,$$($1_EXCLUDE_FILES))) || test "$$$$?" = "12" )$$(NEWLINE)) true
347193323Sed	$(TOUCH) $$@
348193323Sed
349193323Sed  # Add zip to target list
350193323Sed  $1 += $$($1_ZIP)
351193323Sedendef
352193323Sed
353193323Seddefine add_file_to_copy
354193323Sed  # param 1 = BUILD_MYPACKAGE
355193323Sed  # parma 2 = The source file to copy.
356193323Sed  $2_TARGET:=$2
357193323Sed  # Remove the source prefix.
358193323Sed  $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET)))
359193323Sed  # To allow for automatic overrides, do not create a rule for a target file that
360193323Sed  # already has one
361193323Sed  ifeq ($$(findstring $$($2_TARGET), $$($1_COPY_LIST)), )
362193323Sed    $1_COPY_LIST += $$($2_TARGET)
363193323Sed    # Now we can setup the depency that will trigger the copying.
364193323Sed    $$($1_BIN)$$($2_TARGET) : $2
365193323Sed	$(MKDIR) -p $$(@D)
366210299Sed	$(CP) $$< $$@
367212904Sdim	$(CHMOD) -f ug+w $$@
368198090Srdivacky
369193323Sed    # And do not forget this target
370193323Sed    $1_ALL_COPY_TARGETS += $$($1_BIN)$$($2_TARGET)
371243830Sdim  endif
372199481Srdivackyendef
373193323Sed
374193323Sed
375193323Sed# This macro is used only for properties files that are to be
376193323Sed# copied over to the classes directory in cleaned form:
377193323Sed# Previously this was inconsistently done in different repositories.
378210299Sed# This is the new clean standard. Though it is to be superseded by
379193323Sed# a standard annotation processor from with sjavac.
380193323Sed#
381212904Sdim# The sed expression does this:
382234353Sdim# 1. Add a backslash before any :, = or ! that do not have a backslash already.
383193323Sed# 2. Apply the file unicode2x.sed which does a whole bunch of \u00XX to \xXX 
384193323Sed#    conversions.
385193323Sed# 3. Delete all lines starting with #.
386193323Sed# 4. Delete empty lines.
387193323Sed# 5. Append lines ending with \ with the next line.
388193323Sed# 6. Remove leading and trailing white space. Note that tabs must be explicit
389193323Sed#    as sed on macosx does not understand '\t'.
390193323Sed# 7. Replace the first \= with just =.
391193323Sed# 8. Finally it's all sorted to create a stable output.
392193323Sed# 
393193323Sed# It is assumed that = is the character used for separating names and values.
394193323Seddefine add_file_to_clean
395193323Sed  # param 1 = BUILD_MYPACKAGE
396193323Sed  # parma 2 = The source file to copy and clean.
397193323Sed  $2_TARGET:=$2
398198090Srdivacky  # Remove the source prefix.
399193323Sed  $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET)))
400193323Sed  # Now we can setup the depency that will trigger the copying.
401218893Sdim  $$($1_BIN)$$($2_TARGET) : $2
402218893Sdim	$(MKDIR) -p $$(@D)
403193323Sed	$(CAT) $$< | $(SED) -e 's/\([^\\]\):/\1\\:/g' -e 's/\([^\\]\)=/\1\\=/g' \
404193323Sed	        -e 's/\([^\\]\)!/\1\\!/g' -e 's/#.*/#/g' \
405193323Sed	    | $(SED) -f "$(SRC_ROOT)/make/common/support/unicode2x.sed" \
406193323Sed	    | $(SED) -e '/^#/d' -e '/^$$$$/d' \
407199481Srdivacky	        -e :a -e '/\\$$$$/N; s/\\\n//; ta' \
408193323Sed	        -e 's/^[ 	]*//;s/[ 	]*$$$$//' \
409193323Sed	        -e 's/\\=/=/' | LC_ALL=C $(SORT) > $$@
410234353Sdim	$(CHMOD) -f ug+w $$@
411234353Sdim
412234353Sdim  # And do not forget this target
413234353Sdim  $1_ALL_COPY_CLEAN_TARGETS += $$($1_BIN)$$($2_TARGET)
414234353Sdimendef
415234353Sdim
416234353Sdimdefine remove_string
417234353Sdim  $2 := $$(subst $1,,$$($2))
418234353Sdimendef
419234353Sdim
420193323Seddefine replace_space_with_pathsep
421193323Sed  $1:=$(subst $(SPACE),$(PATH_SEP),$(strip $(patsubst %,%,$2)))
422193323Sedendef
423193323Sed
424193323Seddefine SetupJavaCompilation
425193323Sed  # param 1 is for example BUILD_MYPACKAGE
426193323Sed  # param 2,3,4,5,6,7,8 are named args.
427193323Sed  #   SETUP:=must point to a previously setup java compiler, for example: SETUP:=BOOTJAVAC
428210299Sed  #   JVM:=path to ..bin/java
429193323Sed  #   ADD_JAVAC_FLAGS:=javac flags to append to the default ones.
430193323Sed  #   SRC:=one or more directories to search for sources
431193323Sed  #   BIN:=store classes here
432193323Sed  #   INCLUDES:=myapp.foo means will only compile java files in myapp.foo or any of its sub-packages.
433193323Sed  #   EXCLUDES:=myapp.foo means will do not compile java files in myapp.foo or any of its sub-packages.
434193323Sed  #   COPY:=.prp means copy all prp files to the corresponding package in BIN.
435210299Sed  #   COPY_FILES:=myapp/foo/setting.txt means copy this file over to the package myapp/foo
436193323Sed  #   CLEAN:=.properties means copy and clean all properties file to the corresponding package in BIN.
437218893Sdim  #   CLEAN_FILES:=myapp/foo/setting.txt means clean this file over to the package myapp/foo
438218893Sdim  #   SRCZIP:=Create a src.zip based on the found sources and copied files.
439198090Srdivacky  #   INCLUDE_FILES:="com/sun/SolarisFoobar.java" means only compile this file!
440218893Sdim  #   EXCLUDE_FILES:="com/sun/SolarisFoobar.java" means do not compile this particular file!
441218893Sdim  #       "SolarisFoobar.java" means do not compile SolarisFoobar, wherever it is found.
442193323Sed  #   JAVAC_SOURCE_PATH_OVERRIDE:=This forces an explicit -sourcepath to javac instead of the complete
443193323Sed  #       source roots from SRC. This is sometimes needed when compiling specific subsets of the source.
444193323Sed  #   HEADERS:=path to directory where all generated c-headers are written.
445193323Sed  #   DEPENDS:=Extra dependecy
446193323Sed  $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE))
447193323Sed  $(call LogSetupMacroEntry,SetupJavaCompilation($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
448193323Sed  $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompilation, please update JavaCompilation.gmk))
449193323Sed
450193323Sed  # Extract the info from the java compiler setup.
451193323Sed  $1_JVM := $$($$($1_SETUP)_JVM)
452193323Sed  $1_JAVAC := $$($$($1_SETUP)_JAVAC)
453193323Sed  $1_FLAGS := $$($$($1_SETUP)_FLAGS) $(JAVAC_FLAGS) $$($1_ADD_JAVAC_FLAGS)
454193323Sed  ifeq ($$($1_JAVAC),)
455193323Sed    $$(error The Java compilation $1 refers to a non-existant java compiler setup $$($1_SETUP))
456193323Sed  endif
457193323Sed  $1_SJAVAC_PORTFILE := $$($$($1_SETUP)_SJAVAC_PORTFILE)
458193323Sed  $1_SERVER_JVM := $$($$($1_SETUP)_SERVER_JVM)
459193323Sed
460193323Sed  # Handle addons and overrides.
461193323Sed  $1_SRC:=$$(call ADD_SRCS,$$($1_SRC))
462193323Sed  # Make sure the dirs exist.
463193323Sed  $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupJavaCompilation $1 contains missing directory $$d)))
464193323Sed  $$(eval $$(call MakeDir,$$($1_BIN)))
465193323Sed  # Add all source roots to the find cache since we are likely going to run find 
466193323Sed  # on these more than once. The cache will only be updated if necessary.
467193323Sed  $$(eval $$(call FillCacheFind,$$($1_SRC)))
468193323Sed  # Find all files in the source trees. Preserve order of source roots for overrides to
469193323Sed  # work correctly. CacheFind does not preserve order so need to call it for each root.
470193323Sed  $1_ALL_SRCS += $$(filter-out $(OVR_SRCS),$$(foreach s,$$($1_SRC),$$(call CacheFind,$$(s))))
471193323Sed  # Extract the java files.
472193323Sed  ifneq ($$($1_EXCLUDE_FILES),)
473193323Sed    $1_EXCLUDE_FILES_PATTERN:=$$(addprefix %,$$($1_EXCLUDE_FILES))
474193323Sed  endif
475193323Sed  $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$(filter %.java,$$($1_ALL_SRCS)))
476193323Sed  ifneq ($$($1_INCLUDE_FILES),)
477193323Sed    $1_INCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES)))
478193323Sed    $1_SRCS := $$(filter $$($1_INCLUDE_FILES), $$($1_SRCS))
479193323Sed  endif
480193323Sed
481193323Sed  # Now we have a list of all java files to compile: $$($1_SRCS)
482193323Sed
483193323Sed  # Create the corresponding smart javac wrapper command line.
484193323Sed  $1_SJAVAC_ARGS:=$$(addprefix -x ,$$(addsuffix /*,$$($1_EXCLUDES))) \
485193323Sed      $$(addprefix -i ,$$(addsuffix /*,$$($1_INCLUDES))) \
486193323Sed      $$(addprefix -xf *,$$(strip $$($1_EXCLUDE_FILES))) \
487193323Sed      $$(addprefix -if *,$$(strip $$($1_INCLUDE_FILES))) \
488193323Sed      -src "$$(subst $$(SPACE),$$(PATH_SEP),$$(strip $$($1_SRC)))"
489193323Sed
490193323Sed  # Prepend the source/bin path to the filter expressions.
491193323Sed  ifneq ($$($1_INCLUDES),)
492193323Sed    $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES))))
493193323Sed    $1_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS))
494193323Sed  endif
495210299Sed  ifneq ($$($1_EXCLUDES),)
496210299Sed    $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES))))
497193323Sed    $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS))
498193323Sed  endif
499193323Sed
500193323Sed  # All files below META-INF are always copied.
501193323Sed  $1_ALL_COPIES := $$(filter $$(addsuffix /META-INF%,$$($1_SRC)),$$($1_ALL_SRCS))
502234353Sdim  # Find all files to be copied from source to bin.
503234353Sdim  ifneq (,$$($1_COPY)$$($1_COPY_FILES))
504234353Sdim    # Search for all files to be copied.
505234353Sdim    $1_ALL_COPIES += $$(filter $$(addprefix %,$$($1_COPY)),$$($1_ALL_SRCS))
506234353Sdim    # Copy these explicitly
507234353Sdim    $1_ALL_COPIES += $$($1_COPY_FILES)
508234353Sdim    # Copy must also respect filters.
509234353Sdim    ifneq (,$$($1_INCLUDES))
510234353Sdim      $1_ALL_COPIES := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_COPIES))
511234353Sdim    endif
512234353Sdim    ifneq (,$$($1_EXCLUDES))
513234353Sdim      $1_ALL_COPIES := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_COPIES))
514193323Sed    endif
515193323Sed    ifneq (,$$($1_EXCLUDE_FILES))
516193323Sed      $1_ALL_COPIES := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_COPIES))
517193323Sed    endif
518234353Sdim  endif
519234353Sdim    ifneq (,$$($1_ALL_COPIES))
520193323Sed      # Yep, there are files to be copied!
521234353Sdim      $1_ALL_COPY_TARGETS:=
522234353Sdim          $$(foreach i,$$($1_ALL_COPIES),$$(eval $$(call add_file_to_copy,$1,$$i)))
523234353Sdim      # Now we can depend on $$($1_ALL_COPY_TARGETS) to copy all files!
524234353Sdim    endif
525234353Sdim
526234353Sdim  # Find all property files to be copied and cleaned from source to bin.
527234353Sdim  ifneq (,$$($1_CLEAN)$$($1_CLEAN_FILES))
528234353Sdim    # Search for all files to be copied.
529234353Sdim    $1_ALL_CLEANS := $$(filter $$(addprefix %,$$($1_CLEAN)),$$($1_ALL_SRCS))
530234353Sdim    # Clean these explicitly
531234353Sdim    $1_ALL_CLEANS += $$($1_CLEAN_FILES)
532234353Sdim    # Copy and clean must also respect filters.
533234353Sdim    ifneq (,$$($1_INCLUDES))
534234353Sdim      $1_ALL_CLEANS := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_CLEANS))
535234353Sdim    endif
536234353Sdim    ifneq (,$$($1_EXCLUDES))
537234353Sdim      $1_ALL_CLEANS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_CLEANS))
538193323Sed    endif
539193323Sed    ifneq (,$$($1_EXCLUDE_FILES))
540193323Sed      $1_ALL_CLEANS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_CLEANS))
541193323Sed    endif
542234353Sdim    ifneq (,$$($1_ALL_CLEANS))
543193323Sed      # Yep, there are files to be copied and cleaned!
544193323Sed      $1_ALL_COPY_CLEAN_TARGETS:=
545234353Sdim          $$(foreach i,$$($1_ALL_CLEANS),$$(eval $$(call add_file_to_clean,$1,$$i)))
546234353Sdim      # Now we can depend on $$($1_ALL_COPY_CLEAN_TARGETS) to copy all files!
547234353Sdim    endif
548234353Sdim  endif
549234353Sdim
550193323Sed  # Prep the source paths.
551193323Sed  ifneq ($$($1_JAVAC_SOURCE_PATH_OVERRIDE),)
552193323Sed    $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_JAVAC_SOURCE_PATH_OVERRIDE)))
553193323Sed  else
554224145Sdim    $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_SRC)))
555224145Sdim  endif
556224145Sdim
557193323Sed  # Create a sed expression to remove the source roots and to replace / with .
558193323Sed  # and remove .java at the end.
559193323Sed  $1_REWRITE_INTO_CLASSES:=$$(foreach i,$$($1_SRC),-e 's|$$i/||g') -e 's|/|.|g' -e 's|.java$$$$||g'
560193323Sed
561193323Sed  ifeq ($$($1_DISABLE_SJAVAC)x$$(ENABLE_SJAVAC),xyes)
562193323Sed    ifneq (,$$($1_HEADERS))
563193323Sed      $1_HEADERS_ARG := -h $$($1_HEADERS)
564193323Sed    endif
565234353Sdim
566234353Sdim    # Using sjavac to compile.
567234353Sdim    $1_COMPILE_TARGETS := $$($1_BIN)/javac_state
568234353Sdim
569234353Sdim    # Create SJAVAC variable form JAVAC variable. Expects $1_JAVAC to be
570234353Sdim    # "bootclasspathprepend -cp .../javac.jar com.sun.tools.javac.Main"
571234353Sdim    # and javac is simply replaced with sjavac.
572234353Sdim    $1_SJAVAC:=$$(subst com.sun.tools.javac.Main,com.sun.tools.sjavac.Main,$$($1_JAVAC))
573234353Sdim
574193323Sed    # Set the $1_REMOTE to spawn a background javac server.
575    $1_REMOTE:=--server:portfile=$$($1_SJAVAC_PORTFILE),id=$1,sjavac=$$(subst $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_SJAVAC))))
576
577    $$($1_BIN)/javac_state: $$($1_SRCS) $$($1_DEPENDS)
578	$(MKDIR) -p $$(@D)
579	$$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.$1_batch.tmp)
580	$(ECHO) Compiling $1
581	($$($1_JVM) $$($1_SJAVAC) \
582	    $$($1_REMOTE) \
583	    -j 1 \
584	    --permit-unidentified-artifacts \
585	    --permit-sources-without-package \
586	    --compare-found-sources $$($1_BIN)/_the.$1_batch.tmp \
587	    --log=$(LOG_LEVEL) \
588	    $$($1_SJAVAC_ARGS) \
589	    $$($1_FLAGS) \
590	    $$($1_HEADERS_ARG) \
591	    -d $$($1_BIN) && \
592	$(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch)
593        # sjavac doesn't touch this if nothing has changed
594	$(TOUCH) $$@
595  else
596    # Using plain javac to batch compile everything.
597    $1_COMPILE_TARGETS := $$($1_BIN)/_the.$1_batch
598
599    # When building in batch, put headers in a temp dir to filter out those that actually
600    # changed before copying them to the real header dir.
601    ifneq (,$$($1_HEADERS))
602      $1_HEADERS_ARG := -h $$($1_HEADERS).$1.tmp
603
604      $$($1_HEADERS)/_the.$1_headers: $$($1_BIN)/_the.$1_batch
605		$(MKDIR) -p $$(@D)
606		if [ -d "$$($1_HEADERS).$1.tmp" ]; then \
607		  for f in `ls $$($1_HEADERS).$1.tmp`; do \
608		    if [ ! -f "$$($1_HEADERS)/$$$$f" ] \
609		        || [ "`$(DIFF) $$($1_HEADERS)/$$$$f $$($1_HEADERS).$1.tmp/$$$$f`" != "" ]; then \
610		    $(CP) -f $$($1_HEADERS).$1.tmp/$$$$f $$($1_HEADERS)/$$$$f; \
611		  fi; \
612		  done; \
613		fi
614		$(RM) -r $$($1_HEADERS).$1.tmp
615		$(TOUCH) $$@
616
617      $1_HEADER_TARGETS := $$($1_HEADERS)/_the.$1_headers
618    endif
619
620    # When not using sjavac, pass along all sources to javac using an @file.
621    $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS)
622	$(MKDIR) -p $$(@D)
623	$(RM) $$($1_BIN)/_the.$1_batch $$($1_BIN)/_the.$1_batch.tmp
624	$$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.$1_batch.tmp)
625	$(ECHO) Compiling `$(WC) $$($1_BIN)/_the.$1_batch.tmp | $(TR) -s ' ' | $(CUT) -f 2 -d ' '` files for $1
626	($$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) \
627	    -implicit:none -sourcepath "$$($1_SRCROOTSC)" \
628	    -d $$($1_BIN) $$($1_HEADERS_ARG) @$$($1_BIN)/_the.$1_batch.tmp && \
629	$(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch)
630
631  endif
632
633  # Add all targets to main variable
634  $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_COMPILE_TARGETS) \
635      $$($1_HEADER_TARGETS)
636
637  # Check if a jar file was specified, then setup the rules for the jar.
638  ifneq (,$$($1_JAR))
639    # If no suffixes was explicitly set for this jar file.
640    # Use class and the cleaned/copied properties file suffixes as the default
641    # for the types of files to be put into the jar.
642    ifeq (,$$($1_SUFFIXES))
643      $1_SUFFIXES:=.class $$($1_CLEAN) $$($1_COPY)
644    endif
645
646    $$(eval $$(call SetupArchive,ARCHIVE_$1,$$($1), \
647        SRCS:=$$($1_BIN), \
648        SUFFIXES:=$$($1_SUFFIXES), \
649        EXCLUDE:=$$($1_EXCLUDES), \
650        INCLUDES:=$$($1_INCLUDES), \
651        EXTRA_FILES:=$$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS), \
652        JAR:=$$($1_JAR), \
653        JARMAIN:=$$($1_JARMAIN), \
654        MANIFEST:=$$($1_MANIFEST), \
655        EXTRA_MANIFEST_ATTR:=$$($1_EXTRA_MANIFEST_ATTR), \
656        JARINDEX:=$$($1_JARINDEX), \
657        HEADERS:=$$($1_HEADERS), \
658        SETUP:=$$($1_SETUP)))
659
660    # Add jar to target list
661    $1 += $$($1_JAR)
662  endif
663
664  # Check if a srczip was specified, then setup the rules for the srczip.
665  ifneq (,$$($1_SRCZIP))
666    $$(eval $$(call SetupZipArchive,ARCHIVE_$1, \
667        SRC:=$$($1_SRC), \
668        ZIP:=$$($1_SRCZIP), \
669        INCLUDES:=$$($1_INCLUDES), \
670        EXCLUDES:=$$($1_EXCLUDES), \
671        EXCLUDE_FILES:=$$($1_EXCLUDE_FILES)))
672
673    # Add zip to target list
674    $1 += $$($1_SRCZIP)
675  endif
676endef
677
678# Use this macro to find the correct target to depend on when the original
679# SetupJavaCompilation is declared in a different makefile, to avoid having
680# to declare and evaluate it again.
681# param 1 is for example BUILD_MYPACKAGE
682# param 2 is the output directory (BIN)
683define SetupJavaCompilationCompileTarget
684  $(if $(findsring yes, $(ENABLE_SJAVAC)), $(strip $2)/javac_state, \
685      $(strip $2)/_the.$(strip $1)_batch)
686endef
687endif
688