blob: 077ac6f3105a65886f88ebd67d8eee5c51ffb718 [file] [log] [blame]
Gilles Peskinef3d1ae12023-12-22 11:40:58 +01001# To compile on SunOS: add "-lsocket -lnsl" to LDFLAGS
2
Paul Elliott7ed1cf52024-01-05 18:10:44 +00003ifndef MBEDTLS_PATH
4MBEDTLS_PATH := ..
5endif
6
Valerio Setti09172652024-06-27 08:00:54 +02007PSASIM_PATH=$(MBEDTLS_PATH)/tests/psa-client-server/psasim
8
Gilles Peskinef9bbe0d2024-03-04 16:25:14 +01009ifeq (,$(wildcard $(MBEDTLS_PATH)/framework/exported.make))
10 # Use the define keyword to get a multi-line message.
11 # GNU make appends ". Stop.", so tweak the ending of our message accordingly.
12 define error_message
13$(MBEDTLS_PATH)/framework/exported.make not found.
14Run `git submodule update --init` to fetch the submodule contents.
15This is a fatal error
16 endef
17 $(error $(error_message))
18endif
Gilles Peskine469f7812024-02-29 18:19:56 +010019include $(MBEDTLS_PATH)/framework/exported.make
20
Gilles Peskinef3d1ae12023-12-22 11:40:58 +010021CFLAGS ?= -O2
22WARNING_CFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral
23WARNING_CXXFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral
24LDFLAGS ?=
25
Ronald Cron3d817ad2024-06-14 08:43:28 +020026LOCAL_CFLAGS = $(WARNING_CFLAGS) -I$(MBEDTLS_TEST_PATH)/include \
27 -I$(MBEDTLS_PATH)/include -I$(MBEDTLS_PATH)/tf-psa-crypto/include \
28 -I$(MBEDTLS_PATH)/tf-psa-crypto/drivers/builtin/include \
29 -D_FILE_OFFSET_BITS=64
Paul Elliott7ed1cf52024-01-05 18:10:44 +000030LOCAL_CXXFLAGS = $(WARNING_CXXFLAGS) -I$(MBEDTLS_PATH)/include -I$(MBEDTLS_PATH)/tests/include -D_FILE_OFFSET_BITS=64
Valerio Setti09172652024-06-27 08:00:54 +020031
32ifdef PSASIM
33LOCAL_LDFLAGS = ${MBEDTLS_TEST_OBJS} \
34 -L$(PSASIM_PATH)/client_libs \
35 -lpsaclient \
36 -lmbedtls$(SHARED_SUFFIX) \
37 -lmbedx509$(SHARED_SUFFIX) \
38 -lmbedcrypto$(SHARED_SUFFIX)
39else
Gilles Peskinef3d1ae12023-12-22 11:40:58 +010040LOCAL_LDFLAGS = ${MBEDTLS_TEST_OBJS} \
Paul Elliott7ed1cf52024-01-05 18:10:44 +000041 -L$(MBEDTLS_PATH)/library \
Gilles Peskinef3d1ae12023-12-22 11:40:58 +010042 -lmbedtls$(SHARED_SUFFIX) \
43 -lmbedx509$(SHARED_SUFFIX) \
44 -lmbedcrypto$(SHARED_SUFFIX)
Valerio Setti09172652024-06-27 08:00:54 +020045endif
Gilles Peskine076fd252023-12-22 11:45:53 +010046
Paul Elliott7ed1cf52024-01-05 18:10:44 +000047include $(MBEDTLS_PATH)/3rdparty/Makefile.inc
Gilles Peskine076fd252023-12-22 11:45:53 +010048LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES)
49
Valerio Setti09172652024-06-27 08:00:54 +020050ifdef PSASIM
51MBEDLIBS=$(PSASIM_PATH)/client_libs/libmbedcrypto.a \
52 $(PSASIM_PATH)/client_libs/libmbedx509.a \
53 $(PSASIM_PATH)/client_libs/libmbedtls.a \
54 $(PSASIM_PATH)/client_libs/libpsaclient.a
55else ifndef SHARED
56MBEDLIBS=$(MBEDTLS_PATH)/library/libmbedcrypto.a \
57 $(MBEDTLS_PATH)/library/libmbedx509.a \
58 $(MBEDTLS_PATH)/library/libmbedtls.a
Gilles Peskine076fd252023-12-22 11:45:53 +010059else
Valerio Setti09172652024-06-27 08:00:54 +020060MBEDLIBS=$(MBEDTLS_PATH)/library/libmbedcrypto.$(DLEXT) \
61 $(MBEDTLS_PATH)/library/libmbedx509.$(DLEXT) \
62 $(MBEDTLS_PATH)/library/libmbedtls.$(DLEXT)
Gilles Peskine076fd252023-12-22 11:45:53 +010063endif
64
65ifdef DEBUG
66LOCAL_CFLAGS += -g3
67endif
68
69# if we're running on Windows, build for Windows
70ifdef WINDOWS
71WINDOWS_BUILD=1
72endif
73
Gilles Peskinef3316f12023-12-22 18:30:37 +010074## Usage: $(call remove_enabled_options,PREPROCESSOR_INPUT)
75## Remove the preprocessor symbols that are set in the current configuration
Gilles Peskine21570cf2023-12-22 11:49:50 +010076## from PREPROCESSOR_INPUT. Also normalize whitespace.
77## Example:
Gilles Peskinecd06a812024-01-02 18:14:40 +010078## $(call remove_enabled_options,MBEDTLS_FOO MBEDTLS_BAR)
Gilles Peskine21570cf2023-12-22 11:49:50 +010079## This expands to an empty string "" if MBEDTLS_FOO and MBEDTLS_BAR are both
Gilles Peskinef3316f12023-12-22 18:30:37 +010080## enabled, to "MBEDTLS_FOO" if MBEDTLS_BAR is enabled but MBEDTLS_FOO is
Gilles Peskine21570cf2023-12-22 11:49:50 +010081## disabled, etc.
82##
83## This only works with a Unix-like shell environment (Bourne/POSIX-style shell
84## and standard commands) and a Unix-like compiler (supporting -E). In
85## other environments, the output is likely to be empty.
Gilles Peskinef3316f12023-12-22 18:30:37 +010086define remove_enabled_options
Gilles Peskine21570cf2023-12-22 11:49:50 +010087$(strip $(shell
88 exec 2>/dev/null;
89 { echo '#include <mbedtls/build_info.h>'; echo $(1); } |
90 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -E - |
91 tail -n 1
92))
93endef
94
Gilles Peskine076fd252023-12-22 11:45:53 +010095ifdef WINDOWS_BUILD
96 DLEXT=dll
97 EXEXT=.exe
98 LOCAL_LDFLAGS += -lws2_32 -lbcrypt
99 ifdef SHARED
100 SHARED_SUFFIX=.$(DLEXT)
101 endif
102
103else # Not building for Windows
104 DLEXT ?= so
105 EXEXT=
106 SHARED_SUFFIX=
Gilles Peskine21570cf2023-12-22 11:49:50 +0100107 ifndef THREADING
108 # Auto-detect configurations with pthread.
Gilles Peskinef3316f12023-12-22 18:30:37 +0100109 # If the call to remove_enabled_options returns "control", the symbols
Gilles Peskine2337a3b2023-12-22 13:25:18 +0100110 # are confirmed set and we link with pthread.
111 # If the auto-detection fails, the result of the call is empty and
112 # we keep THREADING undefined.
Gilles Peskinef3316f12023-12-22 18:30:37 +0100113 ifeq (control,$(call remove_enabled_options,control MBEDTLS_THREADING_C MBEDTLS_THREADING_PTHREAD))
Gilles Peskine21570cf2023-12-22 11:49:50 +0100114 THREADING := pthread
115 endif
116 endif
Gilles Peskine076fd252023-12-22 11:45:53 +0100117
118 ifeq ($(THREADING),pthread)
119 LOCAL_LDFLAGS += -lpthread
120 endif
121endif
122
123ifdef WINDOWS
124PYTHON ?= python
125else
126PYTHON ?= $(shell if type python3 >/dev/null 2>/dev/null; then echo python3; else echo python; fi)
127endif
128
129# See root Makefile
130GEN_FILES ?= yes
131ifdef GEN_FILES
132gen_file_dep =
133else
134gen_file_dep = |
135endif
Gilles Peskine4392fc12023-12-22 11:49:35 +0100136
137default: all
138
139$(MBEDLIBS):
Paul Elliott7ed1cf52024-01-05 18:10:44 +0000140 $(MAKE) -C $(MBEDTLS_PATH)/library
Gilles Peskine4392fc12023-12-22 11:49:35 +0100141
142neat: clean
143ifndef WINDOWS
144 rm -f $(GENERATED_FILES)
145else
146 for %f in ($(subst /,\,$(GENERATED_FILES))) if exist %f del /Q /F %f
147endif
Gilles Peskine0ae58dd2024-01-02 23:11:24 +0100148
149# Auxiliary modules used by tests and some sample programs
Valerio Setti09172652024-06-27 08:00:54 +0200150MBEDTLS_CORE_TEST_OBJS := $(patsubst %.c,%.o,$(wildcard \
Gilles Peskine0ae58dd2024-01-02 23:11:24 +0100151 ${MBEDTLS_TEST_PATH}/src/*.c \
152 ${MBEDTLS_TEST_PATH}/src/drivers/*.c \
153 ))
Valerio Setti09172652024-06-27 08:00:54 +0200154# Ignore PSA stubs when building for the client side of PSASIM (i.e.
155# CRYPTO_CLIENT && !CRYPTO_C) otherwise there will be functions duplicates.
156ifdef PSASIM
157MBEDTLS_CORE_TEST_OBJS := $(filter-out \
158 ${MBEDTLS_TEST_PATH}/src/psa_crypto_stubs.o, $(MBEDTLS_CORE_TEST_OBJS)\
159 )
160endif
Gilles Peskine0ae58dd2024-01-02 23:11:24 +0100161# Additional auxiliary modules for TLS testing
162MBEDTLS_TLS_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard \
163 ${MBEDTLS_TEST_PATH}/src/test_helpers/*.c \
164 ))
165
166MBEDTLS_TEST_OBJS = $(MBEDTLS_CORE_TEST_OBJS) $(MBEDTLS_TLS_TEST_OBJS)