xref: /freebsd/crypto/libecc/common.mk (revision f0865ec9906d5a18fa2a3b61381f22ce16e606ad)
1*f0865ec9SKyle Evans# Detect mingw, since some versions throw a warning with the -fPIC option
2*f0865ec9SKyle Evans# (which would be caught as an error in our case with -Werror)
3*f0865ec9SKyle Evans# The ELF PIE related hardening flags are also non sense for Windows
4*f0865ec9SKyle EvansMINGW := $(shell $(CROSS_COMPILE)$(CC) -dumpmachine 2>&1 | grep -v mingw)
5*f0865ec9SKyle Evans# Detect Mac OS compilers: these usually don't like ELF pie related flags ...
6*f0865ec9SKyle EvansAPPLE := $(shell $(CROSS_COMPILE)$(CC) -dumpmachine 2>&1 | grep -v apple)
7*f0865ec9SKyle EvansSYS_ROOT :=
8*f0865ec9SKyle Evansifneq ($(MINGW),)
9*f0865ec9SKyle Evans  FPIC_CFLAG=-fPIC
10*f0865ec9SKyle Evans  ifneq ($(APPLE),)
11*f0865ec9SKyle Evans    FPIE_CFLAG=-fPIE
12*f0865ec9SKyle Evans    FPIE_LDFLAGS=-pie -Wl,-z,relro,-z,now
13*f0865ec9SKyle Evans  endif
14*f0865ec9SKyle Evansendif
15*f0865ec9SKyle Evans
16*f0865ec9SKyle Evansifeq ($(APPLE),)
17*f0865ec9SKyle Evans  SYS_ROOT_PATH := $(shell xcode-select --print-path)
18*f0865ec9SKyle Evans  ifneq ($(SYS_ROOT_PATH),)
19*f0865ec9SKyle Evans    SYS_ROOT_PATH := $(SYS_ROOT_PATH)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
20*f0865ec9SKyle Evans    SYS_ROOT := --sysroot=$(SYS_ROOT_PATH)
21*f0865ec9SKyle Evans    $(info Using MacOS SDK $(SYS_ROOT_PATH))
22*f0865ec9SKyle Evans  endif
23*f0865ec9SKyle Evansendif
24*f0865ec9SKyle Evans
25*f0865ec9SKyle Evans# NOTE: with mingw, FORTIFY_SOURCE=2 must be used
26*f0865ec9SKyle Evans# in conjuction with stack-protector as check functions
27*f0865ec9SKyle Evans# are implemented in libssp
28*f0865ec9SKyle EvansSTACK_PROT_FLAG=-fstack-protector-strong
29*f0865ec9SKyle EvansFORTIFY_FLAGS=-D_FORTIFY_SOURCE=2
30*f0865ec9SKyle Evans
31*f0865ec9SKyle Evans# The first goal here is to define a meaningful set of CFLAGS based on compiler,
32*f0865ec9SKyle Evans# debug mode, expected word size (16, 32, 64), etc. Those are then used to
33*f0865ec9SKyle Evans# define two differents kinds of CFLAGS we will use for building our library
34*f0865ec9SKyle Evans# (LIB_CFLAGS) and binaries (BIN_CFLAGS) objects.
35*f0865ec9SKyle Evans
36*f0865ec9SKyle Evans# Detect if we are using clang or gcc
37*f0865ec9SKyle EvansCLANG :=  $(shell $(CROSS_COMPILE)$(CC) -v 2>&1 | grep clang)
38*f0865ec9SKyle Evans
39*f0865ec9SKyle Evansifneq ($(CLANG),)
40*f0865ec9SKyle Evans  # get clang version e.g. 14.1.3
41*f0865ec9SKyle Evans  CLANG_VERSION := $(shell $(CROSS_COMPILE)$(CC) -dumpversion)
42*f0865ec9SKyle Evans  # convert to single number e.g. 14 * 100 + 1
43*f0865ec9SKyle Evans  CLANG_VERSION := $(shell echo $(CLANG_VERSION) | cut -f1-2 -d. | sed -e 's/\./*100+/g')
44*f0865ec9SKyle Evans  # Calculate value - e.g. 1401
45*f0865ec9SKyle Evans  CLANG_VERSION := $(shell echo $$(($(CLANG_VERSION))))
46*f0865ec9SKyle Evans  # Comparison results (true if true, empty if false)
47*f0865ec9SKyle Evans  CLANG_VERSION_GTE_12 := $(shell [ $(CLANG_VERSION) -ge 1200 ]  && echo true)
48*f0865ec9SKyle Evans  CLANG_VERSION_GTE_13 := $(shell [ $(CLANG_VERSION) -ge 1300 ]  && echo true)
49*f0865ec9SKyle Evans  CLANG_VERSION_GTE_16 := $(shell [ $(CLANG_VERSION) -ge 1600 ]  && echo true)
50*f0865ec9SKyle Evans  CLANG_VERSION_GTE_17 := $(shell [ $(CLANG_VERSION) -ge 1700 ]  && echo true)
51*f0865ec9SKyle Evansendif
52*f0865ec9SKyle Evans
53*f0865ec9SKyle Evans# Default warning flags
54*f0865ec9SKyle Evans# -Werror: treat warnings as errors
55*f0865ec9SKyle Evans#
56*f0865ec9SKyle Evans# Pedantic mode: enable more warnings
57*f0865ec9SKyle Evans# -Wshadow: warn the user if a variable declaration shadows one from a parent context
58*f0865ec9SKyle Evans# -Wdouble-promotion: warn about implicit conversion from float to double
59*f0865ec9SKyle Evans# -Wformat=2: warn about format string vulnerabilities
60*f0865ec9SKyle Evans# -fno-common: disallow global variables with same name and type
61*f0865ec9SKyle Evans# -Wconversion: warn about implicit conversion
62*f0865ec9SKyle Evans# -Wformat-security: warn about format string vulnerabilities
63*f0865ec9SKyle EvansWARNING_CFLAGS = -Werror
64*f0865ec9SKyle Evansifeq ($(PEDANTIC),1)
65*f0865ec9SKyle Evans  WARNING_CFLAGS += -Wshadow -Wdouble-promotion -Wformat=2 -fno-common -Wconversion -Wformat-security
66*f0865ec9SKyle Evansendif
67*f0865ec9SKyle Evans
68*f0865ec9SKyle Evans# Disable certain warnings:
69*f0865ec9SKyle Evans# -Wno-unused-parameter: commonly a false positive. Functions may be required to have a certain signature.
70*f0865ec9SKyle Evans# -Wno-declaration-after-statement: our C standard supports declaration after statements
71*f0865ec9SKyle EvansWARNING_CFLAGS += -Wno-unused-parameter -Wno-declaration-after-statement
72*f0865ec9SKyle Evans
73*f0865ec9SKyle Evans# When compiler is *explicitly* set to clang, use its -Weverything option by
74*f0865ec9SKyle Evans# default but disable the sepcific options we cannot support:
75*f0865ec9SKyle Evans#
76*f0865ec9SKyle Evans#   -Wno-reserved-id-macro: our header files use __XXX___ protection macros.
77*f0865ec9SKyle Evans#   -Wno-padded: padding warnings
78*f0865ec9SKyle Evans#   -Wno-packed: warning about packed structure we want to keep that way
79*f0865ec9SKyle Evans#   -Wno-covered-switch-default
80*f0865ec9SKyle Evans#   -Wno-used-but-marked-unused
81*f0865ec9SKyle Evans#
82*f0865ec9SKyle Evansifneq ($(CLANG),)
83*f0865ec9SKyle Evans  WARNING_CFLAGS += -Weverything \
84*f0865ec9SKyle Evans		 -Wno-reserved-id-macro -Wno-padded \
85*f0865ec9SKyle Evans		 -Wno-packed -Wno-covered-switch-default \
86*f0865ec9SKyle Evans		 -Wno-used-but-marked-unused -Wno-switch-enum
87*f0865ec9SKyle Evans  # Add warnings if we are in pedantic mode
88*f0865ec9SKyle Evans  ifeq ($(PEDANTIC),1)
89*f0865ec9SKyle Evans    WARNING_CFLAGS += -Walloca -Wcast-qual -Wnull-dereference -Wstack-protector -Wvla -Warray-bounds -Warray-bounds-pointer-arithmetic -Wassign-enum -Wbad-function-cast -Wconditional-uninitialized -Wfloat-equal -Wformat-type-confusion -Widiomatic-parentheses -Wimplicit-fallthrough -Wloop-analysis -Wpointer-arith -Wshift-sign-overflow -Wshorten-64-to-32 -Wtautological-constant-in-range-compare -Wunreachable-code-aggressive -Wthread-safety -Wthread-safety-beta -Wcomma
90*f0865ec9SKyle Evans  endif
91*f0865ec9SKyle Evans  ifeq ($(CLANG_VERSION_GTE_13), true)
92*f0865ec9SKyle Evans    # We have to do this because the '_' prefix seems now reserved to builtins
93*f0865ec9SKyle Evans    WARNING_CFLAGS += -Wno-reserved-identifier
94*f0865ec9SKyle Evans  endif
95*f0865ec9SKyle Evans  ifeq ($(CLANG_VERSION_GTE_16), true)
96*f0865ec9SKyle Evans    # NOTE: XXX: this is really a shame to remove this, but
97*f0865ec9SKyle Evans    # we have to wait until this is less sensitive and false positive
98*f0865ec9SKyle Evans    # prone to use it!
99*f0865ec9SKyle Evans    WARNING_CFLAGS += -Wno-unsafe-buffer-usage
100*f0865ec9SKyle Evans  endif
101*f0865ec9SKyle Evanselse
102*f0865ec9SKyle Evans  WARNING_CFLAGS += -W -Wextra -Wall -Wunreachable-code
103*f0865ec9SKyle Evans  # Add warnings if we are in pedantic mode
104*f0865ec9SKyle Evans  ifeq ($(PEDANTIC),1)
105*f0865ec9SKyle Evans    WARNING_CFLAGS += -Wpedantic -Wformat-overflow=2 -Wformat-truncation=2 -Wnull-dereference -Wstack-protector -Wtrampolines -Walloca -Wvla -Warray-bounds=2 -Wimplicit-fallthrough=3 -Wshift-overflow=2 -Wcast-qual -Wstringop-overflow=4 -Warith-conversion -Wlogical-op -Wduplicated-cond -Wduplicated-branches -Wformat-signedness -Wstrict-overflow=2 -Wundef -Wstrict-prototypes -Wswitch-default -Wcast-align=strict -Wjump-misses-init
106*f0865ec9SKyle Evans  endif
107*f0865ec9SKyle Evansendif
108*f0865ec9SKyle Evans
109*f0865ec9SKyle Evansifeq ($(WNOERROR), 1)
110*f0865ec9SKyle Evans  # Sometimes "-Werror" might be too much, this can be overriden
111*f0865ec9SKyle Evans  WARNING_CFLAGS := $(subst -Werror,,$(WARNING_CFLAGS))
112*f0865ec9SKyle Evansendif
113*f0865ec9SKyle Evans
114*f0865ec9SKyle Evans# If the user has overridden the CFLAGS or LDFLAGS, let's detect it
115*f0865ec9SKyle Evans# and adapt our compilation process
116*f0865ec9SKyle Evansifdef CFLAGS
117*f0865ec9SKyle EvansUSER_DEFINED_CFLAGS = $(CFLAGS)
118*f0865ec9SKyle Evansendif
119*f0865ec9SKyle Evansifdef LDFLAGS
120*f0865ec9SKyle EvansUSER_DEFINED_LDFLAGS = $(LDFLAGS)
121*f0865ec9SKyle Evansendif
122*f0865ec9SKyle Evans
123*f0865ec9SKyle EvansCFLAGS ?= $(WARNING_CFLAGS) $(SYS_ROOT) -pedantic -fno-builtin -std=c99 \
124*f0865ec9SKyle Evans	  $(FORTIFY_FLAGS) $(STACK_PROT_FLAG) -O3
125*f0865ec9SKyle EvansLDFLAGS ?=
126*f0865ec9SKyle Evans
127*f0865ec9SKyle Evans# Default AR and RANLIB if not overriden by user
128*f0865ec9SKyle EvansAR ?= ar
129*f0865ec9SKyle EvansRANLIB ?= ranlib
130*f0865ec9SKyle Evans# Default AR flags and RANLIB flags if not overriden by user
131*f0865ec9SKyle EvansAR_FLAGS ?= rcs
132*f0865ec9SKyle EvansRANLIB_FLAGS ?=
133*f0865ec9SKyle Evans
134*f0865ec9SKyle Evans# Our debug flags
135*f0865ec9SKyle EvansDEBUG_CFLAGS = -DDEBUG -O -g
136*f0865ec9SKyle Evans
137*f0865ec9SKyle Evansifeq ($(VERBOSE_INNER_VALUES),1)
138*f0865ec9SKyle EvansCFLAGS += -DVERBOSE_INNER_VALUES
139*f0865ec9SKyle Evansendif
140*f0865ec9SKyle Evans
141*f0865ec9SKyle Evans# Default all and clean target that will be expanded
142*f0865ec9SKyle Evans# later in the Makefile
143*f0865ec9SKyle Evansall:
144*f0865ec9SKyle Evansclean:
145*f0865ec9SKyle Evans
146*f0865ec9SKyle Evansdebug: CFLAGS += $(DEBUG_CFLAGS)
147*f0865ec9SKyle Evansdebug: clean all
148*f0865ec9SKyle Evans
149*f0865ec9SKyle Evans# Force 64-bit word size
150*f0865ec9SKyle Evans64: CFLAGS += -DWORDSIZE=64
151*f0865ec9SKyle Evans64: clean all
152*f0865ec9SKyle Evansdebug64: CFLAGS += -DWORDSIZE=64 $(DEBUG_CFLAGS)
153*f0865ec9SKyle Evansdebug64: clean all
154*f0865ec9SKyle Evans
155*f0865ec9SKyle Evans# Force 32-bit word size
156*f0865ec9SKyle Evans32: CFLAGS += -DWORDSIZE=32
157*f0865ec9SKyle Evans32: clean all
158*f0865ec9SKyle Evansdebug32: CFLAGS += -DWORDSIZE=32 $(DEBUG_CFLAGS)
159*f0865ec9SKyle Evansdebug32: clean all
160*f0865ec9SKyle Evans
161*f0865ec9SKyle Evans# Force 16-bit word size
162*f0865ec9SKyle Evans16: CFLAGS += -DWORDSIZE=16
163*f0865ec9SKyle Evans16: clean all
164*f0865ec9SKyle Evansdebug16: CFLAGS += -DWORDSIZE=16 $(DEBUG_CFLAGS)
165*f0865ec9SKyle Evansdebug16: clean all
166*f0865ec9SKyle Evans
167*f0865ec9SKyle Evans# Force to compile with 64-bit arch
168*f0865ec9SKyle Evansforce_arch64: CFLAGS += -m64
169*f0865ec9SKyle Evansforce_arch64: clean all
170*f0865ec9SKyle Evans
171*f0865ec9SKyle Evans# Force to compile with 32-bit arch
172*f0865ec9SKyle Evansforce_arch32: CFLAGS += -m32
173*f0865ec9SKyle Evansforce_arch32: clean all
174*f0865ec9SKyle Evans
175*f0865ec9SKyle Evans# By default, we use an stdlib
176*f0865ec9SKyle Evansifneq ($(LIBECC_NOSTDLIB),1)
177*f0865ec9SKyle EvansCFLAGS += -DWITH_STDLIB
178*f0865ec9SKyle Evansendif
179*f0865ec9SKyle Evans
180*f0865ec9SKyle Evans# Let's now define the two kinds of CFLAGS we will use for building our
181*f0865ec9SKyle Evans# library (LIB_CFLAGS) and binaries (BIN_CFLAGS) objects.
182*f0865ec9SKyle Evans# If the user has not overriden the CFLAGS, we add the usual gcc/clang
183*f0865ec9SKyle Evans# flags to produce binaries compatible with hardening technologies.
184*f0865ec9SKyle Evansifndef USER_DEFINED_CFLAGS
185*f0865ec9SKyle EvansBIN_CFLAGS  ?= $(CFLAGS) $(FPIE_CFLAG) -MMD -MP
186*f0865ec9SKyle EvansLIB_CFLAGS  ?= $(CFLAGS) $(FPIC_CFLAG) -MMD -MP -ffreestanding
187*f0865ec9SKyle Evanselse
188*f0865ec9SKyle EvansBIN_CFLAGS  ?= $(USER_DEFINED_CFLAGS)
189*f0865ec9SKyle EvansLIB_CFLAGS  ?= $(USER_DEFINED_CFLAGS)
190*f0865ec9SKyle Evansendif
191*f0865ec9SKyle Evansifndef USER_DEFINED_LDFLAGS
192*f0865ec9SKyle EvansBIN_LDFLAGS ?= $(LDFLAGS) $(FPIE_LDFLAGS)
193*f0865ec9SKyle Evanselse
194*f0865ec9SKyle EvansBIN_LDFLAGS ?= $(USER_DEFINED_LDFLAGS)
195*f0865ec9SKyle Evansendif
196*f0865ec9SKyle Evans
197*f0865ec9SKyle Evans# If the user wants to add extra flags to the existing flags,
198*f0865ec9SKyle Evans# check it and add them
199*f0865ec9SKyle Evansifdef EXTRA_LIB_CFLAGS
200*f0865ec9SKyle EvansLIB_CFLAGS += $(EXTRA_LIB_CFLAGS)
201*f0865ec9SKyle Evansendif
202*f0865ec9SKyle Evansifdef EXTRA_LIB_DYN_LDFLAGS
203*f0865ec9SKyle EvansLIB_DYN_LDFLAGS += $(EXTRA_LIB_DYN_LDFLAGS)
204*f0865ec9SKyle Evansendif
205*f0865ec9SKyle Evansifdef EXTRA_BIN_CFLAGS
206*f0865ec9SKyle EvansBIN_CFLAGS += $(EXTRA_BIN_CFLAGS)
207*f0865ec9SKyle Evansendif
208*f0865ec9SKyle Evansifdef EXTRA_BIN_LDFLAGS
209*f0865ec9SKyle EvansBIN_LDFLAGS += $(EXTRA_BIN_LDFLAGS)
210*f0865ec9SKyle Evansendif
211*f0865ec9SKyle Evansifdef EXTRA_CFLAGS
212*f0865ec9SKyle EvansCFLAGS += $(EXTRA_CFLAGS)
213*f0865ec9SKyle Evansendif
214*f0865ec9SKyle Evansifdef EXTRA_LDFLAGS
215*f0865ec9SKyle EvansLDFLAGS += $(EXTRA_LDFLAGS)
216*f0865ec9SKyle Evansendif
217*f0865ec9SKyle Evans
218*f0865ec9SKyle Evans# Add the include folder
219*f0865ec9SKyle EvansLIBECC_INCLUDE_FOLDER = include/
220*f0865ec9SKyle EvansLIB_CFLAGS += -I$(LIBECC_INCLUDE_FOLDER)
221*f0865ec9SKyle EvansBIN_CFLAGS += -I$(LIBECC_INCLUDE_FOLDER)
222*f0865ec9SKyle Evans
223*f0865ec9SKyle Evans# Static libraries to produce or link to
224*f0865ec9SKyle EvansLIBARITH = $(BUILD_DIR)/libarith.a
225*f0865ec9SKyle EvansLIBEC = $(BUILD_DIR)/libec.a
226*f0865ec9SKyle EvansLIBSIGN = $(BUILD_DIR)/libsign.a
227*f0865ec9SKyle Evans
228*f0865ec9SKyle Evans# Compile dynamic libraries if the user asked to
229*f0865ec9SKyle Evansifeq ($(WITH_DYNAMIC_LIBS),1)
230*f0865ec9SKyle Evans# Dynamic libraries to produce or link to
231*f0865ec9SKyle EvansLIBARITH_DYN = $(BUILD_DIR)/libarith.so
232*f0865ec9SKyle EvansLIBEC_DYN = $(BUILD_DIR)/libec.so
233*f0865ec9SKyle EvansLIBSIGN_DYN = $(BUILD_DIR)/libsign.so
234*f0865ec9SKyle Evans# The ld flags to generate shared librarie
235*f0865ec9SKyle Evansifeq ($(APPLE),)
236*f0865ec9SKyle EvansLIB_DYN_LDFLAGS ?= -shared -Wl,-undefined,dynamic_lookup
237*f0865ec9SKyle Evanselse
238*f0865ec9SKyle EvansLIB_DYN_LDFLAGS ?= -shared -Wl,-z,relro,-z,now
239*f0865ec9SKyle Evansendif
240*f0865ec9SKyle Evansendif
241*f0865ec9SKyle Evans
242*f0865ec9SKyle Evans# Do we want to use blinding to secure signature against some side channels?
243*f0865ec9SKyle Evansifeq ($(BLINDING),1)
244*f0865ec9SKyle EvansCFLAGS += -DUSE_SIG_BLINDING
245*f0865ec9SKyle Evansendif
246*f0865ec9SKyle Evans
247*f0865ec9SKyle Evans# Use complete formulas for point addition and doubling
248*f0865ec9SKyle Evans# NOTE: complete formulas are used as default since they are
249*f0865ec9SKyle Evans# more resilient against side channel attacks and they do not
250*f0865ec9SKyle Evans# have a major performance impact
251*f0865ec9SKyle Evansifeq ($(COMPLETE),0)
252*f0865ec9SKyle EvansCFLAGS += -DNO_USE_COMPLETE_FORMULAS
253*f0865ec9SKyle Evansendif
254*f0865ec9SKyle Evans
255*f0865ec9SKyle Evans# Force Double and Add always usage
256*f0865ec9SKyle Evansifeq ($(ADALWAYS), 1)
257*f0865ec9SKyle EvansCFLAGS += -DUSE_DOUBLE_ADD_ALWAYS
258*f0865ec9SKyle Evansendif
259*f0865ec9SKyle Evansifeq ($(ADALWAYS), 0)
260*f0865ec9SKyle EvansCFLAGS += -DUSE_MONTY_LADDER
261*f0865ec9SKyle Evansendif
262*f0865ec9SKyle Evans
263*f0865ec9SKyle Evans# Force Montgomery Ladder always usage
264*f0865ec9SKyle Evansifeq ($(LADDER), 1)
265*f0865ec9SKyle EvansCFLAGS += -DUSE_MONTY_LADDER
266*f0865ec9SKyle Evansendif
267*f0865ec9SKyle Evansifeq ($(LADDER), 0)
268*f0865ec9SKyle EvansCFLAGS += -DUSE_DOUBLE_ADD_ALWAYS
269*f0865ec9SKyle Evansendif
270*f0865ec9SKyle Evans
271*f0865ec9SKyle Evans# Force small stack usage
272*f0865ec9SKyle Evansifeq ($(SMALLSTACK), 1)
273*f0865ec9SKyle EvansCFLAGS += -DUSE_SMALL_STACK
274*f0865ec9SKyle Evansendif
275*f0865ec9SKyle Evans
276*f0865ec9SKyle Evans# Are we sure we will not execute known
277*f0865ec9SKyle Evans# vectors self tests?
278*f0865ec9SKyle Evansifeq ($(NOKNOWNTESTS), 1)
279*f0865ec9SKyle EvansCFLAGS += -DNO_KNOWN_VECTORS
280*f0865ec9SKyle Evansendif
281*f0865ec9SKyle Evans
282*f0865ec9SKyle Evans# Specific version for fuzzing with Cryptofuzz
283*f0865ec9SKyle Evans# Allow raw signature and verification APIs
284*f0865ec9SKyle Evans# which is DANGEROUS. Do not activate in production
285*f0865ec9SKyle Evans# mode!
286*f0865ec9SKyle Evansifeq ($(CRYPTOFUZZ), 1)
287*f0865ec9SKyle EvansCFLAGS += -DUSE_CRYPTOFUZZ
288*f0865ec9SKyle Evansendif
289*f0865ec9SKyle Evans
290*f0865ec9SKyle Evansifeq ($(ASSERT_PRINT), 1)
291*f0865ec9SKyle EvansCFLAGS += -DUSE_ASSERT_PRINT
292*f0865ec9SKyle Evansendif
293*f0865ec9SKyle Evans
294*f0865ec9SKyle Evans# By default, we want to catch all unused functions return values by
295*f0865ec9SKyle Evans# triggering a warning. We deactivate this is we are asked to by the user.
296*f0865ec9SKyle Evansifneq ($(NO_WARN_UNUSED_RET), 1)
297*f0865ec9SKyle EvansCFLAGS += -DUSE_WARN_UNUSED_RET
298*f0865ec9SKyle Evansendif
299*f0865ec9SKyle Evans
300*f0865ec9SKyle Evans# Do we want to use clang or gcc sanitizers?
301*f0865ec9SKyle Evansifeq ($(USE_SANITIZERS),1)
302*f0865ec9SKyle EvansCFLAGS += -fsanitize=undefined -fsanitize=address -fsanitize=leak
303*f0865ec9SKyle Evans  ifneq ($(CLANG),)
304*f0865ec9SKyle Evans    # Clang version < 12 do not support unsigned-shift-base
305*f0865ec9SKyle Evans    ifeq ($(CLANG_VERSION_GTE_12), true)
306*f0865ec9SKyle Evans      CFLAGS += -fsanitize=integer -fno-sanitize=unsigned-integer-overflow -fno-sanitize=unsigned-shift-base
307*f0865ec9SKyle Evans    endif
308*f0865ec9SKyle Evans  endif
309*f0865ec9SKyle Evansendif
310*f0865ec9SKyle Evans
311*f0865ec9SKyle Evans# Do we want to use the ISO14888-3 version of the
312*f0865ec9SKyle Evans# ECRDSA algorithm with discrepancies from the Russian
313*f0865ec9SKyle Evans# RFC references?
314*f0865ec9SKyle Evansifeq ($(USE_ISO14888_3_ECRDSA),1)
315*f0865ec9SKyle EvansCFLAGS += -DUSE_ISO14888_3_ECRDSA
316*f0865ec9SKyle Evansendif
317*f0865ec9SKyle Evans
318*f0865ec9SKyle Evans# Do we have a C++ compiler instead of a C compiler?
319*f0865ec9SKyle EvansGPP := $(shell $(CROSS_COMPILE)$(CC) -v 2>&1 | grep g++)
320*f0865ec9SKyle EvansCLANGPP := $(shell echo $(CROSS_COMPILE)$(CC) | grep clang++)
321*f0865ec9SKyle Evans
322*f0865ec9SKyle Evans# g++ case
323*f0865ec9SKyle Evansifneq ($(GPP),)
324*f0865ec9SKyle EvansCFLAGS := $(patsubst -std=c99, -std=c++2a, $(CFLAGS))
325*f0865ec9SKyle EvansCFLAGS += -Wno-deprecated
326*f0865ec9SKyle Evans# Remove C++ unused pedantic flags
327*f0865ec9SKyle EvansCFLAGS := $(patsubst -Wstrict-prototypes,,$(CFLAGS))
328*f0865ec9SKyle EvansCFLAGS := $(patsubst -Wjump-misses-init,,$(CFLAGS))
329*f0865ec9SKyle EvansCFLAGS := $(patsubst -Wduplicated-branches,,$(CFLAGS))
330*f0865ec9SKyle EvansCFLAGS := $(patsubst -Wno-declaration-after-statement,,$(CFLAGS))
331*f0865ec9SKyle Evansendif
332*f0865ec9SKyle Evans# clang++ case
333*f0865ec9SKyle Evansifneq ($(CLANGPP),)
334*f0865ec9SKyle EvansCFLAGS := $(patsubst -std=c99, -std=c++2a, $(CFLAGS))
335*f0865ec9SKyle EvansCFLAGS += -Wno-deprecated -Wno-c++98-c++11-c++14-c++17-compat-pedantic -Wno-old-style-cast -Wno-zero-as-null-pointer-constant -Wno-c++98-compat-pedantic
336*f0865ec9SKyle Evansendif
337*f0865ec9SKyle Evans
338*f0865ec9SKyle Evans# Makefile verbosity
339*f0865ec9SKyle Evansifeq ($(VERBOSE),1)
340*f0865ec9SKyle EvansVERBOSE_MAKE=
341*f0865ec9SKyle Evanselse
342*f0865ec9SKyle EvansVERBOSE_MAKE=@
343*f0865ec9SKyle Evansendif
344*f0865ec9SKyle Evans
345*f0865ec9SKyle Evans# Self tests parallelization
346*f0865ec9SKyle Evansifeq ($(OPENMP_SELF_TESTS),1)
347*f0865ec9SKyle EvansCFLAGS  += -DWITH_OPENMP_SELF_TESTS -fopenmp
348*f0865ec9SKyle EvansLDFLAGS += -fopenmp
349*f0865ec9SKyle Evansendif
350