2
# Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
# This code is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License version 2 only, as
7
# published by the Free Software Foundation. Oracle designates this
8
# particular file as subject to the "Classpath" exception as provided
9
# by Oracle in the LICENSE file that accompanied this code.
11
# This code is distributed in the hope that it will be useful, but WITHOUT
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
# version 2 for more details (a copy is included in the LICENSE file that
15
# accompanied this code).
17
# You should have received a copy of the GNU General Public License version
18
# 2 along with this work; if not, write to the Free Software Foundation,
19
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
# or visit www.oracle.com if you need additional information or have any
26
################################################################################
27
# This file contains functionality related to setting up compiler and linker
28
# flags, based on various more abstract sources of compilation description,
29
# like optimization level.
31
################################################################################
32
# $1 is the prefix of the file to be compiled
33
# $2 is the prefix of the library, i.e. $$($1_BASE)
34
define SetupCompileFileFlags
35
ifeq ($$($1_OPTIMIZATION), )
36
$1_OPT_CFLAGS := $$($2_OPT_CFLAGS)
37
$1_OPT_CXXFLAGS := $$($2_OPT_CXXFLAGS)
39
ifeq ($$($1_OPTIMIZATION), NONE)
40
$1_OPT_CFLAGS := $(C_O_FLAG_NONE)
41
$1_OPT_CXXFLAGS := $(CXX_O_FLAG_NONE)
42
else ifeq ($$($1_OPTIMIZATION), LOW)
43
$1_OPT_CFLAGS := $(C_O_FLAG_NORM)
44
$1_OPT_CXXFLAGS := $(CXX_O_FLAG_NORM)
45
else ifeq ($$($1_OPTIMIZATION), HIGH)
46
$1_OPT_CFLAGS := $(C_O_FLAG_HI)
47
$1_OPT_CXXFLAGS := $(CXX_O_FLAG_HI)
48
else ifeq ($$($1_OPTIMIZATION), HIGHEST)
49
$1_OPT_CFLAGS := $(C_O_FLAG_HIGHEST)
50
$1_OPT_CXXFLAGS := $(CXX_O_FLAG_HIGHEST)
51
else ifeq ($$($1_OPTIMIZATION), HIGHEST_JVM)
52
$1_OPT_CFLAGS := $(C_O_FLAG_HIGHEST_JVM)
53
$1_OPT_CXXFLAGS := $(CXX_O_FLAG_HIGHEST_JVM)
54
else ifeq ($$($1_OPTIMIZATION), SIZE)
55
$1_OPT_CFLAGS := $(C_O_FLAG_SIZE)
56
$1_OPT_CXXFLAGS := $(CXX_O_FLAG_SIZE)
58
$$(error Unknown value for file OPTIMIZATION: $$($1_OPTIMIZATION))
62
ifneq ($$($2_PRECOMPILED_HEADER), )
63
ifeq ($$(filter $$($1_FILENAME), $$($2_PRECOMPILED_HEADER_EXCLUDE)), )
64
$1_USE_PCH_FLAGS := $$($2_USE_PCH_FLAGS)
68
ifneq ($(DISABLE_WARNING_PREFIX), )
69
$1_WARNINGS_FLAGS := $$(addprefix $(DISABLE_WARNING_PREFIX), \
70
$$($2_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)_$$($1_FILENAME)) \
71
$$($2_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)_$(OPENJDK_TARGET_OS)_$$($1_FILENAME)))
74
$1_BASE_CFLAGS := $$($2_CFLAGS) $$($2_EXTRA_CFLAGS) \
76
$1_BASE_CXXFLAGS := $$($2_CXXFLAGS) $$($2_EXTRA_CXXFLAGS) \
77
$$($2_SYSROOT_CFLAGS) $$($1_EXTRA_CXXFLAGS)
78
$1_BASE_ASFLAGS := $$($2_ASFLAGS) $$($2_EXTRA_ASFLAGS)
81
################################################################################
82
define SetupCompilerFlags
83
# Pickup extra OPENJDK_TARGET_OS_TYPE, OPENJDK_TARGET_OS, TOOLCHAIN_TYPE and
84
# OPENJDK_TARGET_OS plus OPENJDK_TARGET_CPU pair dependent variables for CFLAGS.
85
$1_EXTRA_CFLAGS := $$($1_CFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_CFLAGS_$(OPENJDK_TARGET_OS)) \
86
$$($1_CFLAGS_$(TOOLCHAIN_TYPE)) \
87
$$($1_CFLAGS_$(OPENJDK_TARGET_OS)_$(OPENJDK_TARGET_CPU))
89
ifneq ($(DEBUG_LEVEL), release)
90
# Pickup extra debug dependent variables for CFLAGS
91
$1_EXTRA_CFLAGS += $$($1_CFLAGS_debug)
92
$1_EXTRA_CFLAGS += $$($1_CFLAGS_$(OPENJDK_TARGET_OS_TYPE)_debug)
93
$1_EXTRA_CFLAGS += $$($1_CFLAGS_$(OPENJDK_TARGET_OS)_debug)
94
$1_EXTRA_CFLAGS += $$($1_CFLAGS_$(OPENJDK_TARGET_OS)_$(OPENJDK_TARGET_CPU)_debug)
96
$1_EXTRA_CFLAGS += $$($1_CFLAGS_release)
97
$1_EXTRA_CFLAGS += $$($1_CFLAGS_$(OPENJDK_TARGET_OS_TYPE)_release)
98
$1_EXTRA_CFLAGS += $$($1_CFLAGS_$(OPENJDK_TARGET_OS)_release)
99
$1_EXTRA_CFLAGS += $$($1_CFLAGS_$(OPENJDK_TARGET_OS)_$(OPENJDK_TARGET_CPU)_release)
101
ifeq ($(STATIC_LIBS), true)
102
$1_EXTRA_CFLAGS += $$(STATIC_LIBS_CFLAGS)
105
# Pickup extra OPENJDK_TARGET_OS_TYPE, OPENJDK_TARGET_OS and/or TOOLCHAIN_TYPE
106
# dependent variables for CXXFLAGS.
107
$1_EXTRA_CXXFLAGS := $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)) \
108
$$($1_CXXFLAGS_$(TOOLCHAIN_TYPE))
110
ifneq ($(DEBUG_LEVEL), release)
111
# Pickup extra debug dependent variables for CXXFLAGS
112
$1_EXTRA_CXXFLAGS += $$($1_CXXFLAGS_debug)
113
$1_EXTRA_CXXFLAGS += $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_TYPE)_debug)
114
$1_EXTRA_CXXFLAGS += $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)_debug)
116
$1_EXTRA_CXXFLAGS += $$($1_CXXFLAGS_release)
117
$1_EXTRA_CXXFLAGS += $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_TYPE)_release)
118
$1_EXTRA_CXXFLAGS += $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)_release)
120
ifeq ($(STATIC_LIBS), true)
121
$1_EXTRA_CXXFLAGS += $$(STATIC_LIB_CFLAGS)
124
# If no C++ flags are explicitly set, default to using the C flags.
125
# After that, we can set additional C++ flags that should not interfere
126
# with the mechanism for copying the C flags by default.
127
ifeq ($$($1_CXXFLAGS), )
128
$1_CXXFLAGS := $$($1_CFLAGS)
130
ifeq ($$(strip $$($1_EXTRA_CXXFLAGS)), )
131
$1_EXTRA_CXXFLAGS := $$($1_EXTRA_CFLAGS)
134
$$(call SetIfEmpty, $1_COMPILE_WITH_DEBUG_SYMBOLS, $$(COMPILE_WITH_DEBUG_SYMBOLS))
136
ifeq ($(STATIC_LIBS), true)
137
# For release builds where debug symbols are configured to be moved to
138
# separate debuginfo files, disable debug symbols for static libs instead.
139
# We don't currently support this configuration and we don't want symbol
140
# information in release builds unless explicitly asked to provide it.
141
ifeq ($(DEBUG_LEVEL), release)
142
ifeq ($(COPY_DEBUG_SYMBOLS), true)
143
$1_COMPILE_WITH_DEBUG_SYMBOLS := false
148
ifeq ($$($1_COMPILE_WITH_DEBUG_SYMBOLS), true)
149
$1_EXTRA_CFLAGS += $$(CFLAGS_DEBUG_SYMBOLS)
150
$1_EXTRA_CXXFLAGS += $$(CFLAGS_DEBUG_SYMBOLS)
151
$1_EXTRA_ASFLAGS += $$(ASFLAGS_DEBUG_SYMBOLS)
154
# Pass the library name for static JNI library naming
155
ifeq ($$($1_TYPE), STATIC_LIBRARY)
156
$1_EXTRA_CFLAGS += -DLIBRARY_NAME=$$($1_NAME)
157
$1_EXTRA_CXXFLAGS += -DLIBRARY_NAME=$$($1_NAME)
160
# Pick up disabled warnings, if possible on this platform.
161
ifneq ($(DISABLE_WARNING_PREFIX), )
162
$1_EXTRA_CFLAGS += $$(addprefix $(DISABLE_WARNING_PREFIX), \
163
$$(DISABLED_WARNINGS) \
164
$$(DISABLED_WARNINGS_C) \
165
$$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)) \
166
$$($1_DISABLED_WARNINGS_C_$(TOOLCHAIN_TYPE)) \
167
$$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)_$(OPENJDK_TARGET_OS)) \
168
$$($1_DISABLED_WARNINGS_C_$(TOOLCHAIN_TYPE)_$(OPENJDK_TARGET_OS)))
169
$1_EXTRA_CXXFLAGS += $$(addprefix $(DISABLE_WARNING_PREFIX), \
170
$$(DISABLED_WARNINGS) \
171
$$(DISABLED_WARNINGS_CXX) \
172
$$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)) \
173
$$($1_DISABLED_WARNINGS_CXX_$(TOOLCHAIN_TYPE)) \
174
$$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)_$(OPENJDK_TARGET_OS)) \
175
$$($1_DISABLED_WARNINGS_CXX_$(TOOLCHAIN_TYPE)_$(OPENJDK_TARGET_OS)))
178
# Check if warnings should be considered errors.
179
# Pick first binary and toolchain specific, then binary specific, then general setting.
180
ifeq ($$($1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE)), )
181
ifeq ($$($1_WARNINGS_AS_ERRORS), )
182
$1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE) := $$(WARNINGS_AS_ERRORS)
184
$1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE) := $$($1_WARNINGS_AS_ERRORS)
188
ifeq ($$($1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE)), true)
189
$1_EXTRA_CFLAGS += $(CFLAGS_WARNINGS_ARE_ERRORS)
190
$1_EXTRA_CXXFLAGS += $(CFLAGS_WARNINGS_ARE_ERRORS)
193
ifeq (NONE, $$($1_OPTIMIZATION))
194
$1_OPT_CFLAGS := $(C_O_FLAG_NONE)
195
$1_OPT_CXXFLAGS := $(CXX_O_FLAG_NONE)
196
else ifeq (LOW, $$($1_OPTIMIZATION))
197
$1_OPT_CFLAGS := $(C_O_FLAG_NORM)
198
$1_OPT_CXXFLAGS := $(CXX_O_FLAG_NORM)
199
else ifeq (HIGH, $$($1_OPTIMIZATION))
200
$1_OPT_CFLAGS := $(C_O_FLAG_HI)
201
$1_OPT_CXXFLAGS := $(CXX_O_FLAG_HI)
202
else ifeq (HIGHEST, $$($1_OPTIMIZATION))
203
$1_OPT_CFLAGS := $(C_O_FLAG_HIGHEST)
204
$1_OPT_CXXFLAGS := $(CXX_O_FLAG_HIGHEST)
205
else ifeq (HIGHEST_JVM, $$($1_OPTIMIZATION))
206
$1_OPT_CFLAGS := $(C_O_FLAG_HIGHEST_JVM)
207
$1_OPT_CXXFLAGS := $(CXX_O_FLAG_HIGHEST_JVM)
208
else ifeq (SIZE, $$($1_OPTIMIZATION))
209
$1_OPT_CFLAGS := $(C_O_FLAG_SIZE)
210
$1_OPT_CXXFLAGS := $(CXX_O_FLAG_SIZE)
211
else ifneq (, $$($1_OPTIMIZATION))
212
$$(error Unknown value for OPTIMIZATION: $$($1_OPTIMIZATION))
216
################################################################################
217
define SetupLinkerFlags
218
# Pickup extra OPENJDK_TARGET_OS_TYPE, OPENJDK_TARGET_OS and TOOLCHAIN_TYPE
219
# dependent variables for LDFLAGS and LIBS, and additionally the pair dependent
220
# TOOLCHAIN_TYPE plus OPENJDK_TARGET_OS
221
$1_EXTRA_LDFLAGS += $$($1_LDFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS)) \
222
$$($1_LDFLAGS_$(TOOLCHAIN_TYPE)) $$($1_LDFLAGS_$(TOOLCHAIN_TYPE)_$(OPENJDK_TARGET_OS))
223
$1_EXTRA_LIBS += $$($1_LIBS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LIBS_$(OPENJDK_TARGET_OS)) \
224
$$($1_LIBS_$(TOOLCHAIN_TYPE)) $$($1_LIBS_$(TOOLCHAIN_TYPE)_$(OPENJDK_TARGET_OS))