blob: ead1334ca3aae4767e0a3f8768bd47b8d3e1963a [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
Gilles Peskinef9bbe0d2024-03-04 16:25:14 +01007ifeq (,$(wildcard $(MBEDTLS_PATH)/framework/exported.make))
8 # Use the define keyword to get a multi-line message.
9 # GNU make appends ". Stop.", so tweak the ending of our message accordingly.
10 define error_message
11$(MBEDTLS_PATH)/framework/exported.make not found.
12Run `git submodule update --init` to fetch the submodule contents.
13This is a fatal error
14 endef
15 $(error $(error_message))
16endif
Gilles Peskine469f7812024-02-29 18:19:56 +010017include $(MBEDTLS_PATH)/framework/exported.make
18
Gilles Peskinef3d1ae12023-12-22 11:40:58 +010019CFLAGS ?= -O2
20WARNING_CFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral
21WARNING_CXXFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral
22LDFLAGS ?=
23
Ronald Cron3d817ad2024-06-14 08:43:28 +020024LOCAL_CFLAGS = $(WARNING_CFLAGS) -I$(MBEDTLS_TEST_PATH)/include \
25 -I$(MBEDTLS_PATH)/include -I$(MBEDTLS_PATH)/tf-psa-crypto/include \
26 -I$(MBEDTLS_PATH)/tf-psa-crypto/drivers/builtin/include \
27 -D_FILE_OFFSET_BITS=64
Paul Elliott7ed1cf52024-01-05 18:10:44 +000028LOCAL_CXXFLAGS = $(WARNING_CXXFLAGS) -I$(MBEDTLS_PATH)/include -I$(MBEDTLS_PATH)/tests/include -D_FILE_OFFSET_BITS=64
Gilles Peskinef3d1ae12023-12-22 11:40:58 +010029LOCAL_LDFLAGS = ${MBEDTLS_TEST_OBJS} \
Paul Elliott7ed1cf52024-01-05 18:10:44 +000030 -L$(MBEDTLS_PATH)/library \
Gilles Peskinef3d1ae12023-12-22 11:40:58 +010031 -lmbedtls$(SHARED_SUFFIX) \
32 -lmbedx509$(SHARED_SUFFIX) \
33 -lmbedcrypto$(SHARED_SUFFIX)
Gilles Peskine076fd252023-12-22 11:45:53 +010034
Paul Elliott7ed1cf52024-01-05 18:10:44 +000035include $(MBEDTLS_PATH)/3rdparty/Makefile.inc
Gilles Peskine076fd252023-12-22 11:45:53 +010036LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES)
37
38ifndef SHARED
Paul Elliott7ed1cf52024-01-05 18:10:44 +000039MBEDLIBS=$(MBEDTLS_PATH)/library/libmbedcrypto.a $(MBEDTLS_PATH)/library/libmbedx509.a $(MBEDTLS_PATH)/library/libmbedtls.a
Gilles Peskine076fd252023-12-22 11:45:53 +010040else
Paul Elliott7ed1cf52024-01-05 18:10:44 +000041MBEDLIBS=$(MBEDTLS_PATH)/library/libmbedcrypto.$(DLEXT) $(MBEDTLS_PATH)/library/libmbedx509.$(DLEXT) $(MBEDTLS_PATH)/library/libmbedtls.$(DLEXT)
Gilles Peskine076fd252023-12-22 11:45:53 +010042endif
43
44ifdef DEBUG
45LOCAL_CFLAGS += -g3
46endif
47
48# if we're running on Windows, build for Windows
49ifdef WINDOWS
50WINDOWS_BUILD=1
51endif
52
Gilles Peskinef3316f12023-12-22 18:30:37 +010053## Usage: $(call remove_enabled_options,PREPROCESSOR_INPUT)
54## Remove the preprocessor symbols that are set in the current configuration
Gilles Peskine21570cf2023-12-22 11:49:50 +010055## from PREPROCESSOR_INPUT. Also normalize whitespace.
56## Example:
Gilles Peskinecd06a812024-01-02 18:14:40 +010057## $(call remove_enabled_options,MBEDTLS_FOO MBEDTLS_BAR)
Gilles Peskine21570cf2023-12-22 11:49:50 +010058## This expands to an empty string "" if MBEDTLS_FOO and MBEDTLS_BAR are both
Gilles Peskinef3316f12023-12-22 18:30:37 +010059## enabled, to "MBEDTLS_FOO" if MBEDTLS_BAR is enabled but MBEDTLS_FOO is
Gilles Peskine21570cf2023-12-22 11:49:50 +010060## disabled, etc.
61##
62## This only works with a Unix-like shell environment (Bourne/POSIX-style shell
63## and standard commands) and a Unix-like compiler (supporting -E). In
64## other environments, the output is likely to be empty.
Gilles Peskinef3316f12023-12-22 18:30:37 +010065define remove_enabled_options
Gilles Peskine21570cf2023-12-22 11:49:50 +010066$(strip $(shell
67 exec 2>/dev/null;
68 { echo '#include <mbedtls/build_info.h>'; echo $(1); } |
69 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -E - |
70 tail -n 1
71))
72endef
73
Gilles Peskine076fd252023-12-22 11:45:53 +010074ifdef WINDOWS_BUILD
75 DLEXT=dll
76 EXEXT=.exe
77 LOCAL_LDFLAGS += -lws2_32 -lbcrypt
78 ifdef SHARED
79 SHARED_SUFFIX=.$(DLEXT)
80 endif
81
82else # Not building for Windows
83 DLEXT ?= so
84 EXEXT=
85 SHARED_SUFFIX=
Gilles Peskine21570cf2023-12-22 11:49:50 +010086 ifndef THREADING
87 # Auto-detect configurations with pthread.
Gilles Peskinef3316f12023-12-22 18:30:37 +010088 # If the call to remove_enabled_options returns "control", the symbols
Gilles Peskine2337a3b2023-12-22 13:25:18 +010089 # are confirmed set and we link with pthread.
90 # If the auto-detection fails, the result of the call is empty and
91 # we keep THREADING undefined.
Gilles Peskinef3316f12023-12-22 18:30:37 +010092 ifeq (control,$(call remove_enabled_options,control MBEDTLS_THREADING_C MBEDTLS_THREADING_PTHREAD))
Gilles Peskine21570cf2023-12-22 11:49:50 +010093 THREADING := pthread
94 endif
95 endif
Gilles Peskine076fd252023-12-22 11:45:53 +010096
97 ifeq ($(THREADING),pthread)
98 LOCAL_LDFLAGS += -lpthread
99 endif
100endif
101
102ifdef WINDOWS
103PYTHON ?= python
104else
105PYTHON ?= $(shell if type python3 >/dev/null 2>/dev/null; then echo python3; else echo python; fi)
106endif
107
108# See root Makefile
109GEN_FILES ?= yes
110ifdef GEN_FILES
111gen_file_dep =
112else
113gen_file_dep = |
114endif
Gilles Peskine4392fc12023-12-22 11:49:35 +0100115
116default: all
117
118$(MBEDLIBS):
Paul Elliott7ed1cf52024-01-05 18:10:44 +0000119 $(MAKE) -C $(MBEDTLS_PATH)/library
Gilles Peskine4392fc12023-12-22 11:49:35 +0100120
121neat: clean
122ifndef WINDOWS
123 rm -f $(GENERATED_FILES)
124else
125 for %f in ($(subst /,\,$(GENERATED_FILES))) if exist %f del /Q /F %f
126endif
Gilles Peskine0ae58dd2024-01-02 23:11:24 +0100127
128# Auxiliary modules used by tests and some sample programs
129MBEDTLS_CORE_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard \
130 ${MBEDTLS_TEST_PATH}/src/*.c \
131 ${MBEDTLS_TEST_PATH}/src/drivers/*.c \
132 ))
133# Additional auxiliary modules for TLS testing
134MBEDTLS_TLS_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard \
135 ${MBEDTLS_TEST_PATH}/src/test_helpers/*.c \
136 ))
137
138MBEDTLS_TEST_OBJS = $(MBEDTLS_CORE_TEST_OBJS) $(MBEDTLS_TLS_TEST_OBJS)