JavaCompilation.gmk revision 1627:8b56a0ce50f0
138032Speter#
273188Sgshapiro# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
364562Sgshapiro# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
438032Speter#
538032Speter# This code is free software; you can redistribute it and/or modify it
638032Speter# under the terms of the GNU General Public License version 2 only, as
738032Speter# published by the Free Software Foundation.  Oracle designates this
838032Speter# particular file as subject to the "Classpath" exception as provided
938032Speter# by Oracle in the LICENSE file that accompanied this code.
1038032Speter#
1138032Speter# This code is distributed in the hope that it will be useful, but WITHOUT
1238032Speter# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1338032Speter# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1464562Sgshapiro# version 2 for more details (a copy is included in the LICENSE file that
1538032Speter# accompanied this code).
1690792Sgshapiro#
1790792Sgshapiro# You should have received a copy of the GNU General Public License version
1890792Sgshapiro# 2 along with this work; if not, write to the Free Software Foundation,
1964562Sgshapiro# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2064562Sgshapiro#
2164562Sgshapiro# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2290792Sgshapiro# or visit www.oracle.com if you need additional information or have any
2364562Sgshapiro# questions.
2438032Speter#
2538032Speter
2638032Speter# This makefile is much simpler now that it can use the smart javac wrapper
2738032Speter# for dependency tracking between java packages and incremental compiles.
2838032Speter# It could be even more simple if we added support for incremental jar updates
2938032Speter# directly from the smart javac wrapper.
3038032Speter
3138032Speter# Cleaning/copying properties here is not a good solution. The properties
3238032Speter# should be cleaned/copied by a annotation processor in sjavac.
3338032Speter
3438032Speter# When you read this source. Remember that $(sort ...) has the side effect
3538032Speter# of removing duplicates. It is actually this side effect that is
3638032Speter# desired whenever sort is used below!
3738032Speter
3838032Speterifndef _JAVA_COMPILATION_GMK
3938032Speter_JAVA_COMPILATION_GMK := 1
4038032Speter
4190792Sgshapiroifeq (,$(_MAKEBASE_GMK))
4238032Speter  $(error You must include MakeBase.gmk prior to including JavaCompilation.gmk)
4338032Speterendif
4438032Speter
4538032Speter# Java compilation needs SetupZipArchive if we're generating a source zip.
4638032Speterinclude ZipArchive.gmk
4738032Speter
4838032SpeterFALSE_FIND_PATTERN:=-name FILE_NAME_THAT_DOESNT_EXIST
4990792Sgshapiro
5090792Sgshapiro# Setup make rules for defining a Java compiler, which is needed to compile
5138032Speter# Java code. This rule generates no output.
5238032Speter#
5338032Speter# Parameter 1 is the name of the compiler definition. This name needs to be
5438032Speter# passed to SetupJavaCompilation. This name is used as variable prefix.
5538032Speter#
5638032Speter# Remaining parameters are named arguments. These include:
5738032Speter#   JVM:=The jvm used to run the javac/javah command
5890792Sgshapiro#   JAVAC:=The javac jar and bootstrap classpath changes, or just bin/javac if JVM is left out
5938032Speter#   FLAGS:=Flags to be supplied to javac
6038032Speter#   SERVER_DIR:=Use a javac server (-XDserver) and store the server related files here
6138032Speter#   SERVER_JVM:=Use this JVM for the server. Defaults to the JVM above.
6264562SgshapiroSetupJavaCompiler = $(NamedParamsMacroTemplate)
6338032Speterdefine SetupJavaCompilerBody
6438032Speter  # The port file contains the tcp/ip on which the server listens
6590792Sgshapiro  # and the cookie necessary to talk to the server.
6638032Speter  $1_SJAVAC_PORTFILE:=$$($1_SERVER_DIR)/server.port
6738032Speter  # You can use a different JVM to run the background javac server.
6838032Speter  ifeq ($$($1_SERVER_JVM),)
6938032Speter    # It defaults to the same JVM that is used to start the javac command.
7038032Speter    $1_SERVER_JVM:=$$($1_JVM)
7138032Speter  endif
7290792Sgshapiroendef
7338032Speter
7490792Sgshapiro# Setup make rules for creating a jar archive.
7538032Speter#
7664562Sgshapiro# Parameter 1 is the name of the rule. This name is used as variable prefix,
7738032Speter# and the targets generated are listed in a variable by that name.
7838032Speter#
7938032Speter# Remaining parameters are named arguments. These include:
8038032Speter#   DEPENDENCIES:=List of dependencies for the jar target. If left empty,
8138032Speter#       dependencies are calculated automatically from the source files found.
8238032Speter#       For this to work, the source files must exist when the makefile is
8338032Speter#       parsed.
8438032Speter#   SRCS:=List of directories in where to find files to add to archive
8590792Sgshapiro#   SUFFIXES:=File suffixes to include in jar
8638032Speter#   INCLUDES:=List of directories/packages in SRCS that should be included
8738032Speter#   EXCLUDES:=List of directories/packages in SRCS that should be excluded
8838032Speter#   EXCLUDE_FILES:=List of files in SRCS that should be excluded
8938032Speter#   EXTRA_FILES:=List of files in SRCS that should be included regardless of suffix match.
9038032Speter#   JAR:=Jar file to create
9138032Speter#   MANIFEST:=Optional manifest file template.
9238032Speter#   JARMAIN:=Optional main class to add to manifest
9338032Speter#   JARINDEX:=true means generate the index in the jar file.
9490792Sgshapiro#   SKIP_METAINF:=Set to prevent contents of an META-INF directory to be automatically
9564562Sgshapiro#       added to the archive.
9638032Speter#   EXTRA_MANIFEST_ATTR:=Extra attribute to add to manifest.
9738032Speter#   CHECK_COMPRESS_JAR Check the COMPRESS_JAR variable
9890792SgshapiroSetupArchive = $(NamedParamsMacroTemplate)
9938032Speterdefine SetupArchiveBody
10038032Speter
10190792Sgshapiro  $1_JARMAIN:=$(strip $$($1_JARMAIN))
10238032Speter  $1_JARNAME:=$$(notdir $$($1_JAR))
10338032Speter  $1_MANIFEST_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_manifest
10438032Speter  $1_DELETESS_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletess
10538032Speter  $1_DELETES_FILE:=$$(dir $$($1_JAR))_the.$$($1_JARNAME)_deletes
10638032Speter  $1_BIN:=$$(dir $$($1_JAR))
10738032Speter
10838032Speter  ifeq (,$$($1_SUFFIXES))
10938032Speter    # No suffix was set, default to classes.
11038032Speter    $1_SUFFIXES:=.class
11138032Speter  endif
11238032Speter  # Convert suffixes to a find expression
11338032Speter  $1_FIND_PATTERNS:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_SUFFIXES))
11438032Speter  # On windows, a lot of includes/excludes risk making the command line too long, so
11538032Speter  # writing the grep patterns to files.
11638032Speter  # Grep returns 1 if nothing is matched. Do not fail the build for this.
11738032Speter  ifneq (,$$($1_INCLUDES))
11838032Speter    $1_GREP_INCLUDE_PATTERNS:=$$(call EscapeDollar, \
11990792Sgshapiro        $$(foreach src,$$($1_SRCS), $$(addprefix $$(src)/,$$($1_INCLUDES))))
12038032Speter    # If there are a lot of include patterns, output to file to shorten command lines
12138032Speter    ifeq ($$(word 20,$$($1_GREP_INCLUDE_PATTERNS)),)
12238032Speter      $1_GREP_INCLUDES:=| ( $(GREP) $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_INCLUDE_PATTERNS)) \
12338032Speter          || test "$$$$?" = "1" )
12438032Speter    else
12538032Speter      $1_GREP_INCLUDE_OUTPUT:=$(RM) $$($1_BIN)/_the.$$($1_JARNAME)_include $$(NEWLINE) \
12638032Speter          $$(call ListPathsSafely,$1_GREP_INCLUDE_PATTERNS,\n, \
12738032Speter          >> $$($1_BIN)/_the.$$($1_JARNAME)_include)
12838032Speter      $1_GREP_INCLUDES:=| ( $(GREP) -f $$($1_BIN)/_the.$$($1_JARNAME)_include \
12990792Sgshapiro          || test "$$$$?" = "1" )
13090792Sgshapiro    endif
13190792Sgshapiro  endif
13290792Sgshapiro  ifneq (,$$($1_EXCLUDES)$$($1_EXCLUDE_FILES))
13390792Sgshapiro    $1_GREP_EXCLUDE_PATTERNS:=$$(call EscapeDollar, \
13438032Speter        $$(foreach src,$$($1_SRCS),$$(addprefix $$(src)/, \
13538032Speter        $$($1_EXCLUDES) $$($1_EXCLUDE_FILES))))
13638032Speter    # If there are a lot of include patterns, output to file to shorten command lines
13738032Speter    ifeq ($$(word 20,$$($1_GREP_EXCLUDE_PATTERNS)),)
13838032Speter      $1_GREP_EXCLUDES:=| ( $(GREP) -v $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_EXCLUDE_PATTERNS)) \
13938032Speter          || test "$$$$?" = "1" )
14038032Speter    else
14190792Sgshapiro      $1_GREP_EXCLUDE_OUTPUT=$(RM) $$($1_BIN)/_the.$$($1_JARNAME)_exclude $$(NEWLINE) \
14290792Sgshapiro          $$(call ListPathsSafely,$1_GREP_EXCLUDE_PATTERNS,\n, \
14390792Sgshapiro          >> $$($1_BIN)/_the.$$($1_JARNAME)_exclude)
14490792Sgshapiro      $1_GREP_EXCLUDES:=| ( $(GREP) -v -f $$($1_BIN)/_the.$$($1_JARNAME)_exclude \
14590792Sgshapiro          || test "$$$$?" = "1" )
14690792Sgshapiro    endif
14790792Sgshapiro  endif
14838032Speter
14938032Speter  # Check if this jar needs to have its index generated.
15038032Speter  ifneq (,$$($1_JARINDEX))
15138032Speter    $1_JARINDEX = (cd $$(dir $$@) && $(JAR) -i $$(notdir $$@))
15238032Speter  else
15390792Sgshapiro    $1_JARINDEX = true
15464562Sgshapiro  endif
15538032Speter  # When this macro is run in the same makefile as the java compilation, dependencies are
15638032Speter  # transfered in make variables. When the macro is run in a different makefile than the
15738032Speter  # java compilation, the dependencies need to be found in the filesystem.
15890792Sgshapiro  ifeq ($$($1_DEPENDENCIES), )
15990792Sgshapiro    # Add all source roots to the find cache since we are likely going to run find
16090792Sgshapiro    # on these more than once. The cache will only be updated if necessary.
16190792Sgshapiro    $$(eval $$(call FillCacheFind, $$($1_FIND_LIST)))
16290792Sgshapiro    $1_DEPENDENCIES:=$$(filter $$(addprefix %,$$($1_SUFFIXES)), \
16390792Sgshapiro        $$(call CacheFind,$$($1_SRCS)))
16490792Sgshapiro    ifneq (,$$($1_GREP_INCLUDE_PATTERNS))
16590792Sgshapiro      $1_DEPENDENCIES:=$$(filter $$(addsuffix %,$$($1_GREP_INCLUDE_PATTERNS)),$$($1_DEPENDENCIES))
16690792Sgshapiro    endif
16790792Sgshapiro    ifneq (,$$($1_GREP_EXCLUDE_PATTERNS))
16890792Sgshapiro      $1_DEPENDENCIES:=$$(filter-out $$(addsuffix %,$$($1_GREP_EXCLUDE_PATTERNS)),$$($1_DEPENDENCIES))
16990792Sgshapiro    endif
17090792Sgshapiro    # Look for EXTRA_FILES in all SRCS dirs and as absolute paths.
17190792Sgshapiro    $1_DEPENDENCIES+=$$(wildcard $$(foreach src, $$($1_SRCS), \
17290792Sgshapiro        $$(addprefix $$(src)/, $$($1_EXTRA_FILES))) $$($1_EXTRA_FILES))
17390792Sgshapiro    ifeq (,$$($1_SKIP_METAINF))
17490792Sgshapiro      $1_DEPENDENCIES+=$$(call CacheFind,$$(wildcard $$(addsuffix /META-INF,$$($1_SRCS))))
17590792Sgshapiro    endif
17690792Sgshapiro  endif
17790792Sgshapiro  # The dependency list should never be empty
17890792Sgshapiro  ifeq ($$(strip $$($1_DEPENDENCIES)), )
17990792Sgshapiro    $$(warning No dependencies found for $1)
18090792Sgshapiro  endif
18190792Sgshapiro
18290792Sgshapiro  # Utility macros, to make the shell script receipt somewhat easier to decipher.
18390792Sgshapiro
18490792Sgshapiro  # Capture extra files is the same for both CAPTURE_CONTENTS and SCAPTURE_CONTENTS so
18590792Sgshapiro  # only define it once to avoid duplication.
18690792Sgshapiro  # The list of extra files might be long, so need to use ListPathsSafely to print
18790792Sgshapiro  # them out to a separte file. Then process the contents of that file to rewrite
18890792Sgshapiro  # into -C <dir> <file> lines.
18990792Sgshapiro  # The EXTRA_FILES_RESOLVED varible must be set in the macro so that it's evaluated
19090792Sgshapiro  # in the recipe when the files are guaranteed to exist.
19190792Sgshapiro  $1_CAPTURE_EXTRA_FILES=\
19238032Speter      $(RM) $$($1_BIN)/_the.$$($1_JARNAME)_contents.extra $$(NEWLINE) \
19338032Speter      $$(eval $1_EXTRA_FILES_RESOLVED:=$$(call DoubleDollar, $$(call DoubleDollar, \
19438032Speter          $$(wildcard $$(foreach src, $$($1_SRCS), \
19564562Sgshapiro          $$(addprefix $$(src)/, $$($1_EXTRA_FILES))) $$($1_EXTRA_FILES))))) \
19638032Speter      $$(if $$($1_EXTRA_FILES_RESOLVED), \
19738032Speter        $$(call ListPathsSafely,$1_EXTRA_FILES_RESOLVED,\n, \
19838032Speter            >> $$($1_BIN)/_the.$$($1_JARNAME)_contents.extra) $$(NEWLINE) \
19938032Speter        $(SED) $$(foreach src,$$($1_SRCS), -e 's|$$(src)/|-C $$(src) |g') \
20038032Speter            $$($1_BIN)/_the.$$($1_JARNAME)_contents.extra \
20138032Speter            >> $$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE))
20290792Sgshapiro
20338032Speter  # The capture contents macro finds all files (matching the patterns, typically
20438032Speter  # .class and .prp) that are newer than the jar-file, ie the new content to be put into the jar.
20590792Sgshapiro  # NOTICE: please leave the parentheses space separated otherwise the AIX build will break!
20664562Sgshapiro  $1_CAPTURE_CONTENTS=\
20738032Speter      $(RM) $$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE) \
20838032Speter      $$(foreach src,$$($1_SRCS), \
20938032Speter        $(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) -a -newer $$@ $$($1_GREP_INCLUDES) \
21038032Speter          $$($1_GREP_EXCLUDES) | $(SED) 's|$$(src)/|-C $$(src) |g' \
21138032Speter        >> $$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE)) \
21238032Speter      $$($1_CAPTURE_EXTRA_FILES)
21338032Speter
21438032Speter  # The capture metainf macro finds all files below the META-INF directory that are newer than the jar-file.
21538032Speter  # Find returns non zero if the META-INF dir does not exist, ignore this.
21690792Sgshapiro  ifeq (,$$($1_SKIP_METAINF))
21790792Sgshapiro    $1_CAPTURE_METAINF =$$(foreach src,$$($1_SRCS), \
21838032Speter        ( ( $(FIND) $$(src)/META-INF -type f -a -newer $$@ 2> /dev/null || true ) \
21938032Speter            | $(SED) 's|$$(src)/|-C $$(src) |g' >> \
22064562Sgshapiro        $$($1_BIN)/_the.$$($1_JARNAME)_contents ) $$(NEWLINE) )
22138032Speter  endif
22290792Sgshapiro  # The capture deletes macro finds all deleted files and concatenates them. The resulting file
22390792Sgshapiro  # tells us what to remove from the jar-file.
22438032Speter  $1_CAPTURE_DELETES=$$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.deleted -newer $$@ \
22538032Speter      -exec $(SED) 's|$$(src)||g' \{\} >> $$($1_DELETES_FILE) \;) $$(NEWLINE))
22638032Speter  # The update contents macro updates the jar file with the previously capture contents.
22790792Sgshapiro  # Use 'wc -w' to see if the contents file is empty.
22890792Sgshapiro  $1_UPDATE_CONTENTS=\
22990792Sgshapiro      if [ "`$(WC) -l $$($1_BIN)/_the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'`" -gt "0" ]; then \
23038032Speter        $(ECHO) "  updating" `$(WC) -l $$($1_BIN)/_the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'` files && \
23138032Speter        $(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @$$($1_BIN)/_the.$$($1_JARNAME)_contents; \
23290792Sgshapiro      fi $$(NEWLINE)
23390792Sgshapiro  # The s-variants of the above macros are used when the jar is created from scratch.
23490792Sgshapiro  # NOTICE: please leave the parentheses space separated otherwise the AIX build will break!
23538032Speter  $1_SCAPTURE_CONTENTS=\
23638032Speter      $(RM) $$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE) \
23738032Speter      $$(foreach src,$$($1_SRCS), \
23890792Sgshapiro        $(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) $$($1_GREP_INCLUDES) \
23938032Speter            $$($1_GREP_EXCLUDES) | $(SED) 's|$$(src)/|-C $$(src) |g' \
24038032Speter            >> $$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE)) \
24190792Sgshapiro      $$($1_CAPTURE_EXTRA_FILES)
24238032Speter
24390792Sgshapiro  # Find returns non zero if the META-INF dir does not exist, ignore this.
24438032Speter  ifeq (,$$($1_SKIP_METAINF))
24590792Sgshapiro    $1_SCAPTURE_METAINF=$$(foreach src,$$($1_SRCS), \
24638032Speter        ( ( $(FIND) $$(src)/META-INF -type f 2> /dev/null || true ) \
24738032Speter            | $(SED) 's|$$(src)/|-C $$(src) |g' >> \
24838032Speter        $$($1_BIN)/_the.$$($1_JARNAME)_contents) $$(NEWLINE) )
24990792Sgshapiro  endif
25038032Speter  $1_SUPDATE_CONTENTS=$(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @$$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE)
25190792Sgshapiro
25290792Sgshapiro  # Use a slightly shorter name for logging, but with enough path to identify this jar.
25338032Speter  $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_JAR))
25490792Sgshapiro
25538032Speter  ifneq (,$$($1_CHECK_COMPRESS_JAR))
25690792Sgshapiro    $1_JAR_CREATE_OPTIONS := c0fm
25790792Sgshapiro    $1_JAR_UPDATE_OPTIONS := u0f
25890792Sgshapiro    ifeq ($(COMPRESS_JARS), true)
25990792Sgshapiro      $1_JAR_CREATE_OPTIONS := cfm
26090792Sgshapiro      $1_JAR_UPDATE_OPTIONS := uf
26190792Sgshapiro    endif
26290792Sgshapiro  else
26390792Sgshapiro    $1_JAR_CREATE_OPTIONS := cfm
26490792Sgshapiro    $1_JAR_UPDATE_OPTIONS := uf
26590792Sgshapiro  endif
26690792Sgshapiro
26790792Sgshapiro  # Include all variables of significance in the vardeps file
26890792Sgshapiro  $1_VARDEPS := $(JAR) $$($1_JAR_CREATE_OPTIONS) $$($1_MANIFEST) \
26938032Speter      $$($1_JARMAIN) $$($1_EXTRA_MANIFEST_ATTR)
27090792Sgshapiro  $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$(dir $$($1_JAR))_the.$$($1_JARNAME).vardeps)
27190792Sgshapiro
27290792Sgshapiro  # Here is the rule that creates/updates the jar file.
27390792Sgshapiro  $$($1_JAR) : $$($1_DEPENDENCIES) $$($1_MANIFEST) $$($1_VARDEPS_FILE)
27490792Sgshapiro	$(MKDIR) -p $$($1_BIN)
27590792Sgshapiro	$$($1_GREP_INCLUDE_OUTPUT)
27690792Sgshapiro	$$($1_GREP_EXCLUDE_OUTPUT)
27790792Sgshapiro        # If the vardeps file is part of the newer prereq list, it means that
27890792Sgshapiro        # either the jar file does not exist, or we need to recreate it from
27990792Sgshapiro        # from scratch anyway since a simple update will not catch all the
28090792Sgshapiro        # potential changes.
28190792Sgshapiro	$$(if $$(filter $$($1_VARDEPS_FILE) $$($1_MANIFEST), $$?), \
28290792Sgshapiro	  $$(if $$($1_MANIFEST), \
28390792Sgshapiro	    $(CP) $$($1_MANIFEST) $$($1_MANIFEST_FILE) $$(NEWLINE) \
28490792Sgshapiro	  , \
28590792Sgshapiro	    $(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE) $$(NEWLINE)) \
28690792Sgshapiro	  $$(if $$($1_JARMAIN), \
28790792Sgshapiro	    $(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE) $$(NEWLINE)) \
28890792Sgshapiro	  $$(if $$($1_EXTRA_MANIFEST_ATTR), \
28990792Sgshapiro	    $(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE) $$(NEWLINE)) \
29090792Sgshapiro	  $(ECHO) Creating $$($1_NAME) $$(NEWLINE) \
29190792Sgshapiro	  $(JAR) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) $$(NEWLINE) \
29290792Sgshapiro	  $$($1_SCAPTURE_CONTENTS) \
29390792Sgshapiro	  $$($1_SCAPTURE_METAINF) \
29490792Sgshapiro	  $$($1_SUPDATE_CONTENTS) \
29590792Sgshapiro	  $$($1_JARINDEX) && true \
29690792Sgshapiro	, \
29790792Sgshapiro	  $(ECHO) Modifying $$($1_NAME) $$(NEWLINE) \
29890792Sgshapiro	  $$($1_CAPTURE_CONTENTS) \
29990792Sgshapiro	  $$($1_CAPTURE_METAINF) \
30090792Sgshapiro	  $(RM) $$($1_DELETES_FILE) $$(NEWLINE) \
30190792Sgshapiro	  $$($1_CAPTURE_DELETES) \
30290792Sgshapiro	  $(CAT) $$($1_DELETES_FILE) > $$($1_DELETESS_FILE) $$(NEWLINE) \
30390792Sgshapiro	  if [ -s $$($1_DELETESS_FILE) ]; then \
30490792Sgshapiro	    $(ECHO) "  deleting" `$(WC) -l $$($1_DELETESS_FILE) | $(AWK) '{ print $$$$1 }'` files && \
30590792Sgshapiro	    $(ZIP) -q -d $$@ `$(CAT) $$($1_DELETESS_FILE)` ; \
30690792Sgshapiro	  fi $$(NEWLINE) \
30790792Sgshapiro	  $$($1_UPDATE_CONTENTS) true $$(NEWLINE) \
30890792Sgshapiro	  $$($1_JARINDEX) && true )
30990792Sgshapiro
31090792Sgshapiro  # Add jar to target list
31138032Speter  $1 += $$($1_JAR)
31238032Speterendef
31390792Sgshapiro
31490792Sgshapiro
31590792Sgshapirodefine add_file_to_copy
31690792Sgshapiro  # param 1 = BUILD_MYPACKAGE
31790792Sgshapiro  # parma 2 = The source file to copy.
31890792Sgshapiro  $2_TARGET:=$2
31990792Sgshapiro  # Remove the source prefix.
32090792Sgshapiro  $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET)))
32190792Sgshapiro  # To allow for automatic overrides, do not create a rule for a target file that
32290792Sgshapiro  # already has one
32390792Sgshapiro  ifneq ($$($1_COPY_$$($2_TARGET)), 1)
32490792Sgshapiro    $1_COPY_$$($2_TARGET) := 1
32590792Sgshapiro    # Now we can setup the depency that will trigger the copying.
32690792Sgshapiro    $$($1_BIN)$$($2_TARGET) : $2
32790792Sgshapiro	$(MKDIR) -p $$(@D)
32890792Sgshapiro	$(CP) $$< $$@
32938032Speter	$(CHMOD) -f ug+w $$@
33090792Sgshapiro
33190792Sgshapiro    # And do not forget this target
33290792Sgshapiro    $1_ALL_COPY_TARGETS += $$($1_BIN)$$($2_TARGET)
33338032Speter  endif
33490792Sgshapiroendef
33590792Sgshapiro
33690792Sgshapiro
33790792Sgshapiro# This macro is used only for properties files that are to be
33890792Sgshapiro# copied over to the classes directory in cleaned form:
33990792Sgshapiro# Previously this was inconsistently done in different repositories.
34090792Sgshapiro# This is the new clean standard. Though it is to be superseded by
34138032Speter# a standard annotation processor from with sjavac.
34290792Sgshapiro#
34390792Sgshapiro# An empty echo ensures that the input to sed always ends with a newline.
34490792Sgshapiro# Certain implementations (e.g. Solaris) will skip the last line without
34538032Speter# it.
34690792Sgshapiro#
34790792Sgshapiro# The sed expression does this:
34890792Sgshapiro# 1. Add a backslash before any :, = or ! that do not have a backslash already.
34990792Sgshapiro# 2. Apply the file unicode2x.sed which does a whole bunch of \u00XX to \xXX
35038032Speter#    conversions.
35190792Sgshapiro# 3. Delete all lines starting with #.
35238032Speter# 4. Delete empty lines.
35390792Sgshapiro# 5. Append lines ending with \ with the next line.
35438032Speter# 6. Remove leading and trailing white space. Note that tabs must be explicit
35538032Speter#    as sed on macosx does not understand '\t'.
35638032Speter# 7. Replace the first \= with just =.
35738032Speter# 8. Finally it's all sorted to create a stable output.
35838032Speter#
35938032Speter# It is assumed that = is the character used for separating names and values.
36038032Speterdefine add_file_to_clean
36138032Speter  # param 1 = BUILD_MYPACKAGE
36238032Speter  # parma 2 = The source file to copy and clean.
36390792Sgshapiro  $2_TARGET:=$2
36438032Speter  # Remove the source prefix.
36538032Speter  $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET)))
36638032Speter  # Now we can setup the depency that will trigger the copying.
36738032Speter  # To allow for automatic overrides, do not create a rule for a target file that
36838032Speter  # already has one
36938032Speter  ifneq ($$($1_CLEAN_$$($2_TARGET)), 1)
37038032Speter    $1_CLEAN_$$($2_TARGET) := 1
37138032Speter    $$($1_BIN)$$($1_MODULE_SUBDIR)$$($2_TARGET) : $2
37264562Sgshapiro	$(MKDIR) -p $$(@D)
37390792Sgshapiro	export LC_ALL=C ; ( $(CAT) $$< && $(ECHO) "" ) \
37438032Speter	    | $(SED) -e 's/\([^\\]\):/\1\\:/g' -e 's/\([^\\]\)=/\1\\=/g' \
37538032Speter	        -e 's/\([^\\]\)!/\1\\!/g' -e 's/^[ 	]*#.*/#/g' \
37638032Speter	    | $(SED) -f "$(SRC_ROOT)/make/common/support/unicode2x.sed" \
37790792Sgshapiro	    | $(SED) -e '/^#/d' -e '/^$$$$/d' \
37838032Speter	        -e :a -e '/\\$$$$/N; s/\\\n//; ta' \
37938032Speter	        -e 's/^[ 	]*//;s/[ 	]*$$$$//' \
38090792Sgshapiro	        -e 's/\\=/=/' \
38138032Speter	    | $(SORT) > $$@
38238032Speter	$(CHMOD) -f ug+w $$@
38338032Speter
38438032Speter    # And do not forget this target
38590792Sgshapiro    $1_ALL_COPY_CLEAN_TARGETS += $$($1_BIN)$$($2_TARGET)
38638032Speter  endif
38790792Sgshapiroendef
38838032Speter
38938032Speterdefine remove_string
39038032Speter  $2 := $$(subst $1,,$$($2))
39190792Sgshapiroendef
39238032Speter
39390792Sgshapiro# Setup make rules for compiling Java source code to class files and/or a
39438032Speter# resulting jar file.
39538032Speter#
39638032Speter# Parameter 1 is the name of the rule. This name is used as variable prefix,
39790792Sgshapiro# and the targets generated are listed in a variable by that name.
39890792Sgshapiro#
39938032Speter# Remaining parameters are named arguments. These include:
40090792Sgshapiro#   SETUP:=must point to a previously setup java compiler, for example: SETUP:=BOOTJAVAC
40138032Speter#   JVM:=path to ..bin/java
40238032Speter#   ADD_JAVAC_FLAGS:=javac flags to append to the default ones.
40338032Speter#   SRC:=one or more directories to search for sources. The order of the source roots
40464562Sgshapiro#        is significant. The first found file of a certain name has priority.
40564562Sgshapiro#   BIN:=store classes here
40638032Speter#   CLASSPATH:=a list of additional entries to set as classpath to javac
40738032Speter#   INCLUDES:=myapp.foo means will only compile java files in myapp.foo or any of its sub-packages.
40838032Speter#   EXCLUDES:=myapp.foo means will do not compile java files in myapp.foo or any of its sub-packages.
40938032Speter#   COPY:=.prp means copy all prp files to the corresponding package in BIN.
41038032Speter#   COPY_FILES:=myapp/foo/setting.txt means copy this file over to the package myapp/foo
41138032Speter#   CLEAN:=.properties means copy and clean all properties file to the corresponding package in BIN.
41238032Speter#   CLEAN_FILES:=myapp/foo/setting.txt means clean this file over to the package myapp/foo
41338032Speter#   SRCZIP:=Create a src.zip based on the found sources and copied files.
41438032Speter#   INCLUDE_FILES:="com/sun/SolarisFoobar.java" means only compile this file!
41538032Speter#   EXCLUDE_FILES:="com/sun/SolarisFoobar.java" means do not compile this particular file!
41638032Speter#       "SolarisFoobar.java" means do not compile SolarisFoobar, wherever it is found.
41738032Speter#   HEADERS:=path to directory where all generated c-headers are written.
41838032Speter#   DEPENDS:=Extra dependecy
41938032Speter#   DISABLE_SJAVAC:=Explicitly disable the use of sjavac for this compilation unit.
42038032SpeterSetupJavaCompilation = $(NamedParamsMacroTemplate)
42138032Speterdefine SetupJavaCompilationBody
42238032Speter
42338032Speter  # Verify arguments
42438032Speter  ifeq ($$($1_BIN),)
42538032Speter    $$(error Must specify BIN (in $1))
42638032Speter  endif
42738032Speter
42838032Speter  # Extract the info from the java compiler setup.
42938032Speter  $1_JVM := $$($$($1_SETUP)_JVM)
43038032Speter  $1_JAVAC := $$($$($1_SETUP)_JAVAC)
43138032Speter  $1_FLAGS := $$($$($1_SETUP)_FLAGS) $(JAVAC_FLAGS) $$($1_ADD_JAVAC_FLAGS)
43238032Speter  ifneq ($$($1_CLASSPATH), )
43338032Speter    $1_FLAGS += -cp $$(call PathList, $$($1_CLASSPATH))
43438032Speter  endif
43538032Speter  ifeq ($$($1_JAVAC),)
43664562Sgshapiro    $$(error The Java compilation $1 refers to a non-existant java compiler setup $$($1_SETUP))
43764562Sgshapiro  endif
43864562Sgshapiro  $1_SJAVAC_PORTFILE := $$($$($1_SETUP)_SJAVAC_PORTFILE)
43964562Sgshapiro  $1_SERVER_JVM := $$($$($1_SETUP)_SERVER_JVM)
44064562Sgshapiro
44164562Sgshapiro  # Handle addons and overrides.
44238032Speter  $1_SRC:=$$(call ADD_SRCS,$$($1_SRC))
44364562Sgshapiro  # Make sure the dirs exist.
44464562Sgshapiro  $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupJavaCompilation $1 contains missing directory >$$d<)))
44538032Speter  $$(call MakeDir,$$($1_BIN))
44638032Speter  # Add all source roots to the find cache since we are likely going to run find
44764562Sgshapiro  # on these more than once. The cache will only be updated if necessary.
44864562Sgshapiro  $$(eval $$(call FillCacheFind,$$($1_SRC)))
44964562Sgshapiro  # Find all files in the source trees. Preserve order of source roots for overrides to
45038032Speter  # work correctly. CacheFind does not preserve order so need to call it for each root.
45138032Speter  $1_ALL_SRCS += $$(filter-out $(OVR_SRCS),$$(foreach s,$$($1_SRC),$$(call CacheFind,$$(s))))
45238032Speter  # Extract the java files.
45338032Speter  ifneq ($$($1_EXCLUDE_FILES),)
45438032Speter    $1_EXCLUDE_FILES_PATTERN:=$$(addprefix %,$$($1_EXCLUDE_FILES))
45538032Speter  endif
45638032Speter  $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$(filter %.java,$$($1_ALL_SRCS)))
45738032Speter  ifneq ($$($1_INCLUDE_FILES),)
45838032Speter    $1_INCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES)))
45938032Speter    $1_SRCS := $$(filter $$($1_INCLUDE_FILES), $$($1_SRCS))
46038032Speter  endif
46138032Speter
46238032Speter  # Prepend the source/bin path to the filter expressions.
46390792Sgshapiro  ifneq ($$($1_INCLUDES),)
46438032Speter    $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES))))
46538032Speter    $1_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS))
46638032Speter  endif
46738032Speter  ifneq ($$($1_EXCLUDES),)
46838032Speter    $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES))))
46938032Speter    $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS))
47064562Sgshapiro  endif
47138032Speter
47238032Speter  # Remove duplicate source files by keeping the first found of each duplicate.
47338032Speter  # This allows for automatic overrides with custom or platform specific versions
47438032Speter  # source files.
47538032Speter  #
47638032Speter  # For the smart javac wrapper case, add each removed file to an extra exclude
47738032Speter  # file list to prevent sjavac from finding duplicate sources.
47838032Speter  $1_SRCS := $$(strip $$(foreach s, $$($1_SRCS), \
47938032Speter      $$(eval relative_src := $$(call remove-prefixes, $$($1_SRC), $$(s))) \
48038032Speter      $$(if $$($1_$$(relative_src)), \
48138032Speter        $$(eval $1_SJAVAC_EXCLUDE_FILES += $$(s)), \
48238032Speter        $$(eval $1_$$(relative_src) := 1) $$(s))))
48338032Speter
48438032Speter # Create the corresponding smart javac wrapper command line.
48538032Speter  $1_SJAVAC_ARGS:=$$(addprefix -x ,$$(addsuffix /*,$$($1_EXCLUDES))) \
48638032Speter      $$(addprefix -i ,$$(addsuffix /*,$$($1_INCLUDES))) \
48738032Speter      $$(addprefix -xf *,$$(strip $$($1_EXCLUDE_FILES) $$($1_SJAVAC_EXCLUDE_FILES))) \
48838032Speter      $$(addprefix -if *,$$(strip $$($1_INCLUDE_FILES))) \
48938032Speter      -src $$(call PathList, $$($1_SRC))
49038032Speter
49138032Speter  # All files below META-INF are always copied.
49238032Speter  $1_ALL_COPIES := $$(filter $$(addsuffix /META-INF%,$$($1_SRC)),$$($1_ALL_SRCS))
49338032Speter  # Find all files to be copied from source to bin.
49438032Speter  ifneq (,$$($1_COPY)$$($1_COPY_FILES))
49538032Speter    # Search for all files to be copied.
49638032Speter    $1_ALL_COPIES += $$(filter $$(addprefix %,$$($1_COPY)),$$($1_ALL_SRCS))
49738032Speter    # Copy these explicitly
49838032Speter    $1_ALL_COPIES += $$($1_COPY_FILES)
49938032Speter  endif
50038032Speter  # Copy must also respect filters.
50190792Sgshapiro  ifneq (,$$($1_INCLUDES))
50238032Speter    $1_ALL_COPIES := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_COPIES))
50338032Speter  endif
50438032Speter  ifneq (,$$($1_EXCLUDES))
50538032Speter    $1_ALL_COPIES := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_COPIES))
50638032Speter  endif
50738032Speter  ifneq (,$$($1_EXCLUDE_FILES))
50864562Sgshapiro    $1_ALL_COPIES := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_COPIES))
50938032Speter  endif
51038032Speter  ifneq (,$$($1_ALL_COPIES))
51138032Speter    # Yep, there are files to be copied!
51238032Speter    $1_ALL_COPY_TARGETS:=
51338032Speter        $$(foreach i,$$($1_ALL_COPIES),$$(eval $$(call add_file_to_copy,$1,$$i)))
51438032Speter    # Now we can depend on $$($1_ALL_COPY_TARGETS) to copy all files!
51538032Speter  endif
51638032Speter
51738032Speter  # Find all property files to be copied and cleaned from source to bin.
51838032Speter  ifneq (,$$($1_CLEAN)$$($1_CLEAN_FILES))
51938032Speter    # Search for all files to be copied.
52038032Speter    $1_ALL_CLEANS := $$(filter $$(addprefix %,$$($1_CLEAN)),$$($1_ALL_SRCS))
52138032Speter    # Clean these explicitly
52238032Speter    $1_ALL_CLEANS += $$($1_CLEAN_FILES)
52338032Speter    # Copy and clean must also respect filters.
52438032Speter    ifneq (,$$($1_INCLUDES))
52538032Speter      $1_ALL_CLEANS := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_CLEANS))
52638032Speter    endif
52738032Speter    ifneq (,$$($1_EXCLUDES))
52838032Speter      $1_ALL_CLEANS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_CLEANS))
52938032Speter    endif
53038032Speter    ifneq (,$$($1_EXCLUDE_FILES))
53138032Speter      $1_ALL_CLEANS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_CLEANS))
53238032Speter    endif
53338032Speter    ifneq (,$$($1_ALL_CLEANS))
53438032Speter      # Yep, there are files to be copied and cleaned!
53538032Speter      $1_ALL_COPY_CLEAN_TARGETS:=
53638032Speter          $$(foreach i,$$($1_ALL_CLEANS),$$(eval $$(call add_file_to_clean,$1,$$i)))
53738032Speter      # Now we can depend on $$($1_ALL_COPY_CLEAN_TARGETS) to copy all files!
53864562Sgshapiro    endif
53990792Sgshapiro  endif
54064562Sgshapiro
54164562Sgshapiro  # Create a sed expression to remove the source roots and to replace / with .
54264562Sgshapiro  # and remove .java at the end.
54364562Sgshapiro  $1_REWRITE_INTO_CLASSES:=$$(foreach i,$$($1_SRC),-e 's|$$i/||g') -e 's|/|.|g' -e 's|.java$$$$||g'
54464562Sgshapiro
54564562Sgshapiro  ifeq ($$($1_DISABLE_SJAVAC)x$$(ENABLE_SJAVAC),xyes)
54664562Sgshapiro    ifneq (,$$($1_HEADERS))
54764562Sgshapiro      $1_HEADERS_ARG := -h $$($1_HEADERS)
54864562Sgshapiro    endif
54964562Sgshapiro
55064562Sgshapiro    # Using sjavac to compile.
55164562Sgshapiro    $1_COMPILE_TARGETS := $$($1_BIN)/_the.$1_batch
55264562Sgshapiro
55364562Sgshapiro    # Create SJAVAC variable form JAVAC variable. Expects $1_JAVAC to be
55464562Sgshapiro    # "bootclasspathprepend -cp .../javac.jar com.sun.tools.javac.Main"
55564562Sgshapiro    # and javac is simply replaced with sjavac.
55664562Sgshapiro    $1_SJAVAC:=$$(subst com.sun.tools.javac.Main,com.sun.tools.sjavac.Main,$$($1_JAVAC))
55738032Speter
55864562Sgshapiro    # Set the $1_REMOTE to spawn a background javac server.
55964562Sgshapiro    $1_REMOTE:=--server:portfile=$$($1_SJAVAC_PORTFILE),id=$1,sjavac=$$(subst \
56064562Sgshapiro        $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_SJAVAC))))
56164562Sgshapiro
56264562Sgshapiro    $1_VARDEPS := $$($1_JVM) $$($1_SJAVAC) $$($1_SJAVAC_ARGS) $$($1_FLAGS) \
56364562Sgshapiro        $$($1_HEADERS_ARG) $$($1_BIN)
56464562Sgshapiro    $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$($1_BIN)/_the.$1.vardeps)
56564562Sgshapiro
56664562Sgshapiro    $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS) $$($1_VARDEPS_FILE)
56764562Sgshapiro	$(MKDIR) -p $$(@D) $$(dir $$($1_SJAVAC_PORTFILE))
56864562Sgshapiro	$$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.$1_batch.tmp)
56964562Sgshapiro	$(ECHO) Compiling $1
57064562Sgshapiro	$(call LogFailures, $$($1_BIN)/_the.$1_batch.log, $1, \
57164562Sgshapiro	    $$($1_JVM) $$($1_SJAVAC) \
57264562Sgshapiro	        $$($1_REMOTE) \
57364562Sgshapiro	        -j 1 \
57464562Sgshapiro	        --permit-unidentified-artifacts \
57538032Speter	        --permit-sources-without-package \
57664562Sgshapiro	        --compare-found-sources $$($1_BIN)/_the.$1_batch.tmp \
57764562Sgshapiro	        --log=$(LOG_LEVEL) \
57864562Sgshapiro	        $$($1_SJAVAC_ARGS) \
57938032Speter	        $$($1_FLAGS) \
58038032Speter	        $$($1_HEADERS_ARG) \
58138032Speter	        -d $$($1_BIN)) && \
58238032Speter	$(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch
58338032Speter        # Create a pubapi file that only changes when the pubapi changes. Dependent
58438032Speter        # compilations can use this file to only get recompiled when pubapi has changed.
58538032Speter        # Grep returns 1 if no matching lines are found. Do not fail for this.
58690792Sgshapiro	$(GREP) -e "^I" $$($1_BIN)/javac_state > $$($1_BIN)/_the.$1_pubapi.tmp \
58738032Speter	    || test "$$$$?" = "1"
58838032Speter	if [ ! -f $$($1_BIN)/_the.$1_pubapi ] \
58938032Speter	    || [ "`$(DIFF) $$($1_BIN)/_the.$1_pubapi $$($1_BIN)/_the.$1_pubapi.tmp`" != "" ]; then \
59038032Speter	  $(MV) $$($1_BIN)/_the.$1_pubapi.tmp $$($1_BIN)/_the.$1_pubapi; \
59138032Speter	fi
59238032Speter
59338032Speter  else
59438032Speter    # Using plain javac to batch compile everything.
59538032Speter    $1_COMPILE_TARGETS := $$($1_BIN)/_the.$1_batch
59638032Speter
59738032Speter    # When building in batch, put headers in a temp dir to filter out those that actually
59838032Speter    # changed before copying them to the real header dir.
59938032Speter    ifneq (,$$($1_HEADERS))
60064562Sgshapiro      $1_HEADERS_ARG := -h $$($1_HEADERS).$1.tmp
60190792Sgshapiro
60238032Speter      $$($1_HEADERS)/_the.$1_headers: $$($1_BIN)/_the.$1_batch
60338032Speter		$(MKDIR) -p $$(@D)
60438032Speter		if [ -d "$$($1_HEADERS).$1.tmp" ]; then \
60538032Speter		  for f in `ls $$($1_HEADERS).$1.tmp`; do \
60638032Speter		    if [ ! -f "$$($1_HEADERS)/$$$$f" ] \
60738032Speter		        || [ "`$(DIFF) $$($1_HEADERS)/$$$$f $$($1_HEADERS).$1.tmp/$$$$f`" != "" ]; then \
60838032Speter		    $(CP) -f $$($1_HEADERS).$1.tmp/$$$$f $$($1_HEADERS)/$$$$f; \
60990792Sgshapiro		  fi; \
61038032Speter		  done; \
61138032Speter		fi
61238032Speter		$(RM) -r $$($1_HEADERS).$1.tmp
61338032Speter		$(TOUCH) $$@
61438032Speter
61538032Speter      $1_HEADER_TARGETS := $$($1_HEADERS)/_the.$1_headers
61638032Speter    endif
61764562Sgshapiro
61864562Sgshapiro    $1_VARDEPS := $$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) $$($1_BIN) $$($1_HEADERS_ARG)
61990792Sgshapiro    $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$($1_BIN)/_the.$1.vardeps)
62038032Speter
62138032Speter    # When not using sjavac, pass along all sources to javac using an @file.
62238032Speter    $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS) $$($1_VARDEPS_FILE)
62338032Speter	$(MKDIR) -p $$(@D)
62464562Sgshapiro	$(RM) $$($1_BIN)/_the.$1_batch $$($1_BIN)/_the.$1_batch.tmp
62564562Sgshapiro	$$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.$1_batch.tmp)
62638032Speter	$(ECHO) Compiling `$(WC) $$($1_BIN)/_the.$1_batch.tmp | $(TR) -s ' ' | $(CUT) -f 2 -d ' '` files for $1
62738032Speter	$(call LogFailures, $$($1_BIN)/_the.$1_batch.log, $1, \
62838032Speter	    $$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) \
62938032Speter	        -implicit:none \
63038032Speter	        -d $$($1_BIN) $$($1_HEADERS_ARG) @$$($1_BIN)/_the.$1_batch.tmp) && \
63138032Speter	$(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch
63238032Speter  endif
63338032Speter
63438032Speter  # Add all targets to main variable
63590792Sgshapiro  $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_COMPILE_TARGETS) \
63690792Sgshapiro      $$($1_HEADER_TARGETS)
63738032Speter
63838032Speter  # Check if a jar file was specified, then setup the rules for the jar.
63938032Speter  ifneq (,$$($1_JAR))
64038032Speter    # If no suffixes was explicitly set for this jar file.
64138032Speter    # Use class and the cleaned/copied properties file suffixes as the default
64238032Speter    # for the types of files to be put into the jar.
64338032Speter    ifeq (,$$($1_SUFFIXES))
64438032Speter      $1_SUFFIXES:=.class $$($1_CLEAN) $$($1_COPY)
64538032Speter    endif
64690792Sgshapiro
64738032Speter    $$(eval $$(call SetupArchive,ARCHIVE_$1, \
64890792Sgshapiro        DEPENDENCIES:=$$($1), \
64938032Speter        SRCS:=$$($1_BIN), \
65038032Speter        SUFFIXES:=$$($1_SUFFIXES), \
65138032Speter        EXCLUDE:=$$($1_EXCLUDES), \
65238032Speter        INCLUDES:=$$($1_INCLUDES), \
65338032Speter        EXTRA_FILES:=$$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS), \
65438032Speter        JAR:=$$($1_JAR), \
65538032Speter        JARMAIN:=$$($1_JARMAIN), \
65638032Speter        MANIFEST:=$$($1_MANIFEST), \
65738032Speter        EXTRA_MANIFEST_ATTR:=$$($1_EXTRA_MANIFEST_ATTR), \
65838032Speter        JARINDEX:=$$($1_JARINDEX), \
65938032Speter        HEADERS:=$$($1_HEADERS), \
66038032Speter        SETUP:=$$($1_SETUP)))
66138032Speter
66238032Speter    # Add jar to target list
66364562Sgshapiro    $1 += $$($1_JAR)
66490792Sgshapiro  endif
66538032Speter
66638032Speter  # Check if a srczip was specified, then setup the rules for the srczip.
66738032Speter  ifneq (,$$($1_SRCZIP))
66838032Speter    $$(eval $$(call SetupZipArchive,ARCHIVE_$1, \
66938032Speter        SRC:=$$($1_SRC), \
67064562Sgshapiro        ZIP:=$$($1_SRCZIP), \
67138032Speter        INCLUDES:=$$($1_INCLUDES), \
67238032Speter        EXCLUDES:=$$($1_EXCLUDES), \
67338032Speter        EXCLUDE_FILES:=$$($1_EXCLUDE_FILES)))
67438032Speter
67538032Speter    # Add zip to target list
67638032Speter    $1 += $$($1_SRCZIP)
67738032Speter  endif
67838032Speterendef
67938032Speter
68038032Speter# Use this macro to find the correct target to depend on when the original
68138032Speter# SetupJavaCompilation is declared in a different makefile, to avoid having
68238032Speter# to declare and evaluate it again.
68338032Speter# param 1 is for example BUILD_MYPACKAGE
68490792Sgshapiro# param 2 is the output directory (BIN)
68538032Speterdefine SetupJavaCompilationCompileTarget
68638032Speter  $(if $(findstring yes, $(ENABLE_SJAVAC)), $(strip $2)/_the.$(strip $1)_pubapi, \
68738032Speter      $(strip $2)/_the.$(strip $1)_batch)
68838032Speterendef
68990792Sgshapiro
69038032Speterendif # _JAVA_COMPILATION_GMK
69138032Speter