make/common/NativeCompilation.gmk
changeset 54422 f562f8318ebd
parent 54380 e297c7bb6469
child 54490 bf07e140c49c
child 57317 c4980b115ead
equal deleted inserted replaced
54421:a7df0de0835a 54422:f562f8318ebd
   229       $$(OUTPUTDIR)/,,$$($1_OBJ))).json
   229       $$(OUTPUTDIR)/,,$$($1_OBJ))).json
   230   $$($1_BASE)_ALL_OBJS_JSON += $$($1_OBJ_JSON)
   230   $$($1_BASE)_ALL_OBJS_JSON += $$($1_OBJ_JSON)
   231 
   231 
   232   # Only continue if this object file hasn't been processed already. This lets
   232   # Only continue if this object file hasn't been processed already. This lets
   233   # the first found source file override any other with the same name.
   233   # the first found source file override any other with the same name.
   234   ifeq ($$(findstring $$($1_OBJ), $$($$($1_BASE)_OBJS_SO_FAR)), )
   234   ifeq ($$($1_OBJ_PROCESSED), )
   235     $$($1_BASE)_OBJS_SO_FAR += $$($1_OBJ)
   235     $1_OBJ_PROCESSED := true
   236     # This is the definite source file to use for $1_FILENAME.
   236     # This is the definite source file to use for $1_FILENAME.
   237     $1_SRC_FILE := $$($1_FILE)
   237     $1_SRC_FILE := $$($1_FILE)
   238 
   238 
   239     ifneq ($$($1_DISABLE_THIS_FILE_DEFINE), true)
   239     ifneq ($$($1_DISABLE_THIS_FILE_DEFINE), true)
   240       $1_THIS_FILE = -DTHIS_FILE='"$$($1_FILENAME)"'
   240       $1_THIS_FILE = -DTHIS_FILE='"$$($1_FILENAME)"'
   306       $$(error Internal error in NativeCompilation.gmk: no compiler for file $$($1_FILENAME))
   306       $$(error Internal error in NativeCompilation.gmk: no compiler for file $$($1_FILENAME))
   307     endif
   307     endif
   308 
   308 
   309     ifeq ($$(filter %.s %.S, $$($1_FILENAME)), )
   309     ifeq ($$(filter %.s %.S, $$($1_FILENAME)), )
   310       # And this is the dependency file for this obj file.
   310       # And this is the dependency file for this obj file.
   311       $1_DEP := $$(patsubst %$(OBJ_SUFFIX),%.d,$$($1_OBJ))
   311       $1_DEPS_FILE := $$(patsubst %$(OBJ_SUFFIX),%.d,$$($1_OBJ))
   312       # The dependency target file lists all dependencies as empty targets to
   312       # The dependency target file lists all dependencies as empty targets to
   313       # avoid make error "No rule to make target" for removed files
   313       # avoid make error "No rule to make target" for removed files
   314       $1_DEP_TARGETS := $$(patsubst %$(OBJ_SUFFIX),%.d.targets,$$($1_OBJ))
   314       $1_DEPS_TARGETS_FILE := $$(patsubst %$(OBJ_SUFFIX),%.d.targets,$$($1_OBJ))
   315 
   315 
   316       # Include previously generated dependency information. (if it exists)
   316       # Only try to load individual dependency information files if the global
   317       -include $$($1_DEP)
   317       # file hasn't been loaded (could happen if make was interrupted).
   318       -include $$($1_DEP_TARGETS)
   318       ifneq ($$($$($1_BASE)_DEPS_FILE_LOADED), true)
       
   319         # Include previously generated dependency information. (if it exists)
       
   320         -include $$($1_DEPS_FILE)
       
   321         -include $$($1_DEPS_TARGETS_FILE)
       
   322       endif
   319     endif
   323     endif
   320 
   324 
   321     ifneq ($$(strip $$($1_CFLAGS) $$($1_CXXFLAGS) $$($1_OPTIMIZATION)), )
   325     ifneq ($$(strip $$($1_CFLAGS) $$($1_CXXFLAGS) $$($1_OPTIMIZATION)), )
   322       $1_VARDEPS := $$($1_CFLAGS) $$($1_CXXFLAGS) $$($1_OPTIMIZATION)
   326       $1_VARDEPS := $$($1_CFLAGS) $$($1_CXXFLAGS) $$($1_OPTIMIZATION)
   323       $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$($1_OBJ).vardeps)
   327       $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$($1_OBJ).vardeps)
   338           ifeq ($(TOOLCHAIN_TYPE)$$(filter %.s, $$($1_FILENAME)), solstudio)
   342           ifeq ($(TOOLCHAIN_TYPE)$$(filter %.s, $$($1_FILENAME)), solstudio)
   339             # The Solaris studio compiler doesn't output the full path to the
   343             # The Solaris studio compiler doesn't output the full path to the
   340             # object file in the generated deps files. Fixing it with sed. If
   344             # object file in the generated deps files. Fixing it with sed. If
   341             # compiling assembly, don't try this.
   345             # compiling assembly, don't try this.
   342 	    $$(call ExecuteWithLog, $$@, \
   346 	    $$(call ExecuteWithLog, $$@, \
   343 	        $$($1_COMPILER) $$($1_DEP_FLAG) $$($1_DEP).tmp $$($1_COMPILE_OPTIONS))
   347 	        $$($1_COMPILER) $$($1_DEP_FLAG) $$($1_DEPS_FILE).tmp $$($1_COMPILE_OPTIONS))
   344 	    $(SED) 's|^$$(@F):|$$@:|' $$($1_DEP).tmp > $$($1_DEP)
   348 	    $(SED) 's|^$$(@F):|$$@:|' $$($1_DEPS_FILE).tmp > $$($1_DEPS_FILE)
   345           else
   349           else
   346 	    $$(call ExecuteWithLog, $$@, \
   350 	    $$(call ExecuteWithLog, $$@, \
   347 	        $$($1_COMPILER) $$($1_DEP_FLAG) $$($1_DEP) $$($1_COMPILE_OPTIONS))
   351 	        $$($1_COMPILER) $$($1_DEP_FLAG) $$($1_DEPS_FILE) $$($1_COMPILE_OPTIONS))
   348           endif
   352           endif
   349           # Create a dependency target file from the dependency file.
   353           # Create a dependency target file from the dependency file.
   350           # Solution suggested by http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
   354           # Solution suggested by http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
   351           ifneq ($$($1_DEP), )
   355           ifneq ($$($1_DEPS_FILE), )
   352 	    $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_DEP) > $$($1_DEP_TARGETS)
   356 	    $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_DEPS_FILE) > $$($1_DEPS_TARGETS_FILE)
   353           endif
   357           endif
   354         else
   358         else
   355           # The Visual Studio compiler lacks a feature for generating make
   359           # The Visual Studio compiler lacks a feature for generating make
   356           # dependencies, but by setting -showIncludes, all included files are
   360           # dependencies, but by setting -showIncludes, all included files are
   357           # printed. These are filtered out and parsed into make dependences.
   361           # printed. These are filtered out and parsed into make dependences.
   361           # pipefail is always active on Windows.
   365           # pipefail is always active on Windows.
   362 	  $$(call ExecuteWithLog, $$@, \
   366 	  $$(call ExecuteWithLog, $$@, \
   363 	      $$($1_COMPILER) -showIncludes $$($1_COMPILE_OPTIONS)) \
   367 	      $$($1_COMPILER) -showIncludes $$($1_COMPILE_OPTIONS)) \
   364 	      | $(TR) -d '\r' | $(GREP) -v -e "^Note: including file:" \
   368 	      | $(TR) -d '\r' | $(GREP) -v -e "^Note: including file:" \
   365 	          -e "^$$($1_FILENAME)$$$$" || test "$$$$?" = "1" ; \
   369 	          -e "^$$($1_FILENAME)$$$$" || test "$$$$?" = "1" ; \
   366 	  $(ECHO) $$@: \\ > $$($1_DEP) ; \
   370 	  $(ECHO) $$@: \\ > $$($1_DEPS_FILE) ; \
   367 	  $(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_OBJ).log \
   371 	  $(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_OBJ).log \
   368 	      | $(SORT) -u >> $$($1_DEP) ; \
   372 	      | $(SORT) -u >> $$($1_DEPS_FILE) ; \
   369 	  $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_DEP) > $$($1_DEP_TARGETS)
   373 	  $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_DEPS_FILE) > $$($1_DEPS_TARGETS_FILE)
   370         endif
   374         endif
   371   endif
   375   endif
   372 endef
   376 endef
   373 
   377 
   374 # Setup make rules for creating a native binary (a shared library or an
   378 # Setup make rules for creating a native binary (a shared library or an
   484   $1_BASENAME := $$($1_PREFIX)$$($1_NAME)$$($1_SUFFIX)
   488   $1_BASENAME := $$($1_PREFIX)$$($1_NAME)$$($1_SUFFIX)
   485   $1_TARGET := $$($1_OUTPUT_DIR)/$$($1_BASENAME)
   489   $1_TARGET := $$($1_OUTPUT_DIR)/$$($1_BASENAME)
   486   $1_NOSUFFIX := $$($1_PREFIX)$$($1_NAME)
   490   $1_NOSUFFIX := $$($1_PREFIX)$$($1_NAME)
   487   $1_SAFE_NAME := $$(strip $$(subst /,_, $1))
   491   $1_SAFE_NAME := $$(strip $$(subst /,_, $1))
   488 
   492 
       
   493 # Need to make sure TARGET is first on list
       
   494   $1 := $$($1_TARGET)
       
   495 
   489   # Setup the toolchain to be used
   496   # Setup the toolchain to be used
   490   $$(call SetIfEmpty, $1_TOOLCHAIN, TOOLCHAIN_DEFAULT)
   497   $$(call SetIfEmpty, $1_TOOLCHAIN, TOOLCHAIN_DEFAULT)
   491   $$(call SetIfEmpty, $1_CC, $$($$($1_TOOLCHAIN)_CC))
   498   $$(call SetIfEmpty, $1_CC, $$($$($1_TOOLCHAIN)_CC))
   492   $$(call SetIfEmpty, $1_CXX, $$($$($1_TOOLCHAIN)_CXX))
   499   $$(call SetIfEmpty, $1_CXX, $$($$($1_TOOLCHAIN)_CXX))
   493   $$(call SetIfEmpty, $1_LD, $$($$($1_TOOLCHAIN)_LD))
   500   $$(call SetIfEmpty, $1_LD, $$($$($1_TOOLCHAIN)_LD))
   717           $1_USE_PCH_FLAGS := -I$$($1_OBJECT_DIR)/precompiled
   724           $1_USE_PCH_FLAGS := -I$$($1_OBJECT_DIR)/precompiled
   718         else ifeq ($(TOOLCHAIN_TYPE), clang)
   725         else ifeq ($(TOOLCHAIN_TYPE), clang)
   719           $1_PCH_FILE := $$($1_OBJECT_DIR)/precompiled/$$(notdir $$($1_PRECOMPILED_HEADER)).pch
   726           $1_PCH_FILE := $$($1_OBJECT_DIR)/precompiled/$$(notdir $$($1_PRECOMPILED_HEADER)).pch
   720           $1_USE_PCH_FLAGS := -include-pch $$($1_PCH_FILE)
   727           $1_USE_PCH_FLAGS := -include-pch $$($1_PCH_FILE)
   721         endif
   728         endif
   722         $1_PCH_DEP := $$($1_PCH_FILE).d
   729         $1_PCH_DEPS_FILE := $$($1_PCH_FILE).d
   723         $1_PCH_DEP_TARGETS := $$($1_PCH_FILE).d.targets
   730         $1_PCH_DEPS_TARGETS_FILE := $$($1_PCH_FILE).d.targets
   724 
   731 
   725         -include $$($1_PCH_DEP)
   732         -include $$($1_PCH_DEPS_FILE)
   726         -include $$($1_PCH_DEP_TARGETS)
   733         -include $$($1_PCH_DEPS_TARGETS_FILE)
   727 
   734 
   728         $1_PCH_COMMAND := $$($1_CC) $$($1_CFLAGS) $$($1_EXTRA_CFLAGS) $$($1_SYSROOT_CFLAGS) \
   735         $1_PCH_COMMAND := $$($1_CC) $$($1_CFLAGS) $$($1_EXTRA_CFLAGS) $$($1_SYSROOT_CFLAGS) \
   729             $$($1_OPT_CFLAGS) -x c++-header -c $(C_FLAG_DEPS) $$($1_PCH_DEP)
   736             $$($1_OPT_CFLAGS) -x c++-header -c $(C_FLAG_DEPS) $$($1_PCH_DEPS_FILE)
   730 
   737 
   731         $$($1_PCH_FILE): $$($1_PRECOMPILED_HEADER) $$($1_COMPILE_VARDEPS_FILE)
   738         $$($1_PCH_FILE): $$($1_PRECOMPILED_HEADER) $$($1_COMPILE_VARDEPS_FILE)
   732 		$$(call LogInfo, Generating precompiled header)
   739 		$$(call LogInfo, Generating precompiled header)
   733 		$$(call MakeDir, $$(@D))
   740 		$$(call MakeDir, $$(@D))
   734 		$$(call ExecuteWithLog, $$@, $$($1_PCH_COMMAND) $$< -o $$@)
   741 		$$(call ExecuteWithLog, $$@, $$($1_PCH_COMMAND) $$< -o $$@)
   735 		$(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_PCH_DEP) > $$($1_PCH_DEP_TARGETS)
   742 		$(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_PCH_DEPS_FILE) \
       
   743 		    > $$($1_PCH_DEPS_TARGETS_FILE)
   736 
   744 
   737         $$($1_ALL_OBJS): $$($1_PCH_FILE)
   745         $$($1_ALL_OBJS): $$($1_PCH_FILE)
   738 
   746 
   739         # Generate the corresponding compile_commands.json fragment.
   747         # Generate the corresponding compile_commands.json fragment.
   740         $1_PCH_FILE_JSON := $$(MAKESUPPORT_OUTPUTDIR)/compile-commands/$$(subst /,_,$$(subst \
   748         $1_PCH_FILE_JSON := $$(MAKESUPPORT_OUTPUTDIR)/compile-commands/$$(subst /,_,$$(subst \
   744         $$($1_PCH_FILE_JSON): $$($1_PRECOMPILED_HEADER) $$($1_COMPILE_VARDEPS_FILE)
   752         $$($1_PCH_FILE_JSON): $$($1_PRECOMPILED_HEADER) $$($1_COMPILE_VARDEPS_FILE)
   745 		$$(call WriteCompileCommandsFragment, $$@, $$(PWD), $$<, \
   753 		$$(call WriteCompileCommandsFragment, $$@, $$(PWD), $$<, \
   746 		    $$($1_PCH_COMMAND) $$< -o $$($1_PCH_FILE))
   754 		    $$($1_PCH_COMMAND) $$< -o $$($1_PCH_FILE))
   747       endif
   755       endif
   748     endif
   756     endif
       
   757   endif
       
   758 
       
   759   # Create a rule to collect all the individual make dependency files into a
       
   760   # single makefile.
       
   761   $1_DEPS_FILE := $$($1_OBJECT_DIR)/$1.d
       
   762 
       
   763   $$($1_DEPS_FILE): $$($1_ALL_OBJS)
       
   764 	$(RM) $$@
       
   765         # CD into dir to reduce risk of hitting command length limits, which
       
   766         # could otherwise happen if TOPDIR is a very long path.
       
   767 	$(CD) $$($1_OBJECT_DIR) && $(CAT) *.d > $$@.tmp
       
   768 	$(CD) $$($1_OBJECT_DIR) && $(CAT) *.d.targets | $(SORT) -u >> $$@.tmp
       
   769         # After generating the file, which happens after all objects have been
       
   770         # compiled, copy it to .old extension. On the next make invocation, this
       
   771         # .old file will be included by make.
       
   772 	$(CP) $$@.tmp $$@.old
       
   773 	$(MV) $$@.tmp $$@
       
   774 
       
   775   $1 += $$($1_DEPS_FILE)
       
   776 
       
   777   # The include must be on the .old file, which represents the state from the
       
   778   # previous invocation of make. The file being included must not have a rule
       
   779   # defined for it as otherwise make will think it has to run the rule before
       
   780   # being able to include the file, which would be wrong since we specifically
       
   781   # need the file as it was generated by a previous make invocation.
       
   782   ifneq ($$(wildcard $$($1_DEPS_FILE).old), )
       
   783     $1_DEPS_FILE_LOADED := true
       
   784     -include $$($1_DEPS_FILE).old
   749   endif
   785   endif
   750 
   786 
   751   # Now call SetupCompileNativeFile for each source file we are going to compile.
   787   # Now call SetupCompileNativeFile for each source file we are going to compile.
   752   $$(foreach file, $$($1_SRCS), \
   788   $$(foreach file, $$($1_SRCS), \
   753       $$(eval $$(call SetupCompileNativeFile, $1_$$(notdir $$(file)),\
   789       $$(eval $$(call SetupCompileNativeFile, $1_$$(notdir $$(file)),\
   772 
   808 
   773   # On windows we need to create a resource file
   809   # On windows we need to create a resource file
   774   ifeq ($(call isTargetOs, windows), true)
   810   ifeq ($(call isTargetOs, windows), true)
   775     ifneq ($$($1_VERSIONINFO_RESOURCE), )
   811     ifneq ($$($1_VERSIONINFO_RESOURCE), )
   776       $1_RES := $$($1_OBJECT_DIR)/$$($1_BASENAME).res
   812       $1_RES := $$($1_OBJECT_DIR)/$$($1_BASENAME).res
   777       $1_RES_DEP := $$($1_RES).d
   813       $1_RES_DEPS_FILE := $$($1_RES).d
   778       $1_RES_DEP_TARGETS := $$($1_RES).d.targets
   814       $1_RES_DEPS_TARGETS_FILE := $$($1_RES).d.targets
   779       -include $$($1_RES_DEP)
   815       -include $$($1_RES_DEPS_FILE)
   780       -include $$($1_RES_DEP_TARGETS)
   816       -include $$($1_RES_DEPS_TARGETS_FILE)
   781 
   817 
   782       $1_RES_VARDEPS := $$($1_RC) $$($1_RC_FLAGS)
   818       $1_RES_VARDEPS := $$($1_RC) $$($1_RC_FLAGS)
   783       $1_RES_VARDEPS_FILE := $$(call DependOnVariable, $1_RES_VARDEPS, \
   819       $1_RES_VARDEPS_FILE := $$(call DependOnVariable, $1_RES_VARDEPS, \
   784           $$($1_RES).vardeps)
   820           $$($1_RES).vardeps)
   785 
   821 
   792                 # Windows RC compiler does not support -showIncludes, so we mis-use CL
   828                 # Windows RC compiler does not support -showIncludes, so we mis-use CL
   793                 # for this. Filter out RC specific arguments that are unknown to CL.
   829                 # for this. Filter out RC specific arguments that are unknown to CL.
   794                 # For some unknown reason, in this case CL actually outputs the show
   830                 # For some unknown reason, in this case CL actually outputs the show
   795                 # includes to stderr so need to redirect it to hide the output from the
   831                 # includes to stderr so need to redirect it to hide the output from the
   796                 # main log.
   832                 # main log.
   797 		$$(call ExecuteWithLog, $$($1_RES_DEP).obj, \
   833 		$$(call ExecuteWithLog, $$($1_RES_DEPS_FILE).obj, \
   798 		    $$($1_CC) $$(filter-out -l%, $$($1_RC_FLAGS)) \
   834 		    $$($1_CC) $$(filter-out -l%, $$($1_RC_FLAGS)) \
   799 		        $$($1_SYSROOT_CFLAGS) -showIncludes -nologo -TC \
   835 		        $$($1_SYSROOT_CFLAGS) -showIncludes -nologo -TC \
   800 		        $(CC_OUT_OPTION)$$($1_RES_DEP).obj -P -Fi$$($1_RES_DEP).pp \
   836 		        $(CC_OUT_OPTION)$$($1_RES_DEPS_FILE).obj -P -Fi$$($1_RES_DEPS_FILE).pp \
   801 		        $$($1_VERSIONINFO_RESOURCE)) 2>&1 \
   837 		        $$($1_VERSIONINFO_RESOURCE)) 2>&1 \
   802 		    | $(TR) -d '\r' | $(GREP) -v -e "^Note: including file:" \
   838 		    | $(TR) -d '\r' | $(GREP) -v -e "^Note: including file:" \
   803 		        -e "^$$(notdir $$($1_VERSIONINFO_RESOURCE))$$$$" || test "$$$$?" = "1" ; \
   839 		        -e "^$$(notdir $$($1_VERSIONINFO_RESOURCE))$$$$" || test "$$$$?" = "1" ; \
   804 		$(ECHO) $$($1_RES): \\ > $$($1_RES_DEP) ; \
   840 		$(ECHO) $$($1_RES): \\ > $$($1_RES_DEPS_FILE) ; \
   805 		$(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_RES_DEP).obj.log >> $$($1_RES_DEP) ; \
   841 		$(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_RES_DEPS_FILE).obj.log \
   806 		$(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_RES_DEP) > $$($1_RES_DEP_TARGETS)
   842 		    >> $$($1_RES_DEPS_FILE) ; \
       
   843 		$(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_RES_DEPS_FILE) \
       
   844 		    > $$($1_RES_DEPS_TARGETS_FILE)
   807     endif
   845     endif
   808   endif
   846   endif
   809 
   847 
   810   ifneq ($(DISABLE_MAPFILES), true)
   848   ifneq ($(DISABLE_MAPFILES), true)
   811     $1_REAL_MAPFILE := $$($1_MAPFILE)
   849     $1_REAL_MAPFILE := $$($1_MAPFILE)
   827   $1_EXTRA_LDFLAGS += $$($1_LDFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS))
   865   $1_EXTRA_LDFLAGS += $$($1_LDFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS))
   828   $1_EXTRA_LIBS += $$($1_LIBS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LIBS_$(OPENJDK_TARGET_OS))
   866   $1_EXTRA_LIBS += $$($1_LIBS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LIBS_$(OPENJDK_TARGET_OS))
   829   ifneq ($$($1_REAL_MAPFILE), )
   867   ifneq ($$($1_REAL_MAPFILE), )
   830     $1_EXTRA_LDFLAGS += $(call SET_SHARED_LIBRARY_MAPFILE,$$($1_REAL_MAPFILE))
   868     $1_EXTRA_LDFLAGS += $(call SET_SHARED_LIBRARY_MAPFILE,$$($1_REAL_MAPFILE))
   831   endif
   869   endif
   832 
       
   833   # Need to make sure TARGET is first on list
       
   834   $1 := $$($1_TARGET)
       
   835 
   870 
   836   ifneq ($$($1_COPY_DEBUG_SYMBOLS), false)
   871   ifneq ($$($1_COPY_DEBUG_SYMBOLS), false)
   837     $1_COPY_DEBUG_SYMBOLS := $(COPY_DEBUG_SYMBOLS)
   872     $1_COPY_DEBUG_SYMBOLS := $(COPY_DEBUG_SYMBOLS)
   838   endif
   873   endif
   839 
   874