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