common/makefiles/JavaCompilation.gmk

changeset 494
e64f2cb57d05
parent 478
2ba6f4da4bf3
child 502
ed9e5635fc80
     1.1 --- a/common/makefiles/JavaCompilation.gmk	Wed Oct 24 13:11:42 2012 -0700
     1.2 +++ b/common/makefiles/JavaCompilation.gmk	Fri Oct 26 14:29:57 2012 -0700
     1.3 @@ -50,27 +50,17 @@
     1.4      #   FLAGS:=Flags to be supplied to javac
     1.5      #   SERVER_DIR:=Use a javac server (-XDserver) and store the server related files here
     1.6      #   SERVER_JVM:=Use this JVM for the server. Defaults to the JVM above.
     1.7 -    $(if $2,$1_$(strip $2))
     1.8 -    $(if $3,$1_$(strip $3))
     1.9 -    $(if $4,$1_$(strip $4))
    1.10 -    $(if $5,$1_$(strip $5))
    1.11 -    $(if $6,$1_$(strip $6))
    1.12 -    $(if $7,$1_$(strip $7))
    1.13 -    $(if $8,$1_$(strip $8))
    1.14 -    $(if $9,$1_$(strip $9))
    1.15 -    $(if $(10),$(error Internal makefile error: Too many arguments to SetupJavaCompiler, please update JavaCompilation.gmk))
    1.16 +    $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE))
    1.17 +    $(call LogSetupMacroEntry,SetupJavaCompiler($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
    1.18 +    $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompiler, please update JavaCompilation.gmk))
    1.19  
    1.20 -    ifeq ($$(ENABLE_SJAVAC),yes)
    1.21 -        # The port file contains the tcp/ip on which the server listens
    1.22 -        # and the cookie necessary to talk to the server.
    1.23 -        $1_JAVAC_PORTFILE:=$$($1_SERVER_DIR)/server.port
    1.24 -        # You can use a different JVM to run the background javac server.
    1.25 -        ifeq ($$($1_SERVER_JVM),)
    1.26 -            # It defaults to the same JVM that is used to start the javac command.
    1.27 -            $1_SERVER_JVM:=$$($1_JVM)
    1.28 -        endif
    1.29 -        # Set the $1_REMOTE to spawn a background javac server.
    1.30 -        $1_REMOTE:=-XDserver:portfile=$$($1_JAVAC_PORTFILE),poolsize=$(SJAVAC_SERVER_CORES),id=$1,javac=$$(subst $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_JAVAC))))
    1.31 +    # The port file contains the tcp/ip on which the server listens
    1.32 +    # and the cookie necessary to talk to the server.
    1.33 +    $1_SJAVAC_PORTFILE:=$$($1_SERVER_DIR)/server.port
    1.34 +    # You can use a different JVM to run the background javac server.
    1.35 +    ifeq ($$($1_SERVER_JVM),)
    1.36 +        # It defaults to the same JVM that is used to start the javac command.
    1.37 +        $1_SERVER_JVM:=$$($1_JVM)
    1.38      endif
    1.39  endef
    1.40  
    1.41 @@ -92,19 +82,11 @@
    1.42      #                  added to the archive.
    1.43      #    EXTRA_MANIFEST_ATTR:=Extra attribute to add to manifest.
    1.44      #    CHECK_COMPRESS_JAR Check the COMPRESS_JAR variable
    1.45 -    $(if $3,$1_$(strip $3))
    1.46 -    $(if $4,$1_$(strip $4))
    1.47 -    $(if $5,$1_$(strip $5))
    1.48 -    $(if $6,$1_$(strip $6))
    1.49 -    $(if $7,$1_$(strip $7))
    1.50 -    $(if $8,$1_$(strip $8))
    1.51 -    $(if $9,$1_$(strip $9))
    1.52 -    $(if $(10),$1_$(strip $(10)))
    1.53 -    $(if $(11),$1_$(strip $(11)))
    1.54 -    $(if $(12),$1_$(strip $(12)))
    1.55 -    $(if $(13),$1_$(strip $(13)))
    1.56 -    $(if $(14),$1_$(strip $(14)))
    1.57 -    $(if $(15),$1_$(strip $(15)))
    1.58 +
    1.59 +    # NOTE: $2 is dependencies, not a named argument!
    1.60 +    $(foreach i,3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE))
    1.61 +    $(call LogSetupMacroEntry,SetupArchive($1),<dependencies>,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
    1.62 +    $(if $(findstring $(LOG),debug trace), $(info *[2] <dependencies> = $(strip $2)))
    1.63      $(if $(16),$(error Internal makefile error: Too many arguments to SetupArchive, please update JavaCompilation.gmk))
    1.64  
    1.65      $1_JARMAIN:=$(strip $$($1_JARMAIN))
    1.66 @@ -125,16 +107,28 @@
    1.67      ifneq (,$$($1_INCLUDES))
    1.68          $1_GREP_INCLUDE_PATTERNS:=$$(foreach src,$$($1_SRCS),\
    1.69  					$$(addprefix $$(src)/,$$($1_INCLUDES)))
    1.70 -        $$(eval $$(call ListPathsSafelyNow,$1_GREP_INCLUDE_PATTERNS,\n, \
    1.71 +        # If there are a lot of include patterns, output to file to shorten command lines
    1.72 +        ifeq ($$(word 20,$$($1_GREP_INCLUDE_PATTERNS)),)
    1.73 +            $1_GREP_INCLUDES:=| $(GREP) $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_INCLUDE_PATTERNS))
    1.74 +        else
    1.75 +            $$(shell $(RM) $$($1_BIN)/_the.$$($1_JARNAME)_include)
    1.76 +            $$(eval $$(call ListPathsSafelyNow,$1_GREP_INCLUDE_PATTERNS,\n, \
    1.77  			>> $$($1_BIN)/_the.$$($1_JARNAME)_include))
    1.78 -        $1_GREP_INCLUDES:=| $(GREP) -f $$($1_BIN)/_the.$$($1_JARNAME)_include
    1.79 +            $1_GREP_INCLUDES:=| $(GREP) -f $$($1_BIN)/_the.$$($1_JARNAME)_include
    1.80 +        endif
    1.81      endif
    1.82      ifneq (,$$($1_EXCLUDES)$$($1_EXCLUDE_FILES))
    1.83          $1_GREP_EXCLUDE_PATTERNS:=$$(foreach src,$$($1_SRCS),$$(addprefix $$(src)/,\
    1.84  		$$($1_EXCLUDES) $$($1_EXCLUDE_FILES)))
    1.85 -        $$(eval $$(call ListPathsSafelyNow,$1_GREP_EXCLUDE_PATTERNS,\n, \
    1.86 +        # If there are a lot of include patterns, output to file to shorten command lines
    1.87 +        ifeq ($$(word 20,$$($1_GREP_EXCLUDE_PATTERNS)),)
    1.88 +            $1_GREP_EXCLUDES:=| $(GREP) -v $$(patsubst %,$(SPACE)-e$(SPACE)$(DQUOTE)%$(DQUOTE),$$($1_GREP_EXCLUDE_PATTERNS))
    1.89 +        else
    1.90 +            $$(shell $(RM) $$($1_BIN)/_the.$$($1_JARNAME)_exclude)
    1.91 +            $$(eval $$(call ListPathsSafelyNow,$1_GREP_EXCLUDE_PATTERNS,\n, \
    1.92  			>> $$($1_BIN)/_the.$$($1_JARNAME)_exclude))
    1.93 -        $1_GREP_EXCLUDES:=| $(GREP) -v -f $$($1_BIN)/_the.$$($1_JARNAME)_exclude
    1.94 +            $1_GREP_EXCLUDES:=| $(GREP) -v -f $$($1_BIN)/_the.$$($1_JARNAME)_exclude
    1.95 +        endif
    1.96      endif
    1.97  
    1.98      # Check if this jar needs to have its index generated.
    1.99 @@ -149,11 +143,13 @@
   1.100      ifneq (,$2)
   1.101          $1_DEPS:=$2
   1.102      else
   1.103 -        $1_DEPS:=$$(foreach src,$$($1_SRCS),$$(shell ($(FIND) $$(src) -type f \
   1.104 -			-a \( $$($1_FIND_PATTERNS) \) $$($1_GREP_INCLUDES) \
   1.105 -			$$($1_GREP_EXCLUDES) && $(ECHO) $$(addprefix $$(src)/,$$($1_EXTRA_FILES)))))
   1.106 +        # The subst of \ is needed because $ has to be escaped with \ in EXTRA_FILES for the command 
   1.107 +        # lines, but not here for use in make dependencies.
   1.108 +        $1_DEPS:=$$(shell $(FIND) $$($1_SRCS) -type f -a \( $$($1_FIND_PATTERNS) \) \
   1.109 +			  $$($1_GREP_INCLUDES) $$($1_GREP_EXCLUDES)) \
   1.110 +		 $$(subst \,,$$(foreach src,$$($1_SRCS),$$(addprefix $$(src)/,$$($1_EXTRA_FILES))))
   1.111          ifeq (,$$($1_SKIP_METAINF))
   1.112 -            $1_DEPS+=$$(foreach src,$$($1_SRCS),$$(shell $(FIND) $$(src)/META-INF -type f 2> /dev/null))
   1.113 +            $1_DEPS+=$$(shell $(FIND) $$(addsuffix /META-INF,$$($1_SRCS)) -type f 2> /dev/null))
   1.114          endif
   1.115      endif
   1.116  
   1.117 @@ -161,34 +157,39 @@
   1.118  
   1.119      # The capture contents macro finds all files (matching the patterns, typically
   1.120      # .class and .prp) that are newer than the jar-file, ie the new content to be put into the jar.
   1.121 -    $1_CAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS),(($(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) -a -newer $$@ $$($1_GREP_INCLUDES) $$($1_GREP_EXCLUDES) && $(ECHO) $$($1_EXTRA_FILES)) | $(SED) 's|$$(src)/||g' > $$(src)/_the.$$($1_JARNAME)_contents) && )
   1.122 +    $1_CAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS),\
   1.123 +                   (($(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) -a -newer $$@ $$($1_GREP_INCLUDES) \
   1.124 +                       $$($1_GREP_EXCLUDES) | $(SED) 's|$$(src)/||g' &&\
   1.125 +                       $(ECHO) $$(subst $$(src)/,,$$($1_EXTRA_FILES))) > \
   1.126 +                       $$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE))
   1.127      # The capture metainf macro finds all files below the META-INF directory that are newer than the jar-file.
   1.128      ifeq (,$$($1_SKIP_METAINF))
   1.129 -        $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 ) && )
   1.130 +        $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))
   1.131      endif
   1.132      # The capture deletes macro finds all deleted files and concatenates them. The resulting file
   1.133      # tells us what to remove from the jar-file.
   1.134 -    $1_CAPTURE_DELETES=$$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.deleted -newer $$@ -exec $(SED) 's|$$(src)||g' \{\} >> $$($1_DELETES_FILE) \;) &&)
   1.135 +    $1_CAPTURE_DELETES=$$(foreach src,$$($1_SRCS),($(FIND) $$(src) -name _the.package.deleted -newer $$@ -exec $(SED) 's|$$(src)||g' \{\} >> $$($1_DELETES_FILE) \;) $$(NEWLINE))
   1.136      # The update contents macro updates the jar file with the previously capture contents.
   1.137      $1_UPDATE_CONTENTS=$$(foreach src,$$($1_SRCS),\
   1.138                      (cd $$(src) && \
   1.139                       if [ -s _the.$$($1_JARNAME)_contents ]; then \
   1.140                           $(ECHO) "  updating" `$(WC) -l _the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'` files && \
   1.141                           $(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @_the.$$($1_JARNAME)_contents; \
   1.142 -                     fi) &&)
   1.143 +                     fi) $$(NEWLINE))
   1.144      # The s-variants of the above macros are used when the jar is created from scratch.
   1.145      $1_SCAPTURE_CONTENTS=$$(foreach src,$$($1_SRCS),\
   1.146                      (($(FIND) $$(src) -type f -a \( $$($1_FIND_PATTERNS) \) $$($1_GREP_INCLUDES) \
   1.147 -			$$($1_GREP_EXCLUDES) && $(ECHO) $$($1_EXTRA_FILES)) | $(SED) 's|$$(src)/||g' > \
   1.148 -			$$(src)/_the.$$($1_JARNAME)_contents) && )
   1.149 +			$$($1_GREP_EXCLUDES) | $(SED) 's|$$(src)/||g' &&\
   1.150 +			$$(subst $$(src)/,,$(ECHO) $$($1_EXTRA_FILES))) > \
   1.151 +			$$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE))
   1.152  
   1.153      ifeq (,$$($1_SKIP_METAINF))
   1.154          $1_SCAPTURE_METAINF=$$(foreach src,$$($1_SRCS),\
   1.155                      ($(FIND) $$(src)/META-INF -type f 2> /dev/null | $(SED) 's|$$(src)/||g' >> \
   1.156 -			$$(src)/_the.$$($1_JARNAME)_contents) && )
   1.157 +			$$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE))
   1.158      endif
   1.159      $1_SUPDATE_CONTENTS=$$(foreach src,$$($1_SRCS),\
   1.160 -                    (cd $$(src) && $(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @$$(src)/_the.$$($1_JARNAME)_contents) &&)
   1.161 +                    (cd $$(src) && $(JAR) $$($1_JAR_UPDATE_OPTIONS) $$@ @$$(src)/_the.$$($1_JARNAME)_contents) $$(NEWLINE))
   1.162  
   1.163      # Use a slightly shorter name for logging, but with enough path to identify this jar.
   1.164      $1_NAME:=$$(subst $$(OUTPUT_ROOT)/,,$$($1_JAR))
   1.165 @@ -208,38 +209,32 @@
   1.166      # Here is the rule that creates/updates the jar file.
   1.167      $$($1_JAR) : $$($1_DEPS)
   1.168  	$(MKDIR) -p $$($1_BIN)
   1.169 -	if [ -n "$$($1_MANIFEST)" ]; then \
   1.170 +	$$(if $$($1_MANIFEST),\
   1.171  		$(SED) -e "s#@@RELEASE@@#$(RELEASE)#"           \
   1.172 -		       -e "s#@@COMPANY_NAME@@#$(COMPANY_NAME)#" $$($1_MANIFEST) > $$($1_MANIFEST_FILE); \
   1.173 -	else \
   1.174 -		$(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE); \
   1.175 -	fi
   1.176 -	if [ -n "$$(strip $$($1_JARMAIN))" ]; then \
   1.177 -		$(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE); \
   1.178 -	fi
   1.179 -	if [ -n "$$($1_EXTRA_MANIFEST_ATTR)" ]; then \
   1.180 -		$(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE); \
   1.181 -	fi
   1.182 -	+if [ -s $$@ ]; then \
   1.183 -		$(ECHO) Modifying $$($1_NAME) && \
   1.184 +		       -e "s#@@COMPANY_NAME@@#$(COMPANY_NAME)#" $$($1_MANIFEST) > $$($1_MANIFEST_FILE) \
   1.185 +	,\
   1.186 +		$(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE))
   1.187 +	$$(if $$($1_JARMAIN),$(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE))
   1.188 +	$$(if $$($1_EXTRA_MANIFEST_ATTR),$(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE))
   1.189 +	$$(if $$(wildcard $$@),\
   1.190 +		$(ECHO) Modifying $$($1_NAME) $$(NEWLINE)\
   1.191  		$$($1_CAPTURE_CONTENTS) \
   1.192  		$$($1_CAPTURE_METAINF) \
   1.193 -		$(RM) $$($1_DELETES_FILE) && \
   1.194 +		$(RM) $$($1_DELETES_FILE) $$(NEWLINE)\
   1.195  		$$($1_CAPTURE_DELETES) \
   1.196 -		$(CAT) $$($1_DELETES_FILE) > $$($1_DELETESS_FILE) && \
   1.197 +		$(CAT) $$($1_DELETES_FILE) > $$($1_DELETESS_FILE) $$(NEWLINE)\
   1.198  		if [ -s $$($1_DELETESS_FILE) ]; then \
   1.199  			$(ECHO) "  deleting" `$(WC) -l $$($1_DELETESS_FILE) | $(AWK) '{ print $$$$1 }'` files && \
   1.200  	                       $(ZIP) -q -d $$@ `$(CAT) $$($1_DELETESS_FILE)` ; \
   1.201 -		fi && \
   1.202 -		$$($1_UPDATE_CONTENTS) true && \
   1.203 -		$$($1_JARINDEX) && true ; \
   1.204 -	else \
   1.205 -		$(ECHO) Creating $$($1_NAME) && $(JAR) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) && \
   1.206 +		fi $$(NEWLINE) \
   1.207 +		$$($1_UPDATE_CONTENTS) true $$(NEWLINE) \
   1.208 +		$$($1_JARINDEX) && true \
   1.209 +	,\
   1.210 +		$(ECHO) Creating $$($1_NAME) && $(JAR) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) $$(NEWLINE) \
   1.211  	        $$($1_SCAPTURE_CONTENTS) \
   1.212  		$$($1_SCAPTURE_METAINF) \
   1.213  		$$($1_SUPDATE_CONTENTS) \
   1.214 -		$$($1_JARINDEX) && true ; \
   1.215 -	fi; 
   1.216 +		$$($1_JARINDEX) && true ) 
   1.217  
   1.218  endef
   1.219  
   1.220 @@ -247,15 +242,9 @@
   1.221      # param 1 is for example ZIP_MYSOURCE
   1.222      # param 2,3,4,5,6,7,8,9 are named args.
   1.223      #    SRC,ZIP,INCLUDES,EXCLUDES,EXCLUDE_FILES,SUFFIXES,EXTRA_DEPS
   1.224 -    $(if $2,$1_$(strip $2))
   1.225 -    $(if $3,$1_$(strip $3))
   1.226 -    $(if $4,$1_$(strip $4))
   1.227 -    $(if $5,$1_$(strip $5))
   1.228 -    $(if $6,$1_$(strip $6))
   1.229 -    $(if $7,$1_$(strip $7))
   1.230 -    $(if $8,$1_$(strip $8))
   1.231 -    $(if $9,$1_$(strip $9))
   1.232 -    $(if $(10),$(error Internal makefile error: Too many arguments to SetupZipArchive, please update JavaCompilation.gmk))
   1.233 +    $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE))
   1.234 +    $(call LogSetupMacroEntry,SetupZipArchive($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
   1.235 +    $(if $(16),$(error Internal makefile error: Too many arguments to SetupZipArchive, please update JavaCompilation.gmk))
   1.236  
   1.237      # Find all files in the source tree.
   1.238      $1_SUFFIX_FILTER := $$(patsubst %,-o -name $(DQUOTE)*%$(DQUOTE),$$($1_SUFFIXES))
   1.239 @@ -274,7 +263,7 @@
   1.240      ifneq ($$($1_EXCLUDES),)
   1.241          $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES))))
   1.242          $1_ZIP_EXCLUDES := $$(addprefix -x$(SPACE)$(DQUOTE),$$(addsuffix /*$(DQUOTE),$$($1_EXCLUDES)))
   1.243 -        $1_ALL_SRCS     := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRC))
   1.244 +        $1_ALL_SRCS     := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_SRCS))
   1.245      endif
   1.246  
   1.247      # Use a slightly shorter name for logging, but with enough path to identify this zip.
   1.248 @@ -288,7 +277,7 @@
   1.249      $$($1_ZIP) : $$($1_ALL_SRCS) $$($1_EXTRA_DEPS)
   1.250  		$(MKDIR) -p $$(@D)
   1.251  		$(ECHO) Updating $$($1_NAME)
   1.252 -		$$(foreach i,$$($1_SRC),(cd $$i && $(ZIP) -qru $$@ . $$($1_ZIP_INCLUDES) $$($1_ZIP_EXCLUDES) -x \*_the.\* $$(addprefix -x$(SPACE),$$(patsubst $$i/%,%,$$($1_EXCLUDE_FILES)))) ;) true
   1.253 +		$$(foreach i,$$($1_SRC),(cd $$i && $(ZIP) -qru $$@ . $$($1_ZIP_INCLUDES) $$($1_ZIP_EXCLUDES) -x \*_the.\* $$(addprefix -x$(SPACE),$$(patsubst $$i/%,%,$$($1_EXCLUDE_FILES))))$$(NEWLINE)) true
   1.254  		$(TOUCH) $$@
   1.255  endef
   1.256  
   1.257 @@ -324,7 +313,7 @@
   1.258      $$($1_BIN)$$($2_TARGET) : $2
   1.259  	$(MKDIR) -p $$(@D)
   1.260  	$(CAT) $$< | $(SED) -e 's/\([^\\]\):/\1\\:/g' -e  's/\([^\\]\)=/\1\\=/g' -e 's/#.*/#/g' \
   1.261 -                   | $(SED) -f "$(SRC_ROOT)/common/bin/unicode2x.sed" \
   1.262 +                   | $(SED) -f "$(SRC_ROOT)/common/makefiles/support/unicode2x.sed" \
   1.263  		   | $(SED) -e '/^#/d' -e '/^$$$$/d' \
   1.264  		            -e :a -e '/\\$$$$/N; s/\\\n//; ta' \
   1.265  			    -e 's/^[ \t]*//;s/[ \t]*$$$$//' \
   1.266 @@ -364,36 +353,27 @@
   1.267      #                                     Its only here until we cleanup some nasty source code pasta in the jdk.
   1.268      #    HEADERS:=path to directory where all generated c-headers are written.
   1.269      #    DEPENDS:=Extra dependecy
   1.270 -    $(if $2,$1_$(strip $2))
   1.271 -    $(if $3,$1_$(strip $3))
   1.272 -    $(if $4,$1_$(strip $4))
   1.273 -    $(if $5,$1_$(strip $5))
   1.274 -    $(if $6,$1_$(strip $6))
   1.275 -    $(if $7,$1_$(strip $7))
   1.276 -    $(if $8,$1_$(strip $8))
   1.277 -    $(if $9,$1_$(strip $9))
   1.278 -    $(if $(10),$1_$(strip $(10)))
   1.279 -    $(if $(11),$1_$(strip $(11)))
   1.280 -    $(if $(12),$1_$(strip $(12)))
   1.281 -    $(if $(13),$1_$(strip $(13)))
   1.282 -    $(if $(14),$1_$(strip $(14)))
   1.283 -    $(if $(15),$(error Internal makefile error: Too many arguments to SetupJavaCompilation, please update JavaCompilation.gmk))
   1.284 +    $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15, $(if $($i),$1_$(strip $($i)))$(NEWLINE))
   1.285 +    $(call LogSetupMacroEntry,SetupJavaCompilation($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
   1.286 +    $(if $(16),$(error Internal makefile error: Too many arguments to SetupJavaCompilation, please update JavaCompilation.gmk))
   1.287  
   1.288      # Extract the info from the java compiler setup.
   1.289 -    $1_REMOTE := $$($$($1_SETUP)_REMOTE)
   1.290      $1_JVM   := $$($$($1_SETUP)_JVM)
   1.291      $1_JAVAC := $$($$($1_SETUP)_JAVAC)
   1.292      $1_FLAGS := $$($$($1_SETUP)_FLAGS) $(JAVAC_FLAGS) $$($1_ADD_JAVAC_FLAGS)
   1.293      ifeq ($$($1_JAVAC),)
   1.294          $$(error The Java compilation $1 refers to a non-existant java compiler setup $$($1_SETUP))
   1.295      endif
   1.296 +    $1_SJAVAC_PORTFILE := $$($$($1_SETUP)_SJAVAC_PORTFILE)
   1.297 +    $1_SERVER_JVM := $$($$($1_SETUP)_SERVER_JVM)
   1.298  
   1.299      # Handle addons and overrides.
   1.300      $1_SRC:=$$(call ADD_SRCS,$$($1_SRC))
   1.301      # Make sure the dirs exist.
   1.302 -    $$(shell $(MKDIR) -p $$($1_SRC) $$($1_BIN))
   1.303 +    $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupJavaCompilation $1 contains missing directory $$d)))
   1.304 +    $$(eval $$(call MakeDir,$$($1_BIN)))
   1.305      # Find all files in the source trees.
   1.306 -    $1_ALL_SRCS := $$(filter-out $(OVR_SRCS),$$(foreach i,$$($1_SRC),$$(shell $(FIND) $$i -type f)))
   1.307 +    $1_ALL_SRCS := $$(filter-out $(OVR_SRCS),$$(shell $(FIND) $$($1_SRC) -type f))
   1.308      # Extract the java files.
   1.309      ifneq ($$($1_EXCLUDE_FILES),)
   1.310          $1_EXCLUDE_FILES_PATTERN:=$$(addprefix %,$$($1_EXCLUDE_FILES))
   1.311 @@ -428,7 +408,7 @@
   1.312          # Rewrite list of patterns into a find statement.
   1.313          $1_COPY_PATTERN:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_COPY))
   1.314          # Search for all files to be copied.
   1.315 -        $1_ALL_COPIES := $$(foreach i,$$($1_SRC), $$(shell $(FIND) $$i \( $$($1_COPY_PATTERN) \) -a -type f))
   1.316 +        $1_ALL_COPIES := $$(filter $$(addprefix %,$$($1_COPY)),$$($1_ALL_SRCS))
   1.317          # Copy these explicitly
   1.318          $1_ALL_COPIES += $$($1_COPY_FILES)
   1.319          # Copy must also respect filters.
   1.320 @@ -442,7 +422,7 @@
   1.321              $1_ALL_COPIES := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_COPIES))
   1.322          endif
   1.323          # All files below META-INF are always copied.
   1.324 -        $1_ALL_COPIES += $$(foreach i,$$($1_SRC), $$(shell $(FIND) $$i/META-INF -type f 2> /dev/null))
   1.325 +        $1_ALL_COPIES += $$(filter $$(addsuffix /META-INF%,$$($1_SRC)),$$($1_ALL_SRCS))
   1.326          ifneq (,$$($1_ALL_COPIES))
   1.327              # Yep, there are files to be copied!
   1.328              $1_ALL_COPY_TARGETS:=
   1.329 @@ -456,7 +436,7 @@
   1.330          # Rewrite list of patterns into a find statement.
   1.331          $1_CLEAN_PATTERN:=$(FALSE_FIND_PATTERN) $$(patsubst %,$(SPACE)-o$(SPACE)-name$(SPACE)$(DQUOTE)*%$(DQUOTE),$$($1_CLEAN))
   1.332          # Search for all files to be copied.
   1.333 -        $1_ALL_CLEANS := $$(foreach i,$$($1_SRC), $$(shell $(FIND) $$i \( $$($1_CLEAN_PATTERN) \) -a -type f))
   1.334 +        $1_ALL_CLEANS := $$(filter $$(addprefix %,$$($1_CLEAN)),$$($1_ALL_SRCS))
   1.335          # Copy and clean must also respect filters.
   1.336          ifneq (,$$($1_INCLUDES))
   1.337              $1_ALL_CLEANS := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_CLEANS))
   1.338 @@ -482,30 +462,59 @@
   1.339        $$(eval $$(call replace_space_with_pathsep,$1_SRCROOTSC,$$($1_SRC)))
   1.340      endif
   1.341  
   1.342 -    ifneq (,$$($1_HEADERS))
   1.343 -        $1_HEADERS_ARG := -h $$($1_HEADERS)
   1.344 -    endif
   1.345 -
   1.346      # Create a sed expression to remove the source roots and to replace / with .
   1.347      # and remove .java at the end. 
   1.348      $1_REWRITE_INTO_CLASSES:=$$(foreach i,$$($1_SRC),-e 's|$$i/||g') -e 's|/|.|g' -e 's|.java$$$$||g'
   1.349  
   1.350      ifeq ($$($1_DISABLE_SJAVAC)x$$(ENABLE_SJAVAC),xyes)
   1.351 +        ifneq (,$$($1_HEADERS))
   1.352 +            $1_HEADERS_ARG := -h $$($1_HEADERS)
   1.353 +        endif
   1.354 +
   1.355          # Using sjavac to compile. 
   1.356          $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_BIN)/javac_state
   1.357  
   1.358 +        # Create SJAVAC variable,
   1.359 +        # expects $1_JAVAC to be "bootclasspathprepend -jar ...javac.jar"
   1.360 +        # and it is rewritten into "bootclasspathprepend com.sun.tools.sjavac.Main"
   1.361 +        $1_SJAVAC:=$$(word 1,$$($1_JAVAC)) -cp $$(word 3,$$($1_JAVAC)) com.sun.tools.sjavac.Main
   1.362 +
   1.363 +        # Set the $1_REMOTE to spawn a background javac server.
   1.364 +        $1_REMOTE:=--server:portfile=$$($1_SJAVAC_PORTFILE),poolsize=$(SJAVAC_SERVER_CORES),id=$1,sjavac=$$(subst $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_SJAVAC))))
   1.365 +
   1.366          $$($1_BIN)/javac_state: $$($1_SRCS) $$($1_DEPENDS)
   1.367  		$(MKDIR) -p $$(@D)
   1.368  		$$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.batch.tmp)
   1.369  		$(ECHO) Compiling $1
   1.370 -		$$($1_JVM) $$(word 1,$$($1_JAVAC)) com.sun.tools.sjavac.Main \
   1.371 -			$$($1_REMOTE) $$($1_SJAVAC_ARGS) --permit-unidentified-artifacts -mfl $$($1_BIN)/_the.batch.tmp \
   1.372 +		$$($1_JVM) $$($1_SJAVAC) \
   1.373 +			$$($1_REMOTE) $$($1_SJAVAC_ARGS) \
   1.374 +			--permit-unidentified-artifacts \
   1.375 +			--permit-sources-without-package \
   1.376 +			--compare-found-sources $$($1_BIN)/_the.batch.tmp \
   1.377  			$$($1_FLAGS) \
   1.378  			-implicit:none -d $$($1_BIN) $$($1_HEADERS_ARG)
   1.379      else
   1.380          # Using plain javac to batch compile everything.
   1.381          $1 := $$($1_ALL_COPY_TARGETS) $$($1_ALL_COPY_CLEAN_TARGETS) $$($1_BIN)/_the.batch
   1.382  
   1.383 +        # When buliding in batch, put headers in a temp dir to filter out those that actually
   1.384 +        # changed before copying them to the real header dir.
   1.385 +        ifneq (,$$($1_HEADERS))
   1.386 +            $1_HEADERS_ARG := -h $$($1_HEADERS).tmp
   1.387 +
   1.388 +            $$($1_HEADERS)/_the.headers: $$($1_BIN)/_the.batch
   1.389 +		$(MKDIR) -p $$(@D)
   1.390 +		for f in `ls $$($1_HEADERS).tmp`; do \
   1.391 +		  if [ ! -f "$$($1_HEADERS)/$$$$f" ] || [ "`$(DIFF) $$($1_HEADERS)/$$$$f $$($1_HEADERS).tmp/$$$$f`" != "" ]; then \
   1.392 +		    $(CP) -f $$($1_HEADERS).tmp/$$$$f $$($1_HEADERS)/$$$$f; \
   1.393 +		  fi; \
   1.394 +		done
   1.395 +		$(RM) -r $$($1_HEADERS).tmp
   1.396 +		$(TOUCH) $$@
   1.397 +
   1.398 +            $1 += $$($1_HEADERS)/_the.headers
   1.399 +        endif
   1.400 +
   1.401          # When not using sjavac, pass along all sources to javac using an @file.
   1.402          $$($1_BIN)/_the.batch: $$($1_SRCS) $$($1_DEPENDS)
   1.403  		$(MKDIR) -p $$(@D)
   1.404 @@ -516,6 +525,7 @@
   1.405  			-implicit:none -sourcepath "$$($1_SRCROOTSC)" \
   1.406  			-d $$($1_BIN) $$($1_HEADERS_ARG) @$$($1_BIN)/_the.batch.tmp && \
   1.407  			$(MV) $$($1_BIN)/_the.batch.tmp $$($1_BIN)/_the.batch)
   1.408 +
   1.409      endif
   1.410  
   1.411      # Check if a jar file was specified, then setup the rules for the jar.

mercurial