blob: b3d028ff62771b4ab53b0156e09f63a532cb54d3 [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
Gilles Peskine62ee8fd2024-06-06 22:12:06 +020023WARNING_CXXFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral -std=c++11 -pedantic
Gilles Peskinef3d1ae12023-12-22 11:40:58 +010024LDFLAGS ?=
25
Ronald Cron3d817ad2024-06-14 08:43:28 +020026LOCAL_CFLAGS = $(WARNING_CFLAGS) -I$(MBEDTLS_TEST_PATH)/include \
David Horstmannbc06e2a2024-11-04 15:57:57 +000027 -I$(MBEDTLS_PATH)/framework/tests/include \
Ronald Cron3d817ad2024-06-14 08:43:28 +020028 -I$(MBEDTLS_PATH)/include -I$(MBEDTLS_PATH)/tf-psa-crypto/include \
29 -I$(MBEDTLS_PATH)/tf-psa-crypto/drivers/builtin/include \
30 -D_FILE_OFFSET_BITS=64
Gilles Peskine6b3bca52024-08-01 16:11:09 +020031LOCAL_CXXFLAGS = $(WARNING_CXXFLAGS) $(LOCAL_CFLAGS)
Valerio Setti09172652024-06-27 08:00:54 +020032
33ifdef PSASIM
34LOCAL_LDFLAGS = ${MBEDTLS_TEST_OBJS} \
35 -L$(PSASIM_PATH)/client_libs \
36 -lpsaclient \
37 -lmbedtls$(SHARED_SUFFIX) \
38 -lmbedx509$(SHARED_SUFFIX) \
39 -lmbedcrypto$(SHARED_SUFFIX)
40else
Gilles Peskinef3d1ae12023-12-22 11:40:58 +010041LOCAL_LDFLAGS = ${MBEDTLS_TEST_OBJS} \
Paul Elliott7ed1cf52024-01-05 18:10:44 +000042 -L$(MBEDTLS_PATH)/library \
Gilles Peskinef3d1ae12023-12-22 11:40:58 +010043 -lmbedtls$(SHARED_SUFFIX) \
44 -lmbedx509$(SHARED_SUFFIX) \
45 -lmbedcrypto$(SHARED_SUFFIX)
Valerio Setti09172652024-06-27 08:00:54 +020046endif
Gilles Peskine076fd252023-12-22 11:45:53 +010047
Ronald Cronaef8cf32024-07-01 18:33:24 +020048THIRDPARTY_DIR = $(MBEDTLS_PATH)/tf-psa-crypto/drivers
Ronald Cronf250cf62024-07-04 09:43:13 +020049include $(THIRDPARTY_DIR)/everest/Makefile.inc
50include $(THIRDPARTY_DIR)/p256-m/Makefile.inc
Gilles Peskine076fd252023-12-22 11:45:53 +010051LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES)
52
Valerio Setti09172652024-06-27 08:00:54 +020053ifdef PSASIM
54MBEDLIBS=$(PSASIM_PATH)/client_libs/libmbedcrypto.a \
55 $(PSASIM_PATH)/client_libs/libmbedx509.a \
56 $(PSASIM_PATH)/client_libs/libmbedtls.a \
57 $(PSASIM_PATH)/client_libs/libpsaclient.a
58else ifndef SHARED
59MBEDLIBS=$(MBEDTLS_PATH)/library/libmbedcrypto.a \
60 $(MBEDTLS_PATH)/library/libmbedx509.a \
61 $(MBEDTLS_PATH)/library/libmbedtls.a
Gilles Peskine076fd252023-12-22 11:45:53 +010062else
Valerio Setti09172652024-06-27 08:00:54 +020063MBEDLIBS=$(MBEDTLS_PATH)/library/libmbedcrypto.$(DLEXT) \
64 $(MBEDTLS_PATH)/library/libmbedx509.$(DLEXT) \
65 $(MBEDTLS_PATH)/library/libmbedtls.$(DLEXT)
Gilles Peskine076fd252023-12-22 11:45:53 +010066endif
67
68ifdef DEBUG
69LOCAL_CFLAGS += -g3
70endif
71
72# if we're running on Windows, build for Windows
73ifdef WINDOWS
74WINDOWS_BUILD=1
75endif
76
Gilles Peskinef3316f12023-12-22 18:30:37 +010077## Usage: $(call remove_enabled_options,PREPROCESSOR_INPUT)
78## Remove the preprocessor symbols that are set in the current configuration
Gilles Peskine21570cf2023-12-22 11:49:50 +010079## from PREPROCESSOR_INPUT. Also normalize whitespace.
80## Example:
Gilles Peskinecd06a812024-01-02 18:14:40 +010081## $(call remove_enabled_options,MBEDTLS_FOO MBEDTLS_BAR)
Gilles Peskine21570cf2023-12-22 11:49:50 +010082## This expands to an empty string "" if MBEDTLS_FOO and MBEDTLS_BAR are both
Gilles Peskinef3316f12023-12-22 18:30:37 +010083## enabled, to "MBEDTLS_FOO" if MBEDTLS_BAR is enabled but MBEDTLS_FOO is
Gilles Peskine21570cf2023-12-22 11:49:50 +010084## disabled, etc.
85##
86## This only works with a Unix-like shell environment (Bourne/POSIX-style shell
87## and standard commands) and a Unix-like compiler (supporting -E). In
88## other environments, the output is likely to be empty.
Gilles Peskinef3316f12023-12-22 18:30:37 +010089define remove_enabled_options
Gilles Peskine21570cf2023-12-22 11:49:50 +010090$(strip $(shell
91 exec 2>/dev/null;
92 { echo '#include <mbedtls/build_info.h>'; echo $(1); } |
93 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -E - |
94 tail -n 1
95))
96endef
97
Gilles Peskine076fd252023-12-22 11:45:53 +010098ifdef WINDOWS_BUILD
99 DLEXT=dll
100 EXEXT=.exe
101 LOCAL_LDFLAGS += -lws2_32 -lbcrypt
102 ifdef SHARED
103 SHARED_SUFFIX=.$(DLEXT)
104 endif
105
106else # Not building for Windows
107 DLEXT ?= so
108 EXEXT=
109 SHARED_SUFFIX=
Gilles Peskine21570cf2023-12-22 11:49:50 +0100110 ifndef THREADING
111 # Auto-detect configurations with pthread.
Gilles Peskinef3316f12023-12-22 18:30:37 +0100112 # If the call to remove_enabled_options returns "control", the symbols
Gilles Peskine2337a3b2023-12-22 13:25:18 +0100113 # are confirmed set and we link with pthread.
114 # If the auto-detection fails, the result of the call is empty and
115 # we keep THREADING undefined.
Gilles Peskinef3316f12023-12-22 18:30:37 +0100116 ifeq (control,$(call remove_enabled_options,control MBEDTLS_THREADING_C MBEDTLS_THREADING_PTHREAD))
Gilles Peskine21570cf2023-12-22 11:49:50 +0100117 THREADING := pthread
118 endif
119 endif
Gilles Peskine076fd252023-12-22 11:45:53 +0100120
121 ifeq ($(THREADING),pthread)
122 LOCAL_LDFLAGS += -lpthread
123 endif
124endif
125
126ifdef WINDOWS
127PYTHON ?= python
128else
129PYTHON ?= $(shell if type python3 >/dev/null 2>/dev/null; then echo python3; else echo python; fi)
130endif
131
132# See root Makefile
133GEN_FILES ?= yes
134ifdef GEN_FILES
135gen_file_dep =
136else
137gen_file_dep = |
138endif
Gilles Peskine4392fc12023-12-22 11:49:35 +0100139
140default: all
141
142$(MBEDLIBS):
Paul Elliott7ed1cf52024-01-05 18:10:44 +0000143 $(MAKE) -C $(MBEDTLS_PATH)/library
Gilles Peskine4392fc12023-12-22 11:49:35 +0100144
145neat: clean
146ifndef WINDOWS
147 rm -f $(GENERATED_FILES)
148else
149 for %f in ($(subst /,\,$(GENERATED_FILES))) if exist %f del /Q /F %f
150endif
Gilles Peskine0ae58dd2024-01-02 23:11:24 +0100151
152# Auxiliary modules used by tests and some sample programs
Valerio Setti09172652024-06-27 08:00:54 +0200153MBEDTLS_CORE_TEST_OBJS := $(patsubst %.c,%.o,$(wildcard \
David Horstmannd9ad6632024-11-05 14:40:03 +0000154 ${MBEDTLS_PATH}/framework/tests/src/*.c \
155 ${MBEDTLS_PATH}/framework/tests/src/drivers/*.c \
Gilles Peskine0ae58dd2024-01-02 23:11:24 +0100156 ))
Valerio Setti09172652024-06-27 08:00:54 +0200157# Ignore PSA stubs when building for the client side of PSASIM (i.e.
158# CRYPTO_CLIENT && !CRYPTO_C) otherwise there will be functions duplicates.
159ifdef PSASIM
160MBEDTLS_CORE_TEST_OBJS := $(filter-out \
David Horstmannd9ad6632024-11-05 14:40:03 +0000161 ${MBEDTLS_PATH}/framework/tests/src/psa_crypto_stubs.o, $(MBEDTLS_CORE_TEST_OBJS)\
Valerio Setti09172652024-06-27 08:00:54 +0200162 )
163endif
Gilles Peskine0ae58dd2024-01-02 23:11:24 +0100164# Additional auxiliary modules for TLS testing
165MBEDTLS_TLS_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard \
David Horstmannd9ad6632024-11-05 14:40:03 +0000166 ${MBEDTLS_TEST_PATH}/src/*.c \
Gilles Peskine0ae58dd2024-01-02 23:11:24 +0100167 ${MBEDTLS_TEST_PATH}/src/test_helpers/*.c \
168 ))
169
170MBEDTLS_TEST_OBJS = $(MBEDTLS_CORE_TEST_OBJS) $(MBEDTLS_TLS_TEST_OBJS)