NativeCompilation.gmk revision 1973:00ff6af007c0
1#
2# Copyright (c) 2011, 2016, 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
30ifndef _NATIVE_COMPILATION_GMK
31_NATIVE_COMPILATION_GMK := 1
32
33ifeq (,$(_MAKEBASE_GMK))
34  $(error You must include MakeBase.gmk prior to including NativeCompilation.gmk)
35endif
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
43define 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
60endef
61
62################################################################################
63# Define a native toolchain configuration that can be used by
64# SetupNativeCompilation calls
65#
66# Parameter 1 is the name of the toolchain definition
67#
68# Remaining parameters are named arguments:
69#   EXTENDS - Optional parent definition to get defaults from
70#   CC - The C compiler
71#   CXX - The C++ compiler
72#   LD - The Linker
73#   AR - Static linker
74#   AS - Assembler
75#   MT - Windows MT tool
76#   RC - Windows RC tool
77#   OBJCOPY - The objcopy tool for debug symbol handling
78#   STRIP - The tool to use for stripping debug symbols
79#   SYSROOT_CFLAGS - Compiler flags for using the specific sysroot
80#   SYSROOT_LDFLAGS - Linker flags for using the specific sysroot
81DefineNativeToolchain = $(NamedParamsMacroTemplate)
82define DefineNativeToolchainBody
83  # If extending another definition, get default values from that,
84  # otherwise, nothing more needs to be done as variable assignments
85  # already happened in NamedParamsMacroTemplate.
86  ifneq ($$($1_EXTENDS), )
87    $$(call SetIfEmpty, $1_CC, $$($$($1_EXTENDS)_CC))
88    $$(call SetIfEmpty, $1_CXX, $$($$($1_EXTENDS)_CXX))
89    $$(call SetIfEmpty, $1_LD, $$($$($1_EXTENDS)_LD))
90    $$(call SetIfEmpty, $1_AR, $$($$($1_EXTENDS)_AR))
91    $$(call SetIfEmpty, $1_AS, $$($$($1_EXTENDS)_AS))
92    $$(call SetIfEmpty, $1_MT, $$($$($1_EXTENDS)_MT))
93    $$(call SetIfEmpty, $1_RC, $$($$($1_EXTENDS)_RC))
94    $$(call SetIfEmpty, $1_OBJCOPY, $$($$($1_EXTENDS)_OBJCOPY))
95    $$(call SetIfEmpty, $1_STRIP, $$($$($1_EXTENDS)_STRIP))
96    $$(call SetIfEmpty, $1_SYSROOT_CFLAGS, $$($$($1_EXTENDS)_SYSROOT_CFLAGS))
97    $$(call SetIfEmpty, $1_SYSROOT_LDFLAGS, $$($$($1_EXTENDS)_SYSROOT_LDFLAGS))
98  endif
99endef
100
101# Create a default toolchain with the main compiler and linker
102$(eval $(call DefineNativeToolchain, TOOLCHAIN_DEFAULT, \
103    CC := $(CC), \
104    CXX := $(CXX), \
105    LD := $(LD), \
106    AR := $(AR), \
107    AS := $(AS), \
108    MT := $(MT), \
109    RC := $(RC), \
110    OBJCOPY := $(OBJCOPY), \
111    STRIP := $(STRIP), \
112    SYSROOT_CFLAGS := $(SYSROOT_CFLAGS), \
113    SYSROOT_LDFLAGS := $(SYSROOT_LDFLAGS), \
114))
115
116# Create a toolchain where linking is done with the C++ linker
117$(eval $(call DefineNativeToolchain, TOOLCHAIN_LINK_CXX, \
118    EXTENDS := TOOLCHAIN_DEFAULT, \
119    LD := $(LDCXX), \
120))
121
122# Create a toolchain with the BUILD compiler, used for build tools that
123# are to be run during the build.
124$(eval $(call DefineNativeToolchain, TOOLCHAIN_BUILD, \
125    CC := $(BUILD_CC), \
126    CXX := $(BUILD_CXX), \
127    LD := $(BUILD_LD), \
128    AR := $(BUILD_AR), \
129    AS := $(BUILD_AS), \
130    OBJCOPY := $(BUILD_OBJCOPY), \
131    STRIP := $(BUILD_STRIP), \
132    SYSROOT_CFLAGS := $(BUILD_SYSROOT_CFLAGS), \
133    SYSROOT_LDFLAGS := $(BUILD_SYSROOT_LDFLAGS), \
134))
135
136# BUILD toolchain with the C++ linker
137$(eval $(call DefineNativeToolchain, TOOLCHAIN_BUILD_LINK_CXX, \
138    EXTENDS := TOOLCHAIN_BUILD, \
139    LD := $(BUILD_LDCXX), \
140))
141
142################################################################################
143
144# Extensions of files handled by this macro.
145NATIVE_SOURCE_EXTENSIONS := %.s %.S %.c %.cpp %.cc %.m %.mm
146
147# Replaces native source extensions with the object file extension in a string.
148# Param 1: the string containing source file names with extensions
149# The surrounding strip is needed to keep additional whitespace out
150define replace_with_obj_extension
151$(strip \
152  $(foreach extension, $(NATIVE_SOURCE_EXTENSIONS), \
153      $(patsubst $(extension),%$(OBJ_SUFFIX),$(filter $(extension),$1))) \
154)
155endef
156
157ifeq ($(OPENJDK_BUILD_OS_ENV), windows.cygwin)
158  UNIX_PATH_PREFIX := /cygdrive
159else ifeq ($(OPENJDK_BUILD_OS_ENV), windows.msys)
160  UNIX_PATH_PREFIX :=
161endif
162
163# This pattern is used to transform the output of the microsoft CL compiler
164# into a make syntax dependency file (.d)
165WINDOWS_SHOWINCLUDE_SED_PATTERN := \
166    -e '/^Note: including file:/!d' \
167    -e 's|Note: including file: *||' \
168    -e 's|\\|/|g' \
169    -e 's|^\([a-zA-Z]\):|$(UNIX_PATH_PREFIX)/\1|g' \
170    -e '\|$(TOPDIR)|I !d' \
171    -e 's|$$$$| \\|g' \
172    #
173
174# This pattern is used to transform a dependency file (.d) to a list
175# of make targets for dependent files (.d.targets)
176DEPENDENCY_TARGET_SED_PATTERN := \
177    -e 's/\#.*//' \
178    -e 's/^[^:]*: *//' \
179    -e 's/ *\\$$$$//' \
180    -e 's/^[	 ]*//' \
181    -e '/^$$$$/ d' \
182    -e 's/$$$$/ :/' \
183    #
184
185define add_native_source
186  # param 1 = BUILD_MYPACKAGE
187  # parma 2 = the source file name (..../alfa.c or .../beta.cpp)
188  # param 3 = the bin dir that stores all .o (.obj) and .d files.
189  # param 4 = the c flags to the compiler
190  # param 5 = the c compiler
191  # param 6 = the c++ flags to the compiler
192  # param 7 = the c++ compiler
193  # param 8 = the flags to the assembler
194  # param 9 = set to disable THIS_FILE
195
196  ifeq ($9, )
197    $1_$2_THIS_FILE = -DTHIS_FILE='"$$(<F)"'
198  endif
199
200  ifneq (,$$(filter %.c,$2))
201    # Compile as a C file
202    $1_$2_FLAGS=$(CFLAGS_CCACHE) $4 $$($1_$(notdir $2)_CFLAGS) $$($1_$2_THIS_FILE) -c
203    $1_$2_COMP=$5
204    $1_$2_DEP_FLAG:=$(C_FLAG_DEPS)
205  else ifneq (,$$(filter %.m,$2))
206    # Compile as an Objective-C file
207    $1_$2_FLAGS=-x objective-c $(CFLAGS_CCACHE) $4 $$($1_$(notdir $2)_CFLAGS) $$($1_$2_THIS_FILE) -c
208    $1_$2_COMP=$5
209    $1_$2_DEP_FLAG:=$(C_FLAG_DEPS)
210  else ifneq (,$$(filter %.s %.S,$2))
211    # Compile as assembler file
212    $1_$2_FLAGS=$8
213    $1_$2_COMP=$(AS)
214    $1_$2_DEP_FLAG:=
215  else ifneq (,$$(filter %.cpp,$2)$$(filter %.cc,$2)$$(filter %.mm,$2))
216    # Compile as a C++ or Objective-C++ file
217    $1_$2_FLAGS=$(CFLAGS_CCACHE) $6 $$($1_$(notdir $2)_CXXFLAGS) $$($1_$2_THIS_FILE) -c
218    $1_$2_COMP=$7
219    $1_$2_DEP_FLAG:=$(CXX_FLAG_DEPS)
220  else
221    $$(error Internal error in NativeCompilation.gmk: no compiler for file $2)
222  endif
223  # Generate the .o (.obj) file name and place it in the bin dir.
224  $1_$2_OBJ := $3/$$(call replace_with_obj_extension, $$(notdir $2))
225  # Only continue if this object file hasn't been processed already. This lets the first found
226  # source file override any other with the same name.
227  ifeq (,$$(findstring $$($1_$2_OBJ),$$($1_OBJS_SO_FAR)))
228    $1_OBJS_SO_FAR+=$$($1_$2_OBJ)
229    ifeq (,$$(filter %.s %.S,$2))
230      # And this is the dependency file for this obj file.
231      $1_$2_DEP:=$$(patsubst %$(OBJ_SUFFIX),%.d,$$($1_$2_OBJ))
232      # The dependency target file lists all dependencies as empty targets
233      # to avoid make error "No rule to make target" for removed files
234      $1_$2_DEP_TARGETS:=$$(patsubst %$(OBJ_SUFFIX),%.d.targets,$$($1_$2_OBJ))
235
236      # Include previously generated dependency information. (if it exists)
237      -include $$($1_$2_DEP)
238      -include $$($1_$2_DEP_TARGETS)
239
240      ifeq ($(TOOLCHAIN_TYPE), microsoft)
241        # To avoid name clashes between pdbs for objects and libs/execs, put
242        # object pdbs in a separate subdir.
243        $1_$2_DEBUG_OUT_FLAGS:=-Fd$$(strip $$(patsubst $$($1_OBJECT_DIR)/%, \
244            $$($1_OBJECT_DIR)/pdb/%, $$(patsubst %$(OBJ_SUFFIX),%.pdb,$$($1_$2_OBJ))))
245      endif
246    endif
247
248    ifneq ($$($1_$(notdir $2)_CFLAGS)$$($1_$(notdir $2)_CXXFLAGS), )
249      $1_$2_VARDEPS := $$($1_$(notdir $2)_CFLAGS) $$($1_$(notdir $2)_CXXFLAGS)
250      $1_$2_VARDEPS_FILE := $$(call DependOnVariable, $1_$2_VARDEPS, \
251          $$(patsubst %$(OBJ_SUFFIX),%.vardeps,$$($1_$2_OBJ)))
252    endif
253
254    $$($1_$2_OBJ) : $2 $$($1_COMPILE_VARDEPS_FILE) $$($1_$2_VARDEPS_FILE) | $$($1_BUILD_INFO)
255	$$(call LogInfo, Compiling $$(notdir $2) (for $$(notdir $$($1_TARGET))))
256	$$(call MakeDir, $$(@D) $$(@D)/pdb)
257        ifneq ($(TOOLCHAIN_TYPE), microsoft)
258          ifeq ($(TOOLCHAIN_TYPE)$$(filter %.s,$2), solstudio)
259            # The Solaris studio compiler doesn't output the full path to the object file in the
260            # generated deps files. Fixing it with sed. If compiling assembly, don't try this.
261	    $$(call ExecuteWithLog, $$@, \
262	        $$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEP_FLAG) $$($1_$2_DEP).tmp $(CC_OUT_OPTION)$$($1_$2_OBJ) $2)
263	    $(SED) 's|^$$(@F):|$$@:|' $$($1_$2_DEP).tmp > $$($1_$2_DEP)
264          else
265	    $$(call ExecuteWithLog, $$@, \
266	        $$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEP_FLAG) $$($1_$2_DEP) $(CC_OUT_OPTION)$$($1_$2_OBJ) $2)
267          endif
268          # Create a dependency target file from the dependency file.
269          # Solution suggested by http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
270          ifneq ($$($1_$2_DEP),)
271	    $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_$2_DEP) > $$($1_$2_DEP_TARGETS)
272          endif
273        else
274          # The Visual Studio compiler lacks a feature for generating make dependencies, but by
275          # setting -showIncludes, all included files are printed. These are filtered out and
276          # parsed into make dependences.
277          # Keep as much as possible on one execution line for best performance on Windows.
278          # No need to save exit code from compilation since pipefail is always active on
279          # Windows.
280	  $$(call ExecuteWithLog, $$@, \
281	      $$($1_$2_COMP) $$($1_$2_FLAGS) -showIncludes $$($1_$2_DEBUG_OUT_FLAGS) \
282	          $(CC_OUT_OPTION)$$($1_$2_OBJ) $2) \
283	      | $(GREP) -v -e "^Note: including file:" \
284	          -e "^$(notdir $2)$$$$" || test "$$$$?" = "1" ; \
285	  $(ECHO) $$@: \\ > $$($1_$2_DEP) ; \
286	  $(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_$2_OBJ).log \
287	      | $(SORT) -u >> $$($1_$2_DEP) ; \
288	  $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_$2_DEP) > $$($1_$2_DEP_TARGETS)
289        endif
290  endif
291endef
292
293# Setup make rules for creating a native binary (a shared library or an
294# executable).
295#
296# Parameter 1 is the name of the rule. This name is used as variable prefix,
297# and the targets generated are listed in a variable by that name.
298#
299# Remaining parameters are named arguments. These include:
300#   TOOLCHAIN Name of toolchain setup to use. Defaults to TOOLCHAIN_DEFAULT.
301#   SRC one or more directory roots to scan for C/C++ files.
302#   CFLAGS the compiler flags to be used, used both for C and C++.
303#   CXXFLAGS the compiler flags to be used for c++, if set overrides CFLAGS.
304#   LDFLAGS the linker flags to be used, used both for C and C++.
305#   LIBS the libraries to link to
306#   ARFLAGS the archiver flags to be used
307#   OBJECT_DIR the directory where we store the object files
308#   LIBRARY the resulting library file
309#   PROGRAM the resulting exec file
310#   INCLUDES only pick source from these directories
311#   EXCLUDES do not pick source from these directories
312#   INCLUDE_FILES only compile exactly these files!
313#   EXCLUDE_FILES with these names
314#   EXCLUDE_PATTERN exclude files matching any of these substrings
315#   EXTRA_FILES List of extra files not in any of the SRC dirs
316#   EXTRA_OBJECT_FILES List of extra object files to include when linking
317#   VERSIONINFO_RESOURCE Input file for RC. Setting this implies that RC will be run
318#   RC_FLAGS flags for RC.
319#   EMBED_MANIFEST if true, embed manifest on Windows.
320#   MAPFILE mapfile
321#   REORDER reorder file
322#   USE_MAPFILE_FOR_SYMBOLS if true and this is a STATIC_BUILD, just copy the
323#       mapfile for the output symbols file
324#   CC the compiler to use, default is $(CC)
325#   LD the linker to use, default is $(LD)
326#   OPTIMIZATION sets optimization level to NONE, LOW, HIGH, HIGHEST
327#   DISABLED_WARNINGS_<toolchain> Disable the given warnings for the specified toolchain
328#   DISABLED_WARNINGS_C_<toolchain> Disable the given warnings for the specified toolchain
329#       when compiling C code
330#   DISABLED_WARNINGS_CXX_<toolchain> Disable the given warnings for the specified
331#       toolchain when compiling C++ code
332#   STRIP_SYMBOLS Set to true to strip the final binary if the toolchain allows for it
333#   DEBUG_SYMBOLS Set to false to disable generation of debug symbols
334#   STRIPFLAGS Optionally change the flags given to the strip command
335SetupNativeCompilation = $(NamedParamsMacroTemplate)
336define SetupNativeCompilationBody
337
338  # If we're doing a static build and producing a library
339  # force it to be a static library and remove the -l libraries
340  ifeq ($(STATIC_BUILD), true)
341    ifneq ($$($1_LIBRARY),)
342      $1_STATIC_LIBRARY := $$($1_LIBRARY)
343      $1_LIBRARY :=
344    endif
345  endif
346
347  ifneq (,$$($1_BIN))
348    $$(error BIN has been replaced with OBJECT_DIR)
349  endif
350
351  ifneq (,$$($1_LIB))
352    $$(error LIB has been replaced with LIBRARY)
353  endif
354
355  ifneq (,$$($1_EXE))
356    $$(error EXE has been replaced with PROGRAM)
357  endif
358
359  ifneq (,$$($1_LIBRARY))
360    ifeq (,$$($1_OUTPUT_DIR))
361      $$(error LIBRARY requires OUTPUT_DIR)
362    endif
363
364    ifneq ($$($1_LIBRARY),$(basename $$($1_LIBRARY)))
365      $$(error directory of LIBRARY should be specified using OUTPUT_DIR)
366    endif
367
368    ifneq (,$(findstring $(SHARED_LIBRARY_SUFFIX),$$($1_LIBRARY)))
369      $$(error LIBRARY should be specified without SHARED_LIBRARY_SUFFIX: $(SHARED_LIBRARY_SUFFIX))
370    endif
371
372    ifneq (,$(findstring $(LIBRARY_PREFIX),$$($1_LIBRARY)))
373      $$(error LIBRARY should be specified without LIBRARY_PREFIX: $(LIBRARY_PREFIX))
374    endif
375
376    ifeq ($$($1_SUFFIX), )
377      $1_SUFFIX := $(SHARED_LIBRARY_SUFFIX)
378    endif
379
380    $1_BASENAME:=$(LIBRARY_PREFIX)$$($1_LIBRARY)$$($1_SUFFIX)
381    $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME)
382    $1_NOSUFFIX:=$(LIBRARY_PREFIX)$$($1_LIBRARY)
383  endif
384
385  ifneq (,$$($1_STATIC_LIBRARY))
386    ifeq (,$$($1_OUTPUT_DIR))
387      $$(error STATIC_LIBRARY requires OUTPUT_DIR)
388    endif
389
390    ifneq ($$($1_STATIC_LIBRARY),$(basename $$($1_STATIC_LIBRARY)))
391      $$(error directory of STATIC_LIBRARY should be specified using OUTPUT_DIR)
392    endif
393
394    ifneq (,$(findstring $(STATIC_LIBRARY_SUFFIX),$$($1_STATIC_LIBRARY)))
395      $$(error STATIC_LIBRARY should be specified without STATIC_LIBRARY_SUFFIX: $(STATIC_LIBRARY_SUFFIX))
396    endif
397
398    ifneq (,$(findstring $(LIBRARY_PREFIX),$$($1_STATIC_LIBRARY)))
399      $$(error STATIC_LIBRARY should be specified without LIBRARY_PREFIX: $(LIBRARY_PREFIX))
400    endif
401
402    ifeq ($$($1_SUFFIX), )
403      $1_SUFFIX := $(STATIC_LIBRARY_SUFFIX)
404    endif
405
406    $1_BASENAME:=$(LIBRARY_PREFIX)$$($1_STATIC_LIBRARY)$$($1_SUFFIX)
407    $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME)
408    $1_NOSUFFIX:=$(LIBRARY_PREFIX)$$($1_STATIC_LIBRARY)
409  endif
410
411  ifneq (,$$($1_PROGRAM))
412    ifeq (,$$($1_OUTPUT_DIR))
413      $$(error PROGRAM requires OUTPUT_DIR)
414    endif
415
416    ifneq ($$($1_PROGRAM),$(basename $$($1_PROGRAM)))
417      $$(error directory of PROGRAM should be specified using OUTPUT_DIR)
418    endif
419
420    ifneq (,$(findstring $(EXE_SUFFIX),$$($1_PROGRAM)))
421      $$(error PROGRAM should be specified without EXE_SUFFIX: $(EXE_SUFFIX))
422    endif
423
424    ifeq ($$($1_SUFFIX), )
425      $1_SUFFIX := $(EXE_SUFFIX)
426    endif
427
428    $1_BASENAME:=$$($1_PROGRAM)$$($1_SUFFIX)
429    $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME)
430    $1_NOSUFFIX:=$$($1_PROGRAM)
431  endif
432  $1_SAFE_NAME := $$(strip $$(subst /,_, $1))
433
434  ifeq (,$$($1_TARGET))
435    $$(error Neither PROGRAM, LIBRARY nor STATIC_LIBRARY has been specified for SetupNativeCompilation)
436  endif
437
438  # Setup the toolchain to be used
439  $$(call SetIfEmpty, $1_TOOLCHAIN, TOOLCHAIN_DEFAULT)
440  $$(call SetIfEmpty, $1_CC, $$($$($1_TOOLCHAIN)_CC))
441  $$(call SetIfEmpty, $1_CXX, $$($$($1_TOOLCHAIN)_CXX))
442  $$(call SetIfEmpty, $1_LD, $$($$($1_TOOLCHAIN)_LD))
443  $$(call SetIfEmpty, $1_AR, $$($$($1_TOOLCHAIN)_AR))
444  $$(call SetIfEmpty, $1_AS, $$($$($1_TOOLCHAIN)_AS))
445  $$(call SetIfEmpty, $1_MT, $$($$($1_TOOLCHAIN)_MT))
446  $$(call SetIfEmpty, $1_RC, $$($$($1_TOOLCHAIN)_RC))
447  $$(call SetIfEmpty, $1_OBJCOPY, $$($$($1_TOOLCHAIN)_OBJCOPY))
448  $$(call SetIfEmpty, $1_STRIP, $$($$($1_TOOLCHAIN)_STRIP))
449  $$(call SetIfEmpty, $1_SYSROOT_CFLAGS, $$($$($1_TOOLCHAIN)_SYSROOT_CFLAGS))
450  $$(call SetIfEmpty, $1_SYSROOT_LDFLAGS, $$($$($1_TOOLCHAIN)_SYSROOT_LDFLAGS))
451
452  ifneq ($$($1_MANIFEST), )
453    ifeq ($$($1_MANIFEST_VERSION), )
454      $$(error If MANIFEST is provided, then MANIFEST_VERSION is required in $1)
455    endif
456  endif
457
458  # Make sure the dirs exist.
459  $$(call MakeDir,$$($1_OBJECT_DIR) $$($1_OUTPUT_DIR))
460  $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),, \
461      $$(error SRC specified to SetupNativeCompilation $1 contains missing directory $$d)))
462
463  # Find all files in the source trees. Sort to remove duplicates.
464  $1_SRCS := $$(sort $$(call CacheFind,$$($1_SRC)))
465  $1_SRCS := $$(filter $$(NATIVE_SOURCE_EXTENSIONS), $$($1_SRCS))
466  # Extract the C/C++ files.
467  ifneq ($$($1_EXCLUDE_PATTERNS), )
468    # We must not match the exclude pattern against the src root(s).
469    $1_SRCS_WITHOUT_ROOTS := $$($1_SRCS)
470    $$(foreach i,$$($1_SRC),$$(eval $1_SRCS_WITHOUT_ROOTS := $$(patsubst \
471        $$i/%,%, $$($1_SRCS_WITHOUT_ROOTS))))
472    $1_ALL_EXCLUDE_FILES :=  $$(call containing, $$($1_EXCLUDE_PATTERNS), \
473        $$($1_SRCS_WITHOUT_ROOTS))
474  endif
475  ifneq ($$($1_EXCLUDE_FILES),)
476    $1_ALL_EXCLUDE_FILES += $$($1_EXCLUDE_FILES)
477  endif
478  ifneq ($$($1_ALL_EXCLUDE_FILES),)
479    $1_EXCLUDE_FILES_PAT := $$($1_ALL_EXCLUDE_FILES) \
480        $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_ALL_EXCLUDE_FILES)))
481    $1_EXCLUDE_FILES_PAT := $$(addprefix %,$$($1_EXCLUDE_FILES_PAT))
482    $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES_PAT),$$($1_SRCS))
483  endif
484  ifneq ($$($1_INCLUDE_FILES), )
485    $1_INCLUDE_FILES_PAT := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES)))
486    $1_SRCS := $$(filter $$($1_INCLUDE_FILES_PAT),$$($1_SRCS))
487  endif
488  # There can be only a single bin dir root, no need to foreach over the roots.
489  $1_BINS := $$(wildcard $$($1_OBJECT_DIR)/*$(OBJ_SUFFIX))
490  # Now we have a list of all c/c++ files to compile: $$($1_SRCS)
491  # and we have a list of all existing object files: $$($1_BINS)
492
493  # Prepend the source/bin path to the filter expressions. Then do the filtering.
494  ifneq ($$($1_INCLUDES),)
495    $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES))))
496    $1_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS))
497  endif
498  ifneq ($$($1_EXCLUDES),)
499    $1_SRC_EXCLUDES := $$(addsuffix /%,$$($1_EXCLUDES))
500    $1_SRC_EXCLUDES += $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES))))
501    $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS))
502  endif
503
504  $1_SRCS += $$($1_EXTRA_FILES)
505
506  ifeq (,$$($1_SRCS))
507    $$(error No sources found for $1 when looking inside the dirs $$($1_SRC))
508  endif
509
510  # Calculate the expected output from compiling the sources
511  $1_EXPECTED_OBJS_FILENAMES := $$(call replace_with_obj_extension, $$(notdir $$($1_SRCS)))
512  $1_EXPECTED_OBJS := $$(addprefix $$($1_OBJECT_DIR)/,$$($1_EXPECTED_OBJS_FILENAMES))
513  # Are there too many object files on disk? Perhaps because some source file was removed?
514  $1_SUPERFLOUS_OBJS:=$$(sort $$(filter-out $$($1_EXPECTED_OBJS),$$($1_BINS)))
515  # Clean out the superfluous object files.
516  ifneq ($$($1_SUPERFLUOUS_OBJS),)
517    $$(shell $(RM) -f $$($1_SUPERFLUOUS_OBJS))
518  endif
519  # Sort to remove dupliates and provide a reproducable order on the input files to the linker.
520  $1_ALL_OBJS := $$(sort $$($1_EXPECTED_OBJS) $$($1_EXTRA_OBJECT_FILES))
521
522  # Pickup extra OPENJDK_TARGET_OS_TYPE and/or OPENJDK_TARGET_OS dependent variables for CFLAGS.
523  $1_EXTRA_CFLAGS:=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_CFLAGS_$(OPENJDK_TARGET_OS))
524  ifneq ($(DEBUG_LEVEL),release)
525    # Pickup extra debug dependent variables for CFLAGS
526    $1_EXTRA_CFLAGS+=$$($1_CFLAGS_debug)
527    $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_TYPE)_debug)
528    $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS)_debug)
529  else
530    $1_EXTRA_CFLAGS+=$$($1_CFLAGS_release)
531    $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_TYPE)_release)
532    $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS)_release)
533  endif
534
535  # Pickup extra OPENJDK_TARGET_OS_TYPE and/or OPENJDK_TARGET_OS dependent variables for CXXFLAGS.
536  $1_EXTRA_CXXFLAGS:=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS))
537  ifneq ($(DEBUG_LEVEL),release)
538    # Pickup extra debug dependent variables for CXXFLAGS
539    $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_debug)
540    $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_TYPE)_debug)
541    $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)_debug)
542  else
543    $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_release)
544    $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_TYPE)_release)
545    $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)_release)
546  endif
547
548  # If no C++ flags are explicitly set, default to using the C flags.
549  # After that, we can set additional C++ flags that should not interfere
550  # with the mechanism for copying the C flags by default.
551  ifeq ($$($1_CXXFLAGS),)
552    $1_CXXFLAGS:=$$($1_CFLAGS)
553  endif
554  ifeq ($$(strip $$($1_EXTRA_CXXFLAGS)),)
555    $1_EXTRA_CXXFLAGS:=$$($1_EXTRA_CFLAGS)
556  endif
557
558  ifeq ($(COMPILE_WITH_DEBUG_SYMBOLS), true)
559    $1_EXTRA_CFLAGS += $(CFLAGS_DEBUG_SYMBOLS)
560    $1_EXTRA_CXXFLAGS += $(CXXFLAGS_DEBUG_SYMBOLS)
561  endif
562
563  ifneq (,$$($1_REORDER))
564    $1_EXTRA_CFLAGS += $$(C_FLAG_REORDER)
565    $1_EXTRA_CXXFLAGS += $$(CXX_FLAG_REORDER)
566  endif
567
568  # Pass the library name for static JNI library naming
569  ifneq ($$($1_STATIC_LIBRARY),)
570    $1_EXTRA_CFLAGS += -DLIBRARY_NAME=$$($1_STATIC_LIBRARY)
571    $1_EXTRA_CXXFLAGS += -DLIBRARY_NAME=$$($1_STATIC_LIBRARY)
572  endif
573
574  # Pick up disabled warnings, if possible on this platform.
575  ifneq ($(DISABLE_WARNING_PREFIX),)
576    $1_EXTRA_CFLAGS += $$(addprefix $(DISABLE_WARNING_PREFIX), \
577        $$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)) \
578        $$($1_DISABLED_WARNINGS_C_$(TOOLCHAIN_TYPE)))
579    $1_EXTRA_CXXFLAGS += $$(addprefix $(DISABLE_WARNING_PREFIX), \
580        $$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)) \
581        $$($1_DISABLED_WARNINGS_CXX_$(TOOLCHAIN_TYPE)))
582  endif
583
584  # Check if warnings should be considered errors.
585  # Pick first binary and toolchain specific, then binary specific, then general setting.
586  ifeq ($$($1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE)),)
587    ifeq ($$($1_WARNINGS_AS_ERRORS),)
588      $1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE) := $$(WARNINGS_AS_ERRORS)
589    else
590      $1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE) := $$($1_WARNINGS_AS_ERRORS)
591    endif
592  endif
593
594  ifeq ($$($1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE)), true)
595    $1_EXTRA_CFLAGS += $(CFLAGS_WARNINGS_ARE_ERRORS)
596    $1_EXTRA_CXXFLAGS += $(CFLAGS_WARNINGS_ARE_ERRORS)
597  endif
598
599  ifeq (NONE, $$($1_OPTIMIZATION))
600    $1_EXTRA_CFLAGS += $(C_O_FLAG_NONE)
601    $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_NONE)
602  else ifeq (LOW, $$($1_OPTIMIZATION))
603    $1_EXTRA_CFLAGS += $(C_O_FLAG_NORM)
604    $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_NORM)
605  else ifeq (HIGH, $$($1_OPTIMIZATION))
606    $1_EXTRA_CFLAGS += $(C_O_FLAG_HI)
607    $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_HI)
608  else ifeq (HIGHEST, $$($1_OPTIMIZATION))
609    $1_EXTRA_CFLAGS += $(C_O_FLAG_HIGHEST)
610    $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_HIGHEST)
611  else ifneq (, $$($1_OPTIMIZATION))
612    $$(error Unknown value for OPTIMIZATION: $$($1_OPTIMIZATION))
613  endif
614
615  $1_BUILD_INFO := $$($1_OBJECT_DIR)/_build-info.marker
616
617  # Track variable changes for all variables that affect the compilation command
618  # lines for all object files in this setup. This includes at least all the
619  # variables used in the call to add_native_source below.
620  $1_COMPILE_VARDEPS := $$($1_CFLAGS) $$($1_EXTRA_CFLAGS) $$($1_SYSROOT_CFLAGS) \
621      $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS) \
622      $$($1_CC) $$($1_CXX) $$($1_AS) $$($1_ASFLAGS)
623  $1_COMPILE_VARDEPS_FILE := $$(call DependOnVariable, $1_COMPILE_VARDEPS, \
624      $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).comp.vardeps)
625
626  # Now call add_native_source for each source file we are going to compile.
627  $$(foreach p,$$($1_SRCS), \
628      $$(eval $$(call add_native_source,$1,$$p,$$($1_OBJECT_DIR), \
629          $$($1_CFLAGS) $$($1_EXTRA_CFLAGS) $$($1_SYSROOT_CFLAGS), \
630          $$($1_CC), \
631          $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS) $$($1_SYSROOT_CFLAGS), \
632          $$($1_CXX), $$($1_ASFLAGS))))
633
634  # Setup rule for printing progress info when compiling source files.
635  # This is a rough heuristic and may not always print accurate information.
636  $$($1_BUILD_INFO): $$($1_SRCS) $$($1_COMPILE_VARDEPS_FILE)
637        ifeq ($$(wildcard $$($1_TARGET)),)
638	  $(ECHO) 'Creating $$($1_BASENAME) from $$(words $$(filter-out %.vardeps, $$?)) file(s)'
639        else
640	  $(ECHO) $$(strip 'Updating $$($1_BASENAME)' \
641	      $$(if $$(filter-out %.vardeps, $$?), \
642	        'due to $$(words $$(filter-out %.vardeps, $$?)) file(s)', \
643	      $$(if $$(filter %.vardeps, $$?), 'due to makefile changes')))
644        endif
645	$(TOUCH) $$@
646
647  # On windows we need to create a resource file
648  ifeq ($(OPENJDK_TARGET_OS), windows)
649    ifneq (,$$($1_VERSIONINFO_RESOURCE))
650      $1_RES:=$$($1_OBJECT_DIR)/$$($1_BASENAME).res
651      $1_RES_DEP:=$$($1_RES).d
652      $1_RES_DEP_TARGETS:=$$($1_RES).d.targets
653      -include $$($1_RES_DEP)
654      -include $$($1_RES_DEP_TARGETS)
655
656      $1_RES_VARDEPS := $$($1_RC) $$($1_RC_FLAGS)
657      $1_RES_VARDEPS_FILE := $$(call DependOnVariable, $1_RES_VARDEPS, \
658          $$($1_RES).vardeps)
659
660      $$($1_RES): $$($1_VERSIONINFO_RESOURCE) $$($1_RES_VARDEPS_FILE)
661		$$(call LogInfo, Compiling resource $$(notdir $$($1_VERSIONINFO_RESOURCE)) (for $$(notdir $$($1_TARGET))))
662		$$(call MakeDir, $$(@D) $$($1_OBJECT_DIR))
663		$$(call ExecuteWithLog, $$@, \
664		    $$($1_RC) $$($1_RC_FLAGS) $$($1_SYSROOT_CFLAGS) $(CC_OUT_OPTION)$$@ \
665		    $$($1_VERSIONINFO_RESOURCE))
666                # Windows RC compiler does not support -showIncludes, so we mis-use CL for this.
667		$$(call ExecuteWithLog, $$($1_RES_DEP).obj, \
668		    $$($1_CC) $$($1_RC_FLAGS) $$($1_SYSROOT_CFLAGS) -showIncludes -nologo -TC \
669		    $(CC_OUT_OPTION)$$($1_RES_DEP).obj -P -Fi$$($1_RES_DEP).pp \
670		    $$($1_VERSIONINFO_RESOURCE)) > $$($1_RES_DEP).raw 2>&1 || true ; \
671		$(ECHO) $$($1_RES): \\ > $$($1_RES_DEP) ; \
672		$(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_RES_DEP).raw >> $$($1_RES_DEP) ; \
673		$(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_RES_DEP) > $$($1_RES_DEP_TARGETS)
674    endif
675  endif
676
677  ifneq ($(DISABLE_MAPFILES),true)
678    $1_REAL_MAPFILE := $$($1_MAPFILE)
679    ifneq ($(OPENJDK_TARGET_OS),windows)
680      ifneq (,$$($1_REORDER))
681        $1_REAL_MAPFILE := $$($1_OBJECT_DIR)/mapfile
682
683        $$($1_REAL_MAPFILE) : $$($1_MAPFILE) $$($1_REORDER)
684		$$(call MakeDir, $$(@D))
685		$$(CP) $$($1_MAPFILE) $$@.tmp
686		$$(SED) -e 's=OUTPUTDIR=$$($1_OBJECT_DIR)=' $$($1_REORDER) >> $$@.tmp
687		$$(MV) $$@.tmp $$@
688      endif
689    endif
690  endif
691
692  # Pickup extra OPENJDK_TARGET_OS_TYPE and/or OPENJDK_TARGET_OS dependent variables
693  # for LDFLAGS and LIBS
694  $1_EXTRA_LDFLAGS:=$$($1_LDFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS))
695  $1_EXTRA_LIBS:=$$($1_LIBS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LIBS_$(OPENJDK_TARGET_OS))
696  ifneq (,$$($1_REAL_MAPFILE))
697    $1_EXTRA_LDFLAGS += $(call SET_SHARED_LIBRARY_MAPFILE,$$($1_REAL_MAPFILE))
698  endif
699
700  # Need to make sure TARGET is first on list
701  $1 := $$($1_TARGET)
702
703  ifeq ($(COPY_DEBUG_SYMBOLS), true)
704    ifneq ($$($1_DEBUG_SYMBOLS), false)
705      # Only copy debug symbols for dynamic libraries and programs.
706      ifeq ($$($1_STATIC_LIBRARY), )
707        ifneq ($$($1_OUTPUT_DIR), $$($1_OBJECT_DIR))
708          # The dependency on TARGET is needed on windows for debuginfo files
709          # to be rebuilt properly.
710          $$($1_OUTPUT_DIR)/% : $$($1_OBJECT_DIR)/% $$($1_TARGET)
711                # Use cp -r since on macosx, the dSYM is a directory
712		$(CP) -r $$< $$@
713        endif
714
715        # Generate debuginfo files.
716        ifeq ($(OPENJDK_TARGET_OS), windows)
717          $1_EXTRA_LDFLAGS += -debug "-pdb:$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).pdb" \
718              "-map:$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).map"
719          $1_DEBUGINFO_FILES := $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).pdb \
720              $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).map
721          # No separate command is needed for debuginfo on windows, instead
722          # touch target to make sure it has a later time stamp than the debug
723          # symbol files to avoid unnecessary relinking on rebuild.
724          $1_CREATE_DEBUGINFO_CMDS := $(TOUCH) $$($1_TARGET)
725
726        else ifneq ($(findstring $(OPENJDK_TARGET_OS), linux solaris), )
727          $1_DEBUGINFO_FILES := $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).debuginfo
728          # Setup the command line creating debuginfo files, to be run after linking.
729          # It cannot be run separately since it updates the original target file
730          $1_CREATE_DEBUGINFO_CMDS := \
731            $$($1_OBJCOPY) --only-keep-debug $$($1_TARGET) $$($1_DEBUGINFO_FILES) $$(NEWLINE) \
732            $(CD) $$($1_OUTPUT_DIR) && \
733                $$($1_OBJCOPY) --add-gnu-debuglink=$$($1_DEBUGINFO_FILES) $$($1_TARGET)
734
735        else ifeq ($(OPENJDK_TARGET_OS), macosx)
736          $1_DEBUGINFO_FILES := $$($1_OBJECT_DIR)/$$($1_BASENAME).dSYM
737          # On Macosx, the debuginfo generation doesn't touch the linked binary, but
738          # to avoid always relinking, touch it anyway to force a later timestamp than
739          # the dSYM files.
740          $1_CREATE_DEBUGINFO_CMDS := \
741              $(DSYMUTIL) --out $$($1_DEBUGINFO_FILES) $$($1_TARGET) $$(NEWLINE) \
742              $(TOUCH) $$($1_TARGET)
743        endif # OPENJDK_TARGET_OS
744
745        # This dependency dance ensures that debug info files get rebuilt
746        # properly if deleted.
747        $$($1_TARGET): $$($1_DEBUGINFO_FILES)
748        $$($1_DEBUGINFO_FILES): $$($1_ALL_OBJS)
749
750        ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
751          $1_DEBUGINFO_ZIP := $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).diz
752          $1 += $$(subst $$($1_OBJECT_DIR),$$($1_OUTPUT_DIR),$$($1_DEBUGINFO_ZIP))
753
754          # The dependency on TARGET is needed for debuginfo files
755          # to be rebuilt properly.
756          $$($1_DEBUGINFO_ZIP): $$($1_DEBUGINFO_FILES) $$($1_TARGET)
757		$(CD) $$($1_OBJECT_DIR) \
758		&& $(ZIP) -q -r $$@ $$(notdir $$($1_DEBUGINFO_FILES))
759
760        else
761          $1 += $$(subst $$($1_OBJECT_DIR),$$($1_OUTPUT_DIR),$$($1_DEBUGINFO_FILES))
762        endif
763      endif # !STATIC_LIBRARY
764    endif # $1_DEBUG_SYMBOLS != false
765  endif # COPY_DEBUG_SYMBOLS
766
767  ifeq ($$($1_STRIP_SYMBOLS), true)
768    ifneq ($$($1_STRIP), )
769      # Default to using the global STRIPFLAGS. Allow for overriding with an empty value
770      $1_STRIPFLAGS ?= $(STRIPFLAGS)
771      $1_STRIP_CMD := $$($1_STRIP) $$($1_STRIPFLAGS) $$($1_TARGET)
772    endif
773  endif
774
775  ifneq (,$$($1_LIBRARY))
776    # Generating a dynamic library.
777    $1_EXTRA_LDFLAGS += $$(call SET_SHARED_LIBRARY_NAME,$$($1_BASENAME))
778    ifeq ($(OPENJDK_TARGET_OS), windows)
779      $1_EXTRA_LDFLAGS += "-implib:$$($1_OBJECT_DIR)/$$($1_LIBRARY).lib"
780    endif
781
782    # Create loadmap on AIX. Helps in diagnosing some problems.
783    ifneq ($(COMPILER_BINDCMD_FILE_FLAG),)
784      $1_EXTRA_LDFLAGS += $(COMPILER_BINDCMD_FILE_FLAG)$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).loadmap
785    endif
786
787    $1_VARDEPS := $$($1_LD) $$($1_SYSROOT_LDFLAGS) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) \
788        $$($1_LIBS) $$($1_EXTRA_LIBS) $$($1_CREATE_DEBUGINFO_CMDS) \
789        $$($1_STRIP_CMD)
790    $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
791        $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
792
793    $1_LD_OBJ_ARG := $$($1_ALL_OBJS)
794
795    # If there are many object files, use an @-file...
796    ifneq ($$(word 17, $$($1_ALL_OBJS)), )
797      $1_OBJ_FILE_LIST := $$($1_OBJECT_DIR)/_$1_objectfilenames.txt
798      ifneq ($(COMPILER_COMMAND_FILE_FLAG),)
799        $1_LD_OBJ_ARG := $(COMPILER_COMMAND_FILE_FLAG)$$($1_OBJ_FILE_LIST)
800      else
801        # ...except for toolchains which don't support them.
802        $1_LD_OBJ_ARG := `cat $$($1_OBJ_FILE_LIST)`
803      endif
804    endif
805
806    $$($1_TARGET): $$($1_ALL_OBJS) $$($1_RES) $$($1_REAL_MAPFILE) \
807        $$($1_VARDEPS_FILE)
808                ifneq ($$($1_OBJ_FILE_LIST), )
809		  $$(eval $$(call ListPathsSafely, $1_ALL_OBJS, $$($1_OBJ_FILE_LIST)))
810                endif
811                # Keep as much as possible on one execution line for best performance
812                # on Windows
813		$$(call LogInfo, Linking $$($1_BASENAME))
814                ifeq ($(OPENJDK_TARGET_OS), windows)
815		  $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
816		      $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
817		      $(LD_OUT_OPTION)$$@ $$($1_LD_OBJ_ARG) $$($1_RES) $$($1_LIBS) \
818		      $$($1_EXTRA_LIBS)) \
819		      | $(GREP) -v "^   Creating library .*\.lib and object .*\.exp" || \
820		      test "$$$$?" = "1" ; \
821		  $$($1_CREATE_DEBUGINFO_CMDS)
822		  $$($1_STRIP_CMD)
823                else
824		  $$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
825		      $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
826		      $(LD_OUT_OPTION)$$@ $$($1_LD_OBJ_ARG) $$($1_RES) $$($1_LIBS) \
827		      $$($1_EXTRA_LIBS)) ; \
828		  $$($1_CREATE_DEBUGINFO_CMDS)
829		  $$($1_STRIP_CMD)
830                endif
831
832  endif
833
834  ifneq (,$$($1_STATIC_LIBRARY))
835    $1_VARDEPS := $$($1_AR) $$($1_ARFLAGS) $$($1_LIBS) \
836        $$($1_EXTRA_LIBS)
837    $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
838        $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
839
840    # Generating a static library, ie object file archive.
841    ifeq ($(STATIC_BUILD), true)
842      ifeq ($$($1_USE_MAPFILE_FOR_SYMBOLS), true)
843        STATIC_MAPFILE_DEP := $$($1_MAPFILE)
844      endif
845    endif
846
847    $$($1_TARGET): $$($1_ALL_OBJS) $$($1_RES) $$($1_VARDEPS_FILE) $$(STATIC_MAPFILE_DEP)
848	$$(call LogInfo, Archiving $$($1_STATIC_LIBRARY))
849	$$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
850	    $$($1_AR) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_ALL_OBJS) \
851	        $$($1_RES))
852        ifeq ($(STATIC_BUILD), true)
853          ifeq ($$($1_USE_MAPFILE_FOR_SYMBOLS), true)
854	    $(CP) $$($1_MAPFILE) $$(@D)/$$(basename $$(@F)).symbols
855          else
856	    $(GetSymbols)
857          endif
858        endif
859  endif
860
861  ifneq (,$$($1_PROGRAM))
862    # A executable binary has been specified, setup the target for it.
863    $1_VARDEPS := $$($1_LD) $$($1_SYSROOT_LDFLAGS) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) \
864        $$($1_LIBS) $$($1_EXTRA_LIBS) $$($1_MT) \
865        $$($1_CODESIGN) $$($1_CREATE_DEBUGINFO_CMDS) $$($1_MANIFEST_VERSION) \
866        $$($1_STRIP_CMD)
867    $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
868        $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
869
870    ifeq ($(OPENJDK_TARGET_OS), windows)
871      ifeq ($$($1_EMBED_MANIFEST), true)
872        $1_EXTRA_LDFLAGS += -manifest:embed
873      endif
874    endif
875
876    $$($1_TARGET): $$($1_ALL_OBJS) $$($1_RES) $$($1_MANIFEST) \
877        $$($1_VARDEPS_FILE)
878		$$(call LogInfo, Linking executable $$($1_BASENAME))
879		$$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
880		    $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \
881		        $(EXE_OUT_OPTION)$$($1_TARGET) \
882		        $$($1_ALL_OBJS) $$($1_RES) \
883		        $$($1_LIBS) $$($1_EXTRA_LIBS))
884                ifeq ($(OPENJDK_TARGET_OS), windows)
885                  ifneq ($$($1_MANIFEST), )
886		    $$($1_MT) -nologo -manifest $$($1_MANIFEST) -identity:"$$($1_PROGRAM).exe, version=$$($1_MANIFEST_VERSION)" -outputresource:$$@;#1
887                  endif
888                endif
889                # This only works if the openjdk_codesign identity is present on the system. Let
890                # silently fail otherwise.
891                ifneq (,$(CODESIGN))
892                  ifneq (,$$($1_CODESIGN))
893		    $(CODESIGN) -s openjdk_codesign $$@
894                  endif
895                endif
896		$$($1_CREATE_DEBUGINFO_CMDS)
897		$$($1_STRIP_CMD)
898
899  endif
900endef
901
902endif # _NATIVE_COMPILATION_GMK
903