blob: cafad26e01e9d2dbf4b4b28332caeedec66675a8 [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
Paul Elliott7ed1cf52024-01-05 18:10:44 +000024LOCAL_CFLAGS = $(WARNING_CFLAGS) -I$(MBEDTLS_TEST_PATH)/include -I$(MBEDTLS_PATH)/include -D_FILE_OFFSET_BITS=64
David Horstmann99ee7502024-03-28 14:19:09 +000025LOCAL_CXXFLAGS = $(WARNING_CXXFLAGS) -I$(MBEDTLS_PATH)/include -I$(MBEDTLS_PATH)/framework/include -D_FILE_OFFSET_BITS=64
Gilles Peskinef3d1ae12023-12-22 11:40:58 +010026LOCAL_LDFLAGS = ${MBEDTLS_TEST_OBJS} \
Paul Elliott7ed1cf52024-01-05 18:10:44 +000027 -L$(MBEDTLS_PATH)/library \
Gilles Peskinef3d1ae12023-12-22 11:40:58 +010028 -lmbedtls$(SHARED_SUFFIX) \
29 -lmbedx509$(SHARED_SUFFIX) \
30 -lmbedcrypto$(SHARED_SUFFIX)
Gilles Peskine076fd252023-12-22 11:45:53 +010031
Paul Elliott7ed1cf52024-01-05 18:10:44 +000032include $(MBEDTLS_PATH)/3rdparty/Makefile.inc
Gilles Peskine076fd252023-12-22 11:45:53 +010033LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES)
34
35ifndef SHARED
Paul Elliott7ed1cf52024-01-05 18:10:44 +000036MBEDLIBS=$(MBEDTLS_PATH)/library/libmbedcrypto.a $(MBEDTLS_PATH)/library/libmbedx509.a $(MBEDTLS_PATH)/library/libmbedtls.a
Gilles Peskine076fd252023-12-22 11:45:53 +010037else
Paul Elliott7ed1cf52024-01-05 18:10:44 +000038MBEDLIBS=$(MBEDTLS_PATH)/library/libmbedcrypto.$(DLEXT) $(MBEDTLS_PATH)/library/libmbedx509.$(DLEXT) $(MBEDTLS_PATH)/library/libmbedtls.$(DLEXT)
Gilles Peskine076fd252023-12-22 11:45:53 +010039endif
40
41ifdef DEBUG
42LOCAL_CFLAGS += -g3
43endif
44
45# if we're running on Windows, build for Windows
46ifdef WINDOWS
47WINDOWS_BUILD=1
48endif
49
Gilles Peskinef3316f12023-12-22 18:30:37 +010050## Usage: $(call remove_enabled_options,PREPROCESSOR_INPUT)
51## Remove the preprocessor symbols that are set in the current configuration
Gilles Peskine21570cf2023-12-22 11:49:50 +010052## from PREPROCESSOR_INPUT. Also normalize whitespace.
53## Example:
Gilles Peskinecd06a812024-01-02 18:14:40 +010054## $(call remove_enabled_options,MBEDTLS_FOO MBEDTLS_BAR)
Gilles Peskine21570cf2023-12-22 11:49:50 +010055## This expands to an empty string "" if MBEDTLS_FOO and MBEDTLS_BAR are both
Gilles Peskinef3316f12023-12-22 18:30:37 +010056## enabled, to "MBEDTLS_FOO" if MBEDTLS_BAR is enabled but MBEDTLS_FOO is
Gilles Peskine21570cf2023-12-22 11:49:50 +010057## disabled, etc.
58##
59## This only works with a Unix-like shell environment (Bourne/POSIX-style shell
60## and standard commands) and a Unix-like compiler (supporting -E). In
61## other environments, the output is likely to be empty.
Gilles Peskinef3316f12023-12-22 18:30:37 +010062define remove_enabled_options
Gilles Peskine21570cf2023-12-22 11:49:50 +010063$(strip $(shell
64 exec 2>/dev/null;
65 { echo '#include <mbedtls/build_info.h>'; echo $(1); } |
66 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -E - |
67 tail -n 1
68))
69endef
70
Gilles Peskine076fd252023-12-22 11:45:53 +010071ifdef WINDOWS_BUILD
72 DLEXT=dll
73 EXEXT=.exe
74 LOCAL_LDFLAGS += -lws2_32 -lbcrypt
75 ifdef SHARED
76 SHARED_SUFFIX=.$(DLEXT)
77 endif
78
79else # Not building for Windows
80 DLEXT ?= so
81 EXEXT=
82 SHARED_SUFFIX=
Gilles Peskine21570cf2023-12-22 11:49:50 +010083 ifndef THREADING
84 # Auto-detect configurations with pthread.
Gilles Peskinef3316f12023-12-22 18:30:37 +010085 # If the call to remove_enabled_options returns "control", the symbols
Gilles Peskine2337a3b2023-12-22 13:25:18 +010086 # are confirmed set and we link with pthread.
87 # If the auto-detection fails, the result of the call is empty and
88 # we keep THREADING undefined.
Gilles Peskinef3316f12023-12-22 18:30:37 +010089 ifeq (control,$(call remove_enabled_options,control MBEDTLS_THREADING_C MBEDTLS_THREADING_PTHREAD))
Gilles Peskine21570cf2023-12-22 11:49:50 +010090 THREADING := pthread
91 endif
92 endif
Gilles Peskine076fd252023-12-22 11:45:53 +010093
94 ifeq ($(THREADING),pthread)
95 LOCAL_LDFLAGS += -lpthread
96 endif
97endif
98
99ifdef WINDOWS
100PYTHON ?= python
101else
102PYTHON ?= $(shell if type python3 >/dev/null 2>/dev/null; then echo python3; else echo python; fi)
103endif
104
105# See root Makefile
106GEN_FILES ?= yes
107ifdef GEN_FILES
108gen_file_dep =
109else
110gen_file_dep = |
111endif
Gilles Peskine4392fc12023-12-22 11:49:35 +0100112
113default: all
114
115$(MBEDLIBS):
Paul Elliott7ed1cf52024-01-05 18:10:44 +0000116 $(MAKE) -C $(MBEDTLS_PATH)/library
Gilles Peskine4392fc12023-12-22 11:49:35 +0100117
118neat: clean
119ifndef WINDOWS
120 rm -f $(GENERATED_FILES)
121else
122 for %f in ($(subst /,\,$(GENERATED_FILES))) if exist %f del /Q /F %f
123endif
Gilles Peskine0ae58dd2024-01-02 23:11:24 +0100124
125# Auxiliary modules used by tests and some sample programs
126MBEDTLS_CORE_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard \
127 ${MBEDTLS_TEST_PATH}/src/*.c \
128 ${MBEDTLS_TEST_PATH}/src/drivers/*.c \
129 ))
130# Additional auxiliary modules for TLS testing
131MBEDTLS_TLS_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard \
132 ${MBEDTLS_TEST_PATH}/src/test_helpers/*.c \
133 ))
134
135MBEDTLS_TEST_OBJS = $(MBEDTLS_CORE_TEST_OBJS) $(MBEDTLS_TLS_TEST_OBJS)