NativeCompilation.gmk revision 1805:6e9c4ae0edf5
198944Sobrien# 298944Sobrien# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. 3130803Smarcel# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4130803Smarcel# 598944Sobrien# This code is free software; you can redistribute it and/or modify it 698944Sobrien# under the terms of the GNU General Public License version 2 only, as 798944Sobrien# published by the Free Software Foundation. Oracle designates this 898944Sobrien# particular file as subject to the "Classpath" exception as provided 998944Sobrien# by Oracle in the LICENSE file that accompanied this code. 1098944Sobrien# 1198944Sobrien# This code is distributed in the hope that it will be useful, but WITHOUT 1298944Sobrien# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1398944Sobrien# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1498944Sobrien# version 2 for more details (a copy is included in the LICENSE file that 1598944Sobrien# accompanied this code). 1698944Sobrien# 1798944Sobrien# You should have received a copy of the GNU General Public License version 1898944Sobrien# 2 along with this work; if not, write to the Free Software Foundation, 1998944Sobrien# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2098944Sobrien# 2198944Sobrien# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2298944Sobrien# or visit www.oracle.com if you need additional information or have any 2398944Sobrien# questions. 2498944Sobrien# 2598944Sobrien 2698944Sobrien# When you read this source. Remember that $(sort ...) has the side effect 2798944Sobrien# of removing duplicates. It is actually this side effect that is 2898944Sobrien# desired whenever sort is used below! 2998944Sobrien 3098944Sobrienifndef _NATIVE_COMPILATION_GMK 3198944Sobrien_NATIVE_COMPILATION_GMK := 1 3298944Sobrien 3398944Sobrienifeq (,$(_MAKEBASE_GMK)) 3498944Sobrien $(error You must include MakeBase.gmk prior to including NativeCompilation.gmk) 3598944Sobrienendif 36130803Smarcel 3798944Sobrien################################################################################ 3898944Sobrien# Create exported symbols file for static libraries 3998944Sobrien################################################################################ 4098944Sobrien 4198944Sobrien# get the exported symbols from mapfiles and if there 4298944Sobrien# is no mapfile, get them from the archive 4398944Sobriendefine GetSymbols 4498944Sobrien $(RM) $$(@D)/$$(basename $$(@F)).symbols; \ 4598944Sobrien if [ ! -z $$($1_MAPFILE) -a -e $$($1_MAPFILE) ]; then \ 4698944Sobrien $(ECHO) "Getting symbols from mapfile $$($1_MAPFILE)"; \ 4798944Sobrien $(AWK) '/global:/','/local:/' $$($1_MAPFILE) | \ 4898944Sobrien $(SED) -e 's/#.*//;s/global://;s/local://;s/\;//;s/^[ ]*/_/;/^_$$$$/d' | \ 4998944Sobrien $(EGREP) -v "JNI_OnLoad|JNI_OnUnload|Agent_OnLoad|Agent_OnUnload|Agent_OnAttach" > \ 5098944Sobrien $$(@D)/$$(basename $$(@F)).symbols || true; \ 5198944Sobrien $(NM) $$($1_TARGET) | $(GREP) " T " | \ 5298944Sobrien $(EGREP) "JNI_OnLoad|JNI_OnUnload|Agent_OnLoad|Agent_OnUnload|Agent_OnAttach" | \ 5398944Sobrien $(CUT) -d ' ' -f 3 >> $$(@D)/$$(basename $$(@F)).symbols || true;\ 5498944Sobrien else \ 5598944Sobrien $(ECHO) "Getting symbols from nm"; \ 5698944Sobrien $(NM) -m $$($1_TARGET) | $(GREP) "__TEXT" | \ 57130803Smarcel $(EGREP) -v "non-external|private extern|__TEXT,__eh_frame" | \ 5898944Sobrien $(SED) -e 's/.* //' > $$(@D)/$$(basename $$(@F)).symbols; \ 5998944Sobrien fi 6098944Sobrienendef 6198944Sobrien 6298944Sobrien################################################################################ 6398944Sobrien# Define a native toolchain configuration that can be used by 6498944Sobrien# SetupNativeCompilation calls 6598944Sobrien# 6698944Sobrien# Parameter 1 is the name of the toolchain definition 6798944Sobrien# 6898944Sobrien# Remaining parameters are named arguments: 6998944Sobrien# EXTENDS - Optional parent definition to get defaults from 7098944Sobrien# CC - The C compiler 7198944Sobrien# CXX - The C++ compiler 7298944Sobrien# LD - The Linker 7398944Sobrien# AR - Static linker 7498944Sobrien# AS - Assembler 7598944Sobrien# MT - Windows MT tool 7698944Sobrien# RC - Windows RC tool 7798944Sobrien# STRIP - The tool to use for stripping debug symbols 7898944Sobrien# SYSROOT_CFLAGS - Compiler flags for using the specific sysroot 7998944Sobrien# SYSROOT_LDFLAGS - Linker flags for using the specific sysroot 8098944SobrienDefineNativeToolchain = $(NamedParamsMacroTemplate) 8198944Sobriendefine DefineNativeToolchainBody 8298944Sobrien # If extending another definition, get default values from that, 83130803Smarcel # otherwise, nothing more needs to be done as variable assignments 84130803Smarcel # already happened in NamedParamsMacroTemplate. 8598944Sobrien ifneq ($$($1_EXTENDS), ) 8698944Sobrien $$(call SetIfEmpty, $1_CC, $$($$($1_EXTENDS)_CC)) 87130803Smarcel $$(call SetIfEmpty, $1_CXX, $$($$($1_EXTENDS)_CXX)) 88130803Smarcel $$(call SetIfEmpty, $1_LD, $$($$($1_EXTENDS)_LD)) 8998944Sobrien $$(call SetIfEmpty, $1_AR, $$($$($1_EXTENDS)_AR)) 90130803Smarcel $$(call SetIfEmpty, $1_AS, $$($$($1_EXTENDS)_AS)) 91130803Smarcel $$(call SetIfEmpty, $1_MT, $$($$($1_EXTENDS)_MT)) 92130803Smarcel $$(call SetIfEmpty, $1_RC, $$($$($1_EXTENDS)_RC)) 9398944Sobrien $$(call SetIfEmpty, $1_STRIP, $$($$($1_EXTENDS)_STRIP)) 9498944Sobrien $$(call SetIfEmpty, $1_SYSROOT_CFLAGS, $$($$($1_EXTENDS)_SYSROOT_CFLAGS)) 9598944Sobrien $$(call SetIfEmpty, $1_SYSROOT_LDFLAGS, $$($$($1_EXTENDS)_SYSROOT_LDFLAGS)) 9698944Sobrien endif 9798944Sobrienendef 9898944Sobrien 9998944Sobrien# Create a default toolchain with the main compiler and linker 10098944Sobrien$(eval $(call DefineNativeToolchain, TOOLCHAIN_DEFAULT, \ 10198944Sobrien CC := $(CC), \ 10298944Sobrien CXX := $(CXX), \ 10398944Sobrien LD := $(LD), \ 10498944Sobrien AR := $(AR), \ 10598944Sobrien AS := $(AS), \ 10698944Sobrien MT := $(MT), \ 10798944Sobrien RC := $(RC), \ 10898944Sobrien STRIP := $(STRIP), \ 10998944Sobrien SYSROOT_CFLAGS := $(SYSROOT_CFLAGS), \ 11098944Sobrien SYSROOT_LDFLAGS := $(SYSROOT_LDFLAGS), \ 11198944Sobrien)) 112130803Smarcel 113130803Smarcel# Create a toolchain where linking is done with the C++ linker 11498944Sobrien$(eval $(call DefineNativeToolchain, TOOLCHAIN_LINK_CXX, \ 115130803Smarcel EXTENDS := TOOLCHAIN_DEFAULT, \ 116130803Smarcel LD := $(LDCXX), \ 117130803Smarcel)) 118130803Smarcel 11998944Sobrien# Create a toolchain with the BUILD compiler, used for build tools that 12098944Sobrien# are to be run during the build. 12198944Sobrien# The BUILD_SYSROOT_*FLAGS variables are empty for now. 12298944Sobrien$(eval $(call DefineNativeToolchain, TOOLCHAIN_BUILD, \ 12398944Sobrien CC := $(BUILD_CC), \ 12498944Sobrien CXX := $(BUILD_CXX), \ 12598944Sobrien LD := $(BUILD_LD), \ 12698944Sobrien AR := $(BUILD_AR), \ 12798944Sobrien AS := $(BUILD_AS), \ 12898944Sobrien SYSROOT_CFLAGS := $(BUILD_SYSROOT_CFLAGS), \ 12998944Sobrien SYSROOT_LDFLAGS := $(BUILD_SYSROOT_LDFLAGS), \ 13098944Sobrien)) 131130803Smarcel 132130803Smarcel################################################################################ 13398944Sobrien 13498944Sobrien# Extensions of files handled by this macro. 13598944SobrienNATIVE_SOURCE_EXTENSIONS := %.s %.c %.cpp %.cc %.m %.mm 13698944Sobrien 13798944Sobrien# Replaces native source extensions with the object file extension in a string. 13898944Sobrien# Param 1: the string containing source file names with extensions 13998944Sobrien# The surrounding strip is needed to keep additional whitespace out 14098944Sobriendefine replace_with_obj_extension 14198944Sobrien$(strip \ 14298944Sobrien $(foreach extension, $(NATIVE_SOURCE_EXTENSIONS), \ 14398944Sobrien $(patsubst $(extension),%$(OBJ_SUFFIX),$(filter $(extension),$1))) \ 14498944Sobrien) 14598944Sobrienendef 14698944Sobrien 14798944Sobrienifeq ($(OPENJDK_BUILD_OS_ENV), windows.cygwin) 148130803Smarcel UNIX_PATH_PREFIX := /cygdrive 149130803Smarcelelse ifeq ($(OPENJDK_BUILD_OS_ENV), windows.msys) 150130803Smarcel UNIX_PATH_PREFIX := 15198944Sobrienendif 15298944Sobrien 153130803Smarcel# This pattern is used to transform the output of the microsoft CL compiler 154130803Smarcel# into a make syntax dependency file (.d) 155130803SmarcelWINDOWS_SHOWINCLUDE_SED_PATTERN := \ 156130803Smarcel -e '/^Note: including file:/!d' \ 157130803Smarcel -e 's|Note: including file: *||' \ 158130803Smarcel -e 's|\\|/|g' \ 15998944Sobrien -e 's|^\([a-zA-Z]\):|$(UNIX_PATH_PREFIX)/\1|g' \ 16098944Sobrien -e '\|$(TOPDIR)|I !d' \ 16198944Sobrien -e 's|$$$$| \\|g' \ 16298944Sobrien # 16398944Sobrien 16498944Sobrien# This pattern is used to transform a dependency file (.d) to a list 16598944Sobrien# of make targets for dependent files (.d.targets) 16698944SobrienDEPENDENCY_TARGET_SED_PATTERN := \ 16798944Sobrien -e 's/\#.*//' \ 16898944Sobrien -e 's/^[^:]*: *//' \ 16998944Sobrien -e 's/ *\\$$$$//' \ 17098944Sobrien -e 's/^[ ]*//' \ 17198944Sobrien -e '/^$$$$/ d' \ 17298944Sobrien -e 's/$$$$/ :/' \ 17398944Sobrien # 17498944Sobrien 17598944Sobriendefine add_native_source 17698944Sobrien # param 1 = BUILD_MYPACKAGE 17798944Sobrien # parma 2 = the source file name (..../alfa.c or .../beta.cpp) 17898944Sobrien # param 3 = the bin dir that stores all .o (.obj) and .d files. 17998944Sobrien # param 4 = the c flags to the compiler 18098944Sobrien # param 5 = the c compiler 18198944Sobrien # param 6 = the c++ flags to the compiler 18298944Sobrien # param 7 = the c++ compiler 18398944Sobrien # param 8 = the flags to the assembler 18498944Sobrien 18598944Sobrien ifneq (,$$(filter %.c,$2)) 18698944Sobrien # Compile as a C file 18798944Sobrien $1_$2_FLAGS=$(CFLAGS_CCACHE) $4 $$($1_$(notdir $2)_CFLAGS) -DTHIS_FILE='"$$(<F)"' -c 18898944Sobrien $1_$2_COMP=$5 18998944Sobrien $1_$2_DEP_FLAG:=$(C_FLAG_DEPS) 19098944Sobrien else ifneq (,$$(filter %.m,$2)) 19198944Sobrien # Compile as an Objective-C file 19298944Sobrien $1_$2_FLAGS=-x objective-c $(CFLAGS_CCACHE) $4 $$($1_$(notdir $2)_CFLAGS) -DTHIS_FILE='"$$(<F)"' -c 19398944Sobrien $1_$2_COMP=$5 19498944Sobrien $1_$2_DEP_FLAG:=$(C_FLAG_DEPS) 19598944Sobrien else ifneq (,$$(filter %.s,$2)) 19698944Sobrien # Compile as assembler file 19798944Sobrien $1_$2_FLAGS=$8 -DTHIS_FILE='"$$(<F)"' 19898944Sobrien $1_$2_COMP=$(AS) 19998944Sobrien $1_$2_DEP_FLAG:= 20098944Sobrien else ifneq (,$$(filter %.cpp,$2)$$(filter %.cc,$2)$$(filter %.mm,$2)) 20198944Sobrien # Compile as a C++ or Objective-C++ file 20298944Sobrien $1_$2_FLAGS=$(CFLAGS_CCACHE) $6 $$($1_$(notdir $2)_CXXFLAGS) -DTHIS_FILE='"$$(<F)"' -c 20398944Sobrien $1_$2_COMP=$7 20498944Sobrien $1_$2_DEP_FLAG:=$(CXX_FLAG_DEPS) 20598944Sobrien else 20698944Sobrien $$(error Internal error in NativeCompilation.gmk: no compiler for file $2) 20798944Sobrien endif 20898944Sobrien # Generate the .o (.obj) file name and place it in the bin dir. 20998944Sobrien $1_$2_OBJ := $3/$$(call replace_with_obj_extension, $$(notdir $2)) 21098944Sobrien # Only continue if this object file hasn't been processed already. This lets the first found 21198944Sobrien # source file override any other with the same name. 21298944Sobrien ifeq (,$$(findstring $$($1_$2_OBJ),$$($1_ALL_OBJS))) 21398944Sobrien $1_ALL_OBJS+=$$($1_$2_OBJ) 21498944Sobrien ifeq (,$$(filter %.s,$2)) 21598944Sobrien # And this is the dependency file for this obj file. 21698944Sobrien $1_$2_DEP:=$$(patsubst %$(OBJ_SUFFIX),%.d,$$($1_$2_OBJ)) 21798944Sobrien # The dependency target file lists all dependencies as empty targets 21898944Sobrien # to avoid make error "No rule to make target" for removed files 21998944Sobrien $1_$2_DEP_TARGETS:=$$(patsubst %$(OBJ_SUFFIX),%.d.targets,$$($1_$2_OBJ)) 22098944Sobrien 22198944Sobrien # Include previously generated dependency information. (if it exists) 22298944Sobrien -include $$($1_$2_DEP) 22398944Sobrien -include $$($1_$2_DEP_TARGETS) 22498944Sobrien 22598944Sobrien ifeq ($(TOOLCHAIN_TYPE), microsoft) 22698944Sobrien $1_$2_DEBUG_OUT_FLAGS:=-Fd$$(patsubst %$(OBJ_SUFFIX),%.pdb,$$($1_$2_OBJ)) \ 22798944Sobrien -Fm$$(patsubst %$(OBJ_SUFFIX),%.map,$$($1_$2_OBJ)) 22898944Sobrien endif 22998944Sobrien endif 23098944Sobrien 23198944Sobrien $$($1_$2_OBJ) : $2 $$($1_COMPILE_VARDEPS_FILE) | $$($1_BUILD_INFO) 23298944Sobrien $(ECHO) $(LOG_INFO) "Compiling $$(notdir $2) (for $$(notdir $$($1_TARGET)))" 23398944Sobrien ifneq ($(TOOLCHAIN_TYPE), microsoft) 23498944Sobrien ifeq ($(TOOLCHAIN_TYPE)$$(filter %.s,$2), solstudio) 23598944Sobrien # The Solaris studio compiler doesn't output the full path to the object file in the 23698944Sobrien # generated deps files. Fixing it with sed. If compiling assembly, don't try this. 23798944Sobrien $(call LogFailures, $$($1_$2_OBJ).log, $$($1_SAFE_NAME)_$$(notdir $2), \ 23898944Sobrien $$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEP_FLAG) $$($1_$2_DEP).tmp $(CC_OUT_OPTION)$$($1_$2_OBJ) $2) 23998944Sobrien $(SED) 's|^$$(@F):|$$@:|' $$($1_$2_DEP).tmp > $$($1_$2_DEP) 24098944Sobrien else 24198944Sobrien $(call LogFailures, $$($1_$2_OBJ).log, $$($1_SAFE_NAME)_$$(notdir $2), \ 242130803Smarcel $$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEP_FLAG) $$($1_$2_DEP) $(CC_OUT_OPTION)$$($1_$2_OBJ) $2) 243130803Smarcel endif 24498944Sobrien # Create a dependency target file from the dependency file. 245130803Smarcel # Solution suggested by http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/ 246130803Smarcel ifneq ($$($1_$2_DEP),) 247130803Smarcel $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_$2_DEP) > $$($1_$2_DEP_TARGETS) 248130803Smarcel endif 249130803Smarcel else 250130803Smarcel # The Visual Studio compiler lacks a feature for generating make dependencies, but by 251130803Smarcel # setting -showIncludes, all included files are printed. These are filtered out and 252130803Smarcel # parsed into make dependences. 253130803Smarcel # Keep as much as possible on one execution line for best performance on Windows 254130803Smarcel ($(call LogFailures, $$($1_$2_OBJ).log, $$($1_SAFE_NAME)_$$(notdir $2), \ 255130803Smarcel $$($1_$2_COMP) $$($1_$2_FLAGS) -showIncludes $$($1_$2_DEBUG_OUT_FLAGS) \ 256130803Smarcel $(CC_OUT_OPTION)$$($1_$2_OBJ) $2) ; echo $$$$? > $$($1_$2_DEP).exitvalue) \ 257130803Smarcel | $(TEE) $$($1_$2_DEP).raw | $(GREP) -v -e "^Note: including file:" \ 258130803Smarcel -e "^$(notdir $2)$$$$" || test "$$$$?" = "1" ; \ 259130803Smarcel exit `cat $$($1_$2_DEP).exitvalue` ; \ 260130803Smarcel $(RM) $$($1_$2_DEP).exitvalue ; \\ 261130803Smarcel ($(ECHO) $$@: \\ ; \ 262130803Smarcel $(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_$2_DEP).raw) | $(SORT) -u > $$($1_$2_DEP) ; \ 263130803Smarcel $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_$2_DEP) > $$($1_$2_DEP_TARGETS) 264130803Smarcel endif 265130803Smarcel endif 266130803Smarcelendef 267130803Smarcel 268130803Smarcel# Setup make rules for creating a native binary (a shared library or an 269130803Smarcel# executable). 270130803Smarcel# 271130803Smarcel# Parameter 1 is the name of the rule. This name is used as variable prefix, 272130803Smarcel# and the targets generated are listed in a variable by that name. 273130803Smarcel# 274130803Smarcel# Remaining parameters are named arguments. These include: 275130803Smarcel# TOOLCHAIN Name of toolchain setup to use. Defaults to TOOLCHAIN_DEFAULT. 276130803Smarcel# SRC one or more directory roots to scan for C/C++ files. 277130803Smarcel# CFLAGS the compiler flags to be used, used both for C and C++. 278130803Smarcel# CXXFLAGS the compiler flags to be used for c++, if set overrides CFLAGS. 279130803Smarcel# LDFLAGS the linker flags to be used, used both for C and C++. 280130803Smarcel# LIBS the libraries to link to 281130803Smarcel# ARFLAGS the archiver flags to be used 282130803Smarcel# OBJECT_DIR the directory where we store the object files 283130803Smarcel# LIBRARY the resulting library file 284130803Smarcel# PROGRAM the resulting exec file 285130803Smarcel# INCLUDES only pick source from these directories 286130803Smarcel# EXCLUDES do not pick source from these directories 287130803Smarcel# INCLUDE_FILES only compile exactly these files! 288130803Smarcel# EXCLUDE_FILES with these names 289130803Smarcel# EXTRA_FILES List of extra files not in any of the SRC dirs 290130803Smarcel# VERSIONINFO_RESOURCE Input file for RC. Setting this implies that RC will be run 291130803Smarcel# RC_FLAGS flags for RC. 292130803Smarcel# MAPFILE mapfile 293130803Smarcel# REORDER reorder file 294130803Smarcel# DEBUG_SYMBOLS add debug symbols (if configured on) 295130803Smarcel# CC the compiler to use, default is $(CC) 296130803Smarcel# LD the linker to use, default is $(LD) 297130803Smarcel# OPTIMIZATION sets optimization level to NONE, LOW, HIGH, HIGHEST 298130803Smarcel# DISABLED_WARNINGS_<toolchain> Disable the given warnings for the specified toolchain 299130803Smarcel# DISABLED_WARNINGS_C_<toolchain> Disable the given warnings for the specified toolchain 300130803Smarcel# when compiling C code 301130803Smarcel# DISABLED_WARNINGS_CXX_<toolchain> Disable the given warnings for the specified 302130803Smarcel# toolchain when compiling C++ code 303130803Smarcel# STRIP_SYMBOLS Set to true to strip the final binary if the toolchain allows for it 304130803Smarcel# STRIPFLAGS Optionally change the flags given to the strip command 305130803SmarcelSetupNativeCompilation = $(NamedParamsMacroTemplate) 306130803Smarceldefine SetupNativeCompilationBody 307130803Smarcel 308130803Smarcel # If we're doing a static build and producing a library 309130803Smarcel # force it to be a static library and remove the -l libraries 310130803Smarcel ifeq ($(STATIC_BUILD), true) 311130803Smarcel ifneq ($$($1_LIBRARY),) 312130803Smarcel $1_STATIC_LIBRARY := $$($1_LIBRARY) 313130803Smarcel $1_LIBRARY := 314130803Smarcel endif 315130803Smarcel endif 316130803Smarcel 317130803Smarcel ifneq (,$$($1_BIN)) 318130803Smarcel $$(error BIN has been replaced with OBJECT_DIR) 319130803Smarcel endif 320130803Smarcel 321130803Smarcel ifneq (,$$($1_LIB)) 322130803Smarcel $$(error LIB has been replaced with LIBRARY) 323130803Smarcel endif 324130803Smarcel 325130803Smarcel ifneq (,$$($1_EXE)) 326130803Smarcel $$(error EXE has been replaced with PROGRAM) 327130803Smarcel endif 328130803Smarcel 32998944Sobrien ifneq (,$$($1_LIBRARY)) 33098944Sobrien ifeq (,$$($1_OUTPUT_DIR)) 33198944Sobrien $$(error LIBRARY requires OUTPUT_DIR) 33298944Sobrien endif 33398944Sobrien 33498944Sobrien ifneq ($$($1_LIBRARY),$(basename $$($1_LIBRARY))) 33598944Sobrien $$(error directory of LIBRARY should be specified using OUTPUT_DIR) 336130803Smarcel endif 337130803Smarcel 33898944Sobrien ifneq (,$(findstring $(SHARED_LIBRARY_SUFFIX),$$($1_LIBRARY))) 33998944Sobrien $$(error LIBRARY should be specified without SHARED_LIBRARY_SUFFIX: $(SHARED_LIBRARY_SUFFIX)) 34098944Sobrien endif 34198944Sobrien 34298944Sobrien ifneq (,$(findstring $(LIBRARY_PREFIX),$$($1_LIBRARY))) 34398944Sobrien $$(error LIBRARY should be specified without LIBRARY_PREFIX: $(LIBRARY_PREFIX)) 34498944Sobrien endif 34598944Sobrien 346130803Smarcel ifeq ($$($1_SUFFIX), ) 34798944Sobrien $1_SUFFIX := $(SHARED_LIBRARY_SUFFIX) 34898944Sobrien endif 349130803Smarcel 350130803Smarcel $1_BASENAME:=$(LIBRARY_PREFIX)$$($1_LIBRARY)$$($1_SUFFIX) 351130803Smarcel $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME) 35298944Sobrien $1_NOSUFFIX:=$(LIBRARY_PREFIX)$$($1_LIBRARY) 353130803Smarcel endif 35498944Sobrien 35598944Sobrien ifneq (,$$($1_STATIC_LIBRARY)) 35698944Sobrien ifeq (,$$($1_OUTPUT_DIR)) 35798944Sobrien $$(error STATIC_LIBRARY requires OUTPUT_DIR) 35898944Sobrien endif 359130803Smarcel 360130803Smarcel ifneq ($$($1_STATIC_LIBRARY),$(basename $$($1_STATIC_LIBRARY))) 36198944Sobrien $$(error directory of STATIC_LIBRARY should be specified using OUTPUT_DIR) 36298944Sobrien endif 36398944Sobrien 36498944Sobrien ifneq (,$(findstring $(STATIC_LIBRARY_SUFFIX),$$($1_STATIC_LIBRARY))) 365130803Smarcel $$(error STATIC_LIBRARY should be specified without STATIC_LIBRARY_SUFFIX: $(STATIC_LIBRARY_SUFFIX)) 366130803Smarcel endif 36798944Sobrien 368130803Smarcel ifneq (,$(findstring $(LIBRARY_PREFIX),$$($1_STATIC_LIBRARY))) 36998944Sobrien $$(error STATIC_LIBRARY should be specified without LIBRARY_PREFIX: $(LIBRARY_PREFIX)) 37098944Sobrien endif 37198944Sobrien 37298944Sobrien ifeq ($$($1_SUFFIX), ) 37398944Sobrien $1_SUFFIX := $(STATIC_LIBRARY_SUFFIX) 37498944Sobrien endif 37598944Sobrien 37698944Sobrien $1_BASENAME:=$(LIBRARY_PREFIX)$$($1_STATIC_LIBRARY)$$($1_SUFFIX) 37798944Sobrien $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME) 378130803Smarcel $1_NOSUFFIX:=$(LIBRARY_PREFIX)$$($1_STATIC_LIBRARY) 379130803Smarcel endif 380130803Smarcel 381130803Smarcel ifneq (,$$($1_PROGRAM)) 382130803Smarcel ifeq (,$$($1_OUTPUT_DIR)) 383130803Smarcel $$(error PROGRAM requires OUTPUT_DIR) 384130803Smarcel endif 385130803Smarcel 386130803Smarcel ifneq ($$($1_PROGRAM),$(basename $$($1_PROGRAM))) 38798944Sobrien $$(error directory of PROGRAM should be specified using OUTPUT_DIR) 38898944Sobrien endif 38998944Sobrien 39098944Sobrien ifneq (,$(findstring $(EXE_SUFFIX),$$($1_PROGRAM))) 39198944Sobrien $$(error PROGRAM should be specified without EXE_SUFFIX: $(EXE_SUFFIX)) 39298944Sobrien endif 39398944Sobrien 39498944Sobrien ifeq ($$($1_SUFFIX), ) 395130803Smarcel $1_SUFFIX := $(EXE_SUFFIX) 396130803Smarcel endif 397130803Smarcel 398130803Smarcel $1_BASENAME:=$$($1_PROGRAM)$$($1_SUFFIX) 399130803Smarcel $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME) 400130803Smarcel $1_NOSUFFIX:=$$($1_PROGRAM) 401130803Smarcel endif 40298944Sobrien $1_SAFE_NAME := $$(strip $$(subst /,_, $1)) 40398944Sobrien 40498944Sobrien ifeq (,$$($1_TARGET)) 40598944Sobrien $$(error Neither PROGRAM, LIBRARY nor STATIC_LIBRARY has been specified for SetupNativeCompilation) 406130803Smarcel endif 40798944Sobrien 40898944Sobrien # Setup the toolchain to be used 40998944Sobrien $$(call SetIfEmpty, $1_TOOLCHAIN, TOOLCHAIN_DEFAULT) 410130803Smarcel $$(call SetIfEmpty, $1_CC, $$($$($1_TOOLCHAIN)_CC)) 41198944Sobrien $$(call SetIfEmpty, $1_CXX, $$($$($1_TOOLCHAIN)_CXX)) 41298944Sobrien $$(call SetIfEmpty, $1_LD, $$($$($1_TOOLCHAIN)_LD)) 41398944Sobrien $$(call SetIfEmpty, $1_AR, $$($$($1_TOOLCHAIN)_AR)) 414130803Smarcel $$(call SetIfEmpty, $1_AS, $$($$($1_TOOLCHAIN)_AS)) 41598944Sobrien $$(call SetIfEmpty, $1_MT, $$($$($1_TOOLCHAIN)_MT)) 41698944Sobrien $$(call SetIfEmpty, $1_RC, $$($$($1_TOOLCHAIN)_RC)) 41798944Sobrien $$(call SetIfEmpty, $1_STRIP, $$($$($1_TOOLCHAIN)_STRIP)) 418130803Smarcel $$(call SetIfEmpty, $1_SYSROOT_CFLAGS, $$($$($1_TOOLCHAIN)_SYSROOT_CFLAGS)) 41998944Sobrien $$(call SetIfEmpty, $1_SYSROOT_LDFLAGS, $$($$($1_TOOLCHAIN)_SYSROOT_LDFLAGS)) 42098944Sobrien 42198944Sobrien ifneq ($$($1_MANIFEST), ) 422130803Smarcel ifeq ($$($1_MANIFEST_VERSION), ) 42398944Sobrien $$(error If MANIFEST is provided, then MANIFEST_VERSION is required in $1) 42498944Sobrien endif 42598944Sobrien endif 426130803Smarcel 42798944Sobrien # Make sure the dirs exist. 42898944Sobrien $$(call MakeDir,$$($1_OBJECT_DIR) $$($1_OUTPUT_DIR)) 42998944Sobrien $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),, \ 430130803Smarcel $$(error SRC specified to SetupNativeCompilation $1 contains missing directory $$d))) 43198944Sobrien 43298944Sobrien # Find all files in the source trees. Sort to remove duplicates. 43398944Sobrien $1_ALL_SRCS := $$(sort $$(call CacheFind,$$($1_SRC))) 434130803Smarcel # Extract the C/C++ files. 43598944Sobrien $1_EXCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_EXCLUDE_FILES))) 43698944Sobrien $1_INCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES))) 43798944Sobrien ifneq ($$($1_EXCLUDE_FILES),) 438130803Smarcel $1_EXCLUDE_FILES:=$$(addprefix %,$$($1_EXCLUDE_FILES)) 43998944Sobrien endif 44098944Sobrien $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES),$$(filter $$(NATIVE_SOURCE_EXTENSIONS),$$($1_ALL_SRCS))) 44198944Sobrien ifneq (,$$(strip $$($1_INCLUDE_FILES))) 442130803Smarcel $1_SRCS := $$(filter $$($1_INCLUDE_FILES),$$($1_SRCS)) 44398944Sobrien endif 44498944Sobrien ifeq (,$$($1_SRCS)) 44598944Sobrien $$(error No sources found for $1 when looking inside the dirs $$($1_SRC)) 446130803Smarcel endif 44798944Sobrien # There can be only a single bin dir root, no need to foreach over the roots. 44898944Sobrien $1_BINS := $$(wildcard $$($1_OBJECT_DIR)/*$(OBJ_SUFFIX)) 44998944Sobrien # Now we have a list of all c/c++ files to compile: $$($1_SRCS) 45098944Sobrien # and we have a list of all existing object files: $$($1_BINS) 45198944Sobrien 45298944Sobrien # Prepend the source/bin path to the filter expressions. Then do the filtering. 45398944Sobrien ifneq ($$($1_INCLUDES),) 45498944Sobrien $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES)))) 45598944Sobrien $1_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS)) 45698944Sobrien endif 45798944Sobrien ifneq ($$($1_EXCLUDES),) 45898944Sobrien $1_SRC_EXCLUDES := $$(addsuffix /%,$$($1_EXCLUDES)) 45998944Sobrien $1_SRC_EXCLUDES += $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES)))) 46098944Sobrien $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS)) 46198944Sobrien endif 46298944Sobrien 463130803Smarcel $1_SRCS += $$($1_EXTRA_FILES) 46498944Sobrien 46598944Sobrien ifeq (,$$($1_SRCS)) 46698944Sobrien $$(error No sources found for $1 when looking inside the dirs $$($1_SRC)) 46798944Sobrien endif 468130803Smarcel 469130803Smarcel # Calculate the expected output from compiling the sources (sort to remove duplicates. Also provides 470130803Smarcel # a reproducable order on the input files to the linker). 471130803Smarcel $1_EXPECTED_OBJS_FILENAMES := $$(call replace_with_obj_extension, $$(notdir $$($1_SRCS))) 472130803Smarcel $1_EXPECTED_OBJS:=$$(sort $$(addprefix $$($1_OBJECT_DIR)/,$$($1_EXPECTED_OBJS_FILENAMES))) 473130803Smarcel # Are there too many object files on disk? Perhaps because some source file was removed? 474130803Smarcel $1_SUPERFLOUS_OBJS:=$$(sort $$(filter-out $$($1_EXPECTED_OBJS),$$($1_BINS))) 475130803Smarcel # Clean out the superfluous object files. 476130803Smarcel ifneq ($$($1_SUPERFLUOUS_OBJS),) 477130803Smarcel $$(shell $(RM) -f $$($1_SUPERFLUOUS_OBJS)) 478130803Smarcel endif 479130803Smarcel 480130803Smarcel # Pickup extra OPENJDK_TARGET_OS_TYPE and/or OPENJDK_TARGET_OS dependent variables for CFLAGS. 481130803Smarcel $1_EXTRA_CFLAGS:=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_CFLAGS_$(OPENJDK_TARGET_OS)) 482130803Smarcel ifneq ($(DEBUG_LEVEL),release) 483130803Smarcel # Pickup extra debug dependent variables for CFLAGS 484130803Smarcel $1_EXTRA_CFLAGS+=$$($1_CFLAGS_debug) 485130803Smarcel $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_TYPE)_debug) 486130803Smarcel $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS)_debug) 487130803Smarcel else 48898944Sobrien $1_EXTRA_CFLAGS+=$$($1_CFLAGS_release) 48998944Sobrien $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_TYPE)_release) 49098944Sobrien $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS)_release) 49198944Sobrien endif 49298944Sobrien 49398944Sobrien # Pickup extra OPENJDK_TARGET_OS_TYPE and/or OPENJDK_TARGET_OS dependent variables for CXXFLAGS. 49498944Sobrien $1_EXTRA_CXXFLAGS:=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)) 49598944Sobrien ifneq ($(DEBUG_LEVEL),release) 49698944Sobrien # Pickup extra debug dependent variables for CXXFLAGS 49798944Sobrien $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_debug) 49898944Sobrien $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_TYPE)_debug) 49998944Sobrien $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)_debug) 50098944Sobrien else 50198944Sobrien $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_release) 50298944Sobrien $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_TYPE)_release) 50398944Sobrien $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)_release) 50498944Sobrien endif 50598944Sobrien 50698944Sobrien # If no C++ flags are explicitly set, default to using the C flags. 50798944Sobrien # After that, we can set additional C++ flags that should not interfere 50898944Sobrien # with the mechanism for copying the C flags by default. 50998944Sobrien ifeq ($$($1_CXXFLAGS),) 51098944Sobrien $1_CXXFLAGS:=$$($1_CFLAGS) 51198944Sobrien endif 51298944Sobrien ifeq ($$(strip $$($1_EXTRA_CXXFLAGS)),) 51398944Sobrien $1_EXTRA_CXXFLAGS:=$$($1_EXTRA_CFLAGS) 51498944Sobrien endif 51598944Sobrien 51698944Sobrien ifeq ($$($1_DEBUG_SYMBOLS), true) 51798944Sobrien ifeq ($(ENABLE_DEBUG_SYMBOLS), true) 51898944Sobrien ifdef OPENJDK 51998944Sobrien # Always add debug symbols 52098944Sobrien $1_EXTRA_CFLAGS+=$(CFLAGS_DEBUG_SYMBOLS) 521130803Smarcel $1_EXTRA_CXXFLAGS+=$(CXXFLAGS_DEBUG_SYMBOLS) 522130803Smarcel else 52398944Sobrien # Programs don't get the debug symbols added in the old build. It's not clear if 524130803Smarcel # this is intentional. 525130803Smarcel ifeq ($$($1_PROGRAM),) 52698944Sobrien $1_EXTRA_CFLAGS+=$(CFLAGS_DEBUG_SYMBOLS) 52798944Sobrien $1_EXTRA_CXXFLAGS+=$(CXXFLAGS_DEBUG_SYMBOLS) 52898944Sobrien endif 52998944Sobrien endif 53098944Sobrien endif 53198944Sobrien endif 53298944Sobrien 533130803Smarcel ifneq (,$$($1_REORDER)) 534130803Smarcel $1_EXTRA_CFLAGS += $$(C_FLAG_REORDER) 53598944Sobrien $1_EXTRA_CXXFLAGS += $$(CXX_FLAG_REORDER) 53698944Sobrien endif 53798944Sobrien 53898944Sobrien # Pass the library name for static JNI library naming 53998944Sobrien ifneq ($$($1_STATIC_LIBRARY),) 54098944Sobrien $1_EXTRA_CFLAGS += -DLIBRARY_NAME=$$($1_STATIC_LIBRARY) 54198944Sobrien $1_EXTRA_CXXFLAGS += -DLIBRARY_NAME=$$($1_STATIC_LIBRARY) 54298944Sobrien endif 54398944Sobrien 54498944Sobrien # Pick up disabled warnings, if possible on this platform. 54598944Sobrien ifneq ($(DISABLE_WARNING_PREFIX),) 54698944Sobrien $1_EXTRA_CFLAGS += $$(addprefix $(DISABLE_WARNING_PREFIX), \ 54798944Sobrien $$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)) \ 54898944Sobrien $$($1_DISABLED_WARNINGS_C_$(TOOLCHAIN_TYPE))) 54998944Sobrien $1_EXTRA_CXXFLAGS += $$(addprefix $(DISABLE_WARNING_PREFIX), \ 55098944Sobrien $$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)) \ 55198944Sobrien $$($1_DISABLED_WARNINGS_CXX_$(TOOLCHAIN_TYPE))) 55298944Sobrien endif 55398944Sobrien 55498944Sobrien # Check if warnings should be considered errors. 55598944Sobrien # Pick first binary and toolchain specific, then binary specific, then general setting. 55698944Sobrien ifeq ($$($1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE)),) 55798944Sobrien ifeq ($$($1_WARNINGS_AS_ERRORS),) 55898944Sobrien $1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE) := $$(WARNINGS_AS_ERRORS) 55998944Sobrien else 56098944Sobrien $1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE) := $$($1_WARNINGS_AS_ERRORS) 56198944Sobrien endif 56298944Sobrien endif 56398944Sobrien 56498944Sobrien ifeq ($$($1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE)), true) 56598944Sobrien $1_EXTRA_CFLAGS += $(CFLAGS_WARNINGS_ARE_ERRORS) 56698944Sobrien $1_EXTRA_CXXFLAGS += $(CFLAGS_WARNINGS_ARE_ERRORS) 56798944Sobrien endif 56898944Sobrien 56998944Sobrien ifeq (NONE, $$($1_OPTIMIZATION)) 57098944Sobrien $1_EXTRA_CFLAGS += $(C_O_FLAG_NONE) 57198944Sobrien $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_NONE) 57298944Sobrien else ifeq (LOW, $$($1_OPTIMIZATION)) 57398944Sobrien $1_EXTRA_CFLAGS += $(C_O_FLAG_NORM) 57498944Sobrien $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_NORM) 57598944Sobrien else ifeq (HIGH, $$($1_OPTIMIZATION)) 57698944Sobrien $1_EXTRA_CFLAGS += $(C_O_FLAG_HI) 57798944Sobrien $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_HI) 57898944Sobrien else ifeq (HIGHEST, $$($1_OPTIMIZATION)) 57998944Sobrien $1_EXTRA_CFLAGS += $(C_O_FLAG_HIGHEST) 58098944Sobrien $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_HIGHEST) 58198944Sobrien else ifneq (, $$($1_OPTIMIZATION)) 58298944Sobrien $$(error Unknown value for OPTIMIZATION: $$($1_OPTIMIZATION)) 58398944Sobrien endif 58498944Sobrien 58598944Sobrien $1_BUILD_INFO := $$($1_OBJECT_DIR)/_build-info.marker 58698944Sobrien 58798944Sobrien # Track variable changes for all variables that affect the compilation command 58898944Sobrien # lines for all object files in this setup. This includes at least all the 58998944Sobrien # variables used in the call to add_native_source below. 59098944Sobrien $1_COMPILE_VARDEPS := $$($1_CFLAGS) $$($1_EXTRA_CFLAGS) $$($1_SYSROOT_CFLAGS) \ 59198944Sobrien $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS) \ 592130803Smarcel $$($1_CC) $$($1_CXX) $$($1_AS) $$($1_ASFLAGS) \ 593130803Smarcel $$(foreach s, $$($1_SRCS), \ 594130803Smarcel $$($1_$$(notdir $$s)_CFLAGS) $$($1_$$(notdir $$s)_CXXFLAGS)) 595130803Smarcel $1_COMPILE_VARDEPS_FILE := $$(call DependOnVariable, $1_COMPILE_VARDEPS, \ 596130803Smarcel $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).comp.vardeps) 597130803Smarcel 598130803Smarcel # Now call add_native_source for each source file we are going to compile. 599130803Smarcel $$(foreach p,$$($1_SRCS), \ 600130803Smarcel $$(eval $$(call add_native_source,$1,$$p,$$($1_OBJECT_DIR), \ 601130803Smarcel $$($1_CFLAGS) $$($1_EXTRA_CFLAGS) $$($1_SYSROOT_CFLAGS), \ 602130803Smarcel $$($1_CC), \ 603130803Smarcel $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS) $$($1_SYSROOT_CFLAGS), \ 604130803Smarcel $$($1_CXX), $$($1_ASFLAGS)))) 605130803Smarcel 606130803Smarcel # Setup rule for printing progress info when compiling source files. 607130803Smarcel # This is a rough heuristic and may not always print accurate information. 608130803Smarcel $$($1_BUILD_INFO): $$($1_SRCS) $$($1_COMPILE_VARDEPS_FILE) 609130803Smarcel ifeq ($$(wildcard $$($1_TARGET)),) 610130803Smarcel $(ECHO) 'Creating $$($1_BASENAME) from $$(words $$(filter-out %.vardeps, $$?)) file(s)' 611130803Smarcel else 612130803Smarcel $(ECHO) $$(strip 'Updating $$($1_BASENAME)' \ 613130803Smarcel $$(if $$(filter-out %.vardeps, $$?), \ 614130803Smarcel 'due to $$(words $$(filter-out %.vardeps, $$?)) file(s)', \ 615130803Smarcel $$(if $$(filter %.vardeps, $$?), 'due to makefile changes'))) 61698944Sobrien endif 61798944Sobrien $(TOUCH) $$@ 61898944Sobrien 61998944Sobrien # On windows we need to create a resource file 62098944Sobrien ifeq ($(OPENJDK_TARGET_OS), windows) 62198944Sobrien ifneq (,$$($1_VERSIONINFO_RESOURCE)) 62298944Sobrien $1_RES:=$$($1_OBJECT_DIR)/$$($1_BASENAME).res 62398944Sobrien $1_RES_DEP:=$$($1_RES).d 62498944Sobrien $1_RES_DEP_TARGETS:=$$($1_RES).d.targets 62598944Sobrien -include $$($1_RES_DEP) 62698944Sobrien -include $$($1_RES_DEP_TARGETS) 62798944Sobrien 62898944Sobrien $1_RES_VARDEPS := $$($1_RC) $$($1_RC_FLAGS) 62998944Sobrien $1_RES_VARDEPS_FILE := $$(call DependOnVariable, $1_RES_VARDEPS, \ 63098944Sobrien $$($1_RES).vardeps) 63198944Sobrien 63298944Sobrien $$($1_RES): $$($1_VERSIONINFO_RESOURCE) $$($1_RES_VARDEPS_FILE) 63398944Sobrien $(ECHO) $(LOG_INFO) "Compiling resource $$(notdir $$($1_VERSIONINFO_RESOURCE)) (for $$(notdir $$($1_TARGET)))" 63498944Sobrien $$($1_RC) $$($1_RC_FLAGS) $$($1_SYSROOT_CFLAGS) $(CC_OUT_OPTION)$$@ \ 63598944Sobrien $$($1_VERSIONINFO_RESOURCE) 63698944Sobrien # Windows RC compiler does not support -showIncludes, so we mis-use CL for this. 63798944Sobrien $$($1_CC) $$($1_RC_FLAGS) $$($1_SYSROOT_CFLAGS) -showIncludes -nologo -TC \ 63898944Sobrien $(CC_OUT_OPTION)$$($1_RES_DEP).obj $$($1_VERSIONINFO_RESOURCE) > $$($1_RES_DEP).raw 2>&1 || exit 0 63998944Sobrien ($(ECHO) $$($1_RES): \\ \ 64098944Sobrien && $(SED) $(WINDOWS_SHOWINCLUDE_SED_PATTERN) $$($1_RES_DEP).raw) > $$($1_RES_DEP) 64198944Sobrien $(SED) $(DEPENDENCY_TARGET_SED_PATTERN) $$($1_RES_DEP) > $$($1_RES_DEP_TARGETS) 64298944Sobrien endif 64398944Sobrien endif 64498944Sobrien 64598944Sobrien # mapfile doesnt seem to be implemented on macosx (yet??) 64698944Sobrien ifneq ($(OPENJDK_TARGET_OS),macosx) 64798944Sobrien ifneq ($(OPENJDK_TARGET_OS),windows) 64898944Sobrien $1_REAL_MAPFILE:=$$($1_MAPFILE) 64998944Sobrien ifneq (,$$($1_REORDER)) 65098944Sobrien $1_REAL_MAPFILE:=$$($1_OBJECT_DIR)/mapfile 65198944Sobrien 65298944Sobrien $$($1_REAL_MAPFILE) : $$($1_MAPFILE) $$($1_REORDER) 653130803Smarcel $$(MKDIR) -p $$(@D) 654130803Smarcel $$(CP) $$($1_MAPFILE) $$@.tmp 65598944Sobrien $$(SED) -e 's=OUTPUTDIR=$$($1_OBJECT_DIR)=' $$($1_REORDER) >> $$@.tmp 65698944Sobrien $$(MV) $$@.tmp $$@ 65798944Sobrien endif 65898944Sobrien endif 65998944Sobrien endif 66098944Sobrien 66198944Sobrien # Pickup extra OPENJDK_TARGET_OS_TYPE and/or OPENJDK_TARGET_OS dependent variables 66298944Sobrien # for LDFLAGS and LIBS 66398944Sobrien $1_EXTRA_LDFLAGS:=$$($1_LDFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS)) 66498944Sobrien $1_EXTRA_LIBS:=$$($1_LIBS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LIBS_$(OPENJDK_TARGET_OS)) 66598944Sobrien ifneq (,$$($1_REAL_MAPFILE)) 66698944Sobrien $1_EXTRA_LDFLAGS += $(call SET_SHARED_LIBRARY_MAPFILE,$$($1_REAL_MAPFILE)) 66798944Sobrien endif 66898944Sobrien 66998944Sobrien # Need to make sure TARGET is first on list 67098944Sobrien $1 := $$($1_TARGET) 67198944Sobrien ifeq ($$($1_STATIC_LIBRARY),) 67298944Sobrien ifeq ($$($1_DEBUG_SYMBOLS), true) 67398944Sobrien ifeq ($(ENABLE_DEBUG_SYMBOLS), true) 67498944Sobrien ifneq ($(OPENJDK_TARGET_OS), macosx) # no MacOS X support yet 67598944Sobrien ifneq ($$($1_OUTPUT_DIR),$$($1_OBJECT_DIR)) 67698944Sobrien # The dependency on TARGET is needed on windows for debuginfo files 67798944Sobrien # to be rebuilt properly. 67898944Sobrien $$($1_OUTPUT_DIR)/% : $$($1_OBJECT_DIR)/% $$($1_TARGET) 67998944Sobrien $(CP) $$< $$@ 68098944Sobrien endif 68198944Sobrien 68298944Sobrien # Generate debuginfo files. 68398944Sobrien ifeq ($(OPENJDK_TARGET_OS), windows) 68498944Sobrien $1_EXTRA_LDFLAGS += "-pdb:$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).pdb" \ 68598944Sobrien "-map:$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).map" 68698944Sobrien $1_DEBUGINFO_FILES := $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).pdb \ 687130803Smarcel $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).map 68898944Sobrien # No separate command is needed for debuginfo on windows, instead 68998944Sobrien # touch target to make sure it has a later time stamp than the debug 69098944Sobrien # symbol files to avoid unnecessary relinking on rebuild. 69198944Sobrien $1_CREATE_DEBUGINFO_CMDS := $(TOUCH) $$($1_TARGET) 69298944Sobrien 69398944Sobrien else ifneq ($(findstring $(OPENJDK_TARGET_OS), linux solaris), ) 69498944Sobrien $1_DEBUGINFO_FILES := $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).debuginfo 69598944Sobrien # Setup the command line creating debuginfo files, to be run after linking. 69698944Sobrien # It cannot be run separately since it updates the original target file 69798944Sobrien $1_CREATE_DEBUGINFO_CMDS := \ 69898944Sobrien $(OBJCOPY) --only-keep-debug $$($1_TARGET) $$($1_DEBUGINFO_FILES) $$(NEWLINE) \ 69998944Sobrien $(CD) $$($1_OUTPUT_DIR) && \ 70098944Sobrien $(OBJCOPY) --add-gnu-debuglink=$$($1_DEBUGINFO_FILES) $$($1_TARGET) 70198944Sobrien endif # No MacOS X support 70298944Sobrien 70398944Sobrien # This dependency dance ensures that debug info files get rebuilt 704130803Smarcel # properly if deleted. 70598944Sobrien $$($1_TARGET): $$($1_DEBUGINFO_FILES) 706130803Smarcel $$($1_DEBUGINFO_FILES): $$($1_EXPECTED_OBJS) 707130803Smarcel 708130803Smarcel ifeq ($(ZIP_DEBUGINFO_FILES), true) 70998944Sobrien $1_DEBUGINFO_ZIP := $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).diz 71098944Sobrien $1 += $$(subst $$($1_OBJECT_DIR),$$($1_OUTPUT_DIR),$$($1_DEBUGINFO_ZIP)) 71198944Sobrien 71298944Sobrien # The dependency on TARGET is needed for debuginfo files 71398944Sobrien # to be rebuilt properly. 71498944Sobrien $$($1_DEBUGINFO_ZIP): $$($1_DEBUGINFO_FILES) $$($1_TARGET) 71598944Sobrien $(CD) $$($1_OBJECT_DIR) \ 71698944Sobrien && $(ZIP) -q $$@ $$(notdir $$($1_DEBUGINFO_FILES)) 71798944Sobrien 71898944Sobrien else 71998944Sobrien $1 += $$(subst $$($1_OBJECT_DIR),$$($1_OUTPUT_DIR),$$($1_DEBUGINFO_FILES)) 72098944Sobrien endif 72198944Sobrien endif 72298944Sobrien endif # !MacOS X 72398944Sobrien endif # $1_DEBUG_SYMBOLS 72498944Sobrien endif # !STATIC_LIBRARY 72598944Sobrien 72698944Sobrien ifeq ($$($1_STRIP_SYMBOLS), true) 72798944Sobrien ifneq ($$($1_STRIP), ) 72898944Sobrien # Default to using the global STRIPFLAGS. Allow for overriding with an empty value 72998944Sobrien $1_STRIPFLAGS ?= $(STRIPFLAGS) 73098944Sobrien $1_STRIP_CMD := $$($1_STRIP) $$($1_STRIPFLAGS) $$($1_TARGET) 73198944Sobrien endif 73298944Sobrien endif 73398944Sobrien 73498944Sobrien ifneq (,$$($1_LIBRARY)) 73598944Sobrien # Generating a dynamic library. 73698944Sobrien $1_EXTRA_LDFLAGS += $$(call SET_SHARED_LIBRARY_NAME,$$($1_BASENAME)) 73798944Sobrien ifeq ($(OPENJDK_TARGET_OS), windows) 738130803Smarcel $1_EXTRA_LDFLAGS += "-implib:$$($1_OBJECT_DIR)/$$($1_LIBRARY).lib" 73998944Sobrien endif 74098944Sobrien 74198944Sobrien $1_EXTRA_LIBS += $(GLOBAL_LIBS) 74298944Sobrien 74398944Sobrien $1_VARDEPS := $$($1_LD) $$($1_SYSROOT_LDFLAGS) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) \ 74498944Sobrien $$($1_LIBS) $$($1_EXTRA_LIBS) $$($1_CREATE_DEBUGINFO_CMDS) \ 74598944Sobrien $$($1_STRIP_CMD) 74698944Sobrien $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \ 74798944Sobrien $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps) 74898944Sobrien 74998944Sobrien $$($1_TARGET): $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_REAL_MAPFILE) \ 75098944Sobrien $$($1_VARDEPS_FILE) 75198944Sobrien $(ECHO) $(LOG_INFO) "Linking $$($1_BASENAME)" ; \ 75298944Sobrien $(call LogFailures, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link.log, $$($1_SAFE_NAME)_link, \ 75398944Sobrien $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \ 75498944Sobrien $(LD_OUT_OPTION)$$@ \ 75598944Sobrien $$($1_EXPECTED_OBJS) $$($1_RES) \ 75698944Sobrien $$($1_LIBS) $$($1_EXTRA_LIBS)) ; \ 75798944Sobrien $$($1_CREATE_DEBUGINFO_CMDS) 75898944Sobrien $$($1_STRIP_CMD) 75998944Sobrien # Touch target to make sure it has a later time stamp than the debug 76098944Sobrien # symbol files to avoid unnecessary relinking on rebuild. 76198944Sobrien ifeq ($(OPENJDK_TARGET_OS), windows) 76298944Sobrien $(TOUCH) $$@ 76398944Sobrien endif 764130803Smarcel 765130803Smarcel endif 766130803Smarcel 767130803Smarcel ifneq (,$$($1_STATIC_LIBRARY)) 768130803Smarcel $1_VARDEPS := $$($1_AR) $$($1_ARFLAGS) $$($1_LIBS) \ 769130803Smarcel $$($1_EXTRA_LIBS) 770130803Smarcel $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \ 771130803Smarcel $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps) 772130803Smarcel 773130803Smarcel # Generating a static library, ie object file archive. 774130803Smarcel $$($1_TARGET): $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_VARDEPS_FILE) 775130803Smarcel $(ECHO) $(LOG_INFO) "Archiving $$($1_STATIC_LIBRARY)" 776130803Smarcel $(call LogFailures, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link.log, $$($1_SAFE_NAME)_link, \ 77798944Sobrien $$($1_AR) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_EXPECTED_OBJS) \ 77898944Sobrien $$($1_RES)) 77998944Sobrien ifeq ($(STATIC_BUILD), true) 78098944Sobrien $(GetSymbols) 78198944Sobrien endif 78298944Sobrien endif 78398944Sobrien 78498944Sobrien ifneq (,$$($1_PROGRAM)) 78598944Sobrien # A executable binary has been specified, setup the target for it. 78698944Sobrien $1_EXTRA_LIBS += $(GLOBAL_LIBS) 787130803Smarcel 788130803Smarcel $1_VARDEPS := $$($1_LD) $$($1_SYSROOT_LDFLAGS) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) \ 789130803Smarcel $$($1_LIBS) $$($1_EXTRA_LIBS) $$($1_MT) \ 79098944Sobrien $$($1_CODESIGN) $$($1_CREATE_DEBUGINFO_CMDS) $$($1_MANIFEST_VERSION) \ 79198944Sobrien $$($1_STRIP_CMD) 79298944Sobrien $1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \ 79398944Sobrien $$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps) 79498944Sobrien 79598944Sobrien $$($1_TARGET): $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_MANIFEST) \ 79698944Sobrien $$($1_VARDEPS_FILE) 79798944Sobrien $(ECHO) $(LOG_INFO) "Linking executable $$($1_BASENAME)" ; \ 79898944Sobrien $(call LogFailures, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link.log, $$($1_SAFE_NAME)_link, \ 79998944Sobrien $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $$($1_SYSROOT_LDFLAGS) \ 80098944Sobrien $(EXE_OUT_OPTION)$$($1_TARGET) \ 80198944Sobrien $$($1_EXPECTED_OBJS) $$($1_RES) \ 80298944Sobrien $$($1_LIBS) $$($1_EXTRA_LIBS)) 80398944Sobrien ifeq ($(OPENJDK_TARGET_OS), windows) 80498944Sobrien ifneq ($$($1_MANIFEST), ) 80598944Sobrien $$($1_MT) -nologo -manifest $$($1_MANIFEST) -identity:"$$($1_PROGRAM).exe, version=$$($1_MANIFEST_VERSION)" -outputresource:$$@;#1 806130803Smarcel endif 80798944Sobrien endif 80898944Sobrien # This only works if the openjdk_codesign identity is present on the system. Let 80998944Sobrien # silently fail otherwise. 81098944Sobrien ifneq (,$(CODESIGN)) 81198944Sobrien ifneq (,$$($1_CODESIGN)) 81298944Sobrien $(CODESIGN) -s openjdk_codesign $$@ 813130803Smarcel endif 814130803Smarcel endif 815130803Smarcel $$($1_CREATE_DEBUGINFO_CMDS) 816130803Smarcel $$($1_STRIP_CMD) 817130803Smarcel # Touch target to make sure it has a later time stamp than the debug 818130803Smarcel # symbol files to avoid unnecessary relinking on rebuild. 819130803Smarcel ifeq ($(OPENJDK_TARGET_OS), windows) 820130803Smarcel $(TOUCH) $$@ 821130803Smarcel endif 822130803Smarcel 823130803Smarcel endif 824130803Smarcelendef 825130803Smarcel 826130803Smarcelendif # _NATIVE_COMPILATION_GMK 827130803Smarcel