make/common/JavaCompilation.gmk
changeset 25854 98ce0879ab4c
parent 24080 8bfff14321a9
child 26129 5ca768410aba
equal deleted inserted replaced
25853:63fbc565bba5 25854:98ce0879ab4c
    33 
    33 
    34 # When you read this source. Remember that $(sort ...) has the side effect
    34 # When you read this source. Remember that $(sort ...) has the side effect
    35 # of removing duplicates. It is actually this side effect that is
    35 # of removing duplicates. It is actually this side effect that is
    36 # desired whenever sort is used below!
    36 # desired whenever sort is used below!
    37 
    37 
       
    38 ifndef _JAVA_COMPILATION_GMK
       
    39 _JAVA_COMPILATION_GMK := 1
       
    40 
    38 ifeq (,$(_MAKEBASE_GMK))
    41 ifeq (,$(_MAKEBASE_GMK))
    39   $(error You must include MakeBase.gmk prior to including JavaCompilation.gmk)
    42   $(error You must include MakeBase.gmk prior to including JavaCompilation.gmk)
    40 endif
    43 endif
    41 
    44 
    42 FALSE_FIND_PATTERN:=-name FILE_NAME_THAT_DOESNT_EXIST
    45 FALSE_FIND_PATTERN:=-name FILE_NAME_THAT_DOESNT_EXIST
   103   # Convert suffixes to a find expression
   106   # Convert suffixes to a find expression
   104   $1_FIND_PATTERNS:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_SUFFIXES))
   107   $1_FIND_PATTERNS:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_SUFFIXES))
   105   # On windows, a lot of includes/excludes risk making the command line too long, so
   108   # On windows, a lot of includes/excludes risk making the command line too long, so
   106   # writing the grep patterns to files.
   109   # writing the grep patterns to files.
   107   ifneq (,$$($1_INCLUDES))
   110   ifneq (,$$($1_INCLUDES))
   108     $1_GREP_INCLUDE_PATTERNS:=$$(foreach src,$$($1_SRCS), \
   111     $1_GREP_INCLUDE_PATTERNS:=$$(call EscapeDollar, \
   109         $$(addprefix $$(src)/,$$($1_INCLUDES)))
   112         $$(foreach src,$$($1_SRCS), $$(addprefix $$(src)/,$$($1_INCLUDES))))
   110     # If there are a lot of include patterns, output to file to shorten command lines
   113     # If there are a lot of include patterns, output to file to shorten command lines
   111     ifeq ($$(word 20,$$($1_GREP_INCLUDE_PATTERNS)),)
   114     ifeq ($$(word 20,$$($1_GREP_INCLUDE_PATTERNS)),)
   112       $1_GREP_INCLUDES:=| $(GREP) $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_INCLUDE_PATTERNS))
   115       $1_GREP_INCLUDES:=| $(GREP) $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_INCLUDE_PATTERNS))
   113     else
   116     else
   114       $1_GREP_INCLUDE_OUTPUT:=$(RM) $$($1_BIN)/_the.$$($1_JARNAME)_include $$(NEWLINE) \
   117       $1_GREP_INCLUDE_OUTPUT:=$(RM) $$($1_BIN)/_the.$$($1_JARNAME)_include $$(NEWLINE) \
   116           >> $$($1_BIN)/_the.$$($1_JARNAME)_include)
   119           >> $$($1_BIN)/_the.$$($1_JARNAME)_include)
   117       $1_GREP_INCLUDES:=| $(GREP) -f $$($1_BIN)/_the.$$($1_JARNAME)_include
   120       $1_GREP_INCLUDES:=| $(GREP) -f $$($1_BIN)/_the.$$($1_JARNAME)_include
   118     endif
   121     endif
   119   endif
   122   endif
   120   ifneq (,$$($1_EXCLUDES)$$($1_EXCLUDE_FILES))
   123   ifneq (,$$($1_EXCLUDES)$$($1_EXCLUDE_FILES))
   121     $1_GREP_EXCLUDE_PATTERNS:=$$(foreach src,$$($1_SRCS),$$(addprefix $$(src)/, \
   124     $1_GREP_EXCLUDE_PATTERNS:=$$(call EscapeDollar, \
   122         $$($1_EXCLUDES) $$($1_EXCLUDE_FILES)))
   125         $$(foreach src,$$($1_SRCS),$$(addprefix $$(src)/, \
       
   126         $$($1_EXCLUDES) $$($1_EXCLUDE_FILES))))
   123     # If there are a lot of include patterns, output to file to shorten command lines
   127     # If there are a lot of include patterns, output to file to shorten command lines
   124     ifeq ($$(word 20,$$($1_GREP_EXCLUDE_PATTERNS)),)
   128     ifeq ($$(word 20,$$($1_GREP_EXCLUDE_PATTERNS)),)
   125       $1_GREP_EXCLUDES:=| $(GREP) -v $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_EXCLUDE_PATTERNS))
   129       $1_GREP_EXCLUDES:=| $(GREP) -v $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_EXCLUDE_PATTERNS))
   126     else
   130     else
   127       $1_GREP_EXCLUDE_OUTPUT=$(RM) $$($1_BIN)/_the.$$($1_JARNAME)_exclude $$(NEWLINE) \
   131       $1_GREP_EXCLUDE_OUTPUT=$(RM) $$($1_BIN)/_the.$$($1_JARNAME)_exclude $$(NEWLINE) \
   152       $1_DEPS:=$$(filter $$(addsuffix %,$$($1_GREP_INCLUDE_PATTERNS)),$$($1_DEPS))
   156       $1_DEPS:=$$(filter $$(addsuffix %,$$($1_GREP_INCLUDE_PATTERNS)),$$($1_DEPS))
   153     endif
   157     endif
   154     ifneq (,$$($1_GREP_EXCLUDE_PATTERNS))
   158     ifneq (,$$($1_GREP_EXCLUDE_PATTERNS))
   155       $1_DEPS:=$$(filter-out $$(addsuffix %,$$($1_GREP_EXCLUDE_PATTERNS)),$$($1_DEPS))
   159       $1_DEPS:=$$(filter-out $$(addsuffix %,$$($1_GREP_EXCLUDE_PATTERNS)),$$($1_DEPS))
   156     endif
   160     endif
   157     # The subst of \ is needed because $ has to be escaped with \ in EXTRA_FILES for the command
   161     # Look for EXTRA_FILES in all SRCS dirs and as absolute paths.
   158     # lines, but not here for use in make dependencies.
   162     $1_DEPS+=$$(wildcard $$(foreach src, $$($1_SRCS), \
   159     $1_DEPS+=$$(subst \,,$$(foreach src,$$($1_SRCS),$$(addprefix $$(src)/,$$($1_EXTRA_FILES))))
   163         $$(addprefix $$(src)/, $$($1_EXTRA_FILES))) $$($1_EXTRA_FILES))
   160     ifeq (,$$($1_SKIP_METAINF))
   164     ifeq (,$$($1_SKIP_METAINF))
   161       $1_DEPS+=$$(call CacheFind,$$(wildcard $$(addsuffix /META-INF,$$($1_SRCS))))
   165       $1_DEPS+=$$(call CacheFind,$$(wildcard $$(addsuffix /META-INF,$$($1_SRCS))))
   162     endif
   166     endif
   163   endif
   167   endif
   164   # The dependency list should never be empty
   168   # The dependency list should never be empty
   166     $$(warning No dependencies found for $1)
   170     $$(warning No dependencies found for $1)
   167   endif
   171   endif
   168 
   172 
   169   # Utility macros, to make the shell script receipt somewhat easier to decipher.
   173   # Utility macros, to make the shell script receipt somewhat easier to decipher.
   170 
   174 
       
   175   # Capture extra files is the same for both CAPTURE_CONTENTS and SCAPTURE_CONTENTS so
       
   176   # only define it once to avoid duplication.
       
   177   # The list of extra files might be long, so need to use ListPathsSafely to print
       
   178   # them out to a separte file. Then process the contents of that file to rewrite
       
   179   # into -C <dir> <file> lines.
       
   180   # The EXTRA_FILES_RESOLVED varible must be set in the macro so that it's evaluated
       
   181   # in the recipe when the files are guaranteed to exist.
       
   182   $1_CAPTURE_EXTRA_FILES=\
       
   183       $(RM) $$($1_BIN)/_the.$$($1_JARNAME)_contents.extra $$(NEWLINE) \
       
   184       $$(eval $1_EXTRA_FILES_RESOLVED:=$$(call DoubleDollar, $$(call DoubleDollar, \
       
   185           $$(wildcard $$(foreach src, $$($1_SRCS), \
       
   186           $$(addprefix $$(src)/, $$($1_EXTRA_FILES))) $$($1_EXTRA_FILES))))) \
       
   187       $$(if $$($1_EXTRA_FILES_RESOLVED), \
       
   188         $$(call ListPathsSafely,$1_EXTRA_FILES_RESOLVED,\n, \
       
   189             >> $$($1_BIN)/_the.$$($1_JARNAME)_contents.extra) $$(NEWLINE) \
       
   190         $(SED) $$(foreach src,$$($1_SRCS), -e 's|$$(src)/|-C $$(src) |g') \
       
   191             $$($1_BIN)/_the.$$($1_JARNAME)_contents.extra \
       
   192             >> $$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE))
       
   193 
   171   # The capture contents macro finds all files (matching the patterns, typically
   194   # The capture contents macro finds all files (matching the patterns, typically
   172   # .class and .prp) that are newer than the jar-file, ie the new content to be put into the jar.
   195   # .class and .prp) that are newer than the jar-file, ie the new content to be put into the jar.
   173   # NOTICE: please leave the parentheses space separated otherwise the AIX build will break!
   196   # NOTICE: please leave the parentheses space separated otherwise the AIX build will break!
   174   $1_CAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS), \
   197   $1_CAPTURE_CONTENTS=\
   175       ( ( $(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) -a -newer $$@ $$($1_GREP_INCLUDES) \
   198       $(RM) $$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE) \
   176           $$($1_GREP_EXCLUDES) | $(SED) 's|$$(src)/||g' && \
   199       $$(foreach src,$$($1_SRCS), \
   177       $(ECHO) $$(subst $$(src)/,,$$($1_EXTRA_FILES) ) ) > \
   200         $(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) -a -newer $$@ $$($1_GREP_INCLUDES) \
   178       $$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE) )
   201           $$($1_GREP_EXCLUDES) | $(SED) 's|$$(src)/|-C $$(src) |g' \
       
   202         >> $$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE)) \
       
   203       $$($1_CAPTURE_EXTRA_FILES)
       
   204 
   179   # The capture metainf macro finds all files below the META-INF directory that are newer than the jar-file.
   205   # The capture metainf macro finds all files below the META-INF directory that are newer than the jar-file.
   180   ifeq (,$$($1_SKIP_METAINF))
   206   ifeq (,$$($1_SKIP_METAINF))
   181     $1_CAPTURE_METAINF =$$(foreach src,$$($1_SRCS),($(FIND) $$(src)/META-INF -type f -a -newer $$@ 2> /dev/null | $(SED) 's|$$(src)/||g' >> $$(src)/_the.$$($1_JARNAME)_contents ) $$(NEWLINE))
   207     $1_CAPTURE_METAINF =$$(foreach src,$$($1_SRCS), \
       
   208         ( $(FIND) $$(src)/META-INF -type f -a -newer $$@ 2> /dev/null | $(SED) 's|$$(src)/|-C $$(src) |g' >> \
       
   209         $$($1_BIN)/_the.$$($1_JARNAME)_contents ) $$(NEWLINE) )
   182   endif
   210   endif
   183   # The capture deletes macro finds all deleted files and concatenates them. The resulting file
   211   # The capture deletes macro finds all deleted files and concatenates them. The resulting file
   184   # tells us what to remove from the jar-file.
   212   # tells us what to remove from the jar-file.
   185   $1_CAPTURE_DELETES=$$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.deleted -newer $$@ -exec $(SED) 's|$$(src)||g' \{\} >> $$($1_DELETES_FILE) \;) $$(NEWLINE))
   213   $1_CAPTURE_DELETES=$$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.deleted -newer $$@ \
       
   214       -exec $(SED) 's|$$(src)||g' \{\} >> $$($1_DELETES_FILE) \;) $$(NEWLINE))
   186   # The update contents macro updates the jar file with the previously capture contents.
   215   # The update contents macro updates the jar file with the previously capture contents.
   187   # Use 'wc -w' to see if the contents file is empty.
   216   # Use 'wc -w' to see if the contents file is empty.
   188   $1_UPDATE_CONTENTS=$$(foreach src,$$($1_SRCS), \
   217   $1_UPDATE_CONTENTS=\
   189       (cd $$(src) && \
   218       if [ "`$(WC) -l $$($1_BIN)/_the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'`" -gt "0" ]; then \
   190        if [ "`$(WC) -w _the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'`" -gt "0" ]; then \
   219         $(ECHO) "  updating" `$(WC) -l $$($1_BIN)/_the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'` files && \
   191          $(ECHO) "  updating" `$(WC) -l _the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'` files && \
   220         $(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @$$($1_BIN)/_the.$$($1_JARNAME)_contents; \
   192          $(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @_the.$$($1_JARNAME)_contents; \
   221       fi $$(NEWLINE)
   193        fi) $$(NEWLINE))
       
   194   # The s-variants of the above macros are used when the jar is created from scratch.
   222   # The s-variants of the above macros are used when the jar is created from scratch.
   195   # NOTICE: please leave the parentheses space separated otherwise the AIX build will break!
   223   # NOTICE: please leave the parentheses space separated otherwise the AIX build will break!
   196   $1_SCAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS), \
   224   $1_SCAPTURE_CONTENTS=\
   197       ( ( $(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) $$($1_GREP_INCLUDES) \
   225       $(RM) $$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE) \
   198           $$($1_GREP_EXCLUDES) | $(SED) 's|$$(src)/||g' && \
   226       $$(foreach src,$$($1_SRCS), \
   199       $$(subst $$(src)/,,$(ECHO) $$($1_EXTRA_FILES) ) ) > \
   227         $(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) $$($1_GREP_INCLUDES) \
   200       $$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE) )
   228             $$($1_GREP_EXCLUDES) | $(SED) 's|$$(src)/|-C $$(src) |g' \
       
   229             >> $$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE)) \
       
   230       $$($1_CAPTURE_EXTRA_FILES)
   201 
   231 
   202   ifeq (,$$($1_SKIP_METAINF))
   232   ifeq (,$$($1_SKIP_METAINF))
   203     $1_SCAPTURE_METAINF=$$(foreach src,$$($1_SRCS), \
   233     $1_SCAPTURE_METAINF=$$(foreach src,$$($1_SRCS), \
   204         ($(FIND) $$(src)/META-INF -type f 2> /dev/null | $(SED) 's|$$(src)/||g' >> \
   234         ( $(FIND) $$(src)/META-INF -type f 2> /dev/null | $(SED) 's|$$(src)/|-C $$(src) |g' >> \
   205         $$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE))
   235         $$($1_BIN)/_the.$$($1_JARNAME)_contents) $$(NEWLINE) )
   206   endif
   236   endif
   207   $1_SUPDATE_CONTENTS=$$(foreach src,$$($1_SRCS), \
   237   $1_SUPDATE_CONTENTS=$(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @$$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE)
   208       (cd $$(src) && $(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @$$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE))
       
   209 
   238 
   210   # Use a slightly shorter name for logging, but with enough path to identify this jar.
   239   # Use a slightly shorter name for logging, but with enough path to identify this jar.
   211   $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_JAR))
   240   $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_JAR))
   212 
   241 
   213   ifneq (,$$($1_CHECK_COMPRESS_JAR))
   242   ifneq (,$$($1_CHECK_COMPRESS_JAR))
   325   # param 1 = BUILD_MYPACKAGE
   354   # param 1 = BUILD_MYPACKAGE
   326   # parma 2 = The source file to copy.
   355   # parma 2 = The source file to copy.
   327   $2_TARGET:=$2
   356   $2_TARGET:=$2
   328   # Remove the source prefix.
   357   # Remove the source prefix.
   329   $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET)))
   358   $$(foreach i,$$($1_SRC),$$(eval $$(call remove_string,$$i,$2_TARGET)))
   330   # Now we can setup the depency that will trigger the copying.
   359   # To allow for automatic overrides, do not create a rule for a target file that
   331   $$($1_BIN)$$($2_TARGET) : $2
   360   # already has one
       
   361   ifeq ($$(findstring $$($2_TARGET), $$($1_COPY_LIST)), )
       
   362     $1_COPY_LIST += $$($2_TARGET)
       
   363     # Now we can setup the depency that will trigger the copying.
       
   364     $$($1_BIN)$$($2_TARGET) : $2
   332 	$(MKDIR) -p $$(@D)
   365 	$(MKDIR) -p $$(@D)
   333 	$(CP) $$< $$@
   366 	$(CP) $$< $$@
   334 	$(CHMOD) -f ug+w $$@
   367 	$(CHMOD) -f ug+w $$@
   335 
   368 
   336   # And do not forget this target
   369     # And do not forget this target
   337   $1_ALL_COPY_TARGETS += $$($1_BIN)$$($2_TARGET)
   370     $1_ALL_COPY_TARGETS += $$($1_BIN)$$($2_TARGET)
       
   371   endif
   338 endef
   372 endef
   339 
   373 
   340 
   374 
   341 # This macro is used only for properties files that are to be
   375 # This macro is used only for properties files that are to be
   342 # copied over to the classes directory in cleaned form:
   376 # copied over to the classes directory in cleaned form:
   429   $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupJavaCompilation $1 contains missing directory $$d)))
   463   $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupJavaCompilation $1 contains missing directory $$d)))
   430   $$(eval $$(call MakeDir,$$($1_BIN)))
   464   $$(eval $$(call MakeDir,$$($1_BIN)))
   431   # Add all source roots to the find cache since we are likely going to run find 
   465   # Add all source roots to the find cache since we are likely going to run find 
   432   # on these more than once. The cache will only be updated if necessary.
   466   # on these more than once. The cache will only be updated if necessary.
   433   $$(eval $$(call FillCacheFind,$$($1_SRC)))
   467   $$(eval $$(call FillCacheFind,$$($1_SRC)))
   434   # Find all files in the source trees.
   468   # Find all files in the source trees. Preserve order of source roots for overrides to
   435   $1_ALL_SRCS += $$(filter-out $(OVR_SRCS),$$(call CacheFind,$$($1_SRC)))
   469   # work correctly. CacheFind does not preserve order so need to call it for each root.
       
   470   $1_ALL_SRCS += $$(filter-out $(OVR_SRCS),$$(foreach s,$$($1_SRC),$$(call CacheFind,$$(s))))
   436   # Extract the java files.
   471   # Extract the java files.
   437   ifneq ($$($1_EXCLUDE_FILES),)
   472   ifneq ($$($1_EXCLUDE_FILES),)
   438     $1_EXCLUDE_FILES_PATTERN:=$$(addprefix %,$$($1_EXCLUDE_FILES))
   473     $1_EXCLUDE_FILES_PATTERN:=$$(addprefix %,$$($1_EXCLUDE_FILES))
   439   endif
   474   endif
   440   $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$(filter %.java,$$($1_ALL_SRCS)))
   475   $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$(filter %.java,$$($1_ALL_SRCS)))
   460   ifneq ($$($1_EXCLUDES),)
   495   ifneq ($$($1_EXCLUDES),)
   461     $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES))))
   496     $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES))))
   462     $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS))
   497     $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS))
   463   endif
   498   endif
   464 
   499 
       
   500   # All files below META-INF are always copied.
       
   501   $1_ALL_COPIES := $$(filter $$(addsuffix /META-INF%,$$($1_SRC)),$$($1_ALL_SRCS))
   465   # Find all files to be copied from source to bin.
   502   # Find all files to be copied from source to bin.
   466   ifneq (,$$($1_COPY)$$($1_COPY_FILES))
   503   ifneq (,$$($1_COPY)$$($1_COPY_FILES))
   467     # Search for all files to be copied.
   504     # Search for all files to be copied.
   468     $1_ALL_COPIES := $$(filter $$(addprefix %,$$($1_COPY)),$$($1_ALL_SRCS))
   505     $1_ALL_COPIES += $$(filter $$(addprefix %,$$($1_COPY)),$$($1_ALL_SRCS))
   469     # Copy these explicitly
   506     # Copy these explicitly
   470     $1_ALL_COPIES += $$($1_COPY_FILES)
   507     $1_ALL_COPIES += $$($1_COPY_FILES)
   471     # Copy must also respect filters.
   508     # Copy must also respect filters.
   472     ifneq (,$$($1_INCLUDES))
   509     ifneq (,$$($1_INCLUDES))
   473       $1_ALL_COPIES := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_COPIES))
   510       $1_ALL_COPIES := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_COPIES))
   477     endif
   514     endif
   478     ifneq (,$$($1_EXCLUDE_FILES))
   515     ifneq (,$$($1_EXCLUDE_FILES))
   479       $1_ALL_COPIES := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_COPIES))
   516       $1_ALL_COPIES := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_COPIES))
   480     endif
   517     endif
   481   endif
   518   endif
   482   # All files below META-INF are always copied.
   519     ifneq (,$$($1_ALL_COPIES))
   483   $1_ALL_COPIES += $$(filter $$(addsuffix /META-INF%,$$($1_SRC)),$$($1_ALL_SRCS))
   520       # Yep, there are files to be copied!
   484   ifneq (,$$($1_ALL_COPIES))
   521       $1_ALL_COPY_TARGETS:=
   485     # Yep, there are files to be copied!
   522           $$(foreach i,$$($1_ALL_COPIES),$$(eval $$(call add_file_to_copy,$1,$$i)))
   486     $1_ALL_COPY_TARGETS:=
   523       # Now we can depend on $$($1_ALL_COPY_TARGETS) to copy all files!
   487         $$(foreach i,$$($1_ALL_COPIES),$$(eval $$(call add_file_to_copy,$1,$$i)))
   524     endif
   488     # Now we can depend on $$($1_ALL_COPY_TARGETS) to copy all files!
       
   489   endif
       
   490 
   525 
   491   # Find all property files to be copied and cleaned from source to bin.
   526   # Find all property files to be copied and cleaned from source to bin.
   492   ifneq (,$$($1_CLEAN)$$($1_CLEAN_FILES))
   527   ifneq (,$$($1_CLEAN)$$($1_CLEAN_FILES))
   493     # Search for all files to be copied.
   528     # Search for all files to be copied.
   494     $1_ALL_CLEANS := $$(filter $$(addprefix %,$$($1_CLEAN)),$$($1_ALL_SRCS))
   529     $1_ALL_CLEANS := $$(filter $$(addprefix %,$$($1_CLEAN)),$$($1_ALL_SRCS))
   527     ifneq (,$$($1_HEADERS))
   562     ifneq (,$$($1_HEADERS))
   528       $1_HEADERS_ARG := -h $$($1_HEADERS)
   563       $1_HEADERS_ARG := -h $$($1_HEADERS)
   529     endif
   564     endif
   530 
   565 
   531     # Using sjavac to compile.
   566     # Using sjavac to compile.
   532     $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_BIN)/javac_state
   567     $1_COMPILE_TARGETS := $$($1_BIN)/javac_state
   533 
   568 
   534     # Create SJAVAC variable form JAVAC variable. Expects $1_JAVAC to be
   569     # Create SJAVAC variable form JAVAC variable. Expects $1_JAVAC to be
   535     # "bootclasspathprepend -cp .../javac.jar com.sun.tools.javac.Main"
   570     # "bootclasspathprepend -cp .../javac.jar com.sun.tools.javac.Main"
   536     # and javac is simply replaced with sjavac.
   571     # and javac is simply replaced with sjavac.
   537     $1_SJAVAC:=$$(subst com.sun.tools.javac.Main,com.sun.tools.sjavac.Main,$$($1_JAVAC))
   572     $1_SJAVAC:=$$(subst com.sun.tools.javac.Main,com.sun.tools.sjavac.Main,$$($1_JAVAC))
   543 	$(MKDIR) -p $$(@D)
   578 	$(MKDIR) -p $$(@D)
   544 	$$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.$1_batch.tmp)
   579 	$$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.$1_batch.tmp)
   545 	$(ECHO) Compiling $1
   580 	$(ECHO) Compiling $1
   546 	($$($1_JVM) $$($1_SJAVAC) \
   581 	($$($1_JVM) $$($1_SJAVAC) \
   547 	    $$($1_REMOTE) \
   582 	    $$($1_REMOTE) \
   548 	    -j $(JOBS) \
   583 	    -j 1 \
   549 	    --permit-unidentified-artifacts \
   584 	    --permit-unidentified-artifacts \
   550 	    --permit-sources-without-package \
   585 	    --permit-sources-without-package \
   551 	    --compare-found-sources $$($1_BIN)/_the.$1_batch.tmp \
   586 	    --compare-found-sources $$($1_BIN)/_the.$1_batch.tmp \
   552 	    --log=$(LOG_LEVEL) \
   587 	    --log=$(LOG_LEVEL) \
   553 	    $$($1_SJAVAC_ARGS) \
   588 	    $$($1_SJAVAC_ARGS) \
   554 	    $$($1_FLAGS) \
   589 	    $$($1_FLAGS) \
   555 	    $$($1_HEADERS_ARG) \
   590 	    $$($1_HEADERS_ARG) \
   556 	    -d $$($1_BIN) && \
   591 	    -d $$($1_BIN) && \
   557 	$(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch)
   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) $$@
   558   else
   595   else
   559     # Using plain javac to batch compile everything.
   596     # Using plain javac to batch compile everything.
   560     $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_BIN)/_the.$1_batch
   597     $1_COMPILE_TARGETS := $$($1_BIN)/_the.$1_batch
   561 
   598 
   562     # When building in batch, put headers in a temp dir to filter out those that actually
   599     # When building in batch, put headers in a temp dir to filter out those that actually
   563     # changed before copying them to the real header dir.
   600     # changed before copying them to the real header dir.
   564     ifneq (,$$($1_HEADERS))
   601     ifneq (,$$($1_HEADERS))
   565       $1_HEADERS_ARG := -h $$($1_HEADERS).$1.tmp
   602       $1_HEADERS_ARG := -h $$($1_HEADERS).$1.tmp
   566 
   603 
   567       $$($1_HEADERS)/_the.$1_headers: $$($1_BIN)/_the.$1_batch
   604       $$($1_HEADERS)/_the.$1_headers: $$($1_BIN)/_the.$1_batch
   568 		$(MKDIR) -p $$(@D)
   605 		$(MKDIR) -p $$(@D)
   569 		for f in `ls $$($1_HEADERS).$1.tmp`; do \
   606 		if [ -d "$$($1_HEADERS).$1.tmp" ]; then \
   570 		  if [ ! -f "$$($1_HEADERS)/$$$$f" ] || [ "`$(DIFF) $$($1_HEADERS)/$$$$f $$($1_HEADERS).$1.tmp/$$$$f`" != "" ]; 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 \
   571 		    $(CP) -f $$($1_HEADERS).$1.tmp/$$$$f $$($1_HEADERS)/$$$$f; \
   610 		    $(CP) -f $$($1_HEADERS).$1.tmp/$$$$f $$($1_HEADERS)/$$$$f; \
   572 		  fi; \
   611 		  fi; \
   573 		done
   612 		  done; \
       
   613 		fi
   574 		$(RM) -r $$($1_HEADERS).$1.tmp
   614 		$(RM) -r $$($1_HEADERS).$1.tmp
   575 		$(TOUCH) $$@
   615 		$(TOUCH) $$@
   576 
   616 
   577       $1 += $$($1_HEADERS)/_the.$1_headers
   617       $1_HEADER_TARGETS := $$($1_HEADERS)/_the.$1_headers
   578     endif
   618     endif
   579 
   619 
   580     # When not using sjavac, pass along all sources to javac using an @file.
   620     # When not using sjavac, pass along all sources to javac using an @file.
   581     $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS)
   621     $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS)
   582 	$(MKDIR) -p $$(@D)
   622 	$(MKDIR) -p $$(@D)
   587 	    -implicit:none -sourcepath "$$($1_SRCROOTSC)" \
   627 	    -implicit:none -sourcepath "$$($1_SRCROOTSC)" \
   588 	    -d $$($1_BIN) $$($1_HEADERS_ARG) @$$($1_BIN)/_the.$1_batch.tmp && \
   628 	    -d $$($1_BIN) $$($1_HEADERS_ARG) @$$($1_BIN)/_the.$1_batch.tmp && \
   589 	$(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch)
   629 	$(MV) $$($1_BIN)/_the.$1_batch.tmp $$($1_BIN)/_the.$1_batch)
   590 
   630 
   591   endif
   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)
   592 
   636 
   593   # Check if a jar file was specified, then setup the rules for the jar.
   637   # Check if a jar file was specified, then setup the rules for the jar.
   594   ifneq (,$$($1_JAR))
   638   ifneq (,$$($1_JAR))
   595     # If no suffixes was explicitly set for this jar file.
   639     # If no suffixes was explicitly set for this jar file.
   596     # Use class and the cleaned/copied properties file suffixes as the default
   640     # Use class and the cleaned/copied properties file suffixes as the default
   628 
   672 
   629     # Add zip to target list
   673     # Add zip to target list
   630     $1 += $$($1_SRCZIP)
   674     $1 += $$($1_SRCZIP)
   631   endif
   675   endif
   632 endef
   676 endef
       
   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)
       
   683 define SetupJavaCompilationCompileTarget
       
   684   $(if $(findsring yes, $(ENABLE_SJAVAC)), $(strip $2)/javac_state, \
       
   685       $(strip $2)/_the.$(strip $1)_batch)
       
   686 endef
       
   687 endif