jdk-24/make/common/native/ToolchainDefinitions.gmk
Magnus Ihse Bursie 0d51b76947 8325877: Split up NativeCompilation.gmk
Reviewed-by: erikj, jwaters
2024-02-15 10:38:30 +00:00

126 lines
5.0 KiB
Plaintext

#
# Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
################################################################################
# This file contains functionality related to setting up our toolchain
# definition variables.
################################################################################
# Define a native toolchain configuration that can be used by
# SetupNativeCompilation calls
#
# Parameter 1 is the name of the toolchain definition
#
# Remaining parameters are named arguments:
# EXTENDS - Optional parent definition to get defaults from
# CC - The C compiler
# CXX - The C++ compiler
# LD - The Linker
# AR - Static linker
# AS - Assembler
# MT - Windows MT tool
# RC - Windows RC tool
# OBJCOPY - The objcopy tool for debug symbol handling
# STRIP - The tool to use for stripping debug symbols
# SYSROOT_CFLAGS - Compiler flags for using the specific sysroot
# SYSROOT_LDFLAGS - Linker flags for using the specific sysroot
DefineNativeToolchain = $(NamedParamsMacroTemplate)
define DefineNativeToolchainBody
# If extending another definition, get default values from that,
# otherwise, nothing more needs to be done as variable assignments
# already happened in NamedParamsMacroTemplate.
ifneq ($$($1_EXTENDS), )
$$(call SetIfEmpty, $1_CC, $$($$($1_EXTENDS)_CC))
$$(call SetIfEmpty, $1_CXX, $$($$($1_EXTENDS)_CXX))
$$(call SetIfEmpty, $1_LD, $$($$($1_EXTENDS)_LD))
$$(call SetIfEmpty, $1_AR, $$($$($1_EXTENDS)_AR))
$$(call SetIfEmpty, $1_AS, $$($$($1_EXTENDS)_AS))
$$(call SetIfEmpty, $1_MT, $$($$($1_EXTENDS)_MT))
$$(call SetIfEmpty, $1_RC, $$($$($1_EXTENDS)_RC))
$$(call SetIfEmpty, $1_OBJCOPY, $$($$($1_EXTENDS)_OBJCOPY))
$$(call SetIfEmpty, $1_STRIP, $$($$($1_EXTENDS)_STRIP))
$$(call SetIfEmpty, $1_SYSROOT_CFLAGS, $$($$($1_EXTENDS)_SYSROOT_CFLAGS))
$$(call SetIfEmpty, $1_SYSROOT_LDFLAGS, $$($$($1_EXTENDS)_SYSROOT_LDFLAGS))
endif
endef
# Create a default toolchain with the main compiler and linker
$(eval $(call DefineNativeToolchain, TOOLCHAIN_DEFAULT, \
CC := $(CC), \
CXX := $(CXX), \
LD := $(LD), \
AR := $(AR), \
AS := $(AS), \
MT := $(MT), \
RC := $(RC), \
OBJCOPY := $(OBJCOPY), \
STRIP := $(STRIP), \
SYSROOT_CFLAGS := $(SYSROOT_CFLAGS), \
SYSROOT_LDFLAGS := $(SYSROOT_LDFLAGS), \
))
# Create a toolchain where linking is done with the C++ linker
$(eval $(call DefineNativeToolchain, TOOLCHAIN_LINK_CXX, \
EXTENDS := TOOLCHAIN_DEFAULT, \
LD := $(LDCXX), \
))
# Create a toolchain with the BUILD compiler, used for build tools that
# are to be run during the build.
$(eval $(call DefineNativeToolchain, TOOLCHAIN_BUILD, \
CC := $(BUILD_CC), \
CXX := $(BUILD_CXX), \
LD := $(BUILD_LD), \
AR := $(BUILD_AR), \
AS := $(BUILD_AS), \
OBJCOPY := $(BUILD_OBJCOPY), \
STRIP := $(BUILD_STRIP), \
SYSROOT_CFLAGS := $(BUILD_SYSROOT_CFLAGS), \
SYSROOT_LDFLAGS := $(BUILD_SYSROOT_LDFLAGS), \
))
# BUILD toolchain with the C++ linker
$(eval $(call DefineNativeToolchain, TOOLCHAIN_BUILD_LINK_CXX, \
EXTENDS := TOOLCHAIN_BUILD, \
LD := $(BUILD_LDCXX), \
))
################################################################################
# Setup the toolchain to be used
define SetupToolchain
$$(call SetIfEmpty, $1_TOOLCHAIN, TOOLCHAIN_DEFAULT)
$$(call SetIfEmpty, $1_CC, $$($$($1_TOOLCHAIN)_CC))
$$(call SetIfEmpty, $1_CXX, $$($$($1_TOOLCHAIN)_CXX))
$$(call SetIfEmpty, $1_LD, $$($$($1_TOOLCHAIN)_LD))
$$(call SetIfEmpty, $1_AR, $$($$($1_TOOLCHAIN)_AR))
$$(call SetIfEmpty, $1_AS, $$($$($1_TOOLCHAIN)_AS))
$$(call SetIfEmpty, $1_MT, $$($$($1_TOOLCHAIN)_MT))
$$(call SetIfEmpty, $1_RC, $$($$($1_TOOLCHAIN)_RC))
$$(call SetIfEmpty, $1_OBJCOPY, $$($$($1_TOOLCHAIN)_OBJCOPY))
$$(call SetIfEmpty, $1_STRIP, $$($$($1_TOOLCHAIN)_STRIP))
$$(call SetIfEmpty, $1_SYSROOT_CFLAGS, $$($$($1_TOOLCHAIN)_SYSROOT_CFLAGS))
$$(call SetIfEmpty, $1_SYSROOT_LDFLAGS, $$($$($1_TOOLCHAIN)_SYSROOT_LDFLAGS))
endef