NativeCompilation.gmk revision 2430:8cddd16d59ee
1231990Smp#
259243Sobrien# Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
359243Sobrien# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
459243Sobrien#
559243Sobrien# This code is free software; you can redistribute it and/or modify it
659243Sobrien# under the terms of the GNU General Public License version 2 only, as
759243Sobrien# published by the Free Software Foundation.  Oracle designates this
859243Sobrien# particular file as subject to the "Classpath" exception as provided
959243Sobrien# by Oracle in the LICENSE file that accompanied this code.
1059243Sobrien#
1159243Sobrien# This code is distributed in the hope that it will be useful, but WITHOUT
1259243Sobrien# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1359243Sobrien# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1459243Sobrien# version 2 for more details (a copy is included in the LICENSE file that
1559243Sobrien# accompanied this code).
1659243Sobrien#
1759243Sobrien# You should have received a copy of the GNU General Public License version
1859243Sobrien# 2 along with this work; if not, write to the Free Software Foundation,
1959243Sobrien# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20100616Smp#
2159243Sobrien# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2259243Sobrien# or visit www.oracle.com if you need additional information or have any
2359243Sobrien# questions.
2459243Sobrien#
2559243Sobrien
2659243Sobrien# When you read this source. Remember that $(sort ...) has the side effect
2759243Sobrien# of removing duplicates. It is actually this side effect that is
2859243Sobrien# desired whenever sort is used below!
2959243Sobrien
3059243Sobrienifndef _NATIVE_COMPILATION_GMK
3159243Sobrien_NATIVE_COMPILATION_GMK := 1
3259243Sobrien
3359243Sobrienifeq (,$(_MAKEBASE_GMK))
3459243Sobrien  $(error You must include MakeBase.gmk prior to including NativeCompilation.gmk)
3559243Sobrienendif
3659243Sobrien
3759243Sobrien################################################################################
38231990Smp# Create exported symbols file for static libraries
3959243Sobrien################################################################################
4059243Sobrien
4159243Sobrien# get the exported symbols from mapfiles and if there
4259243Sobrien# is no mapfile, get them from the archive
4359243Sobriendefine GetSymbols
44167465Smp  $(RM) $$(@D)/$$(basename $$(@F)).symbols; \
45167465Smp  if [ ! -z $$($1_MAPFILE) -a -e $$($1_MAPFILE) ]; then \
4669408Sache    $(ECHO) "Getting symbols from mapfile $$($1_MAPFILE)"; \
4759243Sobrien    $(AWK) '/global:/','/local:/' $$($1_MAPFILE) | \
4869408Sache        $(SED) -e 's/#.*//;s/global://;s/local://;s/\;//;s/^[ 	]*/_/;/^_$$$$/d' | \
4959243Sobrien        $(EGREP) -v "JNI_OnLoad|JNI_OnUnload|Agent_OnLoad|Agent_OnUnload|Agent_OnAttach" > \
5059243Sobrien        $$(@D)/$$(basename $$(@F)).symbols || true; \
5159243Sobrien    $(NM) $$($1_TARGET) | $(GREP)  " T " | \
5259243Sobrien        $(EGREP) "JNI_OnLoad|JNI_OnUnload|Agent_OnLoad|Agent_OnUnload|Agent_OnAttach" | \
5359243Sobrien        $(CUT) -d ' ' -f 3 >>  $$(@D)/$$(basename $$(@F)).symbols || true;\
5459243Sobrien  else \
5559243Sobrien    $(ECHO) "Getting symbols from nm"; \
5659243Sobrien    $(NM) -m $$($1_TARGET) | $(GREP)  "__TEXT" | \
5759243Sobrien        $(EGREP) -v "non-external|private extern|__TEXT,__eh_frame" | \
5859243Sobrien        $(SED) -e  's/.* //' > $$(@D)/$$(basename $$(@F)).symbols; \
5959243Sobrien  fi
60167465Smpendef
6159243Sobrien
6259243Sobrien################################################################################
6359243Sobrien# Define a native toolchain configuration that can be used by
6459243Sobrien# SetupNativeCompilation calls
6559243Sobrien#
6659243Sobrien# Parameter 1 is the name of the toolchain definition
6759243Sobrien#
68167465Smp# Remaining parameters are named arguments:
69167465Smp#   EXTENDS - Optional parent definition to get defaults from
7059243Sobrien#   CC - The C compiler
7159243Sobrien#   CXX - The C++ compiler
7259243Sobrien#   LD - The Linker
7359243Sobrien#   AR - Static linker
7459243Sobrien#   AS - Assembler
7559243Sobrien#   MT - Windows MT tool
7659243Sobrien#   RC - Windows RC tool
77167465Smp#   OBJCOPY - The objcopy tool for debug symbol handling
7859243Sobrien#   STRIP - The tool to use for stripping debug symbols
7959243Sobrien#   SYSROOT_CFLAGS - Compiler flags for using the specific sysroot
8059243Sobrien#   SYSROOT_LDFLAGS - Linker flags for using the specific sysroot
8159243SobrienDefineNativeToolchain = $(NamedParamsMacroTemplate)
8259243Sobriendefine DefineNativeToolchainBody
8359243Sobrien  # If extending another definition, get default values from that,
8459243Sobrien  # otherwise, nothing more needs to be done as variable assignments
8559243Sobrien  # already happened in NamedParamsMacroTemplate.
8659243Sobrien  ifneq ($$($1_EXTENDS), )
8759243Sobrien    $$(call SetIfEmpty, $1_CC, $$($$($1_EXTENDS)_CC))
8859243Sobrien    $$(call SetIfEmpty, $1_CXX, $$($$($1_EXTENDS)_CXX))
8959243Sobrien    $$(call SetIfEmpty, $1_LD, $$($$($1_EXTENDS)_LD))
9059243Sobrien    $$(call SetIfEmpty, $1_AR, $$($$($1_EXTENDS)_AR))
9159243Sobrien    $$(call SetIfEmpty, $1_AS, $$($$($1_EXTENDS)_AS))
9259243Sobrien    $$(call SetIfEmpty, $1_MT, $$($$($1_EXTENDS)_MT))
9359243Sobrien    $$(call SetIfEmpty, $1_RC, $$($$($1_EXTENDS)_RC))
9459243Sobrien    $$(call SetIfEmpty, $1_OBJCOPY, $$($$($1_EXTENDS)_OBJCOPY))
95145479Smp    $$(call SetIfEmpty, $1_STRIP, $$($$($1_EXTENDS)_STRIP))
9659243Sobrien    $$(call SetIfEmpty, $1_SYSROOT_CFLAGS, $$($$($1_EXTENDS)_SYSROOT_CFLAGS))
9759243Sobrien    $$(call SetIfEmpty, $1_SYSROOT_LDFLAGS, $$($$($1_EXTENDS)_SYSROOT_LDFLAGS))
9859243Sobrien  endif
9959243Sobrienendef
10059243Sobrien
10159243Sobrien# Create a default toolchain with the main compiler and linker
10259243Sobrien$(eval $(call DefineNativeToolchain, TOOLCHAIN_DEFAULT, \
103167465Smp    CC := $(CC), \
104167465Smp    CXX := $(CXX), \
105167465Smp    LD := $(LD), \
106167465Smp    AR := $(AR), \
107167465Smp    AS := $(AS), \
108167465Smp    MT := $(MT), \
109167465Smp    RC := $(RC), \
110167465Smp    OBJCOPY := $(OBJCOPY), \
111167465Smp    STRIP := $(STRIP), \
112167465Smp    SYSROOT_CFLAGS := $(SYSROOT_CFLAGS), \
113167465Smp    SYSROOT_LDFLAGS := $(SYSROOT_LDFLAGS), \
114167465Smp))
115167465Smp
116167465Smp# Create a toolchain where linking is done with the C++ linker
117167465Smp$(eval $(call DefineNativeToolchain, TOOLCHAIN_LINK_CXX, \
118167465Smp    EXTENDS := TOOLCHAIN_DEFAULT, \
119167465Smp    LD := $(LDCXX), \
120167465Smp))
121167465Smp
122167465Smp# Create a toolchain with the BUILD compiler, used for build tools that
123167465Smp# are to be run during the build.
124167465Smp$(eval $(call DefineNativeToolchain, TOOLCHAIN_BUILD, \
125167465Smp    CC := $(BUILD_CC), \
126167465Smp    CXX := $(BUILD_CXX), \
127231990Smp    LD := $(BUILD_LD), \
128231990Smp    AR := $(BUILD_AR), \
129167465Smp    AS := $(BUILD_AS), \
130167465Smp    OBJCOPY := $(BUILD_OBJCOPY), \
131167465Smp    STRIP := $(BUILD_STRIP), \
132167465Smp    SYSROOT_CFLAGS := $(BUILD_SYSROOT_CFLAGS), \
133167465Smp    SYSROOT_LDFLAGS := $(BUILD_SYSROOT_LDFLAGS), \
134167465Smp))
13559243Sobrien
13659243Sobrien# BUILD toolchain with the C++ linker
13759243Sobrien$(eval $(call DefineNativeToolchain, TOOLCHAIN_BUILD_LINK_CXX, \
13859243Sobrien    EXTENDS := TOOLCHAIN_BUILD, \
13959243Sobrien    LD := $(BUILD_LDCXX), \
14059243Sobrien))
14159243Sobrien
14259243Sobrien################################################################################
14359243Sobrien
14459243Sobrien# Extensions of files handled by this macro.
14559243SobrienNATIVE_SOURCE_EXTENSIONS := %.s %.S %.c %.cpp %.cc %.m %.mm
14659243Sobrien
14759243Sobrien# Replaces native source extensions with the object file extension in a string.
14859243Sobrien# Param 1: the string containing source file names with extensions
14959243Sobrien# The surrounding strip is needed to keep additional whitespace out
15059243Sobriendefine replace_with_obj_extension
15159243Sobrien$(strip \
15259243Sobrien  $(foreach extension, $(NATIVE_SOURCE_EXTENSIONS), \
15359243Sobrien      $(patsubst $(extension),%$(OBJ_SUFFIX),$(filter $(extension),$1))) \
15459243Sobrien)
15559243Sobrienendef
15659243Sobrien
15759243Sobrienifeq ($(OPENJDK_BUILD_OS_ENV), windows.cygwin)
15859243Sobrien  UNIX_PATH_PREFIX := /cygdrive
15959243Sobrienelse ifeq ($(OPENJDK_BUILD_OS_ENV), windows.msys)
160167465Smp  UNIX_PATH_PREFIX :=
16159243Sobrienendif
162167465Smp
16359243Sobrien# This pattern is used to transform the output of the microsoft CL compiler
164167465Smp# into a make syntax dependency file (.d)
165167465SmpWINDOWS_SHOWINCLUDE_SED_PATTERN := \
166167465Smp    -e '/^Note: including file:/!d' \
167167465Smp    -e 's|Note: including file: *||' \
168167465Smp    -e 's|\\|/|g' \
16959243Sobrien    -e 's|^\([a-zA-Z]\):|$(UNIX_PATH_PREFIX)/\1|g' \
17059243Sobrien    -e '\|$(TOPDIR)|I !d' \
17159243Sobrien    -e 's|$$$$| \\|g' \
17259243Sobrien    #
17359243Sobrien
174167465Smp# This pattern is used to transform a dependency file (.d) to a list
17559243Sobrien# of make targets for dependent files (.d.targets)
17659243SobrienDEPENDENCY_TARGET_SED_PATTERN := \
177167465Smp    -e 's/\#.*//' \
17859243Sobrien    -e 's/^[^:]*: *//' \
17959243Sobrien    -e 's/ *\\$$$$//' \
18059243Sobrien    -e 's/^[	 ]*//' \
18159243Sobrien    -e '/^$$$$/ d' \
18259243Sobrien    -e 's/$$$$/ :/' \
18359243Sobrien    #
18459243Sobrien
18559243Sobriendefine add_native_source
18659243Sobrien  # param 1 = BUILD_MYPACKAGE
18759243Sobrien  # parma 2 = the source file name (..../alfa.c or .../beta.cpp)
18859243Sobrien  # param 3 = the bin dir that stores all .o (.obj) and .d files.
18959243Sobrien  # param 4 = the c flags to the compiler
19059243Sobrien  # param 5 = the c compiler
19159243Sobrien  # param 6 = the c++ flags to the compiler
192167465Smp  # param 7 = the c++ compiler
19359243Sobrien  # param 8 = the flags to the assembler
19459243Sobrien  # param 9 = set to disable THIS_FILE
19559243Sobrien
19659243Sobrien  ifeq ($9, )
19759243Sobrien    $1_$2_THIS_FILE = -DTHIS_FILE='"$$(<F)"'
19859243Sobrien  endif
199167465Smp
20059243Sobrien  ifeq ($$($1_$(notdir $2)_OPTIMIZATION), )
20159243Sobrien    $1_$(notdir $2)_OPT_CFLAGS := $$($1_OPT_CFLAGS)
20259243Sobrien    $1_$(notdir $2)_OPT_CXXFLAGS := $$($1_OPT_CXXFLAGS)
20359243Sobrien  else
204167465Smp    ifeq (NONE, $$($1_$(notdir $2)_OPTIMIZATION))
20559243Sobrien      $1_$(notdir $2)_OPT_CFLAGS := $(C_O_FLAG_NONE)
20659243Sobrien      $1_$(notdir $2)_OPT_CXXFLAGS := $(CXX_O_FLAG_NONE)
20759243Sobrien    else ifeq (LOW, $$($1_$(notdir $2)_OPTIMIZATION))
20859243Sobrien      $1_$(notdir $2)_OPT_CFLAGS := $(C_O_FLAG_NORM)
209231990Smp      $1_$(notdir $2)_OPT_CXXFLAGS := $(CXX_O_FLAG_NORM)
210231990Smp    else ifeq (HIGH, $$($1_$(notdir $2)_OPTIMIZATION))
211167465Smp      $1_$(notdir $2)_OPT_CFLAGS := $(C_O_FLAG_HI)
212231990Smp      $1_$(notdir $2)_OPT_CXXFLAGS := $(CXX_O_FLAG_HI)
213231990Smp    else ifeq (HIGHEST, $$($1_$(notdir $2)_OPTIMIZATION))
214167465Smp      $1_$(notdir $2)_OPT_CFLAGS := $(C_O_FLAG_HIGHEST)
21559243Sobrien      $1_$(notdir $2)_OPT_CXXFLAGS := $(CXX_O_FLAG_HIGHEST)
216167465Smp    else ifeq (HIGHEST_JVM, $$($1_$(notdir $2)_OPTIMIZATION))
217167465Smp      $1_$(notdir $2)_OPT_CFLAGS := $(C_O_FLAG_HIGHEST_JVM)
218167465Smp      $1_$(notdir $2)_OPT_CXXFLAGS := $(CXX_O_FLAG_HIGHEST_JVM)
219167465Smp    else ifeq (SIZE, $$($1_$(notdir $2)_OPTIMIZATION))
22059243Sobrien      $1_$(notdir $2)_OPT_CFLAGS := $(C_O_FLAG_SIZE)
22159243Sobrien      $1_$(notdir $2)_OPT_CXXFLAGS := $(CXX_O_FLAG_SIZE)
22259243Sobrien    else
223167465Smp      $$(error Unknown value for OPTIMIZATION: $$($1_$(notdir $2)_OPTIMIZATION))
224167465Smp    endif
22559243Sobrien  endif
22659243Sobrien
22759243Sobrien  ifneq ($$($1_PRECOMPILED_HEADER), )
22859243Sobrien    ifeq ($$(filter $$(notdir $2), $$($1_PRECOMPILED_HEADER_EXCLUDE)), )
22959243Sobrien      $1_$2_USE_PCH_FLAGS := $$($1_USE_PCH_FLAGS)
23059243Sobrien    endif
23159243Sobrien  endif
232167465Smp
23359243Sobrien  ifneq (,$$(filter %.c,$2))
23459243Sobrien    # Compile as a C file
23559243Sobrien    $1_$2_FLAGS=$(CFLAGS_CCACHE) $$($1_$2_USE_PCH_FLAGS) $4 \
23659243Sobrien        $$($1_$(notdir $2)_OPT_CFLAGS) \
23759243Sobrien        $$($1_$(notdir $2)_CFLAGS) $$($1_$2_THIS_FILE) -c
238167465Smp    $1_$2_COMP=$5
239167465Smp    $1_$2_DEP_FLAG:=$(C_FLAG_DEPS)
240167465Smp  else ifneq (,$$(filter %.m,$2))
241167465Smp    # Compile as an Objective-C file
242167465Smp    $1_$2_FLAGS=-x objective-c $(CFLAGS_CCACHE) $$($1_$2_USE_PCH_FLAGS) $4 \
243167465Smp        $$($1_$(notdir $2)_OPT_CFLAGS) \
244167465Smp        $$($1_$(notdir $2)_CFLAGS) $$($1_$2_THIS_FILE) -c
245167465Smp    $1_$2_COMP=$5
246167465Smp    $1_$2_DEP_FLAG:=$(C_FLAG_DEPS)
247167465Smp  else ifneq (,$$(filter %.s %.S,$2))
248167465Smp    # Compile as assembler file
249167465Smp    $1_$2_FLAGS=$8
250167465Smp    $1_$2_COMP=$(AS)
251167465Smp    $1_$2_DEP_FLAG:=
252167465Smp  else ifneq (,$$(filter %.cpp,$2)$$(filter %.cc,$2)$$(filter %.mm,$2))
253167465Smp    # Compile as a C++ or Objective-C++ file
25459243Sobrien    $1_$2_FLAGS=$(CFLAGS_CCACHE) $$($1_$2_USE_PCH_FLAGS) $6 \
25559243Sobrien        $$($1_$(notdir $2)_OPT_CXXFLAGS) \
25659243Sobrien        $$($1_$(notdir $2)_CXXFLAGS) $$($1_$2_THIS_FILE) -c
25759243Sobrien    $1_$2_COMP=$7
25859243Sobrien    $1_$2_DEP_FLAG:=$(CXX_FLAG_DEPS)
259167465Smp  else
260167465Smp    $$(error Internal error in NativeCompilation.gmk: no compiler for file $2)
26159243Sobrien  endif
26259243Sobrien  # Generate the .o (.obj) file name and place it in the bin dir.
26359243Sobrien  $1_$2_OBJ := $3/$$(call replace_with_obj_extension, $$(notdir $2))
264167465Smp  # Only continue if this object file hasn't been processed already. This lets the first found
265167465Smp  # source file override any other with the same name.
266167465Smp  ifeq (,$$(findstring $$($1_$2_OBJ),$$($1_OBJS_SO_FAR)))
26759243Sobrien    $1_OBJS_SO_FAR+=$$($1_$2_OBJ)
26859243Sobrien    ifeq (,$$(filter %.s %.S,$2))
26959243Sobrien      # And this is the dependency file for this obj file.
27059243Sobrien      $1_$2_DEP:=$$(patsubst %$(OBJ_SUFFIX),%.d,$$($1_$2_OBJ))
27159243Sobrien      # The dependency target file lists all dependencies as empty targets
27259243Sobrien      # to avoid make error "No rule to make target" for removed files
273167465Smp      $1_$2_DEP_TARGETS:=$$(patsubst %$(OBJ_SUFFIX),%.d.targets,$$($1_$2_OBJ))
27459243Sobrien
27559243Sobrien      # Include previously generated dependency information. (if it exists)
27659243Sobrien      -include $$($1_$2_DEP)
27759243Sobrien      -include $$($1_$2_DEP_TARGETS)
27859243Sobrien
279167465Smp      ifeq ($(TOOLCHAIN_TYPE), microsoft)
280167465Smp        # To avoid name clashes between pdbs for objects and libs/execs, put
281167465Smp        # object pdbs in a separate subdir.
282167465Smp        $1_$2_DEBUG_OUT_FLAGS:=-Fd$$(strip $$(patsubst $$($1_OBJECT_DIR)/%, \
28359243Sobrien            $$($1_OBJECT_DIR)/pdb/%, $$(patsubst %$(OBJ_SUFFIX),%.pdb,$$($1_$2_OBJ))))
284167465Smp      endif
285167465Smp    endif
28659243Sobrien
287167465Smp    ifneq ($$(strip $$($1_$(notdir $2)_CFLAGS) $$($1_$(notdir $2)_CXXFLAGS) \
28859243Sobrien        $$($1_$(notdir $2)_OPTIMIZATION)), )
28959243Sobrien      $1_$2_VARDEPS := $$($1_$(notdir $2)_CFLAGS) $$($1_$(notdir $2)_CXXFLAGS) \
29059243Sobrien          $$($1_$(notdir $2)_OPT_CFLAGS) $$($1_$(notdir $2)_OPT_CXXFLAGS)
29159243Sobrien      $1_$2_VARDEPS_FILE := $$(call DependOnVariable, $1_$2_VARDEPS, $$($1_$2_OBJ).vardeps)
29259243Sobrien    endif
29359243Sobrien
29459243Sobrien    $$($1_$2_OBJ) : $2 $$($1_COMPILE_VARDEPS_FILE) $$($1_$2_VARDEPS_FILE) | $$($1_BUILD_INFO)
29559243Sobrien	$$(call LogInfo, Compiling $$(notdir $2) (for $$(notdir $$($1_TARGET))))
29659243Sobrien	$$(call MakeDir, $$(@D) $$(@D)/pdb)
29759243Sobrien        ifneq ($(TOOLCHAIN_TYPE), microsoft)
29859243Sobrien          ifeq ($(TOOLCHAIN_TYPE)$$(filter %.s,$2), solstudio)
29959243Sobrien            # The Solaris studio compiler doesn't output the full path to the object file in the
30059243Sobrien            # generated deps files. Fixing it with sed. If compiling assembly, don't try this.
301167465Smp	    $$(call ExecuteWithLog, $$@, \
302167465Smp	        $$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEP_FLAG) $$($1_$2_DEP).tmp $(CC_OUT_OPTION)$$($1_$2_OBJ) $2)
303167465Smp	    $(SED) 's|^$$(@F):|$$@:|' $$($1_$2_DEP).tmp > $$($1_$2_DEP)
304167465Smp          else
305167465Smp	    $$(call ExecuteWithLog, $$@, \
306167465Smp	        $$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEP_FLAG) $$($1_$2_DEP) $(CC_OUT_OPTION)$$($1_$2_OBJ) $2)
307167465Smp          endif
308167465Smp          # Create a dependency target file from the dependency file.
30959243Sobrien          # Solution suggested by http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
31059243Sobrien          ifneq ($$($1_$2_DEP),)
31159243Sobrien	    $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_$2_DEP) > $$($1_$2_DEP_TARGETS)
312167465Smp          endif
31359243Sobrien        else
314167465Smp          # The Visual Studio compiler lacks a feature for generating make dependencies, but by
315167465Smp          # setting -showIncludes, all included files are printed. These are filtered out and
31659243Sobrien          # parsed into make dependences.
31759243Sobrien          # Keep as much as possible on one execution line for best performance on Windows.
318167465Smp          # No need to save exit code from compilation since pipefail is always active on
319167465Smp          # Windows.
320167465Smp	  $$(call ExecuteWithLog, $$@, \
321167465Smp	      $$($1_$2_COMP) $$($1_$2_FLAGS) -showIncludes $$($1_$2_DEBUG_OUT_FLAGS) \
322167465Smp	          $(CC_OUT_OPTION)$$($1_$2_OBJ) $2) \
32359243Sobrien	      | $(GREP) -v -e "^Note: including file:" \
324167465Smp	          -e "^$(notdir $2)$$$$" || test "$$$$?" = "1" ; \
325167465Smp	  $(ECHO) $$@: \\ > $$($1_$2_DEP) ; \
326167465Smp	  $(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_$2_OBJ).log \
327167465Smp	      | $(SORT) -u >> $$($1_$2_DEP) ; \
32859243Sobrien	  $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_$2_DEP) > $$($1_$2_DEP_TARGETS)
329167465Smp        endif
330167465Smp  endif
331167465Smpendef
332167465Smp
33359243Sobrien# Setup make rules for creating a native binary (a shared library or an
334167465Smp# executable).
335167465Smp#
336167465Smp# Parameter 1 is the name of the rule. This name is used as variable prefix,
337167465Smp# and the targets generated are listed in a variable by that name.
338167465Smp#
33959243Sobrien# Remaining parameters are named arguments. These include:
340167465Smp#   TOOLCHAIN Name of toolchain setup to use. Defaults to TOOLCHAIN_DEFAULT.
341167465Smp#   SRC one or more directory roots to scan for C/C++ files.
342167465Smp#   CFLAGS the compiler flags to be used, used both for C and C++.
34359243Sobrien#   CXXFLAGS the compiler flags to be used for c++, if set overrides CFLAGS.
34459243Sobrien#   LDFLAGS the linker flags to be used, used both for C and C++.
34559243Sobrien#   LIBS the libraries to link to
34659243Sobrien#   ARFLAGS the archiver flags to be used
34759243Sobrien#   OBJECT_DIR the directory where we store the object files
348167465Smp#   OUTPUT_DIR the directory where the resulting binary is put
349167465Smp#   LIBRARY the resulting library file
350167465Smp#   PROGRAM the resulting exec file
351167465Smp#   INCLUDES only pick source from these directories
35259243Sobrien#   EXCLUDES do not pick source from these directories
353167465Smp#   INCLUDE_FILES only compile exactly these files!
354167465Smp#   EXCLUDE_FILES with these names
355167465Smp#   EXCLUDE_PATTERN exclude files matching any of these substrings
356231990Smp#   EXTRA_FILES List of extra files not in any of the SRC dirs
357231990Smp#   EXTRA_OBJECT_FILES List of extra object files to include when linking
358231990Smp#   VERSIONINFO_RESOURCE Input file for RC. Setting this implies that RC will be run
359231990Smp#   RC_FLAGS flags for RC.
360231990Smp#   EMBED_MANIFEST if true, embed manifest on Windows.
361231990Smp#   MAPFILE mapfile
362231990Smp#   REORDER reorder file
363231990Smp#   USE_MAPFILE_FOR_SYMBOLS if true and this is a STATIC_BUILD, just copy the
364231990Smp#       mapfile for the output symbols file
365231990Smp#   CC the compiler to use, default is $(CC)
366231990Smp#   LD the linker to use, default is $(LD)
367231990Smp#   OPTIMIZATION sets optimization level to NONE, LOW, HIGH, HIGHEST, HIGHEST_JVM, SIZE
368231990Smp#   DISABLED_WARNINGS_<toolchain> Disable the given warnings for the specified toolchain
369231990Smp#   DISABLED_WARNINGS_C_<toolchain> Disable the given warnings for the specified toolchain
370167465Smp#       when compiling C code
371167465Smp#   DISABLED_WARNINGS_CXX_<toolchain> Disable the given warnings for the specified
372167465Smp#       toolchain when compiling C++ code
373167465Smp#   STRIP_SYMBOLS Set to false to override global strip policy and always leave
374167465Smp#       symbols in the binary, if the toolchain allows for it
37559243Sobrien#   DEBUG_SYMBOLS Set to false to disable generation of debug symbols
376167465Smp#   COPY_DEBUG_SYMBOLS Set to false to override global setting of debug symbol copying
377167465Smp#   ZIP_EXTERNAL_DEBUG_SYMBOLS Set to false to override global setting of debug symbol
37859243Sobrien#       zipping
379167465Smp#   CFLAGS_DEBUG_SYMBOLS Overrides the default cflags for enabling debug symbols
380167465Smp#   CXXFLAGS_DEBUG_SYMBOLS Overrides the default cxxflags for enabling debug symbols
38159243Sobrien#   STRIPFLAGS Optionally change the flags given to the strip command
38259243Sobrien#   PRECOMPILED_HEADER Header file to use as precompiled header
383167465Smp#   PRECOMPILED_HEADER_EXCLUDE List of source files that should not use PCH
384167465SmpSetupNativeCompilation = $(NamedParamsMacroTemplate)
385167465Smpdefine SetupNativeCompilationBody
38659243Sobrien
38759243Sobrien  # If we're doing a static build and producing a library
38859243Sobrien  # force it to be a static library and remove the -l libraries
389167465Smp  ifeq ($(STATIC_BUILD), true)
39059243Sobrien    ifneq ($$($1_LIBRARY),)
391167465Smp      $1_STATIC_LIBRARY := $$($1_LIBRARY)
39259243Sobrien      $1_LIBRARY :=
393167465Smp    endif
394167465Smp  endif
39559243Sobrien
396167465Smp  ifneq (,$$($1_BIN))
397167465Smp    $$(error BIN has been replaced with OBJECT_DIR)
398167465Smp  endif
39959243Sobrien
40059243Sobrien  ifneq (,$$($1_LIB))
40159243Sobrien    $$(error LIB has been replaced with LIBRARY)
40259243Sobrien  endif
40359243Sobrien
40459243Sobrien  ifneq (,$$($1_EXE))
40559243Sobrien    $$(error EXE has been replaced with PROGRAM)
40659243Sobrien  endif
40759243Sobrien
40859243Sobrien  ifneq (,$$($1_LIBRARY))
409167465Smp    ifeq (,$$($1_OUTPUT_DIR))
410167465Smp      $$(error LIBRARY requires OUTPUT_DIR)
411167465Smp    endif
41259243Sobrien
41359243Sobrien    ifneq ($$($1_LIBRARY),$(basename $$($1_LIBRARY)))
41459243Sobrien      $$(error directory of LIBRARY should be specified using OUTPUT_DIR)
41559243Sobrien    endif
416167465Smp
417167465Smp    ifneq (,$(findstring $(SHARED_LIBRARY_SUFFIX),$$($1_LIBRARY)))
418167465Smp      $$(error LIBRARY should be specified without SHARED_LIBRARY_SUFFIX: $(SHARED_LIBRARY_SUFFIX))
419167465Smp    endif
42059243Sobrien
42159243Sobrien    ifneq (,$(findstring $(LIBRARY_PREFIX),$$($1_LIBRARY)))
422167465Smp      $$(error LIBRARY should be specified without LIBRARY_PREFIX: $(LIBRARY_PREFIX))
423167465Smp    endif
424167465Smp
425167465Smp    ifeq ($$($1_SUFFIX), )
426167465Smp      $1_SUFFIX := $(SHARED_LIBRARY_SUFFIX)
427167465Smp    endif
428167465Smp
429167465Smp    $1_BASENAME:=$(LIBRARY_PREFIX)$$($1_LIBRARY)$$($1_SUFFIX)
430167465Smp    $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME)
43159243Sobrien    $1_NOSUFFIX:=$(LIBRARY_PREFIX)$$($1_LIBRARY)
432167465Smp  endif
433167465Smp
43459243Sobrien  ifneq (,$$($1_STATIC_LIBRARY))
43559243Sobrien    ifeq (,$$($1_OUTPUT_DIR))
436167465Smp      $$(error STATIC_LIBRARY requires OUTPUT_DIR)
437167465Smp    endif
438167465Smp
439167465Smp    ifneq ($$($1_STATIC_LIBRARY),$(basename $$($1_STATIC_LIBRARY)))
440167465Smp      $$(error directory of STATIC_LIBRARY should be specified using OUTPUT_DIR)
441167465Smp    endif
442167465Smp
443167465Smp    ifneq (,$(findstring $(STATIC_LIBRARY_SUFFIX),$$($1_STATIC_LIBRARY)))
444167465Smp      $$(error STATIC_LIBRARY should be specified without STATIC_LIBRARY_SUFFIX: $(STATIC_LIBRARY_SUFFIX))
44559243Sobrien    endif
446167465Smp
447167465Smp    ifneq (,$(findstring $(LIBRARY_PREFIX),$$($1_STATIC_LIBRARY)))
44859243Sobrien      $$(error STATIC_LIBRARY should be specified without LIBRARY_PREFIX: $(LIBRARY_PREFIX))
449167465Smp    endif
450167465Smp
451167465Smp    ifeq ($$($1_SUFFIX), )
45259243Sobrien      $1_SUFFIX := $(STATIC_LIBRARY_SUFFIX)
453195609Smp    endif
454167465Smp
455167465Smp    $1_BASENAME:=$(LIBRARY_PREFIX)$$($1_STATIC_LIBRARY)$$($1_SUFFIX)
456167465Smp    $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME)
457167465Smp    $1_NOSUFFIX:=$(LIBRARY_PREFIX)$$($1_STATIC_LIBRARY)
458167465Smp  endif
459167465Smp
460167465Smp  ifneq (,$$($1_PROGRAM))
461167465Smp    ifeq (,$$($1_OUTPUT_DIR))
462167465Smp      $$(error PROGRAM requires OUTPUT_DIR)
463167465Smp    endif
464167465Smp
465167465Smp    ifneq ($$($1_PROGRAM),$(basename $$($1_PROGRAM)))
466167465Smp      $$(error directory of PROGRAM should be specified using OUTPUT_DIR)
467167465Smp    endif
468167465Smp
46959243Sobrien    ifneq (,$(findstring $(EXE_SUFFIX),$$($1_PROGRAM)))
470167465Smp      $$(error PROGRAM should be specified without EXE_SUFFIX: $(EXE_SUFFIX))
471167465Smp    endif
47259243Sobrien
473167465Smp    ifeq ($$($1_SUFFIX), )
474167465Smp      $1_SUFFIX := $(EXE_SUFFIX)
475167465Smp    endif
476167465Smp
477167465Smp    $1_BASENAME:=$$($1_PROGRAM)$$($1_SUFFIX)
478167465Smp    $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME)
479167465Smp    $1_NOSUFFIX:=$$($1_PROGRAM)
480167465Smp  endif
481167465Smp  $1_SAFE_NAME := $$(strip $$(subst /,_, $1))
482167465Smp
483167465Smp  ifeq (,$$($1_TARGET))
48459243Sobrien    $$(error Neither PROGRAM, LIBRARY nor STATIC_LIBRARY has been specified for SetupNativeCompilation)
48559243Sobrien  endif
486167465Smp
487167465Smp  # Setup the toolchain to be used
488167465Smp  $$(call SetIfEmpty, $1_TOOLCHAIN, TOOLCHAIN_DEFAULT)
489167465Smp  $$(call SetIfEmpty, $1_CC, $$($$($1_TOOLCHAIN)_CC))
490167465Smp  $$(call SetIfEmpty, $1_CXX, $$($$($1_TOOLCHAIN)_CXX))
49159243Sobrien  $$(call SetIfEmpty, $1_LD, $$($$($1_TOOLCHAIN)_LD))
492167465Smp  $$(call SetIfEmpty, $1_AR, $$($$($1_TOOLCHAIN)_AR))
493167465Smp  $$(call SetIfEmpty, $1_AS, $$($$($1_TOOLCHAIN)_AS))
494167465Smp  $$(call SetIfEmpty, $1_MT, $$($$($1_TOOLCHAIN)_MT))
49559243Sobrien  $$(call SetIfEmpty, $1_RC, $$($$($1_TOOLCHAIN)_RC))
49659243Sobrien  $$(call SetIfEmpty, $1_OBJCOPY, $$($$($1_TOOLCHAIN)_OBJCOPY))
49759243Sobrien  $$(call SetIfEmpty, $1_STRIP, $$($$($1_TOOLCHAIN)_STRIP))
49859243Sobrien  $$(call SetIfEmpty, $1_SYSROOT_CFLAGS, $$($$($1_TOOLCHAIN)_SYSROOT_CFLAGS))
49959243Sobrien  $$(call SetIfEmpty, $1_SYSROOT_LDFLAGS, $$($$($1_TOOLCHAIN)_SYSROOT_LDFLAGS))
50059243Sobrien
50159243Sobrien  ifneq ($$($1_MANIFEST), )
502167465Smp    ifeq ($$($1_MANIFEST_VERSION), )
50359243Sobrien      $$(error If MANIFEST is provided, then MANIFEST_VERSION is required in $1)
50459243Sobrien    endif
505167465Smp  endif
50659243Sobrien
50759243Sobrien  # Make sure the dirs exist.
50859243Sobrien  $$(call MakeDir,$$($1_OBJECT_DIR) $$($1_OUTPUT_DIR))
509167465Smp  $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),, \
51059243Sobrien      $$(error SRC specified to SetupNativeCompilation $1 contains missing directory $$d)))
511167465Smp
512167465Smp  # Find all files in the source trees. Sort to remove duplicates.
51359243Sobrien  $1_SRCS := $$(sort $$(call CacheFind,$$($1_SRC)))
514167465Smp  $1_SRCS := $$(filter $$(NATIVE_SOURCE_EXTENSIONS), $$($1_SRCS))
51559243Sobrien  # Extract the C/C++ files.
516167465Smp  ifneq ($$($1_EXCLUDE_PATTERNS), )
517167465Smp    # We must not match the exclude pattern against the src root(s).
51859243Sobrien    $1_SRCS_WITHOUT_ROOTS := $$($1_SRCS)
51959243Sobrien    $$(foreach i,$$($1_SRC),$$(eval $1_SRCS_WITHOUT_ROOTS := $$(patsubst \
52059243Sobrien        $$i/%,%, $$($1_SRCS_WITHOUT_ROOTS))))
52159243Sobrien    $1_ALL_EXCLUDE_FILES :=  $$(call containing, $$($1_EXCLUDE_PATTERNS), \
52259243Sobrien        $$($1_SRCS_WITHOUT_ROOTS))
52359243Sobrien  endif
52459243Sobrien  ifneq ($$($1_EXCLUDE_FILES),)
52559243Sobrien    $1_ALL_EXCLUDE_FILES += $$($1_EXCLUDE_FILES)
52659243Sobrien  endif
52759243Sobrien  ifneq ($$($1_ALL_EXCLUDE_FILES),)
52859243Sobrien    $1_EXCLUDE_FILES_PAT := $$($1_ALL_EXCLUDE_FILES) \
52959243Sobrien        $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_ALL_EXCLUDE_FILES)))
53059243Sobrien    $1_EXCLUDE_FILES_PAT := $$(addprefix %,$$($1_EXCLUDE_FILES_PAT))
53159243Sobrien    $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES_PAT),$$($1_SRCS))
532167465Smp  endif
53359243Sobrien  ifneq ($$($1_INCLUDE_FILES), )
534167465Smp    $1_INCLUDE_FILES_PAT := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES)))
53559243Sobrien    $1_SRCS := $$(filter $$($1_INCLUDE_FILES_PAT),$$($1_SRCS))
53659243Sobrien  endif
53759243Sobrien  # There can be only a single bin dir root, no need to foreach over the roots.
53859243Sobrien  $1_BINS := $$(wildcard $$($1_OBJECT_DIR)/*$(OBJ_SUFFIX))
539167465Smp  # Now we have a list of all c/c++ files to compile: $$($1_SRCS)
54059243Sobrien  # and we have a list of all existing object files: $$($1_BINS)
54159243Sobrien
54259243Sobrien  # Prepend the source/bin path to the filter expressions. Then do the filtering.
54359243Sobrien  ifneq ($$($1_INCLUDES),)
54459243Sobrien    $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES))))
54559243Sobrien    $1_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS))
54659243Sobrien  endif
54759243Sobrien  ifneq ($$($1_EXCLUDES),)
548167465Smp    $1_SRC_EXCLUDES := $$(addsuffix /%,$$($1_EXCLUDES))
54959243Sobrien    $1_SRC_EXCLUDES += $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES))))
55059243Sobrien    $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS))
55159243Sobrien  endif
55259243Sobrien
55359243Sobrien  $1_SRCS += $$($1_EXTRA_FILES)
55459243Sobrien
55559243Sobrien  ifeq (,$$($1_SRCS))
556167465Smp    $$(error No sources found for $1 when looking inside the dirs $$($1_SRC))
55759243Sobrien  endif
558167465Smp
559167465Smp  # Calculate the expected output from compiling the sources
560167465Smp  $1_EXPECTED_OBJS_FILENAMES := $$(call replace_with_obj_extension, $$(notdir $$($1_SRCS)))
561167465Smp  $1_EXPECTED_OBJS := $$(addprefix $$($1_OBJECT_DIR)/,$$($1_EXPECTED_OBJS_FILENAMES))
56259243Sobrien  # Are there too many object files on disk? Perhaps because some source file was removed?
56359243Sobrien  $1_SUPERFLOUS_OBJS:=$$(sort $$(filter-out $$($1_EXPECTED_OBJS),$$($1_BINS)))
56459243Sobrien  # Clean out the superfluous object files.
56559243Sobrien  ifneq ($$($1_SUPERFLUOUS_OBJS),)
566167465Smp    $$(shell $(RM) -f $$($1_SUPERFLUOUS_OBJS))
567167465Smp  endif
568167465Smp  # Sort to remove dupliates and provide a reproducable order on the input files to the linker.
56959243Sobrien  $1_ALL_OBJS := $$(sort $$($1_EXPECTED_OBJS) $$($1_EXTRA_OBJECT_FILES))
57059243Sobrien
571167465Smp  # Pickup extra OPENJDK_TARGET_OS_TYPE, OPENJDK_TARGET_OS, and/or OPENJDK_TARGET_OS plus
572167465Smp  # OPENJDK_TARGET_CPU pair dependent variables for CFLAGS.
573167465Smp  $1_EXTRA_CFLAGS:=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_CFLAGS_$(OPENJDK_TARGET_OS)) \
574167465Smp      $$($1_CFLAGS_$(OPENJDK_TARGET_OS)_$(OPENJDK_TARGET_CPU))
575167465Smp  ifneq ($(DEBUG_LEVEL),release)
57659243Sobrien    # Pickup extra debug dependent variables for CFLAGS
577167465Smp    $1_EXTRA_CFLAGS+=$$($1_CFLAGS_debug)
578167465Smp    $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_TYPE)_debug)
579167465Smp    $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS)_debug)
58059243Sobrien    $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS)_$(OPENJDK_TARGET_CPU)_debug)
581167465Smp  else
58259243Sobrien    $1_EXTRA_CFLAGS+=$$($1_CFLAGS_release)
58359243Sobrien    $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_TYPE)_release)
58459243Sobrien    $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS)_release)
58559243Sobrien    $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS)_$(OPENJDK_TARGET_CPU)_release)
58659243Sobrien  endif
58759243Sobrien
58859243Sobrien  # Pickup extra OPENJDK_TARGET_OS_TYPE and/or OPENJDK_TARGET_OS dependent variables for CXXFLAGS.
58959243Sobrien  $1_EXTRA_CXXFLAGS:=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS))
59059243Sobrien  ifneq ($(DEBUG_LEVEL),release)
59159243Sobrien    # Pickup extra debug dependent variables for CXXFLAGS
59259243Sobrien    $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_debug)
59359243Sobrien    $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_TYPE)_debug)
59459243Sobrien    $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)_debug)
595167465Smp  else
596167465Smp    $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_release)
59759243Sobrien    $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_TYPE)_release)
598167465Smp    $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)_release)
599167465Smp  endif
600167465Smp
60159243Sobrien  # If no C++ flags are explicitly set, default to using the C flags.
602145479Smp  # After that, we can set additional C++ flags that should not interfere
60359243Sobrien  # with the mechanism for copying the C flags by default.
60459243Sobrien  ifeq ($$($1_CXXFLAGS),)
605167465Smp    $1_CXXFLAGS:=$$($1_CFLAGS)
60659243Sobrien  endif
607167465Smp  ifeq ($$(strip $$($1_EXTRA_CXXFLAGS)),)
60859243Sobrien    $1_EXTRA_CXXFLAGS:=$$($1_EXTRA_CFLAGS)
60959243Sobrien  endif
61059243Sobrien
61159243Sobrien  ifeq ($(COMPILE_WITH_DEBUG_SYMBOLS), true)
61259243Sobrien    $$(call SetIfEmpty, $1_CFLAGS_DEBUG_SYMBOLS, $(CFLAGS_DEBUG_SYMBOLS))
613167465Smp    $$(call SetIfEmpty, $1_CXXFLAGS_DEBUG_SYMBOLS, $(CXXFLAGS_DEBUG_SYMBOLS))
61459243Sobrien    $1_EXTRA_CFLAGS += $$($1_CFLAGS_DEBUG_SYMBOLS)
61559243Sobrien    $1_EXTRA_CXXFLAGS += $$($1_CXXFLAGS_DEBUG_SYMBOLS)
61659243Sobrien  endif
61759243Sobrien
61859243Sobrien  ifneq (,$$($1_REORDER))
61959243Sobrien    $1_EXTRA_CFLAGS += $$(C_FLAG_REORDER)
62059243Sobrien    $1_EXTRA_CXXFLAGS += $$(CXX_FLAG_REORDER)
62159243Sobrien  endif
62259243Sobrien
62359243Sobrien  # Pass the library name for static JNI library naming
62459243Sobrien  ifneq ($$($1_STATIC_LIBRARY),)
62559243Sobrien    $1_EXTRA_CFLAGS += -DLIBRARY_NAME=$$($1_STATIC_LIBRARY)
62659243Sobrien    $1_EXTRA_CXXFLAGS += -DLIBRARY_NAME=$$($1_STATIC_LIBRARY)
62759243Sobrien  endif
62859243Sobrien
62959243Sobrien  # Pick up disabled warnings, if possible on this platform.
630167465Smp  ifneq ($(DISABLE_WARNING_PREFIX),)
63159243Sobrien    $1_EXTRA_CFLAGS += $$(addprefix $(DISABLE_WARNING_PREFIX), \
632167465Smp        $$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)) \
633167465Smp        $$($1_DISABLED_WARNINGS_C_$(TOOLCHAIN_TYPE)))
63459243Sobrien    $1_EXTRA_CXXFLAGS += $$(addprefix $(DISABLE_WARNING_PREFIX), \
63559243Sobrien        $$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)) \
63659243Sobrien        $$($1_DISABLED_WARNINGS_CXX_$(TOOLCHAIN_TYPE)))
637167465Smp  endif
63859243Sobrien
63959243Sobrien  # Check if warnings should be considered errors.
64059243Sobrien  # Pick first binary and toolchain specific, then binary specific, then general setting.
641167465Smp  ifeq ($$($1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE)),)
64259243Sobrien    ifeq ($$($1_WARNINGS_AS_ERRORS),)
643167465Smp      $1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE) := $$(WARNINGS_AS_ERRORS)
644167465Smp    else
64559243Sobrien      $1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE) := $$($1_WARNINGS_AS_ERRORS)
64659243Sobrien    endif
647167465Smp  endif
648167465Smp
649167465Smp  ifeq ($$($1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE)), true)
650167465Smp    $1_EXTRA_CFLAGS += $(CFLAGS_WARNINGS_ARE_ERRORS)
65159243Sobrien    $1_EXTRA_CXXFLAGS += $(CFLAGS_WARNINGS_ARE_ERRORS)
65259243Sobrien  endif
65359243Sobrien
65459243Sobrien  ifeq (NONE, $$($1_OPTIMIZATION))
655167465Smp    $1_OPT_CFLAGS := $(C_O_FLAG_NONE)
656167465Smp    $1_OPT_CXXFLAGS := $(CXX_O_FLAG_NONE)
657167465Smp  else ifeq (LOW, $$($1_OPTIMIZATION))
658167465Smp    $1_OPT_CFLAGS := $(C_O_FLAG_NORM)
659167465Smp    $1_OPT_CXXFLAGS := $(CXX_O_FLAG_NORM)
660231990Smp  else ifeq (HIGH, $$($1_OPTIMIZATION))
661231990Smp    $1_OPT_CFLAGS := $(C_O_FLAG_HI)
662231990Smp    $1_OPT_CXXFLAGS := $(CXX_O_FLAG_HI)
66359243Sobrien  else ifeq (HIGHEST, $$($1_OPTIMIZATION))
664167465Smp    $1_OPT_CFLAGS := $(C_O_FLAG_HIGHEST)
665167465Smp    $1_OPT_CXXFLAGS := $(CXX_O_FLAG_HIGHEST)
66659243Sobrien  else ifeq (HIGHEST_JVM, $$($1_OPTIMIZATION))
66759243Sobrien    $1_OPT_CFLAGS := $(C_O_FLAG_HIGHEST_JVM)
66859243Sobrien    $1_OPT_CXXFLAGS := $(CXX_O_FLAG_HIGHEST_JVM)
669167465Smp  else ifeq (SIZE, $$($1_OPTIMIZATION))
67059243Sobrien    $1_OPT_CFLAGS := $(C_O_FLAG_SIZE)
67159243Sobrien    $1_OPT_CXXFLAGS := $(CXX_O_FLAG_SIZE)
67259243Sobrien  else ifneq (, $$($1_OPTIMIZATION))
67359243Sobrien    $$(error Unknown value for OPTIMIZATION: $$($1_OPTIMIZATION))
67459243Sobrien  endif
67559243Sobrien
676167465Smp  $1_BUILD_INFO := $$($1_OBJECT_DIR)/_build-info.marker
677167465Smp
67859243Sobrien  # Track variable changes for all variables that affect the compilation command
67959243Sobrien  # lines for all object files in this setup. This includes at least all the
680167465Smp  # variables used in the call to add_native_source below.
681167465Smp  $1_COMPILE_VARDEPS := $$($1_CFLAGS) $$($1_EXTRA_CFLAGS) $$($1_SYSROOT_CFLAGS) \
682167465Smp      $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS) $$($1_OPT_CFLAGS) $$($1_OPT_CXXFLAGS) \
68359243Sobrien      $$($1_CC) $$($1_CXX) $$($1_AS) $$($1_ASFLAGS)
68459243Sobrien  $1_COMPILE_VARDEPS_FILE := $$(call DependOnVariable, $1_COMPILE_VARDEPS, \
68559243Sobrien      $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).comp.vardeps)
68659243Sobrien
68759243Sobrien  ifneq ($$($1_PRECOMPILED_HEADER), )
68859243Sobrien    ifeq ($(USE_PRECOMPILED_HEADER), 1)
68959243Sobrien      ifeq ($(TOOLCHAIN_TYPE), microsoft)
69059243Sobrien        $1_PCH_FILE := $$($1_OBJECT_DIR)/$1.pch
69159243Sobrien        $1_GENERATED_PCH_SRC := $$($1_OBJECT_DIR)/$1_pch.cpp
69259243Sobrien        $1_GENERATED_PCH_OBJ := $$($1_OBJECT_DIR)/$1_pch.obj
693167465Smp
69459243Sobrien        $$(eval $$(call add_native_source,$1,$$($1_GENERATED_PCH_SRC), \
69559243Sobrien            $$($1_OBJECT_DIR),,, \
69659243Sobrien            $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS) $$($1_SYSROOT_CFLAGS) \
69759243Sobrien                -Fp$$($1_PCH_FILE) -Yc$$(notdir $$($1_PRECOMPILED_HEADER)), \
69859243Sobrien            $$($1_CXX),,no_this_file))
69959243Sobrien
70059243Sobrien        $1_USE_PCH_FLAGS := \
70159243Sobrien            -Fp$$($1_PCH_FILE) -Yu$$(notdir $$($1_PRECOMPILED_HEADER))
70259243Sobrien
70359243Sobrien        $$($1_ALL_OBJS): $$($1_GENERATED_PCH_OBJ)
70459243Sobrien
70559243Sobrien        # Explicitly add the pch obj file first to ease comparing to old
70659243Sobrien        # hotspot build.
70759243Sobrien        $1_ALL_OBJS := $$($1_GENERATED_PCH_OBJ) $$($1_ALL_OBJS)
70859243Sobrien
709231990Smp        $$($1_GENERATED_PCH_SRC):
71059243Sobrien		$(ECHO) "#include \"$$(notdir $$($1_PRECOMPILED_HEADER))\"" > $$@
711231990Smp
71259243Sobrien      else ifneq ($(findstring $(TOOLCHAIN_TYPE), gcc clang), )
71359243Sobrien        ifeq ($(TOOLCHAIN_TYPE), gcc)
71459243Sobrien          $1_PCH_FILE := $$($1_OBJECT_DIR)/precompiled/$$(notdir $$($1_PRECOMPILED_HEADER)).gch
715231990Smp          $1_USE_PCH_FLAGS := -I$$($1_OBJECT_DIR)/precompiled
716231990Smp        else ifeq ($(TOOLCHAIN_TYPE), clang)
717231990Smp          $1_PCH_FILE := $$($1_OBJECT_DIR)/precompiled/$$(notdir $$($1_PRECOMPILED_HEADER)).pch
718231990Smp          $1_USE_PCH_FLAGS := -include-pch $$($1_PCH_FILE)
719231990Smp        endif
720231990Smp        $1_PCH_DEP := $$($1_PCH_FILE).d
721231990Smp        $1_PCH_DEP_TARGETS := $$($1_PCH_FILE).d.targets
722231990Smp
723231990Smp        -include $$($1_PCH_DEP)
72459243Sobrien        -include $$($1_PCH_DEP_TARGETS)
72559243Sobrien
726231990Smp        $$($1_PCH_FILE): $$($1_PRECOMPILED_HEADER) $$($1_COMPILE_VARDEPS_FILE)
727231990Smp		$$(call LogInfo, Generating precompiled header)
728231990Smp		$$(call MakeDir, $$(@D))
729231990Smp		$$(call ExecuteWithLog, $$@, \
730231990Smp		    $$($1_CC) $$($1_CFLAGS) $$($1_EXTRA_CFLAGS) $$($1_SYSROOT_CFLAGS) \
731231990Smp		    $$($1_OPT_CFLAGS) \
732231990Smp		    -x c++-header -c $(C_FLAG_DEPS) $$($1_PCH_DEP) $$< -o $$@)
733231990Smp		$(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_PCH_DEP) > $$($1_PCH_DEP_TARGETS)
73459243Sobrien
735231990Smp        $$($1_ALL_OBJS): $$($1_PCH_FILE)
73659243Sobrien
737231990Smp      endif
738231990Smp    endif
739231990Smp  endif
740231990Smp
741231990Smp  # Now call add_native_source for each source file we are going to compile.
742231990Smp  $$(foreach p,$$($1_SRCS), \
74359243Sobrien      $$(eval $$(call add_native_source,$1,$$p,$$($1_OBJECT_DIR), \
74459243Sobrien          $$($1_CFLAGS) $$($1_EXTRA_CFLAGS) $$($1_SYSROOT_CFLAGS), \
74559243Sobrien          $$($1_CC), \
74659243Sobrien          $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS) $$($1_SYSROOT_CFLAGS), \
74759243Sobrien          $$($1_CXX), $$($1_ASFLAGS))))
74859243Sobrien
74959243Sobrien  # Setup rule for printing progress info when compiling source files.
75059243Sobrien  # This is a rough heuristic and may not always print accurate information.
75159243Sobrien  $$($1_BUILD_INFO): $$($1_SRCS) $$($1_COMPILE_VARDEPS_FILE)
75259243Sobrien        ifeq ($$(wildcard $$($1_TARGET)),)
753167465Smp	  $(ECHO) 'Creating $$(subst $$(BUILD_OUTPUT)/,,$$($1_TARGET)) from $$(words \
75459243Sobrien	      $$(filter-out %.vardeps, $$?)) file(s)'
755145479Smp        else
75659243Sobrien	  $(ECHO) $$(strip 'Updating $$(subst $$(BUILD_OUTPUT)/,,$$($1_TARGET))' \
757167465Smp	      $$(if $$(filter-out %.vardeps, $$?), \
758167465Smp	        'due to $$(words $$(filter-out %.vardeps, $$?)) file(s)', \
75959243Sobrien	      $$(if $$(filter %.vardeps, $$?), 'due to makefile changes')))
76059243Sobrien        endif
76159243Sobrien	$(TOUCH) $$@
76259243Sobrien
76359243Sobrien  # On windows we need to create a resource file
76459243Sobrien  ifeq ($(OPENJDK_TARGET_OS), windows)
76559243Sobrien    ifneq (,$$($1_VERSIONINFO_RESOURCE))
76659243Sobrien      $1_RES:=$$($1_OBJECT_DIR)/$$($1_BASENAME).res
76759243Sobrien      $1_RES_DEP:=$$($1_RES).d
76859243Sobrien      $1_RES_DEP_TARGETS:=$$($1_RES).d.targets
76959243Sobrien      -include $$($1_RES_DEP)
77059243Sobrien      -include $$($1_RES_DEP_TARGETS)
77159243Sobrien
772167465Smp      $1_RES_VARDEPS := $$($1_RC) $$($1_RC_FLAGS)
77359243Sobrien      $1_RES_VARDEPS_FILE := $$(call DependOnVariable, $1_RES_VARDEPS, \
77459243Sobrien          $$($1_RES).vardeps)
775145479Smp
77659243Sobrien      $$($1_RES): $$($1_VERSIONINFO_RESOURCE) $$($1_RES_VARDEPS_FILE)
77759243Sobrien		$$(call LogInfo, Compiling resource $$(notdir $$($1_VERSIONINFO_RESOURCE)) (for $$(notdir $$($1_TARGET))))
77859243Sobrien		$$(call MakeDir, $$(@D) $$($1_OBJECT_DIR))
77959243Sobrien		$$(call ExecuteWithLog, $$@, \
78059243Sobrien		    $$($1_RC) $$($1_RC_FLAGS) $$($1_SYSROOT_CFLAGS) $(CC_OUT_OPTION)$$@ \
78159243Sobrien		    $$($1_VERSIONINFO_RESOURCE))
78259243Sobrien                # Windows RC compiler does not support -showIncludes, so we mis-use CL
78359243Sobrien                # for this. Filter out RC specific arguments that are unknown to CL.
78459243Sobrien                # For some unknown reason, in this case CL actually outputs the show
78559243Sobrien                # includes to stderr so need to redirect it to hide the output from the
78659243Sobrien                # main log.
78759243Sobrien		$$(call ExecuteWithLog, $$($1_RES_DEP).obj, \
78859243Sobrien		    $$($1_CC) $$(filter-out -l%, $$($1_RC_FLAGS)) \
78959243Sobrien		        $$($1_SYSROOT_CFLAGS) -showIncludes -nologo -TC \
79059243Sobrien		        $(CC_OUT_OPTION)$$($1_RES_DEP).obj -P -Fi$$($1_RES_DEP).pp \
791167465Smp		        $$($1_VERSIONINFO_RESOURCE)) 2>&1 \
79259243Sobrien		    | $(GREP) -v -e "^Note: including file:" \
793145479Smp		        -e "^$$(notdir $$($1_VERSIONINFO_RESOURCE))$$$$" || test "$$$$?" = "1" ; \
794145479Smp		$(ECHO) $$($1_RES): \\ > $$($1_RES_DEP) ; \
79559243Sobrien		$(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_RES_DEP).obj.log >> $$($1_RES_DEP) ; \
79659243Sobrien		$(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_RES_DEP) > $$($1_RES_DEP_TARGETS)
79759243Sobrien    endif
79859243Sobrien  endif
79959243Sobrien
80059243Sobrien  ifneq ($(DISABLE_MAPFILES),true)
80159243Sobrien    $1_REAL_MAPFILE := $$($1_MAPFILE)
80259243Sobrien    ifneq ($(OPENJDK_TARGET_OS),windows)
80359243Sobrien      ifneq (,$$($1_REORDER))
80459243Sobrien        $1_REAL_MAPFILE := $$($1_OBJECT_DIR)/mapfile
80559243Sobrien
80659243Sobrien        $$($1_REAL_MAPFILE) : $$($1_MAPFILE) $$($1_REORDER)
80759243Sobrien		$$(call MakeDir, $$(@D))
80859243Sobrien		$$(CP) $$($1_MAPFILE) $$@.tmp
80959243Sobrien		$$(SED) -e 's=OUTPUTDIR=$$($1_OBJECT_DIR)=' $$($1_REORDER) >> $$@.tmp
81059243Sobrien		$$(MV) $$@.tmp $$@
81159243Sobrien      endif
81259243Sobrien    endif
81359243Sobrien  endif
81459243Sobrien
81559243Sobrien  # Pickup extra OPENJDK_TARGET_OS_TYPE and/or OPENJDK_TARGET_OS dependent variables
81659243Sobrien  # for LDFLAGS and LIBS
81759243Sobrien  $1_EXTRA_LDFLAGS:=$$($1_LDFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS))
81859243Sobrien  $1_EXTRA_LIBS:=$$($1_LIBS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LIBS_$(OPENJDK_TARGET_OS))
81959243Sobrien  ifneq (,$$($1_REAL_MAPFILE))
82059243Sobrien    $1_EXTRA_LDFLAGS += $(call SET_SHARED_LIBRARY_MAPFILE,$$($1_REAL_MAPFILE))
82159243Sobrien  endif
82259243Sobrien
82359243Sobrien  # Need to make sure TARGET is first on list
824145479Smp  $1 := $$($1_TARGET)
825145479Smp
826145479Smp  ifneq ($$($1_COPY_DEBUG_SYMBOLS), false)
827145479Smp    $1_COPY_DEBUG_SYMBOLS := $(COPY_DEBUG_SYMBOLS)
828145479Smp  endif
829145479Smp
830145479Smp  ifneq ($$($1_ZIP_EXTERNAL_DEBUG_SYMBOLS), false)
831145479Smp    $1_ZIP_EXTERNAL_DEBUG_SYMBOLS := $(ZIP_EXTERNAL_DEBUG_SYMBOLS)
83259243Sobrien  endif
83359243Sobrien
83459243Sobrien  ifeq ($$($1_COPY_DEBUG_SYMBOLS), true)
83559243Sobrien    ifneq ($$($1_DEBUG_SYMBOLS), false)
83659243Sobrien      # Only copy debug symbols for dynamic libraries and programs.
83759243Sobrien      ifeq ($$($1_STATIC_LIBRARY), )
83859243Sobrien        # Generate debuginfo files.
83959243Sobrien        ifeq ($(OPENJDK_TARGET_OS), windows)
84059243Sobrien          $1_EXTRA_LDFLAGS += -debug "-pdb:$$($1_OUTPUT_DIR)/$$($1_NOSUFFIX).pdb" \
84159243Sobrien              "-map:$$($1_OUTPUT_DIR)/$$($1_NOSUFFIX).map"
84259243Sobrien          $1_DEBUGINFO_FILES := $$($1_OUTPUT_DIR)/$$($1_NOSUFFIX).pdb \
84359243Sobrien              $$($1_OUTPUT_DIR)/$$($1_NOSUFFIX).map
84459243Sobrien          # No separate command is needed for debuginfo on windows, instead
84559243Sobrien          # touch target to make sure it has a later time stamp than the debug
84659243Sobrien          # symbol files to avoid unnecessary relinking on rebuild.
84759243Sobrien          $1_CREATE_DEBUGINFO_CMDS := $(TOUCH) $$($1_TARGET)
84859243Sobrien
84959243Sobrien        else ifneq ($(findstring $(OPENJDK_TARGET_OS), linux solaris), )
85059243Sobrien          $1_DEBUGINFO_FILES := $$($1_OUTPUT_DIR)/$$($1_NOSUFFIX).debuginfo
85159243Sobrien          # Setup the command line creating debuginfo files, to be run after linking.
85259243Sobrien          # It cannot be run separately since it updates the original target file
85359243Sobrien          $1_CREATE_DEBUGINFO_CMDS := \
85459243Sobrien              $$($1_OBJCOPY) --only-keep-debug $$($1_TARGET) $$($1_DEBUGINFO_FILES) $$(NEWLINE) \
85559243Sobrien              $(CD) $$($1_OUTPUT_DIR) && \
85659243Sobrien                  $$($1_OBJCOPY) --add-gnu-debuglink=$$($1_DEBUGINFO_FILES) $$($1_TARGET)
85759243Sobrien
85859243Sobrien        else ifeq ($(OPENJDK_TARGET_OS), macosx)
85959243Sobrien          $1_DEBUGINFO_FILES := \
86059243Sobrien              $$($1_OUTPUT_DIR)/$$($1_BASENAME).dSYM/Contents/Info.plist \
86159243Sobrien              $$($1_OUTPUT_DIR)/$$($1_BASENAME).dSYM/Contents/Resources/DWARF/$$($1_BASENAME)
86259243Sobrien          # On Macosx, the debuginfo generation doesn't touch the linked binary, but
86359243Sobrien          # to avoid always relinking, touch it anyway to force a later timestamp than
86459243Sobrien          # the dSYM files.
86559243Sobrien          $1_CREATE_DEBUGINFO_CMDS := \
86659243Sobrien              $(DSYMUTIL) --out $$($1_OUTPUT_DIR)/$$($1_BASENAME).dSYM $$($1_TARGET) $$(NEWLINE) \
86759243Sobrien              $(TOUCH) $$($1_TARGET)
86859243Sobrien        endif # OPENJDK_TARGET_OS
86959243Sobrien
87059243Sobrien        $$($1_DEBUGINFO_FILES): $$($1_TARGET)
87159243Sobrien
87259243Sobrien        $1 += $$($1_DEBUGINFO_FILES)
87359243Sobrien
874167465Smp        ifeq ($$($1_ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
875167465Smp          $1_DEBUGINFO_ZIP := $$($1_OUTPUT_DIR)/$$($1_NOSUFFIX).diz
87659243Sobrien          $1 += $$($1_DEBUGINFO_ZIP)
877231990Smp
878167465Smp          # The dependency on TARGET is needed for debuginfo files
879167465Smp          # to be rebuilt properly.
880167465Smp          $$($1_DEBUGINFO_ZIP): $$($1_DEBUGINFO_FILES) $$($1_TARGET)
88159243Sobrien		$(CD) $$($1_OUTPUT_DIR) && \
88259243Sobrien		    $(ZIPEXE) -q -r $$@ $$(subst $$($1_OUTPUT_DIR)/,, $$($1_DEBUGINFO_FILES))
883167465Smp
884167465Smp        endif
885167465Smp       endif # !STATIC_LIBRARY
88659243Sobrien    endif # $1_DEBUG_SYMBOLS != false
88759243Sobrien  endif # COPY_DEBUG_SYMBOLS
888131962Smp
889167465Smp  # Unless specifically set, stripping should only happen if symbols are also
890167465Smp  # being copied.
89159243Sobrien  $$(call SetIfEmpty, $1_STRIP_SYMBOLS, $$($1_COPY_DEBUG_SYMBOLS))
89259243Sobrien
893167465Smp  ifneq ($$($1_STRIP_SYMBOLS), false)
89459243Sobrien    ifneq ($$($1_STRIP), )
89559243Sobrien      # Default to using the global STRIPFLAGS. Allow for overriding with an empty value
896231990Smp      $1_STRIPFLAGS ?= $(STRIPFLAGS)
897231990Smp      $1_STRIP_CMD := $$($1_STRIP) $$($1_STRIPFLAGS) $$($1_TARGET)
898231990Smp    endif
899231990Smp  endif
900231990Smp
901231990Smp  ifneq (,$$($1_LIBRARY))
902231990Smp    # Generating a dynamic library.
903231990Smp    $1_EXTRA_LDFLAGS += $$(call SET_SHARED_LIBRARY_NAME,$$($1_BASENAME))
90459243Sobrien    ifeq ($(OPENJDK_TARGET_OS), windows)
90559243Sobrien      $1_EXTRA_LDFLAGS += "-implib:$$($1_OBJECT_DIR)/$$($1_LIBRARY).lib"
90659243Sobrien      # Create a rule for the import lib so that other rules may depend on it
90759243Sobrien      $$($1_OBJECT_DIR)/$$($1_LIBRARY).lib: $$($1_TARGET)
908167465Smp    endif
909231990Smp
910231990Smp    # Create loadmap on AIX. Helps in diagnosing some problems.
91159243Sobrien    ifneq ($(COMPILER_BINDCMD_FILE_FLAG),)
91259243Sobrien      $1_EXTRA_LDFLAGS += $(COMPILER_BINDCMD_FILE_FLAG)$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).loadmap
91359243Sobrien    endif
91459243Sobrien
91559243Sobrien    $1_VARDEPS := $$($1_LD) $$($1_SYSROOT_LDFLAGS) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) \
91659243Sobrien        $$($1_LIBS) $$($1_EXTRA_LIBS) $$($1_CREATE_DEBUGINFO_CMDS) \
91759243Sobrien        $$($1_STRIP_CMD)
91859243Sobrien    $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
91959243Sobrien        $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
92059243Sobrien
92159243Sobrien    $1_LD_OBJ_ARG := $$($1_ALL_OBJS)
92259243Sobrien
92359243Sobrien    # If there are many object files, use an @-file...
92459243Sobrien    ifneq ($$(word 17, $$($1_ALL_OBJS)), )
92559243Sobrien      $1_OBJ_FILE_LIST := $$($1_OBJECT_DIR)/_$1_objectfilenames.txt
926167465Smp      ifneq ($(COMPILER_COMMAND_FILE_FLAG),)
927167465Smp        $1_LD_OBJ_ARG := $(COMPILER_COMMAND_FILE_FLAG)$$($1_OBJ_FILE_LIST)
928167465Smp      else
92959243Sobrien        # ...except for toolchains which don't support them.
93059243Sobrien        $1_LD_OBJ_ARG := `cat $$($1_OBJ_FILE_LIST)`
93159243Sobrien      endif
93259243Sobrien    endif
93359243Sobrien
934167465Smp    $$($1_TARGET): $$($1_ALL_OBJS) $$($1_RES) $$($1_REAL_MAPFILE) \
93559243Sobrien        $$($1_VARDEPS_FILE)
93659243Sobrien                ifneq ($$($1_OBJ_FILE_LIST), )
93759243Sobrien		  $$(eval $$(call ListPathsSafely, $1_ALL_OBJS, $$($1_OBJ_FILE_LIST)))
93859243Sobrien                endif
93959243Sobrien                # Keep as much as possible on one execution line for best performance
94059243Sobrien                # on Windows
94159243Sobrien		$$(call LogInfo, Linking $$($1_BASENAME))
942231990Smp                ifeq ($(OPENJDK_TARGET_OS), windows)
943167465Smp		  $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
94459243Sobrien		      $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
945167465Smp		      $(LD_OUT_OPTION)$$@ $$($1_LD_OBJ_ARG) $$($1_RES) $$($1_LIBS) \
946167465Smp		      $$($1_EXTRA_LIBS)) \
94759243Sobrien		      | $(GREP) -v "^   Creating library .*\.lib and object .*\.exp" || \
94859243Sobrien		      test "$$$$?" = "1" ; \
94959243Sobrien		  $$($1_CREATE_DEBUGINFO_CMDS)
95059243Sobrien		  $$($1_STRIP_CMD)
95159243Sobrien                else
95259243Sobrien		  $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
95359243Sobrien		      $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
95459243Sobrien		      $(LD_OUT_OPTION)$$@ $$($1_LD_OBJ_ARG) $$($1_RES) $$($1_LIBS) \
95559243Sobrien		      $$($1_EXTRA_LIBS)) ; \
95659243Sobrien		  $$($1_CREATE_DEBUGINFO_CMDS)
95759243Sobrien		  $$($1_STRIP_CMD)
95859243Sobrien                endif
95959243Sobrien
96059243Sobrien  endif
96159243Sobrien
96259243Sobrien  ifneq (,$$($1_STATIC_LIBRARY))
96359243Sobrien    $1_VARDEPS := $$($1_AR) $$($1_ARFLAGS) $$($1_LIBS) \
96459243Sobrien        $$($1_EXTRA_LIBS)
96559243Sobrien    $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
96659243Sobrien        $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
967231990Smp
968231990Smp    # Generating a static library, ie object file archive.
969231990Smp    ifeq ($(STATIC_BUILD), true)
970231990Smp      ifeq ($$($1_USE_MAPFILE_FOR_SYMBOLS), true)
971231990Smp        STATIC_MAPFILE_DEP := $$($1_MAPFILE)
972231990Smp      endif
973231990Smp    endif
974231990Smp
975231990Smp    $$($1_TARGET): $$($1_ALL_OBJS) $$($1_RES) $$($1_VARDEPS_FILE) $$(STATIC_MAPFILE_DEP)
976231990Smp	$$(call LogInfo, Archiving $$($1_STATIC_LIBRARY))
977231990Smp	$$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
978167465Smp	    $$($1_AR) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_ALL_OBJS) \
979167465Smp	        $$($1_RES))
980167465Smp        ifeq ($(STATIC_BUILD), true)
981167465Smp          ifeq ($$($1_USE_MAPFILE_FOR_SYMBOLS), true)
982167465Smp	    $(CP) $$($1_MAPFILE) $$(@D)/$$(basename $$(@F)).symbols
983167465Smp          else
98459243Sobrien	    $(GetSymbols)
985167465Smp          endif
98659243Sobrien        endif
98759243Sobrien  endif
98859243Sobrien
98959243Sobrien  ifneq (,$$($1_PROGRAM))
99059243Sobrien    # A executable binary has been specified, setup the target for it.
99159243Sobrien    $1_VARDEPS := $$($1_LD) $$($1_SYSROOT_LDFLAGS) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) \
99259243Sobrien        $$($1_LIBS) $$($1_EXTRA_LIBS) $$($1_MT) \
99359243Sobrien        $$($1_CODESIGN) $$($1_CREATE_DEBUGINFO_CMDS) $$($1_MANIFEST_VERSION) \
994167465Smp        $$($1_STRIP_CMD)
99559243Sobrien    $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
996167465Smp        $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
99759243Sobrien
99859243Sobrien    ifeq ($(OPENJDK_TARGET_OS), windows)
99959243Sobrien      ifeq ($$($1_EMBED_MANIFEST), true)
100059243Sobrien        $1_EXTRA_LDFLAGS += -manifest:embed
1001131962Smp      endif
1002167465Smp    endif
1003167465Smp
1004167465Smp    $$($1_TARGET): $$($1_ALL_OBJS) $$($1_RES) $$($1_MANIFEST) \
1005231990Smp        $$($1_VARDEPS_FILE)
1006231990Smp		$$(call LogInfo, Linking executable $$($1_BASENAME))
1007131962Smp		$$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
1008131962Smp		    $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
1009231990Smp		        $(EXE_OUT_OPTION)$$($1_TARGET) \
1010231990Smp		        $$($1_ALL_OBJS) $$($1_RES) \
1011231990Smp		        $$($1_LIBS) $$($1_EXTRA_LIBS))
1012167465Smp                ifeq ($(OPENJDK_TARGET_OS), windows)
1013231990Smp                  ifneq ($$($1_MANIFEST), )
1014167465Smp		    $$($1_MT) -nologo -manifest $$($1_MANIFEST) -identity:"$$($1_PROGRAM).exe, version=$$($1_MANIFEST_VERSION)" -outputresource:$$@;#1
1015167465Smp                  endif
1016167465Smp                endif
1017167465Smp                # This only works if the openjdk_codesign identity is present on the system. Let
1018167465Smp                # silently fail otherwise.
1019167465Smp                ifneq (,$(CODESIGN))
1020167465Smp                  ifneq (,$$($1_CODESIGN))
1021167465Smp		    $(CODESIGN) -s openjdk_codesign $$@
1022167465Smp                  endif
1023167465Smp                endif
1024167465Smp		$$($1_CREATE_DEBUGINFO_CMDS)
1025167465Smp		$$($1_STRIP_CMD)
1026167465Smp
1027131962Smp  endif
1028131962Smpendef
102959243Sobrien
103059243Sobrienendif # _NATIVE_COMPILATION_GMK
103159243Sobrien