NativeCompilation.gmk revision 1886:f382e4228537
1139826Simp# 253541Sshin# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. 353541Sshin# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 453541Sshin# 553541Sshin# This code is free software; you can redistribute it and/or modify it 653541Sshin# under the terms of the GNU General Public License version 2 only, as 753541Sshin# published by the Free Software Foundation. Oracle designates this 853541Sshin# particular file as subject to the "Classpath" exception as provided 953541Sshin# by Oracle in the LICENSE file that accompanied this code. 1053541Sshin# 1153541Sshin# This code is distributed in the hope that it will be useful, but WITHOUT 1253541Sshin# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1353541Sshin# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1453541Sshin# version 2 for more details (a copy is included in the LICENSE file that 1553541Sshin# accompanied this code). 1653541Sshin# 1753541Sshin# You should have received a copy of the GNU General Public License version 1853541Sshin# 2 along with this work; if not, write to the Free Software Foundation, 1953541Sshin# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2053541Sshin# 2153541Sshin# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2253541Sshin# or visit www.oracle.com if you need additional information or have any 2353541Sshin# questions. 2453541Sshin# 2553541Sshin 2653541Sshin# When you read this source. Remember that $(sort ...) has the side effect 2753541Sshin# of removing duplicates. It is actually this side effect that is 2853541Sshin# desired whenever sort is used below! 29174510Sobrien 3053541Sshinifndef _NATIVE_COMPILATION_GMK 3153541Sshin_NATIVE_COMPILATION_GMK := 1 32139826Simp 3353541Sshinifeq (,$(_MAKEBASE_GMK)) 3453541Sshin $(error You must include MakeBase.gmk prior to including NativeCompilation.gmk) 3553541Sshinendif 3653541Sshin 3753541Sshin################################################################################ 3853541Sshin# Create exported symbols file for static libraries 3953541Sshin################################################################################ 4053541Sshin 4153541Sshin# get the exported symbols from mapfiles and if there 4253541Sshin# is no mapfile, get them from the archive 4353541Sshindefine GetSymbols 4453541Sshin $(RM) $$(@D)/$$(basename $$(@F)).symbols; \ 4553541Sshin if [ ! -z $$($1_MAPFILE) -a -e $$($1_MAPFILE) ]; then \ 4653541Sshin $(ECHO) "Getting symbols from mapfile $$($1_MAPFILE)"; \ 4753541Sshin $(AWK) '/global:/','/local:/' $$($1_MAPFILE) | \ 4853541Sshin $(SED) -e 's/#.*//;s/global://;s/local://;s/\;//;s/^[ ]*/_/;/^_$$$$/d' | \ 4953541Sshin $(EGREP) -v "JNI_OnLoad|JNI_OnUnload|Agent_OnLoad|Agent_OnUnload|Agent_OnAttach" > \ 5053541Sshin $$(@D)/$$(basename $$(@F)).symbols || true; \ 5153541Sshin $(NM) $$($1_TARGET) | $(GREP) " T " | \ 5253541Sshin $(EGREP) "JNI_OnLoad|JNI_OnUnload|Agent_OnLoad|Agent_OnUnload|Agent_OnAttach" | \ 5353541Sshin $(CUT) -d ' ' -f 3 >> $$(@D)/$$(basename $$(@F)).symbols || true;\ 5453541Sshin else \ 5553541Sshin $(ECHO) "Getting symbols from nm"; \ 5653541Sshin $(NM) -m $$($1_TARGET) | $(GREP) "__TEXT" | \ 5753541Sshin $(EGREP) -v "non-external|private extern|__TEXT,__eh_frame" | \ 5853541Sshin $(SED) -e 's/.* //' > $$(@D)/$$(basename $$(@F)).symbols; \ 5953541Sshin fi 6053541Sshinendef 6153541Sshin 6253541Sshin################################################################################ 63174510Sobrien# Define a native toolchain configuration that can be used by 64174510Sobrien# SetupNativeCompilation calls 65174510Sobrien# 6678064Sume# Parameter 1 is the name of the toolchain definition 6778064Sume# 6855009Sshin# Remaining parameters are named arguments: 69174717Srwatson# EXTENDS - Optional parent definition to get defaults from 7053541Sshin# CC - The C compiler 7153541Sshin# CXX - The C++ compiler 7253541Sshin# LD - The Linker 7353541Sshin# AR - Static linker 7453541Sshin# AS - Assembler 7555679Sshin# MT - Windows MT tool 7653541Sshin# RC - Windows RC tool 7753541Sshin# STRIP - The tool to use for stripping debug symbols 7853541Sshin# SYSROOT_CFLAGS - Compiler flags for using the specific sysroot 7953541Sshin# SYSROOT_LDFLAGS - Linker flags for using the specific sysroot 8053541SshinDefineNativeToolchain = $(NamedParamsMacroTemplate) 8153541Sshindefine DefineNativeToolchainBody 82164033Srwatson # If extending another definition, get default values from that, 8353541Sshin # otherwise, nothing more needs to be done as variable assignments 8453541Sshin # already happened in NamedParamsMacroTemplate. 85181803Sbz ifneq ($$($1_EXTENDS), ) 8653541Sshin $$(call SetIfEmpty, $1_CC, $$($$($1_EXTENDS)_CC)) 8792767Sjeff $$(call SetIfEmpty, $1_CXX, $$($$($1_EXTENDS)_CXX)) 8853541Sshin $$(call SetIfEmpty, $1_LD, $$($$($1_EXTENDS)_LD)) 8953541Sshin $$(call SetIfEmpty, $1_AR, $$($$($1_EXTENDS)_AR)) 9053541Sshin $$(call SetIfEmpty, $1_AS, $$($$($1_EXTENDS)_AS)) 9153541Sshin $$(call SetIfEmpty, $1_MT, $$($$($1_EXTENDS)_MT)) 9253541Sshin $$(call SetIfEmpty, $1_RC, $$($$($1_EXTENDS)_RC)) 9353541Sshin $$(call SetIfEmpty, $1_STRIP, $$($$($1_EXTENDS)_STRIP)) 9453541Sshin $$(call SetIfEmpty, $1_SYSROOT_CFLAGS, $$($$($1_EXTENDS)_SYSROOT_CFLAGS)) 9553541Sshin $$(call SetIfEmpty, $1_SYSROOT_LDFLAGS, $$($$($1_EXTENDS)_SYSROOT_LDFLAGS)) 9698102Shsu endif 9762587Sitojunendef 9855679Sshin 99181887Sjulian# Create a default toolchain with the main compiler and linker 10053541Sshin$(eval $(call DefineNativeToolchain, TOOLCHAIN_DEFAULT, \ 10153541Sshin CC := $(CC), \ 10253541Sshin CXX := $(CXX), \ 10353541Sshin LD := $(LD), \ 104148385Sume AR := $(AR), \ 10553541Sshin AS := $(AS), \ 106171167Sgnn MT := $(MT), \ 107105199Ssam RC := $(RC), \ 108105199Ssam STRIP := $(STRIP), \ 109105199Ssam SYSROOT_CFLAGS := $(SYSROOT_CFLAGS), \ 110171167Sgnn SYSROOT_LDFLAGS := $(SYSROOT_LDFLAGS), \ 111105199Ssam)) 112174717Srwatson 113174717Srwatson# Create a toolchain where linking is done with the C++ linker 11453541Sshin$(eval $(call DefineNativeToolchain, TOOLCHAIN_LINK_CXX, \ 11553541Sshin EXTENDS := TOOLCHAIN_DEFAULT, \ 11653541Sshin LD := $(LDCXX), \ 117171259Sdelphij)) 118171259Sdelphij 11953541Sshin# Create a toolchain with the BUILD compiler, used for build tools that 120183550Szec# are to be run during the build. 121183550Szec# The BUILD_SYSROOT_*FLAGS variables are empty for now. 12253541Sshin$(eval $(call DefineNativeToolchain, TOOLCHAIN_BUILD, \ 12353541Sshin CC := $(BUILD_CC), \ 12453541Sshin CXX := $(BUILD_CXX), \ 12553541Sshin LD := $(BUILD_LD), \ 12697658Stanimura AR := $(BUILD_AR), \ 12753541Sshin AS := $(BUILD_AS), \ 128132714Srwatson SYSROOT_CFLAGS := $(BUILD_SYSROOT_CFLAGS), \ 129178285Srwatson SYSROOT_LDFLAGS := $(BUILD_SYSROOT_LDFLAGS), \ 130132714Srwatson)) 131181803Sbz 13253541Sshin# BUILD toolchain with the C++ linker 13353541Sshin$(eval $(call DefineNativeToolchain, TOOLCHAIN_BUILD_LINK_CXX, \ 134120856Sume EXTENDS := TOOLCHAIN_BUILD, \ 13553541Sshin LD := $(BUILD_LDCXX), \ 136160024Sbz)) 13753541Sshin 138148385Sume################################################################################ 139148385Sume 14053541Sshin# Extensions of files handled by this macro. 14153541SshinNATIVE_SOURCE_EXTENSIONS := %.s %.c %.cpp %.cc %.m %.mm 142120856Sume 14353541Sshin# Replaces native source extensions with the object file extension in a string. 14453541Sshin# Param 1: the string containing source file names with extensions 14553541Sshin# The surrounding strip is needed to keep additional whitespace out 14653541Sshindefine replace_with_obj_extension 147120856Sume$(strip \ 14853541Sshin $(foreach extension, $(NATIVE_SOURCE_EXTENSIONS), \ 149181803Sbz $(patsubst $(extension),%$(OBJ_SUFFIX),$(filter $(extension),$1))) \ 150148385Sume) 15153541Sshinendef 15253541Sshin 15353541Sshinifeq ($(OPENJDK_BUILD_OS_ENV), windows.cygwin) 15453541Sshin UNIX_PATH_PREFIX := /cygdrive 15553541Sshinelse ifeq ($(OPENJDK_BUILD_OS_ENV), windows.msys) 15653541Sshin UNIX_PATH_PREFIX := 15753541Sshinendif 15853541Sshin 15953541Sshin# This pattern is used to transform the output of the microsoft CL compiler 16053541Sshin# into a make syntax dependency file (.d) 16153541SshinWINDOWS_SHOWINCLUDE_SED_PATTERN := \ 16253541Sshin -e '/^Note: including file:/!d' \ 16353541Sshin -e 's|Note: including file: *||' \ 16453541Sshin -e 's|\\|/|g' \ 16553541Sshin -e 's|^\([a-zA-Z]\):|$(UNIX_PATH_PREFIX)/\1|g' \ 16653541Sshin -e '\|$(TOPDIR)|I !d' \ 16753541Sshin -e 's|$$$$| \\|g' \ 168120856Sume # 16953541Sshin 17053541Sshin# This pattern is used to transform a dependency file (.d) to a list 17153541Sshin# of make targets for dependent files (.d.targets) 17253541SshinDEPENDENCY_TARGET_SED_PATTERN := \ 17378064Sume -e 's/\#.*//' \ 174120913Sume -e 's/^[^:]*: *//' \ 17553541Sshin -e 's/ *\\$$$$//' \ 17653541Sshin -e 's/^[ ]*//' \ 17753541Sshin -e '/^$$$$/ d' \ 17878064Sume -e 's/$$$$/ :/' \ 179120856Sume # 18053541Sshin 18153541Sshindefine add_native_source 18253541Sshin # param 1 = BUILD_MYPACKAGE 18353541Sshin # parma 2 = the source file name (..../alfa.c or .../beta.cpp) 18453541Sshin # param 3 = the bin dir that stores all .o (.obj) and .d files. 18553541Sshin # param 4 = the c flags to the compiler 186181803Sbz # param 5 = the c compiler 187181803Sbz # param 6 = the c++ flags to the compiler 188164033Srwatson # param 7 = the c++ compiler 189170587Srwatson # param 8 = the flags to the assembler 190120856Sume 191159976Spjd ifneq (,$$(filter %.c,$2)) 192183606Sbz # Compile as a C file 193170587Srwatson $1_$2_FLAGS=$(CFLAGS_CCACHE) $4 $$($1_$(notdir $2)_CFLAGS) -DTHIS_FILE='"$$(<F)"' -c 19455679Sshin $1_$2_COMP=$5 19553541Sshin $1_$2_DEP_FLAG:=$(C_FLAG_DEPS) 196180427Sbz else ifneq (,$$(filter %.m,$2)) 197132699Syar # Compile as an Objective-C file 198132699Syar $1_$2_FLAGS=-x objective-c $(CFLAGS_CCACHE) $4 $$($1_$(notdir $2)_CFLAGS) -DTHIS_FILE='"$$(<F)"' -c 199132699Syar $1_$2_COMP=$5 200132699Syar $1_$2_DEP_FLAG:=$(C_FLAG_DEPS) 20197658Stanimura else ifneq (,$$(filter %.s,$2)) 202171260Sdelphij # Compile as assembler file 203171260Sdelphij $1_$2_FLAGS=$8 -DTHIS_FILE='"$$(<F)"' 204183606Sbz $1_$2_COMP=$(AS) 205183606Sbz $1_$2_DEP_FLAG:= 20697658Stanimura else ifneq (,$$(filter %.cpp,$2)$$(filter %.cc,$2)$$(filter %.mm,$2)) 20778064Sume # Compile as a C++ or Objective-C++ file 20855679Sshin $1_$2_FLAGS=$(CFLAGS_CCACHE) $6 $$($1_$(notdir $2)_CXXFLAGS) -DTHIS_FILE='"$$(<F)"' -c 20955679Sshin $1_$2_COMP=$7 21055679Sshin $1_$2_DEP_FLAG:=$(CXX_FLAG_DEPS) 21155679Sshin else 21255679Sshin $$(error Internal error in NativeCompilation.gmk: no compiler for file $2) 213180427Sbz endif 214180427Sbz # Generate the .o (.obj) file name and place it in the bin dir. 215132699Syar $1_$2_OBJ := $3/$$(call replace_with_obj_extension, $$(notdir $2)) 216132699Syar # Only continue if this object file hasn't been processed already. This lets the first found 217132699Syar # source file override any other with the same name. 218132699Syar ifeq (,$$(findstring $$($1_$2_OBJ),$$($1_OBJS_SO_FAR))) 219132699Syar $1_OBJS_SO_FAR+=$$($1_$2_OBJ) 220132699Syar ifeq (,$$(filter %.s,$2)) 221183606Sbz # And this is the dependency file for this obj file. 222183606Sbz $1_$2_DEP:=$$(patsubst %$(OBJ_SUFFIX),%.d,$$($1_$2_OBJ)) 22355679Sshin # The dependency target file lists all dependencies as empty targets 22455679Sshin # to avoid make error "No rule to make target" for removed files 22553541Sshin $1_$2_DEP_TARGETS:=$$(patsubst %$(OBJ_SUFFIX),%.d.targets,$$($1_$2_OBJ)) 22653541Sshin 227180427Sbz # Include previously generated dependency information. (if it exists) 228116453Scognet -include $$($1_$2_DEP) 229171260Sdelphij -include $$($1_$2_DEP_TARGETS) 230116453Scognet 231120856Sume ifeq ($(TOOLCHAIN_TYPE), microsoft) 23278064Sume $1_$2_DEBUG_OUT_FLAGS:=-Fd$$(patsubst %$(OBJ_SUFFIX),%.pdb,$$($1_$2_OBJ)) 23355679Sshin endif 23455679Sshin endif 23555679Sshin 23655679Sshin ifneq ($$($1_$(notdir $2)_CFLAGS)$$($1_$(notdir $2)_CXXFLAGS), ) 23755679Sshin $1_$2_VARDEPS := $$($1_$(notdir $2)_CFLAGS) $$($1_$(notdir $2)_CXXFLAGS) 238180427Sbz $1_$2_VARDEPS_FILE := $$(call DependOnVariable, $1_$2_VARDEPS, \ 239116453Scognet $$(patsubst %$(OBJ_SUFFIX),%.vardeps,$$($1_$2_OBJ))) 240171260Sdelphij endif 241116453Scognet 242116453Scognet $$($1_$2_OBJ) : $2 $$($1_COMPILE_VARDEPS_FILE) $$($1_$2_VARDEPS_FILE) | $$($1_BUILD_INFO) 243171260Sdelphij $$(call LogInfo, Compiling $$(notdir $2) (for $$(notdir $$($1_TARGET)))) 244171260Sdelphij ifneq ($(TOOLCHAIN_TYPE), microsoft) 245116453Scognet ifeq ($(TOOLCHAIN_TYPE)$$(filter %.s,$2), solstudio) 246116453Scognet # The Solaris studio compiler doesn't output the full path to the object file in the 247116453Scognet # generated deps files. Fixing it with sed. If compiling assembly, don't try this. 248171260Sdelphij $(call LogFailures, $$($1_$2_OBJ).log, $$($1_SAFE_NAME)_$$(notdir $2), \ 249171260Sdelphij $$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEP_FLAG) $$($1_$2_DEP).tmp $(CC_OUT_OPTION)$$($1_$2_OBJ) $2) 250171260Sdelphij $(SED) 's|^$$(@F):|$$@:|' $$($1_$2_DEP).tmp > $$($1_$2_DEP) 251116453Scognet else 25297658Stanimura $(call LogFailures, $$($1_$2_OBJ).log, $$($1_SAFE_NAME)_$$(notdir $2), \ 25397658Stanimura $$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEP_FLAG) $$($1_$2_DEP) $(CC_OUT_OPTION)$$($1_$2_OBJ) $2) 25455679Sshin endif 25553541Sshin # Create a dependency target file from the dependency file. 25653541Sshin # Solution suggested by http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/ 25753541Sshin ifneq ($$($1_$2_DEP),) 25853541Sshin $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_$2_DEP) > $$($1_$2_DEP_TARGETS) 25962587Sitojun endif 260127505Spjd else 261120856Sume # The Visual Studio compiler lacks a feature for generating make dependencies, but by 262183611Sbz # setting -showIncludes, all included files are printed. These are filtered out and 26362587Sitojun # parsed into make dependences. 26462587Sitojun # Keep as much as possible on one execution line for best performance on Windows. 26562587Sitojun # No need to save exit code from compilation since pipefail is always active on 26662587Sitojun # Windows. 26762587Sitojun $(call LogFailures, $$($1_$2_OBJ).log, $$($1_SAFE_NAME)_$$(notdir $2), \ 26853541Sshin $$($1_$2_COMP) $$($1_$2_FLAGS) -showIncludes $$($1_$2_DEBUG_OUT_FLAGS) \ 26953541Sshin $(CC_OUT_OPTION)$$($1_$2_OBJ) $2) \ 270120856Sume | $(GREP) -v -e "^Note: including file:" \ 27153541Sshin -e "^$(notdir $2)$$$$" || test "$$$$?" = "1" ; \ 27253541Sshin $(ECHO) $$@: \\ > $$($1_$2_DEP) ; \ 27353541Sshin $(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_$2_OBJ).log \ 27453541Sshin | $(SORT) -u >> $$($1_$2_DEP) ; \ 27553541Sshin $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_$2_DEP) > $$($1_$2_DEP_TARGETS) 27653541Sshin endif 27753541Sshin endif 27853541Sshinendef 27953541Sshin 28053541Sshin# Setup make rules for creating a native binary (a shared library or an 28153541Sshin# executable). 28253541Sshin# 28353541Sshin# Parameter 1 is the name of the rule. This name is used as variable prefix, 28453541Sshin# and the targets generated are listed in a variable by that name. 285171259Sdelphij# 286171259Sdelphij# Remaining parameters are named arguments. These include: 28753541Sshin# TOOLCHAIN Name of toolchain setup to use. Defaults to TOOLCHAIN_DEFAULT. 288183550Szec# SRC one or more directory roots to scan for C/C++ files. 28953541Sshin# CFLAGS the compiler flags to be used, used both for C and C++. 290148385Sume# CXXFLAGS the compiler flags to be used for c++, if set overrides CFLAGS. 29153541Sshin# LDFLAGS the linker flags to be used, used both for C and C++. 292148385Sume# LIBS the libraries to link to 29353541Sshin# ARFLAGS the archiver flags to be used 294158011Srwatson# OBJECT_DIR the directory where we store the object files 295178285Srwatson# LIBRARY the resulting library file 296158011Srwatson# PROGRAM the resulting exec file 29753541Sshin# INCLUDES only pick source from these directories 29853541Sshin# EXCLUDES do not pick source from these directories 29953541Sshin# INCLUDE_FILES only compile exactly these files! 30053541Sshin# EXCLUDE_FILES with these names 30153541Sshin# EXCLUDE_PATTERN exclude files matching any of these substrings 30253541Sshin# EXTRA_FILES List of extra files not in any of the SRC dirs 30353541Sshin# EXTRA_OBJECT_FILES List of extra object files to include when linking 304181803Sbz# VERSIONINFO_RESOURCE Input file for RC. Setting this implies that RC will be run 305148385Sume# RC_FLAGS flags for RC. 306181803Sbz# MAPFILE mapfile 307148385Sume# REORDER reorder file 308148385Sume# CC the compiler to use, default is $(CC) 309181803Sbz# LD the linker to use, default is $(LD) 31053541Sshin# OPTIMIZATION sets optimization level to NONE, LOW, HIGH, HIGHEST 31153541Sshin# DISABLED_WARNINGS_<toolchain> Disable the given warnings for the specified toolchain 31253541Sshin# DISABLED_WARNINGS_C_<toolchain> Disable the given warnings for the specified toolchain 31353541Sshin# when compiling C code 31453541Sshin# DISABLED_WARNINGS_CXX_<toolchain> Disable the given warnings for the specified 31553541Sshin# toolchain when compiling C++ code 31653541Sshin# STRIP_SYMBOLS Set to true to strip the final binary if the toolchain allows for it 317148385Sume# STRIPFLAGS Optionally change the flags given to the strip command 318148385SumeSetupNativeCompilation = $(NamedParamsMacroTemplate) 319148385Sumedefine SetupNativeCompilationBody 320148385Sume 321148385Sume # If we're doing a static build and producing a library 322148385Sume # force it to be a static library and remove the -l libraries 323148385Sume ifeq ($(STATIC_BUILD), true) 324180371Sbz ifneq ($$($1_LIBRARY),) 325183606Sbz $1_STATIC_LIBRARY := $$($1_LIBRARY) 326180371Sbz $1_LIBRARY := 327148385Sume endif 328148385Sume endif 329148385Sume 33053541Sshin ifneq (,$$($1_BIN)) 331148385Sume $$(error BIN has been replaced with OBJECT_DIR) 332183611Sbz endif 333148385Sume 334148385Sume ifneq (,$$($1_LIB)) 335148385Sume $$(error LIB has been replaced with LIBRARY) 336148385Sume endif 337148385Sume 338148385Sume ifneq (,$$($1_EXE)) 339148385Sume $$(error EXE has been replaced with PROGRAM) 340148385Sume endif 341148385Sume 342148385Sume ifneq (,$$($1_LIBRARY)) 343120856Sume ifeq (,$$($1_OUTPUT_DIR)) 34453541Sshin $$(error LIBRARY requires OUTPUT_DIR) 34553541Sshin endif 34653541Sshin 34753541Sshin ifneq ($$($1_LIBRARY),$(basename $$($1_LIBRARY))) 34853541Sshin $$(error directory of LIBRARY should be specified using OUTPUT_DIR) 34953541Sshin endif 35053541Sshin 35153541Sshin ifneq (,$(findstring $(SHARED_LIBRARY_SUFFIX),$$($1_LIBRARY))) 35253541Sshin $$(error LIBRARY should be specified without SHARED_LIBRARY_SUFFIX: $(SHARED_LIBRARY_SUFFIX)) 35353541Sshin endif 354171259Sdelphij 355171259Sdelphij ifneq (,$(findstring $(LIBRARY_PREFIX),$$($1_LIBRARY))) 35653541Sshin $$(error LIBRARY should be specified without LIBRARY_PREFIX: $(LIBRARY_PREFIX)) 35753541Sshin endif 35853541Sshin 35953541Sshin ifeq ($$($1_SUFFIX), ) 36053541Sshin $1_SUFFIX := $(SHARED_LIBRARY_SUFFIX) 361132714Srwatson endif 362178285Srwatson 363132714Srwatson $1_BASENAME:=$(LIBRARY_PREFIX)$$($1_LIBRARY)$$($1_SUFFIX) 36453541Sshin $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME) 36595023Ssuz $1_NOSUFFIX:=$(LIBRARY_PREFIX)$$($1_LIBRARY) 36695023Ssuz endif 36753541Sshin 36853541Sshin ifneq (,$$($1_STATIC_LIBRARY)) 369120856Sume ifeq (,$$($1_OUTPUT_DIR)) 37053541Sshin $$(error STATIC_LIBRARY requires OUTPUT_DIR) 37153541Sshin endif 37253541Sshin 37353541Sshin ifneq ($$($1_STATIC_LIBRARY),$(basename $$($1_STATIC_LIBRARY))) 37453541Sshin $$(error directory of STATIC_LIBRARY should be specified using OUTPUT_DIR) 37553541Sshin endif 37653541Sshin 37753541Sshin ifneq (,$(findstring $(STATIC_LIBRARY_SUFFIX),$$($1_STATIC_LIBRARY))) 37853541Sshin $$(error STATIC_LIBRARY should be specified without STATIC_LIBRARY_SUFFIX: $(STATIC_LIBRARY_SUFFIX)) 37953541Sshin endif 380127505Spjd 38153541Sshin ifneq (,$(findstring $(LIBRARY_PREFIX),$$($1_STATIC_LIBRARY))) 38253541Sshin $$(error STATIC_LIBRARY should be specified without LIBRARY_PREFIX: $(LIBRARY_PREFIX)) 38353541Sshin endif 38453541Sshin 38553541Sshin ifeq ($$($1_SUFFIX), ) 38653541Sshin $1_SUFFIX := $(STATIC_LIBRARY_SUFFIX) 38753541Sshin endif 38878064Sume 38978064Sume $1_BASENAME:=$(LIBRARY_PREFIX)$$($1_STATIC_LIBRARY)$$($1_SUFFIX) 39078064Sume $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME) 39155679Sshin $1_NOSUFFIX:=$(LIBRARY_PREFIX)$$($1_STATIC_LIBRARY) 392120649Sume endif 39353541Sshin 39453541Sshin ifneq (,$$($1_PROGRAM)) 395171133Sgnn ifeq (,$$($1_OUTPUT_DIR)) 39653541Sshin $$(error PROGRAM requires OUTPUT_DIR) 39753541Sshin endif 39853541Sshin 39953541Sshin ifneq ($$($1_PROGRAM),$(basename $$($1_PROGRAM))) 400171259Sdelphij $$(error directory of PROGRAM should be specified using OUTPUT_DIR) 40153541Sshin endif 402132714Srwatson 403132714Srwatson ifneq (,$(findstring $(EXE_SUFFIX),$$($1_PROGRAM))) 404178285Srwatson $$(error PROGRAM should be specified without EXE_SUFFIX: $(EXE_SUFFIX)) 405132714Srwatson endif 40653541Sshin 40753541Sshin ifeq ($$($1_SUFFIX), ) 40878064Sume $1_SUFFIX := $(EXE_SUFFIX) 40978064Sume endif 41053541Sshin 41153541Sshin $1_BASENAME:=$$($1_PROGRAM)$$($1_SUFFIX) 41253541Sshin $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME) 41353541Sshin $1_NOSUFFIX:=$$($1_PROGRAM) 414157373Srwatson endif 41553541Sshin $1_SAFE_NAME := $$(strip $$(subst /,_, $1)) 416157373Srwatson 417157373Srwatson ifeq (,$$($1_TARGET)) 418157373Srwatson $$(error Neither PROGRAM, LIBRARY nor STATIC_LIBRARY has been specified for SetupNativeCompilation) 419157373Srwatson endif 420157373Srwatson 421157373Srwatson # Setup the toolchain to be used 422157373Srwatson $$(call SetIfEmpty, $1_TOOLCHAIN, TOOLCHAIN_DEFAULT) 423157373Srwatson $$(call SetIfEmpty, $1_CC, $$($$($1_TOOLCHAIN)_CC)) 424157373Srwatson $$(call SetIfEmpty, $1_CXX, $$($$($1_TOOLCHAIN)_CXX)) 42553541Sshin $$(call SetIfEmpty, $1_LD, $$($$($1_TOOLCHAIN)_LD)) 42653541Sshin $$(call SetIfEmpty, $1_AR, $$($$($1_TOOLCHAIN)_AR)) 427157373Srwatson $$(call SetIfEmpty, $1_AS, $$($$($1_TOOLCHAIN)_AS)) 428132714Srwatson $$(call SetIfEmpty, $1_MT, $$($$($1_TOOLCHAIN)_MT)) 429178285Srwatson $$(call SetIfEmpty, $1_RC, $$($$($1_TOOLCHAIN)_RC)) 430132714Srwatson $$(call SetIfEmpty, $1_STRIP, $$($$($1_TOOLCHAIN)_STRIP)) 431171167Sgnn $$(call SetIfEmpty, $1_SYSROOT_CFLAGS, $$($$($1_TOOLCHAIN)_SYSROOT_CFLAGS)) 43258452Sgreen $$(call SetIfEmpty, $1_SYSROOT_LDFLAGS, $$($$($1_TOOLCHAIN)_SYSROOT_LDFLAGS)) 43358452Sgreen 434171167Sgnn ifneq ($$($1_MANIFEST), ) 43553541Sshin ifeq ($$($1_MANIFEST_VERSION), ) 43653541Sshin $$(error If MANIFEST is provided, then MANIFEST_VERSION is required in $1) 437171260Sdelphij endif 438171260Sdelphij endif 43955679Sshin 44055679Sshin # Make sure the dirs exist. 44155679Sshin $$(call MakeDir,$$($1_OBJECT_DIR) $$($1_OUTPUT_DIR)) 442170613Sbms $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),, \ 443170613Sbms $$(error SRC specified to SetupNativeCompilation $1 contains missing directory $$d))) 44453541Sshin 445174717Srwatson # Find all files in the source trees. Sort to remove duplicates. 446174717Srwatson $1_SRCS := $$(sort $$(call CacheFind,$$($1_SRC))) 447174717Srwatson $1_SRCS := $$(filter $$(NATIVE_SOURCE_EXTENSIONS), $$($1_SRCS)) 448178285Srwatson # Extract the C/C++ files. 44992767Sjeff ifneq ($$($1_EXCLUDE_PATTERNS), ) 45053541Sshin # We must not match the exclude pattern against the src root(s). 45153541Sshin $1_SRCS_WITHOUT_ROOTS := $$($1_SRCS) 452102218Struckman $$(foreach i,$$($1_SRC),$$(eval $1_SRCS_WITHOUT_ROOTS := $$(patsubst \ 453171259Sdelphij $$i/%,%, $$($1_SRCS_WITHOUT_ROOTS)))) 454102218Struckman $1_ALL_EXCLUDE_FILES := $$(call containing, $$($1_EXCLUDE_PATTERNS), \ 455102218Struckman $$($1_SRCS_WITHOUT_ROOTS)) 456102218Struckman endif 457111119Simp ifneq ($$($1_EXCLUDE_FILES),) 458102218Struckman $1_ALL_EXCLUDE_FILES += $$($1_EXCLUDE_FILES) 459102218Struckman endif 460102218Struckman ifneq ($$($1_ALL_EXCLUDE_FILES),) 461102218Struckman $1_EXCLUDE_FILES_PAT := $$($1_ALL_EXCLUDE_FILES) \ 462102218Struckman $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_ALL_EXCLUDE_FILES))) 463148385Sume $1_EXCLUDE_FILES_PAT := $$(addprefix %,$$($1_EXCLUDE_FILES_PAT)) 464102218Struckman $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES_PAT),$$($1_SRCS)) 465102218Struckman endif 466102218Struckman ifneq ($$($1_INCLUDE_FILES), ) 467102218Struckman $1_INCLUDE_FILES_PAT := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES))) 468102218Struckman $1_SRCS := $$(filter $$($1_INCLUDE_FILES_PAT),$$($1_SRCS)) 469171259Sdelphij endif 470102218Struckman # There can be only a single bin dir root, no need to foreach over the roots. 471102218Struckman $1_BINS := $$(wildcard $$($1_OBJECT_DIR)/*$(OBJ_SUFFIX)) 472102218Struckman # Now we have a list of all c/c++ files to compile: $$($1_SRCS) 473102218Struckman # and we have a list of all existing object files: $$($1_BINS) 474102218Struckman 475102218Struckman # Prepend the source/bin path to the filter expressions. Then do the filtering. 476102218Struckman ifneq ($$($1_INCLUDES),) 477102218Struckman $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES)))) 478102218Struckman $1_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS)) 479102218Struckman endif 480102218Struckman ifneq ($$($1_EXCLUDES),) 481111119Simp $1_SRC_EXCLUDES := $$(addsuffix /%,$$($1_EXCLUDES)) 482102218Struckman $1_SRC_EXCLUDES += $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES)))) 483102218Struckman $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS)) 484102218Struckman endif 485102218Struckman 486102218Struckman $1_SRCS += $$($1_EXTRA_FILES) 48753541Sshin 488171259Sdelphij ifeq (,$$($1_SRCS)) 48953541Sshin $$(error No sources found for $1 when looking inside the dirs $$($1_SRC)) 49053541Sshin endif 491102218Struckman 492102218Struckman # Calculate the expected output from compiling the sources 49353541Sshin $1_EXPECTED_OBJS_FILENAMES := $$(call replace_with_obj_extension, $$(notdir $$($1_SRCS))) 49453541Sshin $1_EXPECTED_OBJS := $$(addprefix $$($1_OBJECT_DIR)/,$$($1_EXPECTED_OBJS_FILENAMES)) 495169462Srwatson # Are there too many object files on disk? Perhaps because some source file was removed? 496157673Srwatson $1_SUPERFLOUS_OBJS:=$$(sort $$(filter-out $$($1_EXPECTED_OBJS),$$($1_BINS))) 497178320Srwatson # Clean out the superfluous object files. 498102218Struckman ifneq ($$($1_SUPERFLUOUS_OBJS),) 499102218Struckman $$(shell $(RM) -f $$($1_SUPERFLUOUS_OBJS)) 500178320Srwatson endif 50153541Sshin # Sort to remove dupliates and provide a reproducable order on the input files to the linker. 502102218Struckman $1_ALL_OBJS := $$(sort $$($1_EXPECTED_OBJS) $$($1_EXTRA_OBJECT_FILES)) 50353541Sshin 50453541Sshin # Pickup extra OPENJDK_TARGET_OS_TYPE and/or OPENJDK_TARGET_OS dependent variables for CFLAGS. 50553541Sshin $1_EXTRA_CFLAGS:=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_CFLAGS_$(OPENJDK_TARGET_OS)) 50653541Sshin ifneq ($(DEBUG_LEVEL),release) 507171259Sdelphij # Pickup extra debug dependent variables for CFLAGS 50853541Sshin $1_EXTRA_CFLAGS+=$$($1_CFLAGS_debug) 50953541Sshin $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_TYPE)_debug) 510102218Struckman $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS)_debug) 511102218Struckman else 51253541Sshin $1_EXTRA_CFLAGS+=$$($1_CFLAGS_release) 51353541Sshin $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_TYPE)_release) 514169462Srwatson $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS)_release) 515157673Srwatson endif 516178320Srwatson 517102218Struckman # Pickup extra OPENJDK_TARGET_OS_TYPE and/or OPENJDK_TARGET_OS dependent variables for CXXFLAGS. 518102218Struckman $1_EXTRA_CXXFLAGS:=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)) 519178320Srwatson ifneq ($(DEBUG_LEVEL),release) 52053541Sshin # Pickup extra debug dependent variables for CXXFLAGS 521102218Struckman $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_debug) 52253541Sshin $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_TYPE)_debug) 52353541Sshin $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)_debug) 52453541Sshin else 52553541Sshin $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_release) 52653541Sshin $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_TYPE)_release) 52753541Sshin $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)_release) 528157673Srwatson endif 52953541Sshin 53053541Sshin # If no C++ flags are explicitly set, default to using the C flags. 531157673Srwatson # After that, we can set additional C++ flags that should not interfere 532157673Srwatson # with the mechanism for copying the C flags by default. 533157673Srwatson ifeq ($$($1_CXXFLAGS),) 534124332Sume $1_CXXFLAGS:=$$($1_CFLAGS) 535169462Srwatson endif 53654952Seivind ifeq ($$(strip $$($1_EXTRA_CXXFLAGS)),) 53753541Sshin $1_EXTRA_CXXFLAGS:=$$($1_EXTRA_CFLAGS) 538120913Sume endif 539169462Srwatson 540169462Srwatson ifeq ($(COMPILE_WITH_DEBUG_SYMBOLS), true) 541120913Sume $1_EXTRA_CFLAGS += $(CFLAGS_DEBUG_SYMBOLS) 54253541Sshin $1_EXTRA_CXXFLAGS += $(CXXFLAGS_DEBUG_SYMBOLS) 54353541Sshin endif 54453541Sshin 54553541Sshin ifneq (,$$($1_REORDER)) 54653541Sshin $1_EXTRA_CFLAGS += $$(C_FLAG_REORDER) 54753541Sshin $1_EXTRA_CXXFLAGS += $$(CXX_FLAG_REORDER) 54853541Sshin endif 549157673Srwatson 55053541Sshin # Pass the library name for static JNI library naming 55153541Sshin ifneq ($$($1_STATIC_LIBRARY),) 552157673Srwatson $1_EXTRA_CFLAGS += -DLIBRARY_NAME=$$($1_STATIC_LIBRARY) 553157673Srwatson $1_EXTRA_CXXFLAGS += -DLIBRARY_NAME=$$($1_STATIC_LIBRARY) 554157673Srwatson endif 555124332Sume 556169462Srwatson # Pick up disabled warnings, if possible on this platform. 55754952Seivind ifneq ($(DISABLE_WARNING_PREFIX),) 55853541Sshin $1_EXTRA_CFLAGS += $$(addprefix $(DISABLE_WARNING_PREFIX), \ 55953541Sshin $$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)) \ 560169462Srwatson $$($1_DISABLED_WARNINGS_C_$(TOOLCHAIN_TYPE))) 561169462Srwatson $1_EXTRA_CXXFLAGS += $$(addprefix $(DISABLE_WARNING_PREFIX), \ 56253541Sshin $$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)) \ 56353541Sshin $$($1_DISABLED_WARNINGS_CXX_$(TOOLCHAIN_TYPE))) 56453541Sshin endif 56553541Sshin 56653541Sshin # Check if warnings should be considered errors. 56753541Sshin # Pick first binary and toolchain specific, then binary specific, then general setting. 56853541Sshin ifeq ($$($1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE)),) 56953541Sshin ifeq ($$($1_WARNINGS_AS_ERRORS),) 57053541Sshin $1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE) := $$(WARNINGS_AS_ERRORS) 57153541Sshin else 57253541Sshin $1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE) := $$($1_WARNINGS_AS_ERRORS) 57353541Sshin endif 57453541Sshin endif 57553541Sshin 576171259Sdelphij ifeq ($$($1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE)), true) 577171259Sdelphij $1_EXTRA_CFLAGS += $(CFLAGS_WARNINGS_ARE_ERRORS) 578171259Sdelphij $1_EXTRA_CXXFLAGS += $(CFLAGS_WARNINGS_ARE_ERRORS) 579175162Sobrien endif 58053541Sshin 581177961Srwatson ifeq (NONE, $$($1_OPTIMIZATION)) 58278064Sume $1_EXTRA_CFLAGS += $(C_O_FLAG_NONE) 58353541Sshin $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_NONE) 58478064Sume else ifeq (LOW, $$($1_OPTIMIZATION)) 585157673Srwatson $1_EXTRA_CFLAGS += $(C_O_FLAG_NORM) 58653541Sshin $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_NORM) 587119995Sru else ifeq (HIGH, $$($1_OPTIMIZATION)) 58853541Sshin $1_EXTRA_CFLAGS += $(C_O_FLAG_HI) 58978064Sume $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_HI) 59078064Sume else ifeq (HIGHEST, $$($1_OPTIMIZATION)) 59178064Sume $1_EXTRA_CFLAGS += $(C_O_FLAG_HIGHEST) 59253541Sshin $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_HIGHEST) 59353541Sshin else ifneq (, $$($1_OPTIMIZATION)) 59453541Sshin $$(error Unknown value for OPTIMIZATION: $$($1_OPTIMIZATION)) 59578064Sume endif 59678064Sume 59791346Salfred $1_BUILD_INFO := $$($1_OBJECT_DIR)/_build-info.marker 59878064Sume 59978064Sume # Track variable changes for all variables that affect the compilation command 60078064Sume # lines for all object files in this setup. This includes at least all the 60153541Sshin # variables used in the call to add_native_source below. 60262587Sitojun $1_COMPILE_VARDEPS := $$($1_CFLAGS) $$($1_EXTRA_CFLAGS) $$($1_SYSROOT_CFLAGS) \ 60362587Sitojun $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS) \ 60462587Sitojun $$($1_CC) $$($1_CXX) $$($1_AS) $$($1_ASFLAGS) 60553541Sshin $1_COMPILE_VARDEPS_FILE := $$(call DependOnVariable, $1_COMPILE_VARDEPS, \ 60653541Sshin $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).comp.vardeps) 60753541Sshin 60853541Sshin # Now call add_native_source for each source file we are going to compile. 60953541Sshin $$(foreach p,$$($1_SRCS), \ 61053541Sshin $$(eval $$(call add_native_source,$1,$$p,$$($1_OBJECT_DIR), \ 61178064Sume $$($1_CFLAGS) $$($1_EXTRA_CFLAGS) $$($1_SYSROOT_CFLAGS), \ 61262587Sitojun $$($1_CC), \ 61378064Sume $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS) $$($1_SYSROOT_CFLAGS), \ 61478064Sume $$($1_CXX), $$($1_ASFLAGS)))) 61553541Sshin 61653541Sshin # Setup rule for printing progress info when compiling source files. 617133192Srwatson # This is a rough heuristic and may not always print accurate information. 618177961Srwatson $$($1_BUILD_INFO): $$($1_SRCS) $$($1_COMPILE_VARDEPS_FILE) 619178285Srwatson ifeq ($$(wildcard $$($1_TARGET)),) 620171260Sdelphij $(ECHO) 'Creating $$($1_BASENAME) from $$(words $$(filter-out %.vardeps, $$?)) file(s)' 621178285Srwatson else 62253541Sshin $(ECHO) $$(strip 'Updating $$($1_BASENAME)' \ 623133192Srwatson $$(if $$(filter-out %.vardeps, $$?), \ 62462587Sitojun 'due to $$(words $$(filter-out %.vardeps, $$?)) file(s)', \ 62578064Sume $$(if $$(filter %.vardeps, $$?), 'due to makefile changes'))) 626125776Sume endif 627125776Sume $(TOUCH) $$@ 628125776Sume 629125776Sume # On windows we need to create a resource file 630125776Sume ifeq ($(OPENJDK_TARGET_OS), windows) 631125776Sume ifneq (,$$($1_VERSIONINFO_RESOURCE)) 632125776Sume $1_RES:=$$($1_OBJECT_DIR)/$$($1_BASENAME).res 633125776Sume $1_RES_DEP:=$$($1_RES).d 634125776Sume $1_RES_DEP_TARGETS:=$$($1_RES).d.targets 635125776Sume -include $$($1_RES_DEP) 636125776Sume -include $$($1_RES_DEP_TARGETS) 637125776Sume 638125776Sume $1_RES_VARDEPS := $$($1_RC) $$($1_RC_FLAGS) 639125776Sume $1_RES_VARDEPS_FILE := $$(call DependOnVariable, $1_RES_VARDEPS, \ 640125776Sume $$($1_RES).vardeps) 641125776Sume 64278064Sume $$($1_RES): $$($1_VERSIONINFO_RESOURCE) $$($1_RES_VARDEPS_FILE) 64378064Sume $$(call LogInfo, Compiling resource $$(notdir $$($1_VERSIONINFO_RESOURCE)) (for $$(notdir $$($1_TARGET)))) 64478064Sume $$($1_RC) $$($1_RC_FLAGS) $$($1_SYSROOT_CFLAGS) $(CC_OUT_OPTION)$$@ \ 64578064Sume $$($1_VERSIONINFO_RESOURCE) 64678064Sume # Windows RC compiler does not support -showIncludes, so we mis-use CL for this. 64778064Sume $$($1_CC) $$($1_RC_FLAGS) $$($1_SYSROOT_CFLAGS) -showIncludes -nologo -TC \ 64878064Sume $(CC_OUT_OPTION)$$($1_RES_DEP).obj $$($1_VERSIONINFO_RESOURCE) > $$($1_RES_DEP).raw 2>&1 || true ; \ 64978064Sume $(ECHO) $$($1_RES): \\ > $$($1_RES_DEP) ; \ 65078064Sume $(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_RES_DEP).raw >> $$($1_RES_DEP) ; \ 65178064Sume $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_RES_DEP) > $$($1_RES_DEP_TARGETS) 65278064Sume endif 65378064Sume endif 65478064Sume 65578064Sume # mapfile doesnt seem to be implemented on macosx (yet??) 65678064Sume ifneq ($(OPENJDK_TARGET_OS),macosx) 65778064Sume ifneq ($(OPENJDK_TARGET_OS),windows) 65878064Sume $1_REAL_MAPFILE:=$$($1_MAPFILE) 65978064Sume ifneq (,$$($1_REORDER)) 66078064Sume $1_REAL_MAPFILE:=$$($1_OBJECT_DIR)/mapfile 661133192Srwatson 662178285Srwatson $$($1_REAL_MAPFILE) : $$($1_MAPFILE) $$($1_REORDER) 66353541Sshin $$(MKDIR) -p $$(@D) 664133192Srwatson $$(CP) $$($1_MAPFILE) $$@.tmp 66562587Sitojun $$(SED) -e 's=OUTPUTDIR=$$($1_OBJECT_DIR)=' $$($1_REORDER) >> $$@.tmp 66678064Sume $$(MV) $$@.tmp $$@ 667134121Srwatson endif 668134121Srwatson endif 669178285Srwatson endif 670134121Srwatson 671178285Srwatson # Pickup extra OPENJDK_TARGET_OS_TYPE and/or OPENJDK_TARGET_OS dependent variables 67253541Sshin # for LDFLAGS and LIBS 673133192Srwatson $1_EXTRA_LDFLAGS:=$$($1_LDFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS)) 67453541Sshin $1_EXTRA_LIBS:=$$($1_LIBS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LIBS_$(OPENJDK_TARGET_OS)) 67553541Sshin ifneq (,$$($1_REAL_MAPFILE)) 67653541Sshin $1_EXTRA_LDFLAGS += $(call SET_SHARED_LIBRARY_MAPFILE,$$($1_REAL_MAPFILE)) 67753541Sshin endif 67853541Sshin 67953541Sshin # Need to make sure TARGET is first on list 680171259Sdelphij $1 := $$($1_TARGET) 681180427Sbz 68253541Sshin ifeq ($(COPY_DEBUG_SYMBOLS), true) 68353541Sshin # Only copy debug symbols for dynamic libraries and programs. 68453541Sshin ifeq ($$($1_STATIC_LIBRARY), ) 68553541Sshin ifneq ($$($1_OUTPUT_DIR), $$($1_OBJECT_DIR)) 686158011Srwatson # The dependency on TARGET is needed on windows for debuginfo files 687158011Srwatson # to be rebuilt properly. 68853541Sshin $$($1_OUTPUT_DIR)/% : $$($1_OBJECT_DIR)/% $$($1_TARGET) 68953541Sshin $(CP) $$< $$@ 69053541Sshin endif 69153541Sshin 69253541Sshin # Generate debuginfo files. 69353541Sshin ifeq ($(OPENJDK_TARGET_OS), windows) 694169154Srwatson $1_EXTRA_LDFLAGS += "-pdb:$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).pdb" \ 695169154Srwatson "-map:$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).map" 69653541Sshin $1_DEBUGINFO_FILES := $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).pdb \ 69754952Seivind $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).map 69853541Sshin # No separate command is needed for debuginfo on windows, instead 69953541Sshin # touch target to make sure it has a later time stamp than the debug 70053541Sshin # symbol files to avoid unnecessary relinking on rebuild. 70153541Sshin $1_CREATE_DEBUGINFO_CMDS := $(TOUCH) $$($1_TARGET) 70253541Sshin 70353541Sshin else ifneq ($(findstring $(OPENJDK_TARGET_OS), linux solaris), ) 70453541Sshin $1_DEBUGINFO_FILES := $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).debuginfo 70553541Sshin # Setup the command line creating debuginfo files, to be run after linking. 70653541Sshin # It cannot be run separately since it updates the original target file 70753541Sshin $1_CREATE_DEBUGINFO_CMDS := \ 70853541Sshin $(OBJCOPY) --only-keep-debug $$($1_TARGET) $$($1_DEBUGINFO_FILES) $$(NEWLINE) \ 70953541Sshin $(CD) $$($1_OUTPUT_DIR) && \ 71053541Sshin $(OBJCOPY) --add-gnu-debuglink=$$($1_DEBUGINFO_FILES) $$($1_TARGET) 71153541Sshin 71253541Sshin else ifeq ($(OPENJDK_TARGET_OS), macosx) 71353541Sshin $1_DEBUGINFO_FILES := $$($1_OBJECT_DIR)/$$($1_BASENAME).dSYM 71453541Sshin # On Macosx, the debuginfo generation doesn't touch the linked binary, but 71553541Sshin # to avoid always relinking, touch it anyway to force a later timestamp than 71653541Sshin # the dSYM files. 71753541Sshin $1_CREATE_DEBUGINFO_CMDS := \ 71853541Sshin $(DSYMUTIL) --out $$($1_DEBUGINFO_FILES) $$($1_TARGET) $$(NEWLINE) \ 71953541Sshin $(TOUCH) $$($1_TARGET) 72053541Sshin endif # OPENJDK_TARGET_OS 72153541Sshin 722169154Srwatson # This dependency dance ensures that debug info files get rebuilt 723169154Srwatson # properly if deleted. 72453541Sshin $$($1_TARGET): $$($1_DEBUGINFO_FILES) 72553541Sshin $$($1_DEBUGINFO_FILES): $$($1_ALL_OBJS) 72653541Sshin 72753541Sshin ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true) 72853541Sshin $1_DEBUGINFO_ZIP := $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).diz 72953541Sshin $1 += $$(subst $$($1_OBJECT_DIR),$$($1_OUTPUT_DIR),$$($1_DEBUGINFO_ZIP)) 73053541Sshin 73153541Sshin # The dependency on TARGET is needed for debuginfo files 73253541Sshin # to be rebuilt properly. 73353541Sshin $$($1_DEBUGINFO_ZIP): $$($1_DEBUGINFO_FILES) $$($1_TARGET) 73453541Sshin $(CD) $$($1_OBJECT_DIR) \ 73554952Seivind && $(ZIP) -q -r $$@ $$(notdir $$($1_DEBUGINFO_FILES)) 73653541Sshin 73753541Sshin else 73853541Sshin $1 += $$(subst $$($1_OBJECT_DIR),$$($1_OUTPUT_DIR),$$($1_DEBUGINFO_FILES)) 73953541Sshin endif 74053541Sshin endif # !STATIC_LIBRARY 74153541Sshin endif # COPY_DEBUG_SYMBOLS 74253541Sshin 74353541Sshin ifeq ($$($1_STRIP_SYMBOLS), true) 74453541Sshin ifneq ($$($1_STRIP), ) 74553541Sshin # Default to using the global STRIPFLAGS. Allow for overriding with an empty value 74653541Sshin $1_STRIPFLAGS ?= $(STRIPFLAGS) 74753541Sshin $1_STRIP_CMD := $$($1_STRIP) $$($1_STRIPFLAGS) $$($1_TARGET) 74853541Sshin endif 74953541Sshin endif 75053541Sshin 75153541Sshin ifneq (,$$($1_LIBRARY)) 75253541Sshin # Generating a dynamic library. 75353541Sshin $1_EXTRA_LDFLAGS += $$(call SET_SHARED_LIBRARY_NAME,$$($1_BASENAME)) 75453541Sshin ifeq ($(OPENJDK_TARGET_OS), windows) 75553541Sshin $1_EXTRA_LDFLAGS += "-implib:$$($1_OBJECT_DIR)/$$($1_LIBRARY).lib" 75653541Sshin endif 75753541Sshin 75853541Sshin $1_EXTRA_LIBS += $(GLOBAL_LIBS) 75953541Sshin 76053541Sshin $1_VARDEPS := $$($1_LD) $$($1_SYSROOT_LDFLAGS) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) \ 76153541Sshin $$($1_LIBS) $$($1_EXTRA_LIBS) $$($1_CREATE_DEBUGINFO_CMDS) \ 76253541Sshin $$($1_STRIP_CMD) 76381127Sume $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \ 764171259Sdelphij $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps) 76581127Sume 76681127Sume $1_LD_OBJ_ARG := $$($1_ALL_OBJS) 76781127Sume 76881127Sume # If there are many object files, use an @-file... 76981127Sume ifneq ($$(word 17, $$($1_ALL_OBJS)), ) 770157978Srwatson $1_OBJ_FILE_LIST := $$($1_OBJECT_DIR)/_$1_objectfilenames.txt 771169154Srwatson ifneq ($(COMPILER_COMMAND_FILE_FLAG),) 772178285Srwatson $1_LD_OBJ_ARG := $(COMPILER_COMMAND_FILE_FLAG)$$($1_OBJ_FILE_LIST) 77381127Sume else 77481127Sume # ...except for toolchains which don't support them. 77581127Sume $1_LD_OBJ_ARG := `cat $$($1_OBJ_FILE_LIST)` 77681127Sume endif 77781127Sume endif 77881127Sume 77981127Sume $$($1_TARGET): $$($1_ALL_OBJS) $$($1_RES) $$($1_REAL_MAPFILE) \ 78081127Sume $$($1_VARDEPS_FILE) 78181127Sume ifneq ($$($1_OBJ_FILE_LIST), ) 78281127Sume $$(eval $$(call ListPathsSafely, $1_ALL_OBJS, $$($1_OBJ_FILE_LIST))) 78381127Sume endif 78481127Sume # Keep as much as possible on one execution line for best performance 78581127Sume # on Windows 78681127Sume $$(call LogInfo, Linking $$($1_BASENAME)) 78781127Sume $(call LogFailures, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link.log, $$($1_SAFE_NAME)_link, \ 78881127Sume $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \ 78981127Sume $(LD_OUT_OPTION)$$@ \ 79081127Sume $$($1_LD_OBJ_ARG) $$($1_RES) \ 79181127Sume $$($1_LIBS) $$($1_EXTRA_LIBS)) ; \ 79281127Sume $$($1_CREATE_DEBUGINFO_CMDS) 79381127Sume $$($1_STRIP_CMD) 79481127Sume 795149849Sobrien endif 79681127Sume 79781127Sume ifneq (,$$($1_STATIC_LIBRARY)) 79881127Sume $1_VARDEPS := $$($1_AR) $$($1_ARFLAGS) $$($1_LIBS) \ 799178285Srwatson $$($1_EXTRA_LIBS) 80081127Sume $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \ 801157978Srwatson $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps) 80281127Sume 80381127Sume # Generating a static library, ie object file archive. 80453541Sshin $$($1_TARGET): $$($1_ALL_OBJS) $$($1_RES) $$($1_VARDEPS_FILE) 80553541Sshin $$(call LogInfo, Archiving $$($1_STATIC_LIBRARY)) 80653541Sshin $(call LogFailures, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link.log, $$($1_SAFE_NAME)_link, \ 80753541Sshin $$($1_AR) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_ALL_OBJS) \ 80853541Sshin $$($1_RES)) 80953541Sshin ifeq ($(STATIC_BUILD), true) 81053541Sshin $(GetSymbols) 811171259Sdelphij endif 81253541Sshin endif 813171259Sdelphij 814122922Sandre ifneq (,$$($1_PROGRAM)) 815122922Sandre # A executable binary has been specified, setup the target for it. 816122922Sandre $1_EXTRA_LIBS += $(GLOBAL_LIBS) 817122922Sandre 81853541Sshin $1_VARDEPS := $$($1_LD) $$($1_SYSROOT_LDFLAGS) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) \ 81953541Sshin $$($1_LIBS) $$($1_EXTRA_LIBS) $$($1_MT) \ 82053541Sshin $$($1_CODESIGN) $$($1_CREATE_DEBUGINFO_CMDS) $$($1_MANIFEST_VERSION) \ 82153541Sshin $$($1_STRIP_CMD) 82253541Sshin $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \ 82353541Sshin $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps) 82498211Shsu 825171259Sdelphij $$($1_TARGET): $$($1_ALL_OBJS) $$($1_RES) $$($1_MANIFEST) \ 82653541Sshin $$($1_VARDEPS_FILE) 827122922Sandre $$(call LogInfo, Linking executable $$($1_BASENAME)) 828122922Sandre $(call LogFailures, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link.log, $$($1_SAFE_NAME)_link, \ 829122922Sandre $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \ 83098211Shsu $(EXE_OUT_OPTION)$$($1_TARGET) \ 83153541Sshin $$($1_ALL_OBJS) $$($1_RES) \ 83253541Sshin $$($1_LIBS) $$($1_EXTRA_LIBS)) 83353541Sshin ifeq ($(OPENJDK_TARGET_OS), windows) 83453541Sshin ifneq ($$($1_MANIFEST), ) 83553541Sshin $$($1_MT) -nologo -manifest $$($1_MANIFEST) -identity:"$$($1_PROGRAM).exe, version=$$($1_MANIFEST_VERSION)" -outputresource:$$@;#1 83653541Sshin endif 837171259Sdelphij endif 838171259Sdelphij # This only works if the openjdk_codesign identity is present on the system. Let 839171259Sdelphij # silently fail otherwise. 84053541Sshin ifneq (,$(CODESIGN)) 84153541Sshin ifneq (,$$($1_CODESIGN)) 84253541Sshin $(CODESIGN) -s openjdk_codesign $$@ 84353541Sshin endif 84478064Sume endif 84553541Sshin $$($1_CREATE_DEBUGINFO_CMDS) 846178285Srwatson $$($1_STRIP_CMD) 847158011Srwatson 84883934Sbrooks endif 84983934Sbrooksendef 85083934Sbrooks 85183934Sbrooksendif # _NATIVE_COMPILATION_GMK 85278064Sume