make/common/JavaCompilation.gmk
changeset 28713 c1ea17b60964
parent 28605 68bf16ffbd7a
parent 28601 de178dea78cd
child 28906 741a25ba3b20
child 28900 dd0303e8c9ce
equal deleted inserted replaced
28605:68bf16ffbd7a 28713:c1ea17b60964
   277   else
   277   else
   278     $1_JAR_CREATE_OPTIONS := cfm
   278     $1_JAR_CREATE_OPTIONS := cfm
   279     $1_JAR_UPDATE_OPTIONS := uf
   279     $1_JAR_UPDATE_OPTIONS := uf
   280   endif
   280   endif
   281 
   281 
       
   282   # Include all variables of significance in the vardeps file
       
   283   $1_VARDEPS := $(JAR) $$($1_JAR_CREATE_OPTIONS) $$($1_MANIFEST) $(RELEASE) $(COMPANY_NAME) \
       
   284       $$($1_JARMAIN) $$($1_EXTRA_MANIFEST_ATTR)
       
   285   $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$(dir $$($1_JAR))_the.$$($1_JARNAME).vardeps)
       
   286 
   282   # Here is the rule that creates/updates the jar file.
   287   # Here is the rule that creates/updates the jar file.
   283   $$($1_JAR) : $$($1_DEPS)
   288   $$($1_JAR) : $$($1_DEPS) $$($1_MANIFEST) $$($1_VARDEPS_FILE)
   284 	$(MKDIR) -p $$($1_BIN)
   289 	$(MKDIR) -p $$($1_BIN)
   285 	$$($1_GREP_INCLUDE_OUTPUT)
   290 	$$($1_GREP_INCLUDE_OUTPUT)
   286 	$$($1_GREP_EXCLUDE_OUTPUT)
   291 	$$($1_GREP_EXCLUDE_OUTPUT)
   287 	$$(if $$($1_MANIFEST), \
   292         # If the vardeps file is part of the newer prereq list, it means that
   288 	  $(SED) -e "s#@@RELEASE@@#$(RELEASE)#" \
   293         # either the jar file does not exist, or we need to recreate it from
   289 	      -e "s#@@COMPANY_NAME@@#$(COMPANY_NAME)#" $$($1_MANIFEST) > $$($1_MANIFEST_FILE) \
   294         # from scratch anyway since a simple update will not catch all the 
       
   295         # potential changes.
       
   296 	$$(if $$(filter $$($1_VARDEPS_FILE) $$($1_MANIFEST), $$?), \
       
   297 	  $$(if $$($1_MANIFEST), \
       
   298 	    $(SED) -e "s#@@RELEASE@@#$(RELEASE)#" \
       
   299 	        -e "s#@@COMPANY_NAME@@#$(COMPANY_NAME)#" $$($1_MANIFEST) > $$($1_MANIFEST_FILE) $$(NEWLINE) \
       
   300 	  , \
       
   301 	    $(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE) $$(NEWLINE)) \
       
   302 	  $$(if $$($1_JARMAIN), \
       
   303 	    $(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE) $$(NEWLINE)) \
       
   304 	  $$(if $$($1_EXTRA_MANIFEST_ATTR), \
       
   305 	    $(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE) $$(NEWLINE)) \
       
   306 	  $(ECHO) Creating $$($1_NAME) $$(NEWLINE) \
       
   307 	  $(JAR) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) $$(NEWLINE) \
       
   308 	  $$($1_SCAPTURE_CONTENTS) \
       
   309 	  $$($1_SCAPTURE_METAINF) \
       
   310 	  $$($1_SUPDATE_CONTENTS) \
       
   311 	  $$($1_JARINDEX) && true \
   290 	, \
   312 	, \
   291 	  $(RM) $$($1_MANIFEST_FILE) && $(TOUCH) $$($1_MANIFEST_FILE))
       
   292 	$$(if $$($1_JARMAIN),$(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE))
       
   293 	$$(if $$($1_EXTRA_MANIFEST_ATTR),$(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE))
       
   294 	$$(if $$(wildcard $$@), \
       
   295 	  $(ECHO) Modifying $$($1_NAME) $$(NEWLINE) \
   313 	  $(ECHO) Modifying $$($1_NAME) $$(NEWLINE) \
   296 	  $$($1_CAPTURE_CONTENTS) \
   314 	  $$($1_CAPTURE_CONTENTS) \
   297 	  $$($1_CAPTURE_METAINF) \
   315 	  $$($1_CAPTURE_METAINF) \
   298 	  $(RM) $$($1_DELETES_FILE) $$(NEWLINE) \
   316 	  $(RM) $$($1_DELETES_FILE) $$(NEWLINE) \
   299 	  $$($1_CAPTURE_DELETES) \
   317 	  $$($1_CAPTURE_DELETES) \
   301 	  if [ -s $$($1_DELETESS_FILE) ]; then \
   319 	  if [ -s $$($1_DELETESS_FILE) ]; then \
   302 	    $(ECHO) "  deleting" `$(WC) -l $$($1_DELETESS_FILE) | $(AWK) '{ print $$$$1 }'` files && \
   320 	    $(ECHO) "  deleting" `$(WC) -l $$($1_DELETESS_FILE) | $(AWK) '{ print $$$$1 }'` files && \
   303 	    $(ZIP) -q -d $$@ `$(CAT) $$($1_DELETESS_FILE)` ; \
   321 	    $(ZIP) -q -d $$@ `$(CAT) $$($1_DELETESS_FILE)` ; \
   304 	  fi $$(NEWLINE) \
   322 	  fi $$(NEWLINE) \
   305 	  $$($1_UPDATE_CONTENTS) true $$(NEWLINE) \
   323 	  $$($1_UPDATE_CONTENTS) true $$(NEWLINE) \
   306 	  $$($1_JARINDEX) && true \
       
   307 	, \
       
   308 	  $(ECHO) Creating $$($1_NAME) && $(JAR) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) $$(NEWLINE) \
       
   309 	  $$($1_SCAPTURE_CONTENTS) \
       
   310 	  $$($1_SCAPTURE_METAINF) \
       
   311 	  $$($1_SUPDATE_CONTENTS) \
       
   312 	  $$($1_JARINDEX) && true )
   324 	  $$($1_JARINDEX) && true )
   313 
   325 
   314   # Add jar to target list
   326   # Add jar to target list
   315   $1 += $$($1_JAR)
   327   $1 += $$($1_JAR)
   316 endef
   328 endef
   438 
   450 
   439   # Handle addons and overrides.
   451   # Handle addons and overrides.
   440   $1_SRC:=$$(call ADD_SRCS,$$($1_SRC))
   452   $1_SRC:=$$(call ADD_SRCS,$$($1_SRC))
   441   # Make sure the dirs exist.
   453   # Make sure the dirs exist.
   442   $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupJavaCompilation $1 contains missing directory $$d)))
   454   $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupJavaCompilation $1 contains missing directory $$d)))
   443   $$(eval $$(call MakeDir,$$($1_BIN)))
   455   $$(call MakeDir,$$($1_BIN))
   444   # Add all source roots to the find cache since we are likely going to run find
   456   # Add all source roots to the find cache since we are likely going to run find
   445   # on these more than once. The cache will only be updated if necessary.
   457   # on these more than once. The cache will only be updated if necessary.
   446   $$(eval $$(call FillCacheFind,$$($1_SRC)))
   458   $$(eval $$(call FillCacheFind,$$($1_SRC)))
   447   # Find all files in the source trees. Preserve order of source roots for overrides to
   459   # Find all files in the source trees. Preserve order of source roots for overrides to
   448   # work correctly. CacheFind does not preserve order so need to call it for each root.
   460   # work correctly. CacheFind does not preserve order so need to call it for each root.
   482   ifneq (,$$($1_COPY)$$($1_COPY_FILES))
   494   ifneq (,$$($1_COPY)$$($1_COPY_FILES))
   483     # Search for all files to be copied.
   495     # Search for all files to be copied.
   484     $1_ALL_COPIES += $$(filter $$(addprefix %,$$($1_COPY)),$$($1_ALL_SRCS))
   496     $1_ALL_COPIES += $$(filter $$(addprefix %,$$($1_COPY)),$$($1_ALL_SRCS))
   485     # Copy these explicitly
   497     # Copy these explicitly
   486     $1_ALL_COPIES += $$($1_COPY_FILES)
   498     $1_ALL_COPIES += $$($1_COPY_FILES)
   487     # Copy must also respect filters.
   499   endif
   488     ifneq (,$$($1_INCLUDES))
   500   # Copy must also respect filters.
   489       $1_ALL_COPIES := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_COPIES))
   501   ifneq (,$$($1_INCLUDES))
   490     endif
   502     $1_ALL_COPIES := $$(filter $$($1_SRC_INCLUDES),$$($1_ALL_COPIES))
   491     ifneq (,$$($1_EXCLUDES))
   503   endif
   492       $1_ALL_COPIES := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_COPIES))
   504   ifneq (,$$($1_EXCLUDES))
   493     endif
   505     $1_ALL_COPIES := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_ALL_COPIES))
   494     ifneq (,$$($1_EXCLUDE_FILES))
   506   endif
   495       $1_ALL_COPIES := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_COPIES))
   507   ifneq (,$$($1_EXCLUDE_FILES))
   496     endif
   508     $1_ALL_COPIES := $$(filter-out $$($1_EXCLUDE_FILES_PATTERN),$$($1_ALL_COPIES))
   497   endif
   509   endif
   498     ifneq (,$$($1_ALL_COPIES))
   510   ifneq (,$$($1_ALL_COPIES))
   499       # Yep, there are files to be copied!
   511     # Yep, there are files to be copied!
   500       $1_ALL_COPY_TARGETS:=
   512     $1_ALL_COPY_TARGETS:=
   501           $$(foreach i,$$($1_ALL_COPIES),$$(eval $$(call add_file_to_copy,$1,$$i)))
   513         $$(foreach i,$$($1_ALL_COPIES),$$(eval $$(call add_file_to_copy,$1,$$i)))
   502       # Now we can depend on $$($1_ALL_COPY_TARGETS) to copy all files!
   514     # Now we can depend on $$($1_ALL_COPY_TARGETS) to copy all files!
   503     endif
   515   endif
   504 
   516 
   505   # Find all property files to be copied and cleaned from source to bin.
   517   # Find all property files to be copied and cleaned from source to bin.
   506   ifneq (,$$($1_CLEAN)$$($1_CLEAN_FILES))
   518   ifneq (,$$($1_CLEAN)$$($1_CLEAN_FILES))
   507     # Search for all files to be copied.
   519     # Search for all files to be copied.
   508     $1_ALL_CLEANS := $$(filter $$(addprefix %,$$($1_CLEAN)),$$($1_ALL_SRCS))
   520     $1_ALL_CLEANS := $$(filter $$(addprefix %,$$($1_CLEAN)),$$($1_ALL_SRCS))
   542     # "bootclasspathprepend -cp .../javac.jar com.sun.tools.javac.Main"
   554     # "bootclasspathprepend -cp .../javac.jar com.sun.tools.javac.Main"
   543     # and javac is simply replaced with sjavac.
   555     # and javac is simply replaced with sjavac.
   544     $1_SJAVAC:=$$(subst com.sun.tools.javac.Main,com.sun.tools.sjavac.Main,$$($1_JAVAC))
   556     $1_SJAVAC:=$$(subst com.sun.tools.javac.Main,com.sun.tools.sjavac.Main,$$($1_JAVAC))
   545 
   557 
   546     # Set the $1_REMOTE to spawn a background javac server.
   558     # Set the $1_REMOTE to spawn a background javac server.
   547     $1_REMOTE:=--server:portfile=$$($1_SJAVAC_PORTFILE),id=$1,sjavac=$$(subst $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_SJAVAC))))
   559     $1_REMOTE:=--server:portfile=$$($1_SJAVAC_PORTFILE),id=$1,sjavac=$$(subst \
   548 
   560         $$(SPACE),%20,$$(subst $$(COMMA),%2C,$$(strip $$($1_SERVER_JVM) $$($1_SJAVAC))))
   549     $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS)
   561 
       
   562     $1_VARDEPS := $$($1_JVM) $$($1_SJAVAC) $$($1_SJAVAC_ARGS) $$($1_FLAGS) \
       
   563         $$($1_HEADERS_ARG) $$($1_BIN)
       
   564     $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$($1_BIN)/_the.$1.vardeps)
       
   565 
       
   566     $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS) $$($1_VARDEPS_FILE)
   550 	$(MKDIR) -p $$(@D) $$(dir $$($1_SJAVAC_PORTFILE))
   567 	$(MKDIR) -p $$(@D) $$(dir $$($1_SJAVAC_PORTFILE))
   551         # As a workaround for sjavac not tracking api changed from the classpath, force full
   568         # As a workaround for sjavac not tracking api changed from the classpath, force full
   552         # recompile if an external dependency, which is something other than a source
   569         # recompile if an external dependency, which is something other than a source
   553         # change, triggered this compilation.
   570         # change, triggered this compilation.
   554 	$$(if $$(filter-out $$($1_SRCS), $$?), $(FIND) $$(@D) -name "*.class" $(FIND_DELETE))
   571 	$$(if $$(filter-out $$($1_SRCS), $$?), $(FIND) $$(@D) -name "*.class" $(FIND_DELETE))
   599 		$(TOUCH) $$@
   616 		$(TOUCH) $$@
   600 
   617 
   601       $1_HEADER_TARGETS := $$($1_HEADERS)/_the.$1_headers
   618       $1_HEADER_TARGETS := $$($1_HEADERS)/_the.$1_headers
   602     endif
   619     endif
   603 
   620 
       
   621     $1_VARDEPS := $$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) $$($1_BIN) $$($1_HEADERS_ARG)
       
   622     $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$($1_BIN)/_the.$1.vardeps)
       
   623 
   604     # When not using sjavac, pass along all sources to javac using an @file.
   624     # When not using sjavac, pass along all sources to javac using an @file.
   605     $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS)
   625     $$($1_BIN)/_the.$1_batch: $$($1_SRCS) $$($1_DEPENDS) $$($1_VARDEPS_FILE)
   606 	$(MKDIR) -p $$(@D)
   626 	$(MKDIR) -p $$(@D)
   607 	$(RM) $$($1_BIN)/_the.$1_batch $$($1_BIN)/_the.$1_batch.tmp
   627 	$(RM) $$($1_BIN)/_the.$1_batch $$($1_BIN)/_the.$1_batch.tmp
   608 	$$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.$1_batch.tmp)
   628 	$$(call ListPathsSafely,$1_SRCS,\n, >> $$($1_BIN)/_the.$1_batch.tmp)
   609 	$(ECHO) Compiling `$(WC) $$($1_BIN)/_the.$1_batch.tmp | $(TR) -s ' ' | $(CUT) -f 2 -d ' '` files for $1
   629 	$(ECHO) Compiling `$(WC) $$($1_BIN)/_the.$1_batch.tmp | $(TR) -s ' ' | $(CUT) -f 2 -d ' '` files for $1
   610 	($$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) \
   630 	($$($1_JVM) $$($1_JAVAC) $$($1_FLAGS) \
   666 # param 2 is the output directory (BIN)
   686 # param 2 is the output directory (BIN)
   667 define SetupJavaCompilationCompileTarget
   687 define SetupJavaCompilationCompileTarget
   668   $(if $(findstring yes, $(ENABLE_SJAVAC)), $(strip $2)/_the.$(strip $1)_pubapi, \
   688   $(if $(findstring yes, $(ENABLE_SJAVAC)), $(strip $2)/_the.$(strip $1)_pubapi, \
   669       $(strip $2)/_the.$(strip $1)_batch)
   689       $(strip $2)/_the.$(strip $1)_batch)
   670 endef
   690 endef
   671 endif
   691 
       
   692 endif # _JAVA_COMPILATION_GMK