1 #
   2 # Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
   3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4 #
   5 # This code is free software; you can redistribute it and/or modify it
   6 # under the terms of the GNU General Public License version 2 only, as
   7 # published by the Free Software Foundation.  Oracle designates this
   8 # particular file as subject to the "Classpath" exception as provided
   9 # by Oracle in the LICENSE file that accompanied this code.
  10 #
  11 # This code is distributed in the hope that it will be useful, but WITHOUT
  12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14 # version 2 for more details (a copy is included in the LICENSE file that
  15 # accompanied this code).
  16 #
  17 # You should have received a copy of the GNU General Public License version
  18 # 2 along with this work; if not, write to the Free Software Foundation,
  19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 #
  21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22 # or visit www.oracle.com if you need additional information or have any
  23 # questions.
  24 #
  25 
  26 # When you read this source. Remember that $(sort ...) has the side effect
  27 # of removing duplicates. It is actually this side effect that is
  28 # desired whenever sort is used below!
  29 
  30 ifndef _NATIVE_COMPILATION_GMK
  31 _NATIVE_COMPILATION_GMK := 1
  32 
  33 ifeq ($(_MAKEBASE_GMK), )
  34   $(error You must include MakeBase.gmk prior to including NativeCompilation.gmk)
  35 endif
  36 
  37 ################################################################################
  38 # Create exported symbols file for static libraries
  39 ################################################################################
  40 
  41 # get the exported symbols from mapfiles and if there
  42 # is no mapfile, get them from the archive
  43 define GetSymbols
  44   $(RM) $$(@D)/$$(basename $$(@F)).symbols; \
  45   if [ ! -z $$($1_MAPFILE) -a -e $$($1_MAPFILE) ]; then \
  46     $(ECHO) "Getting symbols from mapfile $$($1_MAPFILE)"; \
  47     $(AWK) '/global:/','/local:/' $$($1_MAPFILE) | \
  48         $(SED) -e 's/#.*//;s/global://;s/local://;s/\;//;s/^[   ]*/_/;/^_$$$$/d' | \
  49         $(EGREP) -v "JNI_OnLoad|JNI_OnUnload|Agent_OnLoad|Agent_OnUnload|Agent_OnAttach" > \
  50         $$(@D)/$$(basename $$(@F)).symbols || true; \
  51     $(NM) $$($1_TARGET) | $(GREP)  " T " | \
  52         $(EGREP) "JNI_OnLoad|JNI_OnUnload|Agent_OnLoad|Agent_OnUnload|Agent_OnAttach" | \
  53         $(CUT) -d ' ' -f 3 >>  $$(@D)/$$(basename $$(@F)).symbols || true;\
  54   else \
  55     $(ECHO) "Getting symbols from nm"; \
  56     $(NM) -m $$($1_TARGET) | $(GREP)  "__TEXT" | \
  57         $(EGREP) -v "non-external|private extern|__TEXT,__eh_frame" | \
  58         $(SED) -e  's/.* //' > $$(@D)/$$(basename $$(@F)).symbols; \
  59   fi
  60 endef
  61 
  62 ################################################################################
  63 # Creates a recipe that creates a compile_commands.json fragment. Remove any
  64 # occurences of FIXPATH programs from the command to show the actual invocation.
  65 #
  66 # Param 1: Name of file to create
  67 # Param 2: Working directory
  68 # Param 3: Source file
  69 # Param 4: Compile command
  70 ################################################################################
  71 define WriteCompileCommandsFragment
  72   $(call LogInfo, Creating compile commands fragment for $(notdir $3))
  73   $(call MakeDir, $(dir $1))
  74   $(call WriteFile,{ \
  75       "directory": "$(strip $2)"$(COMMA) \
  76       "file": "$(strip $3)"$(COMMA) \
  77       "command": "$(strip $(subst $(DQUOTE),\$(DQUOTE),$(subst \,\\,\
  78         $(subst $(FIXPATH),,$4))))" \
  79     }$(COMMA), \
  80     $1)
  81 endef
  82 
  83 ################################################################################
  84 # Define a native toolchain configuration that can be used by
  85 # SetupNativeCompilation calls
  86 #
  87 # Parameter 1 is the name of the toolchain definition
  88 #
  89 # Remaining parameters are named arguments:
  90 #   EXTENDS - Optional parent definition to get defaults from
  91 #   CC - The C compiler
  92 #   CXX - The C++ compiler
  93 #   LD - The Linker
  94 #   AR - Static linker
  95 #   AS - Assembler
  96 #   MT - Windows MT tool
  97 #   RC - Windows RC tool
  98 #   OBJCOPY - The objcopy tool for debug symbol handling
  99 #   STRIP - The tool to use for stripping debug symbols
 100 #   SYSROOT_CFLAGS - Compiler flags for using the specific sysroot
 101 #   SYSROOT_LDFLAGS - Linker flags for using the specific sysroot
 102 DefineNativeToolchain = $(NamedParamsMacroTemplate)
 103 define DefineNativeToolchainBody
 104   # If extending another definition, get default values from that,
 105   # otherwise, nothing more needs to be done as variable assignments
 106   # already happened in NamedParamsMacroTemplate.
 107   ifneq ($$($1_EXTENDS), )
 108     $$(call SetIfEmpty, $1_CC, $$($$($1_EXTENDS)_CC))
 109     $$(call SetIfEmpty, $1_CXX, $$($$($1_EXTENDS)_CXX))
 110     $$(call SetIfEmpty, $1_LD, $$($$($1_EXTENDS)_LD))
 111     $$(call SetIfEmpty, $1_AR, $$($$($1_EXTENDS)_AR))
 112     $$(call SetIfEmpty, $1_AS, $$($$($1_EXTENDS)_AS))
 113     $$(call SetIfEmpty, $1_MT, $$($$($1_EXTENDS)_MT))
 114     $$(call SetIfEmpty, $1_RC, $$($$($1_EXTENDS)_RC))
 115     $$(call SetIfEmpty, $1_OBJCOPY, $$($$($1_EXTENDS)_OBJCOPY))
 116     $$(call SetIfEmpty, $1_STRIP, $$($$($1_EXTENDS)_STRIP))
 117     $$(call SetIfEmpty, $1_SYSROOT_CFLAGS, $$($$($1_EXTENDS)_SYSROOT_CFLAGS))
 118     $$(call SetIfEmpty, $1_SYSROOT_LDFLAGS, $$($$($1_EXTENDS)_SYSROOT_LDFLAGS))
 119   endif
 120 endef
 121 
 122 # Create a default toolchain with the main compiler and linker
 123 $(eval $(call DefineNativeToolchain, TOOLCHAIN_DEFAULT, \
 124     CC := $(CC), \
 125     CXX := $(CXX), \
 126     LD := $(LD), \
 127     AR := $(AR), \
 128     AS := $(AS), \
 129     MT := $(MT), \
 130     RC := $(RC), \
 131     OBJCOPY := $(OBJCOPY), \
 132     STRIP := $(STRIP), \
 133     SYSROOT_CFLAGS := $(SYSROOT_CFLAGS), \
 134     SYSROOT_LDFLAGS := $(SYSROOT_LDFLAGS), \
 135 ))
 136 
 137 # Create a toolchain where linking is done with the C++ linker
 138 $(eval $(call DefineNativeToolchain, TOOLCHAIN_LINK_CXX, \
 139     EXTENDS := TOOLCHAIN_DEFAULT, \
 140     LD := $(LDCXX), \
 141 ))
 142 
 143 # Create a toolchain with the BUILD compiler, used for build tools that
 144 # are to be run during the build.
 145 $(eval $(call DefineNativeToolchain, TOOLCHAIN_BUILD, \
 146     CC := $(BUILD_CC), \
 147     CXX := $(BUILD_CXX), \
 148     LD := $(BUILD_LD), \
 149     AR := $(BUILD_AR), \
 150     AS := $(BUILD_AS), \
 151     OBJCOPY := $(BUILD_OBJCOPY), \
 152     STRIP := $(BUILD_STRIP), \
 153     SYSROOT_CFLAGS := $(BUILD_SYSROOT_CFLAGS), \
 154     SYSROOT_LDFLAGS := $(BUILD_SYSROOT_LDFLAGS), \
 155 ))
 156 
 157 # BUILD toolchain with the C++ linker
 158 $(eval $(call DefineNativeToolchain, TOOLCHAIN_BUILD_LINK_CXX, \
 159     EXTENDS := TOOLCHAIN_BUILD, \
 160     LD := $(BUILD_LDCXX), \
 161 ))
 162 
 163 ################################################################################
 164 
 165 # Extensions of files handled by this macro.
 166 NATIVE_SOURCE_EXTENSIONS := %.s %.S %.c %.cpp %.cc %.m %.mm
 167 
 168 # Replaces native source extensions with the object file extension in a string.
 169 # Param 1: the string containing source file names with extensions
 170 # The surrounding strip is needed to keep additional whitespace out
 171 define replace_with_obj_extension
 172 $(strip \
 173   $(foreach extension, $(NATIVE_SOURCE_EXTENSIONS), \
 174       $(patsubst $(extension),%$(OBJ_SUFFIX), $(filter $(extension), $1))) \
 175 )
 176 endef
 177 
 178 ifeq ($(call isBuildOsEnv, windows.cygwin), true)
 179   UNIX_PATH_PREFIX := /cygdrive
 180 else ifeq ($(call isBuildOsEnv, windows.msys), true)
 181   UNIX_PATH_PREFIX :=
 182 endif
 183 
 184 # This pattern is used to transform the output of the microsoft CL compiler
 185 # into a make syntax dependency file (.d)
 186 WINDOWS_SHOWINCLUDE_SED_PATTERN := \
 187     -e '/^Note: including file:/!d' \
 188     -e 's|Note: including file: *||' \
 189     -e 's|\r||g' \
 190     -e 's|\\|/|g' \
 191     -e 's|^\([a-zA-Z]\):|$(UNIX_PATH_PREFIX)/\1|g' \
 192     -e '\|$(TOPDIR)|I !d' \
 193     -e 's|$$$$| \\|g' \
 194     #
 195 
 196 # This pattern is used to transform a dependency file (.d) to a list
 197 # of make targets for dependent files (.d.targets)
 198 DEPENDENCY_TARGET_SED_PATTERN := \
 199     -e 's/\#.*//' \
 200     -e 's/^[^:]*: *//' \
 201     -e 's/ *\\$$$$//' \
 202     -e 's/^[     ]*//' \
 203     -e '/^$$$$/ d' \
 204     -e 's/$$$$/ :/' \
 205     #
 206 
 207 ################################################################################
 208 # When absolute paths are not allowed in the output, and the compiler does not
 209 # support any options to avoid it, we need to rewrite compile commands to use
 210 # relative paths. By doing this, the __FILE__ macro will resolve to relative
 211 # paths. The relevant input paths on the command line are the -I flags and the
 212 # path to the source file itself.
 213 #
 214 # The macro MakeCommandRelative is used to rewrite the command line like this:
 215 # 'CD $(WORKSPACE_ROOT) && <cmd>'
 216 # and changes all paths in cmd to be relative to the workspace root. This only
 217 # works properly if the build dir is inside the workspace root. If it's not,
 218 # relative paths are still calculated, but depending on the distance between the
 219 # dirs, paths in the build dir may end up as essentially absolute anyway.
 220 #
 221 # The fix-deps-file macro is used to adjust the contents of the generated make
 222 # dependency files to contain paths compatible with make.
 223 #
 224 ifeq ($(ALLOW_ABSOLUTE_PATHS_IN_OUTPUT)-$(FILE_MACRO_CFLAGS), false-)
 225   # Need to handle -I flags as both '-Ifoo' and '-I foo'.
 226   MakeCommandRelative = \
 227       $(CD) $(WORKSPACE_ROOT) && \
 228       $(foreach o, $1, \
 229         $(if $(filter $(WORKSPACE_ROOT)/% $(OUTPUTDIR)/%, $o), \
 230           $(call RelativePath, $o, $(WORKSPACE_ROOT)) \
 231         , \
 232           $(if $(filter -I$(WORKSPACE_ROOT)/%, $o), \
 233             -I$(call RelativePath, $(patsubst -I%, %, $o), $(WORKSPACE_ROOT)) \
 234           , \
 235             $o \
 236           ) \
 237         ) \
 238       )
 239 
 240   # When compiling with relative paths, the deps file comes out with relative
 241   # paths.
 242   ifeq ($(TOOLCHAIN_TYPE), solstudio)
 243     define fix-deps-file
 244         $(SED) -e 's|\./|$(WORKSPACE_ROOT)/|g' $1.tmp > $1
 245     endef
 246   else
 247     define fix-deps-file
 248         $(SED) -e 's|^\([ ]*\)|\1$(WORKSPACE_ROOT)|' $1.tmp > $1
 249     endef
 250   endif
 251 else
 252   # By default the MakeCommandRelative macro does nothing.
 253   MakeCommandRelative = $1
 254 
 255   # Even with absolute paths on the command line, the Solaris studio compiler
 256   # doesn't output the full path to the object file in the generated deps files.
 257   # For other toolchains, no adjustment is needed.
 258   ifeq ($(TOOLCHAIN_TYPE), solstudio)
 259     define fix-deps-file
 260         $(SED) 's|^$$(@F):|$$@:|' $1.tmp > $1
 261     endef
 262   else
 263     define fix-deps-file
 264         $(MV) $1.tmp $1
 265     endef
 266   endif
 267 endif
 268 
 269 ################################################################################
 270 # Create the recipe needed to compile a single native source file.
 271 #
 272 # Parameter 1 is the name of the rule, based on the name of the library/
 273 # program being build and the name of the source code file, e.g.
 274 # BUILD_LIBFOO_fooMain.cpp.
 275 #
 276 # Remaining parameters are named arguments:
 277 #   FILE - The full path of the source file to compiler
 278 #   BASE - The name of the rule for the entire binary to build ($1)
 279 #
 280 SetupCompileNativeFile = $(NamedParamsMacroTemplate)
 281 define SetupCompileNativeFileBody
 282   $1_FILENAME := $$(notdir $$($1_FILE))
 283 
 284   # The target file to be generated.
 285   $1_OBJ := $$($$($1_BASE)_OBJECT_DIR)/$$(call replace_with_obj_extension, \
 286       $$($1_FILENAME))
 287 
 288   # Generate the corresponding compile_commands.json fragment.
 289   $1_OBJ_JSON = $$(MAKESUPPORT_OUTPUTDIR)/compile-commands/$$(subst /,_,$$(subst \
 290       $$(OUTPUTDIR)/,,$$($1_OBJ))).json
 291   $$($1_BASE)_ALL_OBJS_JSON += $$($1_OBJ_JSON)
 292 
 293   # Only continue if this object file hasn't been processed already. This lets
 294   # the first found source file override any other with the same name.
 295   ifeq ($$($1_OBJ_PROCESSED), )
 296     $1_OBJ_PROCESSED := true
 297     # This is the definite source file to use for $1_FILENAME.
 298     $1_SRC_FILE := $$($1_FILE)
 299 
 300     ifeq ($$($1_OPTIMIZATION), )
 301       $1_OPT_CFLAGS := $$($$($1_BASE)_OPT_CFLAGS)
 302       $1_OPT_CXXFLAGS := $$($$($1_BASE)_OPT_CXXFLAGS)
 303     else
 304       ifeq ($$($1_OPTIMIZATION), NONE)
 305         $1_OPT_CFLAGS := $(C_O_FLAG_NONE)
 306         $1_OPT_CXXFLAGS := $(CXX_O_FLAG_NONE)
 307       else ifeq ($$($1_OPTIMIZATION), LOW)
 308         $1_OPT_CFLAGS := $(C_O_FLAG_NORM)
 309         $1_OPT_CXXFLAGS := $(CXX_O_FLAG_NORM)
 310       else ifeq ($$($1_OPTIMIZATION), HIGH)
 311         $1_OPT_CFLAGS := $(C_O_FLAG_HI)
 312         $1_OPT_CXXFLAGS := $(CXX_O_FLAG_HI)
 313       else ifeq ($$($1_OPTIMIZATION), HIGHEST)
 314         $1_OPT_CFLAGS := $(C_O_FLAG_HIGHEST)
 315         $1_OPT_CXXFLAGS := $(CXX_O_FLAG_HIGHEST)
 316       else ifeq ($$($1_OPTIMIZATION), HIGHEST_JVM)
 317         $1_OPT_CFLAGS := $(C_O_FLAG_HIGHEST_JVM)
 318         $1_OPT_CXXFLAGS := $(CXX_O_FLAG_HIGHEST_JVM)
 319       else ifeq ($$($1_OPTIMIZATION), SIZE)
 320         $1_OPT_CFLAGS := $(C_O_FLAG_SIZE)
 321         $1_OPT_CXXFLAGS := $(CXX_O_FLAG_SIZE)
 322       else
 323         $$(error Unknown value for file OPTIMIZATION: $$($1_OPTIMIZATION))
 324       endif
 325     endif
 326 
 327     ifneq ($$($$($1_BASE)_PRECOMPILED_HEADER), )
 328       ifeq ($$(filter $$($1_FILENAME), $$($$($1_BASE)_PRECOMPILED_HEADER_EXCLUDE)), )
 329         $1_USE_PCH_FLAGS := $$($$($1_BASE)_USE_PCH_FLAGS)
 330       endif
 331     endif
 332 
 333     $1_BASE_CFLAGS :=  $$($$($1_BASE)_CFLAGS) $$($$($1_BASE)_EXTRA_CFLAGS) \
 334         $$($$($1_BASE)_SYSROOT_CFLAGS)
 335     $1_BASE_CXXFLAGS := $$($$($1_BASE)_CXXFLAGS) $$($$($1_BASE)_EXTRA_CXXFLAGS) \
 336         $$($$($1_BASE)_SYSROOT_CFLAGS) $$($1_EXTRA_CXXFLAGS)
 337     $1_BASE_ASFLAGS := $$($$($1_BASE)_ASFLAGS) $$($$($1_BASE)_EXTRA_ASFLAGS)
 338 
 339     ifneq ($$(filter %.c, $$($1_FILENAME)), )
 340       # Compile as a C file
 341       $1_FLAGS := $(CFLAGS_CCACHE) $$($1_USE_PCH_FLAGS) $$($1_BASE_CFLAGS) \
 342           $$($1_OPT_CFLAGS) $$($1_CFLAGS) -c
 343       $1_COMPILER := $$($$($1_BASE)_CC)
 344       $1_DEP_FLAG := $(C_FLAG_DEPS)
 345     else ifneq ($$(filter %.m, $$($1_FILENAME)), )
 346       # Compile as an Objective-C file
 347       $1_FLAGS := -x objective-c $(CFLAGS_CCACHE) $$($1_USE_PCH_FLAGS) \
 348           $$($1_BASE_CFLAGS) $$($1_OPT_CFLAGS) $$($1_CFLAGS) -c
 349       $1_COMPILER := $$($$($1_BASE)_CC)
 350       $1_DEP_FLAG := $(C_FLAG_DEPS)
 351     else ifneq ($$(filter %.s %.S, $$($1_FILENAME)), )
 352       # Compile as assembler file
 353       $1_FLAGS := $$($1_BASE_ASFLAGS)
 354       $1_COMPILER := $(AS)
 355       $1_DEP_FLAG :=
 356     else ifneq ($$(filter %.cpp %.cc %.mm, $$($1_FILENAME)), )
 357       # Compile as a C++ or Objective-C++ file
 358       $1_FLAGS := $(CFLAGS_CCACHE) $$($1_USE_PCH_FLAGS) $$($1_BASE_CXXFLAGS) \
 359           $$($1_OPT_CXXFLAGS) $$($1_CXXFLAGS) -c
 360       $1_COMPILER := $$($$($1_BASE)_CXX)
 361       $1_DEP_FLAG := $(CXX_FLAG_DEPS)
 362     else
 363       $$(error Internal error in NativeCompilation.gmk: no compiler for file $$($1_FILENAME))
 364     endif
 365 
 366     ifeq ($$(filter %.s %.S, $$($1_FILENAME)), )
 367       # And this is the dependency file for this obj file.
 368       $1_DEPS_FILE := $$(patsubst %$(OBJ_SUFFIX),%.d,$$($1_OBJ))
 369       # The dependency target file lists all dependencies as empty targets to
 370       # avoid make error "No rule to make target" for removed files
 371       $1_DEPS_TARGETS_FILE := $$(patsubst %$(OBJ_SUFFIX),%.d.targets,$$($1_OBJ))
 372 
 373       # Only try to load individual dependency information files if the global
 374       # file hasn't been loaded (could happen if make was interrupted).
 375       ifneq ($$($$($1_BASE)_DEPS_FILE_LOADED), true)
 376         # Include previously generated dependency information. (if it exists)
 377         -include $$($1_DEPS_FILE)
 378         -include $$($1_DEPS_TARGETS_FILE)
 379       endif
 380     endif
 381 
 382     ifneq ($$(strip $$($1_CFLAGS) $$($1_CXXFLAGS) $$($1_OPTIMIZATION)), )
 383       $1_VARDEPS := $$($1_CFLAGS) $$($1_CXXFLAGS) $$($1_OPTIMIZATION)
 384       $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, $$($1_OBJ).vardeps)
 385     endif
 386 
 387     $1_OBJ_DEPS := $$($1_SRC_FILE) $$($$($1_BASE)_COMPILE_VARDEPS_FILE) \
 388         $$($$($1_BASE)_EXTRA_DEPS) $$($1_VARDEPS_FILE)
 389     $1_COMPILE_OPTIONS := $$($1_FLAGS) $(CC_OUT_OPTION)$$($1_OBJ) $$($1_SRC_FILE)
 390 
 391     $$($1_OBJ_JSON): $$($1_OBJ_DEPS)
 392         $$(call WriteCompileCommandsFragment, $$@, $$(PWD), $$($1_SRC_FILE), \
 393             $$($1_COMPILER) $$($1_COMPILE_OPTIONS))
 394 
 395     $$($1_OBJ): $$($1_OBJ_DEPS) | $$($$($1_BASE)_BUILD_INFO)
 396         $$(call LogInfo, Compiling $$($1_FILENAME) (for $$($$($1_BASE)_BASENAME)))
 397         $$(call MakeDir, $$(@D))
 398         ifneq ($(TOOLCHAIN_TYPE), microsoft)
 399           $$(call ExecuteWithLog, $$@, $$(call MakeCommandRelative, \
 400               $$($1_COMPILER) $$($1_DEP_FLAG) \
 401               $$(addsuffix .tmp, $$($1_DEPS_FILE)) \
 402               $$($1_COMPILE_OPTIONS)))
 403           ifneq ($$($1_DEPS_FILE), )
 404             $$(call fix-deps-file, $$($1_DEPS_FILE))
 405             # Create a dependency target file from the dependency file.
 406             # Solution suggested by:
 407             # http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
 408             $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_DEPS_FILE) \
 409                 > $$($1_DEPS_TARGETS_FILE)
 410           endif
 411         else
 412           # The Visual Studio compiler lacks a feature for generating make
 413           # dependencies, but by setting -showIncludes, all included files are
 414           # printed. These are filtered out and parsed into make dependences.
 415           #
 416           # Keep as much as possible on one execution line for best performance
 417           # on Windows. No need to save exit code from compilation since
 418           # pipefail is always active on Windows.
 419           $$(call ExecuteWithLog, $$@, $$(call MakeCommandRelative, \
 420               $$($1_COMPILER) -showIncludes $$($1_COMPILE_OPTIONS))) \
 421               | $(TR) -d '\r' | $(GREP) -v -e "^Note: including file:" \
 422                   -e "^$$($1_FILENAME)$$$$" || test "$$$$?" = "1" ; \
 423           $(ECHO) $$@: \\ > $$($1_DEPS_FILE) ; \
 424           $(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_OBJ).log \
 425               | $(SORT) -u >> $$($1_DEPS_FILE) ; \
 426           $(ECHO) >> $$($1_DEPS_FILE) ; \
 427           $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_DEPS_FILE) > $$($1_DEPS_TARGETS_FILE)
 428         endif
 429   endif
 430 endef
 431 
 432 # Setup make rules for creating a native binary (a shared library or an
 433 # executable).
 434 #
 435 # Parameter 1 is the name of the rule. This name is used as variable prefix,
 436 # and the targets generated are listed in a variable by that name.
 437 #
 438 # Remaining parameters are named arguments. These include:
 439 #   NAME The base name for the resulting binary, excluding decorations (like *.exe)
 440 #   TYPE Type of binary (EXECUTABLE, LIBRARY or STATIC_LIBRARY). Default is LIBRARY.
 441 #   SUFFIX Override the default suffix for the output file
 442 #   TOOLCHAIN Name of toolchain setup to use. Defaults to TOOLCHAIN_DEFAULT.
 443 #   SRC one or more directory roots to scan for C/C++ files.
 444 #   CFLAGS the compiler flags to be used, used both for C and C++.
 445 #   CXXFLAGS the compiler flags to be used for c++, if set overrides CFLAGS.
 446 #   LDFLAGS the linker flags to be used, used both for C and C++.
 447 #   LIBS the libraries to link to
 448 #   ARFLAGS the archiver flags to be used
 449 #   OBJECT_DIR the directory where we store the object files
 450 #   OUTPUT_DIR the directory where the resulting binary is put
 451 #   SYMBOLS_DIR the directory where the debug symbols are put, defaults to OUTPUT_DIR
 452 #   INCLUDES only pick source from these directories
 453 #   EXCLUDES do not pick source from these directories
 454 #   INCLUDE_FILES only compile exactly these files!
 455 #   EXCLUDE_FILES with these names
 456 #   EXCLUDE_PATTERN exclude files matching any of these substrings
 457 #   EXTRA_FILES List of extra files not in any of the SRC dirs
 458 #   EXTRA_OBJECT_FILES List of extra object files to include when linking
 459 #   EXTRA_DEPS List of extra dependencies to be added to each compiled file
 460 #   VERSIONINFO_RESOURCE Input file for RC. Setting this implies that RC will be run
 461 #   RC_FLAGS flags for RC.
 462 #   EMBED_MANIFEST if true, embed manifest on Windows.
 463 #   MAPFILE mapfile
 464 #   REORDER reorder file
 465 #   USE_MAPFILE_FOR_SYMBOLS if true and this is a STATIC_BUILD, just copy the
 466 #       mapfile for the output symbols file
 467 #   CC the compiler to use, default is $(CC)
 468 #   LD the linker to use, default is $(LD)
 469 #   OPTIMIZATION sets optimization level to NONE, LOW, HIGH, HIGHEST, HIGHEST_JVM, SIZE
 470 #   DISABLED_WARNINGS_<toolchain> Disable the given warnings for the specified toolchain
 471 #   DISABLED_WARNINGS_C_<toolchain> Disable the given warnings for the specified toolchain
 472 #       when compiling C code
 473 #   DISABLED_WARNINGS_CXX_<toolchain> Disable the given warnings for the specified
 474 #       toolchain when compiling C++ code
 475 #   STRIP_SYMBOLS Set to false to override global strip policy and always leave
 476 #       symbols in the binary, if the toolchain allows for it
 477 #   DEBUG_SYMBOLS Set to false to disable generation of debug symbols
 478 #   COPY_DEBUG_SYMBOLS Set to false to override global setting of debug symbol copying
 479 #   ZIP_EXTERNAL_DEBUG_SYMBOLS Set to false to override global setting of debug symbol
 480 #       zipping
 481 #   STRIPFLAGS Optionally change the flags given to the strip command
 482 #   PRECOMPILED_HEADER Header file to use as precompiled header
 483 #   PRECOMPILED_HEADER_EXCLUDE List of source files that should not use PCH
 484 #
 485 # After being called, some variables are exported from this macro, all prefixed
 486 # with parameter 1 followed by a '_':
 487 #   TARGET The library or executable created by the macro
 488 #   TARGET_DEPS All prerequisites for the target calculated by the macro
 489 #   ALL_OBJS All object files
 490 #   IMPORT_LIBRARY The import library created for a shared library on Windows
 491 SetupNativeCompilation = $(NamedParamsMacroTemplate)
 492 define SetupNativeCompilationBody
 493 
 494   # If type is unspecified, default to LIBRARY
 495   ifeq ($$($1_TYPE), )
 496     $1_TYPE := LIBRARY
 497   endif
 498 
 499   # If we're doing a static build and producing a library
 500   # force it to be a static library and remove the -l libraries
 501   ifeq ($(STATIC_BUILD), true)
 502     ifeq ($$($1_TYPE), LIBRARY)
 503       $1_TYPE := STATIC_LIBRARY
 504     endif
 505   endif
 506 
 507   $$(call SetIfEmpty, $1_COMPILE_WITH_DEBUG_SYMBOLS, $$(COMPILE_WITH_DEBUG_SYMBOLS))
 508 
 509   # STATIC_LIBS is set from Main.gmk when building static versions of certain
 510   # native libraries.
 511   ifeq ($(STATIC_LIBS), true)
 512     $1_TYPE := STATIC_LIBRARY
 513     # The static versions need to be redirected to different output dirs, both
 514     # to not interfere with the main build as well as to not end up inside the
 515     # jmods.
 516     $1_OBJECT_DIR := $$($1_OBJECT_DIR)/static
 517     $1_OUTPUT_DIR := $$($1_OBJECT_DIR)
 518     # For release builds where debug symbols are configured to be moved to
 519     # separate debuginfo files, disable debug symbols for static libs instead.
 520     # We don't currently support this configuration and we don't want symbol
 521     # information in release builds unless explicitly asked to provide it.
 522     ifeq ($(DEBUG_LEVEL), release)
 523       ifeq ($(COPY_DEBUG_SYMBOLS), true)
 524         $1_COMPILE_WITH_DEBUG_SYMBOLS := false
 525       endif
 526     endif
 527   endif
 528 
 529   ifeq ($$($1_TYPE), EXECUTABLE)
 530     $1_PREFIX :=
 531     ifeq ($$($1_SUFFIX), )
 532       $1_SUFFIX := $(EXE_SUFFIX)
 533     endif
 534   else
 535     $1_PREFIX := $(LIBRARY_PREFIX)
 536     ifeq ($$($1_TYPE), LIBRARY)
 537       ifeq ($$($1_SUFFIX), )
 538         $1_SUFFIX := $(SHARED_LIBRARY_SUFFIX)
 539       endif
 540     else ifeq ($$($1_TYPE), STATIC_LIBRARY)
 541       ifeq ($$($1_SUFFIX), )
 542         $1_SUFFIX := $(STATIC_LIBRARY_SUFFIX)
 543       endif
 544     endif
 545   endif
 546 
 547   ifneq ($$($1_NAME), $(basename $$($1_NAME)))
 548     $$(error NAME must not contain any directory path in $1)
 549   endif
 550   ifneq ($(findstring $$($1_SUFFIX), $$($1_NAME)), )
 551     $$(error NAME should be specified without suffix: $$($1_SUFFIX) in $1)
 552   endif
 553   ifneq ($(findstring $$($1_PREFIX), $$($1_NAME)), )
 554     $$(error NAME should be specified without prefix: $$($1_PREFIX) in $1)
 555   endif
 556   ifeq ($$($1_OUTPUT_DIR), )
 557     $$(error OUTPUT_DIR is missing in $1)
 558   endif
 559   ifneq ($$($1_MANIFEST), )
 560     ifeq ($$($1_MANIFEST_VERSION), )
 561       $$(error If MANIFEST is provided, then MANIFEST_VERSION is required in $1)
 562     endif
 563   endif
 564 
 565   $1_BASENAME := $$($1_PREFIX)$$($1_NAME)$$($1_SUFFIX)
 566   $1_TARGET := $$($1_OUTPUT_DIR)/$$($1_BASENAME)
 567   $1_NOSUFFIX := $$($1_PREFIX)$$($1_NAME)
 568   $1_SAFE_NAME := $$(strip $$(subst /,_, $1))
 569 
 570 # Need to make sure TARGET is first on list
 571   $1 := $$($1_TARGET)
 572 
 573   # Setup the toolchain to be used
 574   $$(call SetIfEmpty, $1_TOOLCHAIN, TOOLCHAIN_DEFAULT)
 575   $$(call SetIfEmpty, $1_CC, $$($$($1_TOOLCHAIN)_CC))
 576   $$(call SetIfEmpty, $1_CXX, $$($$($1_TOOLCHAIN)_CXX))
 577   $$(call SetIfEmpty, $1_LD, $$($$($1_TOOLCHAIN)_LD))
 578   $$(call SetIfEmpty, $1_AR, $$($$($1_TOOLCHAIN)_AR))
 579   $$(call SetIfEmpty, $1_AS, $$($$($1_TOOLCHAIN)_AS))
 580   $$(call SetIfEmpty, $1_MT, $$($$($1_TOOLCHAIN)_MT))
 581   $$(call SetIfEmpty, $1_RC, $$($$($1_TOOLCHAIN)_RC))
 582   $$(call SetIfEmpty, $1_OBJCOPY, $$($$($1_TOOLCHAIN)_OBJCOPY))
 583   $$(call SetIfEmpty, $1_STRIP, $$($$($1_TOOLCHAIN)_STRIP))
 584   $$(call SetIfEmpty, $1_SYSROOT_CFLAGS, $$($$($1_TOOLCHAIN)_SYSROOT_CFLAGS))
 585   $$(call SetIfEmpty, $1_SYSROOT_LDFLAGS, $$($$($1_TOOLCHAIN)_SYSROOT_LDFLAGS))
 586 
 587   $$(foreach d, $$($1_SRC), $$(if $$(wildcard $$d), , \
 588       $$(error SRC specified to SetupNativeCompilation $1 contains missing directory $$d)))
 589 
 590   $1_SRCS_RAW := $$(call FindFiles, $$($1_SRC))
 591   # Order src files according to the order of the src dirs
 592   $1_SRCS := $$(foreach d, $$($1_SRC), $$(filter $$d%, $$($1_SRCS_RAW)))
 593   $1_SRCS := $$(filter $$(NATIVE_SOURCE_EXTENSIONS), $$($1_SRCS))
 594   # Extract the C/C++ files.
 595   ifneq ($$($1_EXCLUDE_PATTERNS), )
 596     # We must not match the exclude pattern against the src root(s).
 597     $1_SRCS_WITHOUT_ROOTS := $$($1_SRCS)
 598     $$(foreach i, $$($1_SRC), $$(eval $1_SRCS_WITHOUT_ROOTS := $$(patsubst \
 599         $$i/%,%, $$($1_SRCS_WITHOUT_ROOTS))))
 600     $1_ALL_EXCLUDE_FILES :=  $$(call containing, $$($1_EXCLUDE_PATTERNS), \
 601         $$($1_SRCS_WITHOUT_ROOTS))
 602   endif
 603   ifneq ($$($1_EXCLUDE_FILES), )
 604     $1_ALL_EXCLUDE_FILES += $$($1_EXCLUDE_FILES)
 605   endif
 606   ifneq ($$($1_ALL_EXCLUDE_FILES), )
 607     $1_EXCLUDE_FILES_PAT := $$($1_ALL_EXCLUDE_FILES) \
 608         $$(foreach i, $$($1_SRC), $$(addprefix $$i/, $$($1_ALL_EXCLUDE_FILES)))
 609     $1_EXCLUDE_FILES_PAT := $$(addprefix %, $$($1_EXCLUDE_FILES_PAT))
 610     $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES_PAT), $$($1_SRCS))
 611   endif
 612   ifneq ($$($1_INCLUDE_FILES), )
 613     $1_INCLUDE_FILES_PAT := $$(foreach i, $$($1_SRC), $$(addprefix $$i/, $$($1_INCLUDE_FILES)))
 614     $1_SRCS := $$(filter $$($1_INCLUDE_FILES_PAT), $$($1_SRCS))
 615   endif
 616   # There can be only a single bin dir root, no need to foreach over the roots.
 617   $1_BINS := $$(wildcard $$($1_OBJECT_DIR)/*$(OBJ_SUFFIX))
 618   # Now we have a list of all c/c++ files to compile: $$($1_SRCS)
 619   # and we have a list of all existing object files: $$($1_BINS)
 620 
 621   # Prepend the source/bin path to the filter expressions. Then do the filtering.
 622   ifneq ($$($1_INCLUDES), )
 623     $1_SRC_INCLUDES := $$(foreach i, $$($1_SRC), $$(addprefix $$i/, $$(addsuffix /%, $$($1_INCLUDES))))
 624     $1_SRCS := $$(filter $$($1_SRC_INCLUDES), $$($1_SRCS))
 625   endif
 626   ifneq ($$($1_EXCLUDES), )
 627     $1_SRC_EXCLUDES := $$(addsuffix /%, $$($1_EXCLUDES))
 628     $1_SRC_EXCLUDES += $$(foreach i, $$($1_SRC), $$(addprefix $$i/, $$(addsuffix /%, $$($1_EXCLUDES))))
 629     $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES), $$($1_SRCS))
 630   endif
 631 
 632   $1_SRCS += $$($1_EXTRA_FILES)
 633 
 634   ifeq ($$($1_SRCS), )
 635     $$(error No sources found for $1 when looking inside the dirs $$($1_SRC))
 636   endif
 637 
 638   # Calculate the expected output from compiling the sources
 639   $1_EXPECTED_OBJS_FILENAMES := $$(call replace_with_obj_extension, $$(notdir $$($1_SRCS)))
 640   $1_EXPECTED_OBJS := $$(addprefix $$($1_OBJECT_DIR)/, $$($1_EXPECTED_OBJS_FILENAMES))
 641   # Are there too many object files on disk? Perhaps because some source file was removed?
 642   $1_SUPERFLOUS_OBJS := $$(sort $$(filter-out $$($1_EXPECTED_OBJS), $$($1_BINS)))
 643   # Clean out the superfluous object files.
 644   ifneq ($$($1_SUPERFLUOUS_OBJS), )
 645     $$(shell $(RM) -f $$($1_SUPERFLUOUS_OBJS))
 646   endif
 647   # Sort to remove dupliates and provide a reproducable order on the input files to the linker.
 648   $1_ALL_OBJS := $$(sort $$($1_EXPECTED_OBJS) $$($1_EXTRA_OBJECT_FILES))
 649 
 650   # Pickup extra OPENJDK_TARGET_OS_TYPE, OPENJDK_TARGET_OS, and/or OPENJDK_TARGET_OS plus
 651   # OPENJDK_TARGET_CPU pair dependent variables for CFLAGS.
 652   $1_EXTRA_CFLAGS := $$($1_CFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_CFLAGS_$(OPENJDK_TARGET_OS)) \
 653       $$($1_CFLAGS_$(OPENJDK_TARGET_OS)_$(OPENJDK_TARGET_CPU))
 654   ifneq ($(DEBUG_LEVEL), release)
 655     # Pickup extra debug dependent variables for CFLAGS
 656     $1_EXTRA_CFLAGS += $$($1_CFLAGS_debug)
 657     $1_EXTRA_CFLAGS += $$($1_CFLAGS_$(OPENJDK_TARGET_OS_TYPE)_debug)
 658     $1_EXTRA_CFLAGS += $$($1_CFLAGS_$(OPENJDK_TARGET_OS)_debug)
 659     $1_EXTRA_CFLAGS += $$($1_CFLAGS_$(OPENJDK_TARGET_OS)_$(OPENJDK_TARGET_CPU)_debug)
 660   else
 661     $1_EXTRA_CFLAGS += $$($1_CFLAGS_release)
 662     $1_EXTRA_CFLAGS += $$($1_CFLAGS_$(OPENJDK_TARGET_OS_TYPE)_release)
 663     $1_EXTRA_CFLAGS += $$($1_CFLAGS_$(OPENJDK_TARGET_OS)_release)
 664     $1_EXTRA_CFLAGS += $$($1_CFLAGS_$(OPENJDK_TARGET_OS)_$(OPENJDK_TARGET_CPU)_release)
 665   endif
 666   ifeq ($(STATIC_LIBS), true)
 667     $1_EXTRA_CFLAGS += $$(STATIC_LIBS_CFLAGS)
 668   endif
 669 
 670   # Pickup extra OPENJDK_TARGET_OS_TYPE and/or OPENJDK_TARGET_OS dependent variables for CXXFLAGS.
 671   $1_EXTRA_CXXFLAGS := $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS))
 672   ifneq ($(DEBUG_LEVEL), release)
 673     # Pickup extra debug dependent variables for CXXFLAGS
 674     $1_EXTRA_CXXFLAGS += $$($1_CXXFLAGS_debug)
 675     $1_EXTRA_CXXFLAGS += $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_TYPE)_debug)
 676     $1_EXTRA_CXXFLAGS += $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)_debug)
 677   else
 678     $1_EXTRA_CXXFLAGS += $$($1_CXXFLAGS_release)
 679     $1_EXTRA_CXXFLAGS += $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_TYPE)_release)
 680     $1_EXTRA_CXXFLAGS += $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)_release)
 681   endif
 682   ifeq ($(STATIC_LIBS), true)
 683     $1_EXTRA_CXXFLAGS += $$(STATIC_LIB_CFLAGS)
 684   endif
 685 
 686   # If no C++ flags are explicitly set, default to using the C flags.
 687   # After that, we can set additional C++ flags that should not interfere
 688   # with the mechanism for copying the C flags by default.
 689   ifeq ($$($1_CXXFLAGS), )
 690     $1_CXXFLAGS := $$($1_CFLAGS)
 691   endif
 692   ifeq ($$(strip $$($1_EXTRA_CXXFLAGS)), )
 693     $1_EXTRA_CXXFLAGS := $$($1_EXTRA_CFLAGS)
 694   endif
 695 
 696   ifeq ($$($1_COMPILE_WITH_DEBUG_SYMBOLS), true)
 697     $1_EXTRA_CFLAGS += $$(CFLAGS_DEBUG_SYMBOLS)
 698     $1_EXTRA_CXXFLAGS += $$(CFLAGS_DEBUG_SYMBOLS)
 699     $1_EXTRA_ASFLAGS += $$(ASFLAGS_DEBUG_SYMBOLS)
 700   endif
 701 
 702   ifneq ($$($1_REORDER), )
 703     $1_EXTRA_CFLAGS += $$(C_FLAG_REORDER)
 704     $1_EXTRA_CXXFLAGS += $$(C_FLAG_REORDER)
 705   endif
 706 
 707   # Pass the library name for static JNI library naming
 708   ifeq ($$($1_TYPE), STATIC_LIBRARY)
 709     $1_EXTRA_CFLAGS += -DLIBRARY_NAME=$$($1_NAME)
 710     $1_EXTRA_CXXFLAGS += -DLIBRARY_NAME=$$($1_NAME)
 711   endif
 712 
 713   # Pick up disabled warnings, if possible on this platform.
 714   ifneq ($(DISABLE_WARNING_PREFIX), )
 715     $1_EXTRA_CFLAGS += $$(addprefix $(DISABLE_WARNING_PREFIX), \
 716         $$(DISABLED_WARNINGS) \
 717         $$(DISABLED_WARNINGS_C) \
 718         $$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)) \
 719         $$($1_DISABLED_WARNINGS_C_$(TOOLCHAIN_TYPE)))
 720     $1_EXTRA_CXXFLAGS += $$(addprefix $(DISABLE_WARNING_PREFIX), \
 721         $$(DISABLED_WARNINGS) \
 722         $$(DISABLED_WARNINGS_CXX) \
 723         $$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)) \
 724         $$($1_DISABLED_WARNINGS_CXX_$(TOOLCHAIN_TYPE)))
 725   endif
 726 
 727   # Check if warnings should be considered errors.
 728   # Pick first binary and toolchain specific, then binary specific, then general setting.
 729   ifeq ($$($1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE)), )
 730     ifeq ($$($1_WARNINGS_AS_ERRORS), )
 731       $1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE) := $$(WARNINGS_AS_ERRORS)
 732     else
 733       $1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE) := $$($1_WARNINGS_AS_ERRORS)
 734     endif
 735   endif
 736 
 737   ifeq ($$($1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE)), true)
 738     $1_EXTRA_CFLAGS += $(CFLAGS_WARNINGS_ARE_ERRORS)
 739     $1_EXTRA_CXXFLAGS += $(CFLAGS_WARNINGS_ARE_ERRORS)
 740     $1_EXTRA_LDFLAGS += $(LDFLAGS_WARNINGS_ARE_ERRORS)
 741   endif
 742 
 743   ifeq (NONE, $$($1_OPTIMIZATION))
 744     $1_OPT_CFLAGS := $(C_O_FLAG_NONE)
 745     $1_OPT_CXXFLAGS := $(CXX_O_FLAG_NONE)
 746   else ifeq (LOW, $$($1_OPTIMIZATION))
 747     $1_OPT_CFLAGS := $(C_O_FLAG_NORM)
 748     $1_OPT_CXXFLAGS := $(CXX_O_FLAG_NORM)
 749   else ifeq (HIGH, $$($1_OPTIMIZATION))
 750     $1_OPT_CFLAGS := $(C_O_FLAG_HI)
 751     $1_OPT_CXXFLAGS := $(CXX_O_FLAG_HI)
 752   else ifeq (HIGHEST, $$($1_OPTIMIZATION))
 753     $1_OPT_CFLAGS := $(C_O_FLAG_HIGHEST)
 754     $1_OPT_CXXFLAGS := $(CXX_O_FLAG_HIGHEST)
 755   else ifeq (HIGHEST_JVM, $$($1_OPTIMIZATION))
 756     $1_OPT_CFLAGS := $(C_O_FLAG_HIGHEST_JVM)
 757     $1_OPT_CXXFLAGS := $(CXX_O_FLAG_HIGHEST_JVM)
 758   else ifeq (SIZE, $$($1_OPTIMIZATION))
 759     $1_OPT_CFLAGS := $(C_O_FLAG_SIZE)
 760     $1_OPT_CXXFLAGS := $(CXX_O_FLAG_SIZE)
 761   else ifneq (, $$($1_OPTIMIZATION))
 762     $$(error Unknown value for OPTIMIZATION: $$($1_OPTIMIZATION))
 763   endif
 764 
 765   $1_BUILD_INFO := $$($1_OBJECT_DIR)/_build-info.marker
 766 
 767   # Track variable changes for all variables that affect the compilation command
 768   # lines for all object files in this setup. This includes at least all the
 769   # variables used in the call to add_native_source below.
 770   $1_COMPILE_VARDEPS := $$($1_CFLAGS) $$($1_EXTRA_CFLAGS) $$($1_SYSROOT_CFLAGS) \
 771       $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS) $$($1_OPT_CFLAGS) $$($1_OPT_CXXFLAGS) \
 772       $$($1_CC) $$($1_CXX) $$($1_AS) $$($1_ASFLAGS)
 773   $1_COMPILE_VARDEPS_FILE := $$(call DependOnVariable, $1_COMPILE_VARDEPS, \
 774       $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).comp.vardeps)
 775 
 776   ifneq ($$($1_PRECOMPILED_HEADER), )
 777     ifeq ($(USE_PRECOMPILED_HEADER), true)
 778       ifeq ($(TOOLCHAIN_TYPE), microsoft)
 779         $1_PCH_FILE := $$($1_OBJECT_DIR)/$1.pch
 780         $1_GENERATED_PCH_SRC := $$($1_OBJECT_DIR)/$1_pch.cpp
 781         $1_GENERATED_PCH_OBJ := $$($1_OBJECT_DIR)/$1_pch.obj
 782 
 783         $$(eval $$(call SetupCompileNativeFile, $1_$$(notdir $$($1_GENERATED_PCH_SRC)), \
 784             FILE := $$($1_GENERATED_PCH_SRC), \
 785             BASE := $1, \
 786             EXTRA_CXXFLAGS := -Fp$$($1_PCH_FILE) -Yc$$(notdir $$($1_PRECOMPILED_HEADER)), \
 787         ))
 788 
 789         $1_USE_PCH_FLAGS := \
 790             -Fp$$($1_PCH_FILE) -Yu$$(notdir $$($1_PRECOMPILED_HEADER))
 791 
 792         $$($1_ALL_OBJS): $$($1_GENERATED_PCH_OBJ)
 793 
 794         # Explicitly add the pch obj file first to ease comparing to old
 795         # hotspot build.
 796         $1_ALL_OBJS := $$($1_GENERATED_PCH_OBJ) $$($1_ALL_OBJS)
 797 
 798         $$($1_GENERATED_PCH_SRC):
 799                 $(ECHO) "#include \"$$(notdir $$($1_PRECOMPILED_HEADER))\"" > $$@
 800 
 801       else ifneq ($(findstring $(TOOLCHAIN_TYPE), gcc clang), )
 802         ifeq ($(TOOLCHAIN_TYPE), gcc)
 803           $1_PCH_FILE := $$($1_OBJECT_DIR)/precompiled/$$(notdir $$($1_PRECOMPILED_HEADER)).gch
 804           $1_USE_PCH_FLAGS := -I$$($1_OBJECT_DIR)/precompiled
 805         else ifeq ($(TOOLCHAIN_TYPE), clang)
 806           $1_PCH_FILE := $$($1_OBJECT_DIR)/precompiled/$$(notdir $$($1_PRECOMPILED_HEADER)).pch
 807           $1_USE_PCH_FLAGS := -include-pch $$($1_PCH_FILE)
 808         endif
 809         $1_PCH_DEPS_FILE := $$($1_PCH_FILE).d
 810         $1_PCH_DEPS_TARGETS_FILE := $$($1_PCH_FILE).d.targets
 811 
 812         -include $$($1_PCH_DEPS_FILE)
 813         -include $$($1_PCH_DEPS_TARGETS_FILE)
 814 
 815         $1_PCH_COMMAND := $$($1_CC) $$($1_CFLAGS) $$($1_EXTRA_CFLAGS) $$($1_SYSROOT_CFLAGS) \
 816             $$($1_OPT_CFLAGS) -x c++-header -c $(C_FLAG_DEPS) $$($1_PCH_DEPS_FILE)
 817 
 818         $$($1_PCH_FILE): $$($1_PRECOMPILED_HEADER) $$($1_COMPILE_VARDEPS_FILE)
 819                 $$(call LogInfo, Generating precompiled header)
 820                 $$(call MakeDir, $$(@D))
 821                 $$(call ExecuteWithLog, $$@, $$(call MakeCommandRelative, \
 822                     $$($1_PCH_COMMAND) $$< -o $$@))
 823                 $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_PCH_DEPS_FILE) \
 824                     > $$($1_PCH_DEPS_TARGETS_FILE)
 825 
 826         $$($1_ALL_OBJS): $$($1_PCH_FILE)
 827 
 828         # Generate the corresponding compile_commands.json fragment.
 829         $1_PCH_FILE_JSON := $$(MAKESUPPORT_OUTPUTDIR)/compile-commands/$$(subst /,_,$$(subst \
 830             $$(OUTPUTDIR)/,,$$($1_PCH_FILE))).json
 831         $1_ALL_OBJS_JSON += $$($1_PCH_FILE_JSON)
 832 
 833         $$($1_PCH_FILE_JSON): $$($1_PRECOMPILED_HEADER) $$($1_COMPILE_VARDEPS_FILE)
 834                 $$(call WriteCompileCommandsFragment, $$@, $$(PWD), $$<, \
 835                     $$($1_PCH_COMMAND) $$< -o $$($1_PCH_FILE))
 836       endif
 837     endif
 838   endif
 839 
 840   # Now call SetupCompileNativeFile for each source file we are going to compile.
 841   $$(foreach file, $$($1_SRCS), \
 842       $$(eval $$(call SetupCompileNativeFile, $1_$$(notdir $$(file)),\
 843           FILE := $$(file), \
 844           BASE := $1, \
 845       )) \
 846   )
 847 
 848   # Setup rule for printing progress info when compiling source files.
 849   # This is a rough heuristic and may not always print accurate information.
 850   $$($1_BUILD_INFO): $$($1_SRCS) $$($1_COMPILE_VARDEPS_FILE)
 851         ifeq ($$(wildcard $$($1_TARGET)), )
 852           $$(call LogWarn, Creating $$(subst $$(OUTPUTDIR)/,,$$($1_TARGET)) from $$(words \
 853               $$(filter-out %.vardeps, $$?)) file(s))
 854         else
 855           $$(call LogWarn, $$(strip Updating $$(subst $$(OUTPUTDIR)/,,$$($1_TARGET)) \
 856               $$(if $$(filter-out %.vardeps, $$?), \
 857                 due to $$(words $$(filter-out %.vardeps, $$?)) file(s), \
 858               $$(if $$(filter %.vardeps, $$?), due to makefile changes))))
 859         endif
 860         $(TOUCH) $$@
 861 
 862   # On windows we need to create a resource file
 863   ifeq ($(call isTargetOs, windows), true)
 864     ifneq ($$($1_VERSIONINFO_RESOURCE), )
 865       $1_RES := $$($1_OBJECT_DIR)/$$($1_BASENAME).res
 866       $1_RES_DEPS_FILE := $$($1_RES).d
 867       $1_RES_DEPS_TARGETS_FILE := $$($1_RES).d.targets
 868       -include $$($1_RES_DEPS_FILE)
 869       -include $$($1_RES_DEPS_TARGETS_FILE)
 870 
 871       $1_RES_VARDEPS := $$($1_RC) $$($1_RC_FLAGS)
 872       $1_RES_VARDEPS_FILE := $$(call DependOnVariable, $1_RES_VARDEPS, \
 873           $$($1_RES).vardeps)
 874 
 875       $$($1_RES): $$($1_VERSIONINFO_RESOURCE) $$($1_RES_VARDEPS_FILE)
 876                 $$(call LogInfo, Compiling resource $$(notdir $$($1_VERSIONINFO_RESOURCE)) (for $$($1_BASENAME)))
 877                 $$(call MakeDir, $$(@D) $$($1_OBJECT_DIR))
 878                 $$(call ExecuteWithLog, $$@, $$(call MakeCommandRelative, \
 879                     $$($1_RC) $$($1_RC_FLAGS) $$($1_SYSROOT_CFLAGS) $(CC_OUT_OPTION)$$@ \
 880                     $$($1_VERSIONINFO_RESOURCE) 2>&1 ))
 881                 # Windows RC compiler does not support -showIncludes, so we mis-use CL
 882                 # for this. Filter out RC specific arguments that are unknown to CL.
 883                 # For some unknown reason, in this case CL actually outputs the show
 884                 # includes to stderr so need to redirect it to hide the output from the
 885                 # main log.
 886                 $$(call ExecuteWithLog, $$($1_RES_DEPS_FILE).obj, \
 887                     $$($1_CC) $$(filter-out -l%, $$($1_RC_FLAGS)) \
 888                         $$($1_SYSROOT_CFLAGS) -showIncludes -nologo -TC \
 889                         $(CC_OUT_OPTION)$$($1_RES_DEPS_FILE).obj -P -Fi$$($1_RES_DEPS_FILE).pp \
 890                         $$($1_VERSIONINFO_RESOURCE)) 2>&1 \
 891                     | $(TR) -d '\r' | $(GREP) -v -e "^Note: including file:" \
 892                         -e "^$$(notdir $$($1_VERSIONINFO_RESOURCE))$$$$" || test "$$$$?" = "1" ; \
 893                 $(ECHO) $$($1_RES): \\ > $$($1_RES_DEPS_FILE) ; \
 894                 $(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_RES_DEPS_FILE).obj.log \
 895                     >> $$($1_RES_DEPS_FILE) ; \
 896                 $(ECHO) >> $$($1_RES_DEPS_FILE) ;\
 897                 $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_RES_DEPS_FILE) \
 898                     > $$($1_RES_DEPS_TARGETS_FILE)
 899     endif
 900   endif
 901 
 902   # Create a rule to collect all the individual make dependency files into a
 903   # single makefile.
 904   $1_DEPS_FILE := $$($1_OBJECT_DIR)/$1.d
 905 
 906   $$($1_DEPS_FILE): $$($1_ALL_OBJS) $$($1_RES)
 907         $(RM) $$@
 908         # CD into dir to reduce risk of hitting command length limits, which
 909         # could otherwise happen if TOPDIR is a very long path.
 910         $(CD) $$($1_OBJECT_DIR) && $(CAT) *.d > $$@.tmp
 911         $(CD) $$($1_OBJECT_DIR) && $(CAT) *.d.targets | $(SORT) -u >> $$@.tmp
 912         # After generating the file, which happens after all objects have been
 913         # compiled, copy it to .old extension. On the next make invocation, this
 914         # .old file will be included by make.
 915         $(CP) $$@.tmp $$@.old
 916         $(MV) $$@.tmp $$@
 917 
 918   $1 += $$($1_DEPS_FILE)
 919 
 920   # The include must be on the .old file, which represents the state from the
 921   # previous invocation of make. The file being included must not have a rule
 922   # defined for it as otherwise make will think it has to run the rule before
 923   # being able to include the file, which would be wrong since we specifically
 924   # need the file as it was generated by a previous make invocation.
 925   ifneq ($$(wildcard $$($1_DEPS_FILE).old), )
 926     $1_DEPS_FILE_LOADED := true
 927     -include $$($1_DEPS_FILE).old
 928   endif
 929 
 930   ifneq ($(DISABLE_MAPFILES), true)
 931     $1_REAL_MAPFILE := $$($1_MAPFILE)
 932     ifeq ($(call isTargetOs, windows), false)
 933       ifneq ($$($1_REORDER), )
 934         $1_REAL_MAPFILE := $$($1_OBJECT_DIR)/mapfile
 935 
 936         $$($1_REAL_MAPFILE) : $$($1_MAPFILE) $$($1_REORDER)
 937                 $$(call MakeDir, $$(@D))
 938                 $$(CP) $$($1_MAPFILE) $$@.tmp
 939                 $$(SED) -e 's=OUTPUTDIR=$$($1_OBJECT_DIR)=' $$($1_REORDER) >> $$@.tmp
 940                 $$(MV) $$@.tmp $$@
 941       endif
 942     endif
 943   endif
 944 
 945   # Pickup extra OPENJDK_TARGET_OS_TYPE and/or OPENJDK_TARGET_OS dependent variables
 946   # for LDFLAGS and LIBS
 947   $1_EXTRA_LDFLAGS += $$($1_LDFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS))
 948   $1_EXTRA_LIBS += $$($1_LIBS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LIBS_$(OPENJDK_TARGET_OS))
 949   ifneq ($$($1_REAL_MAPFILE), )
 950     $1_EXTRA_LDFLAGS += $(call SET_SHARED_LIBRARY_MAPFILE,$$($1_REAL_MAPFILE))
 951   endif
 952 
 953   ifneq ($$($1_COPY_DEBUG_SYMBOLS), false)
 954     $1_COPY_DEBUG_SYMBOLS := $(COPY_DEBUG_SYMBOLS)
 955   endif
 956 
 957   ifneq ($$($1_ZIP_EXTERNAL_DEBUG_SYMBOLS), false)
 958     $1_ZIP_EXTERNAL_DEBUG_SYMBOLS := $(ZIP_EXTERNAL_DEBUG_SYMBOLS)
 959   endif
 960 
 961   ifeq ($$($1_COPY_DEBUG_SYMBOLS), true)
 962     ifneq ($$($1_DEBUG_SYMBOLS), false)
 963       $$(call SetIfEmpty, $1_SYMBOLS_DIR, $$($1_OUTPUT_DIR))
 964       # Only copy debug symbols for dynamic libraries and programs.
 965       ifneq ($$($1_TYPE), STATIC_LIBRARY)
 966         # Generate debuginfo files.
 967         ifeq ($(call isTargetOs, windows), true)
 968           $1_EXTRA_LDFLAGS += -debug "-pdb:$$($1_SYMBOLS_DIR)/$$($1_NOSUFFIX).pdb" \
 969               "-map:$$($1_SYMBOLS_DIR)/$$($1_NOSUFFIX).map"
 970           ifeq ($(SHIP_DEBUG_SYMBOLS), public)
 971             $1_EXTRA_LDFLAGS += "-pdbstripped:$$($1_SYMBOLS_DIR)/$$($1_NOSUFFIX).stripped.pdb"
 972           endif
 973           $1_DEBUGINFO_FILES := $$($1_SYMBOLS_DIR)/$$($1_NOSUFFIX).pdb \
 974               $$($1_SYMBOLS_DIR)/$$($1_NOSUFFIX).map
 975 
 976         else ifeq ($(call isTargetOs, linux solaris), true)
 977           $1_DEBUGINFO_FILES := $$($1_SYMBOLS_DIR)/$$($1_NOSUFFIX).debuginfo
 978           # Setup the command line creating debuginfo files, to be run after linking.
 979           # It cannot be run separately since it updates the original target file
 980           $1_CREATE_DEBUGINFO_CMDS := \
 981               $$($1_OBJCOPY) --only-keep-debug $$($1_TARGET) $$($1_DEBUGINFO_FILES) $$(NEWLINE) \
 982               $(CD) $$($1_SYMBOLS_DIR) && \
 983                   $$($1_OBJCOPY) --add-gnu-debuglink=$$($1_DEBUGINFO_FILES) $$($1_TARGET)
 984 
 985         else ifeq ($(call isTargetOs, macosx), true)
 986           $1_DEBUGINFO_FILES := \
 987               $$($1_SYMBOLS_DIR)/$$($1_BASENAME).dSYM/Contents/Info.plist \
 988               $$($1_SYMBOLS_DIR)/$$($1_BASENAME).dSYM/Contents/Resources/DWARF/$$($1_BASENAME)
 989           $1_CREATE_DEBUGINFO_CMDS := \
 990               $(DSYMUTIL) --out $$($1_SYMBOLS_DIR)/$$($1_BASENAME).dSYM $$($1_TARGET)
 991         endif
 992 
 993         # Since the link rule creates more than one file that we want to track,
 994         # we have to use some tricks to get make to cooperate. To properly
 995         # trigger downstream dependants of $$($1_DEBUGINFO_FILES), we must have
 996         # a recipe in the rule below. To avoid rerunning the recipe every time
 997         # have it touch the target. If a debuginfo file is deleted by something
 998         # external, explicitly delete the TARGET to trigger a rebuild of both.
 999         ifneq ($$(wildcard $$($1_DEBUGINFO_FILES)), $$($1_DEBUGINFO_FILES))
1000           $$(call LogDebug, Deleting $$($1_BASENAME) because debuginfo files are missing)
1001           $$(shell $(RM) $$($1_TARGET))
1002         endif
1003         $$($1_DEBUGINFO_FILES): $$($1_TARGET)
1004                 $$(if $$(CORRECT_FUNCTION_IN_RECIPE_EVALUATION), \
1005                   $$(if $$(wildcard $$@), , $$(error $$@ was not created for $$<)) \
1006                 )
1007                 $(TOUCH) $$@
1008 
1009         $1 += $$($1_DEBUGINFO_FILES)
1010 
1011         ifeq ($$($1_ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
1012           $1_DEBUGINFO_ZIP := $$($1_SYMBOLS_DIR)/$$($1_NOSUFFIX).diz
1013           $1 += $$($1_DEBUGINFO_ZIP)
1014 
1015           # The dependency on TARGET is needed for debuginfo files
1016           # to be rebuilt properly.
1017           $$($1_DEBUGINFO_ZIP): $$($1_DEBUGINFO_FILES) $$($1_TARGET)
1018                 $(CD) $$($1_SYMBOLS_DIR) && \
1019                     $(ZIPEXE) -q -r $$@ $$(subst $$($1_SYMBOLS_DIR)/,, $$($1_DEBUGINFO_FILES))
1020 
1021         endif
1022        endif # !STATIC_LIBRARY
1023     endif # $1_DEBUG_SYMBOLS != false
1024   endif # COPY_DEBUG_SYMBOLS
1025 
1026   # Unless specifically set, stripping should only happen if symbols are also
1027   # being copied.
1028   $$(call SetIfEmpty, $1_STRIP_SYMBOLS, $$($1_COPY_DEBUG_SYMBOLS))
1029 
1030   ifneq ($$($1_STRIP_SYMBOLS), false)
1031     ifneq ($$($1_STRIP), )
1032       # Default to using the global STRIPFLAGS. Allow for overriding with an empty value
1033       $1_STRIPFLAGS ?= $(STRIPFLAGS)
1034       $1_STRIP_CMD := $$($1_STRIP) $$($1_STRIPFLAGS) $$($1_TARGET)
1035     endif
1036   endif
1037 
1038   ifeq ($$($1_TYPE), STATIC_LIBRARY)
1039     $1_VARDEPS := $$($1_AR) $$($1_ARFLAGS) $$($1_LIBS) \
1040         $$($1_EXTRA_LIBS)
1041     $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
1042         $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
1043 
1044     # Generating a static library, ie object file archive.
1045     ifeq ($(STATIC_BUILD), true)
1046       ifeq ($$($1_USE_MAPFILE_FOR_SYMBOLS), true)
1047         STATIC_MAPFILE_DEP := $$($1_MAPFILE)
1048       endif
1049     endif
1050 
1051     $1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_VARDEPS_FILE) $$(STATIC_MAPFILE_DEP)
1052 
1053     $$($1_TARGET): $$($1_TARGET_DEPS)
1054         $$(call LogInfo, Building static library $$($1_BASENAME))
1055         $$(call MakeDir, $$($1_OUTPUT_DIR) $$($1_SYMBOLS_DIR))
1056         $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
1057             $$($1_AR) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_ALL_OBJS) \
1058                 $$($1_RES))
1059         ifeq ($(STATIC_BUILD), true)
1060           ifeq ($$($1_USE_MAPFILE_FOR_SYMBOLS), true)
1061             $(CP) $$($1_MAPFILE) $$(@D)/$$(basename $$(@F)).symbols
1062           else
1063             $(GetSymbols)
1064           endif
1065         endif
1066   else
1067     # A shared dynamic library or an executable binary has been specified
1068     ifeq ($$($1_TYPE), LIBRARY)
1069       # Generating a dynamic library.
1070       $1_EXTRA_LDFLAGS += $$(call SET_SHARED_LIBRARY_NAME,$$($1_BASENAME))
1071 
1072       # Create loadmap on AIX. Helps in diagnosing some problems.
1073       ifneq ($(COMPILER_BINDCMD_FILE_FLAG), )
1074         $1_EXTRA_LDFLAGS += $(COMPILER_BINDCMD_FILE_FLAG)$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).loadmap
1075       endif
1076     endif
1077 
1078     ifeq ($(call isTargetOs, windows), true)
1079       ifeq ($$($1_EMBED_MANIFEST), true)
1080         $1_EXTRA_LDFLAGS += -manifest:embed
1081       endif
1082 
1083       $1_IMPORT_LIBRARY := $$($1_OBJECT_DIR)/$$($1_NAME).lib
1084       $1_EXTRA_LDFLAGS += "-implib:$$($1_IMPORT_LIBRARY)"
1085       ifeq ($$($1_TYPE), LIBRARY)
1086         # To properly trigger downstream dependants of the import library, just as
1087         # for debug files, we must have a recipe in the rule. To avoid rerunning
1088         # the recipe every time have it touch the target. If an import library
1089         # file is deleted by something external, explicitly delete the target to
1090         # trigger a rebuild of both.
1091         ifneq ($$(wildcard $$($1_IMPORT_LIBRARY)), $$($1_IMPORT_LIBRARY))
1092           $$(call LogDebug, Deleting $$($1_BASENAME) because import library is missing)
1093           $$(shell $(RM) $$($1_TARGET))
1094         endif
1095         $$($1_IMPORT_LIBRARY): $$($1_TARGET)
1096                 $(TOUCH) $$@
1097 
1098         $1 += $$($1_IMPORT_LIBRARY)
1099       endif
1100     endif
1101 
1102     $1_VARDEPS := $$($1_LD) $$($1_SYSROOT_LDFLAGS) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) \
1103         $$(GLOBAL_LIBS) $$($1_LIBS) $$($1_EXTRA_LIBS) $$($1_MT) \
1104         $$($1_CREATE_DEBUGINFO_CMDS) $$($1_MANIFEST_VERSION) \
1105         $$($1_STRIP_CMD)
1106     $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
1107         $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
1108 
1109     $1_LD_OBJ_ARG := $$($1_ALL_OBJS)
1110 
1111     # If there are many object files, use an @-file...
1112     ifneq ($$(word 17, $$($1_ALL_OBJS)), )
1113       $1_OBJ_FILE_LIST := $$($1_OBJECT_DIR)/_$1_objectfilenames.txt
1114       ifneq ($(COMPILER_COMMAND_FILE_FLAG), )
1115         $1_LD_OBJ_ARG := $(COMPILER_COMMAND_FILE_FLAG)$$($1_OBJ_FILE_LIST)
1116       else
1117         # ...except for toolchains which don't support them.
1118         $1_LD_OBJ_ARG := `cat $$($1_OBJ_FILE_LIST)`
1119       endif
1120     endif
1121 
1122     # Unfortunately the @-file trick does not work reliably when using clang.
1123     # Clang does not propagate the @-file parameter to the ld sub process, but
1124     # instead puts the full content on the command line. At least the llvm ld
1125     # does not even support an @-file.
1126     #
1127     # When linking a large amount of object files, we risk hitting the limit
1128     # of the command line length even on posix systems if the path length of
1129     # the output dir is very long due to our use of absolute paths. To
1130     # mitigate this, use paths relative to the output dir when linking over
1131     # 500 files with clang and the output dir path is deep.
1132     ifneq ($$(word 500, $$($1_ALL_OBJS)), )
1133       ifeq ($$(TOOLCHAIN_TYPE), clang)
1134         # There is no strlen function in make, but checking path depth is a
1135         # reasonable approximation.
1136         ifneq ($$(word 10, $$(subst /, ,$$(OUTPUTDIR))), )
1137           $1_LINK_OBJS_RELATIVE := true
1138           $1_ALL_OBJS_RELATIVE := $$(patsubst $$(OUTPUTDIR)/%, %, $$($1_ALL_OBJS))
1139         endif
1140       endif
1141     endif
1142 
1143     $1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_MANIFEST) \
1144         $$($1_REAL_MAPFILE) $$($1_VARDEPS_FILE)
1145 
1146     $$($1_TARGET): $$($1_TARGET_DEPS)
1147                 ifneq ($$($1_OBJ_FILE_LIST), )
1148                   ifeq ($$($1_LINK_OBJS_RELATIVE), true)
1149                     $$(eval $$(call ListPathsSafely, $1_ALL_OBJS_RELATIVE, $$($1_OBJ_FILE_LIST)))
1150                   else
1151                     $$(eval $$(call ListPathsSafely, $1_ALL_OBJS, $$($1_OBJ_FILE_LIST)))
1152                   endif
1153                 endif
1154                 # Keep as much as possible on one execution line for best performance
1155                 # on Windows
1156                 $$(call LogInfo, Linking $$($1_BASENAME))
1157                 $$(call MakeDir, $$($1_OUTPUT_DIR) $$($1_SYMBOLS_DIR))
1158                 ifeq ($(call isTargetOs, windows), true)
1159 
1160                   $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
1161                       $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
1162                           $(LD_OUT_OPTION)$$($1_TARGET) $$($1_LD_OBJ_ARG) $$($1_RES) $$(GLOBAL_LIBS) \
1163                           $$($1_LIBS) $$($1_EXTRA_LIBS)) \
1164                       | $(GREP) -v "^   Creating library .*\.lib and object .*\.exp" || \
1165                           test "$$$$?" = "1" ; \
1166                   $$($1_CREATE_DEBUGINFO_CMDS)
1167                   $$($1_STRIP_CMD)
1168                 else
1169                   $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
1170                       $$(if $$($1_LINK_OBJS_RELATIVE), $$(CD) $$(OUTPUTDIR) ; ) \
1171                       $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
1172                           $(LD_OUT_OPTION)$$($1_TARGET) $$($1_LD_OBJ_ARG) $$($1_RES) $$(GLOBAL_LIBS) \
1173                           $$($1_LIBS) $$($1_EXTRA_LIBS)) ; \
1174                   $$($1_CREATE_DEBUGINFO_CMDS)
1175                   $$($1_STRIP_CMD)
1176                 endif
1177                 ifeq ($(call isTargetOs, windows), true)
1178                   ifneq ($$($1_MANIFEST), )
1179                     $$($1_MT) -nologo -manifest $$($1_MANIFEST) -identity:"$$($1_NAME).exe, version=$$($1_MANIFEST_VERSION)" -outputresource:$$@;#1
1180                   endif
1181                 endif
1182                 # This only works if the openjdk_codesign identity is present on the system. Let
1183                 # silently fail otherwise.
1184                 ifneq ($(CODESIGN), )
1185                   $(CODESIGN) -s "$(MACOSX_CODESIGN_IDENTITY)" --timestamp --options runtime \
1186                   --entitlements $(TOPDIR)/make/data/macosxsigning/entitlements.plist $$@
1187                 endif
1188   endif
1189 
1190   ifeq ($(GENERATE_COMPILE_COMMANDS_ONLY), true)
1191     $1 := $$($1_ALL_OBJS_JSON)
1192   endif
1193 endef
1194 
1195 endif # _NATIVE_COMPILATION_GMK