blob: 362712ba1f2acd7380c96481c0c769e66a8f19e5 [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
Gilles Peskinef5db72b2024-06-06 22:12:06 +020021WARNING_CXXFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral -std=c++11 -pedantic
Gilles Peskinef3d1ae12023-12-22 11:40:58 +010022LDFLAGS ?=
23
David Horstmannc2d7f5f2024-11-04 15:57:57 +000024LOCAL_CFLAGS = $(WARNING_CFLAGS) -I$(MBEDTLS_TEST_PATH)/include \
25 -I$(MBEDTLS_PATH)/framework/tests/include \
26 -I$(MBEDTLS_PATH)/include \
27 -D_FILE_OFFSET_BITS=64
28LOCAL_CXXFLAGS = $(WARNING_CXXFLAGS) $(LOCAL_CFLAGS)
29
Gilles Peskinef3d1ae12023-12-22 11:40:58 +010030LOCAL_LDFLAGS = ${MBEDTLS_TEST_OBJS} \
Paul Elliott7ed1cf52024-01-05 18:10:44 +000031 -L$(MBEDTLS_PATH)/library \
Gilles Peskinef3d1ae12023-12-22 11:40:58 +010032 -lmbedtls$(SHARED_SUFFIX) \
33 -lmbedx509$(SHARED_SUFFIX) \
34 -lmbedcrypto$(SHARED_SUFFIX)
Gilles Peskine076fd252023-12-22 11:45:53 +010035
Paul Elliott7ed1cf52024-01-05 18:10:44 +000036include $(MBEDTLS_PATH)/3rdparty/Makefile.inc
Gilles Peskine076fd252023-12-22 11:45:53 +010037LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES)
38
39ifndef SHARED
Paul Elliott7ed1cf52024-01-05 18:10:44 +000040MBEDLIBS=$(MBEDTLS_PATH)/library/libmbedcrypto.a $(MBEDTLS_PATH)/library/libmbedx509.a $(MBEDTLS_PATH)/library/libmbedtls.a
Gilles Peskine076fd252023-12-22 11:45:53 +010041else
Paul Elliott7ed1cf52024-01-05 18:10:44 +000042MBEDLIBS=$(MBEDTLS_PATH)/library/libmbedcrypto.$(DLEXT) $(MBEDTLS_PATH)/library/libmbedx509.$(DLEXT) $(MBEDTLS_PATH)/library/libmbedtls.$(DLEXT)
Gilles Peskine076fd252023-12-22 11:45:53 +010043endif
44
45ifdef DEBUG
46LOCAL_CFLAGS += -g3
47endif
48
49# if we're running on Windows, build for Windows
50ifdef WINDOWS
51WINDOWS_BUILD=1
52endif
53
Gilles Peskinef3316f12023-12-22 18:30:37 +010054## Usage: $(call remove_enabled_options,PREPROCESSOR_INPUT)
55## Remove the preprocessor symbols that are set in the current configuration
Gilles Peskine21570cf2023-12-22 11:49:50 +010056## from PREPROCESSOR_INPUT. Also normalize whitespace.
57## Example:
Gilles Peskinecd06a812024-01-02 18:14:40 +010058## $(call remove_enabled_options,MBEDTLS_FOO MBEDTLS_BAR)
Gilles Peskine21570cf2023-12-22 11:49:50 +010059## This expands to an empty string "" if MBEDTLS_FOO and MBEDTLS_BAR are both
Gilles Peskinef3316f12023-12-22 18:30:37 +010060## enabled, to "MBEDTLS_FOO" if MBEDTLS_BAR is enabled but MBEDTLS_FOO is
Gilles Peskine21570cf2023-12-22 11:49:50 +010061## disabled, etc.
62##
63## This only works with a Unix-like shell environment (Bourne/POSIX-style shell
64## and standard commands) and a Unix-like compiler (supporting -E). In
65## other environments, the output is likely to be empty.
Gilles Peskinef3316f12023-12-22 18:30:37 +010066define remove_enabled_options
Gilles Peskine21570cf2023-12-22 11:49:50 +010067$(strip $(shell
68 exec 2>/dev/null;
69 { echo '#include <mbedtls/build_info.h>'; echo $(1); } |
70 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -E - |
71 tail -n 1
72))
73endef
74
Gilles Peskine076fd252023-12-22 11:45:53 +010075ifdef WINDOWS_BUILD
76 DLEXT=dll
77 EXEXT=.exe
78 LOCAL_LDFLAGS += -lws2_32 -lbcrypt
79 ifdef SHARED
80 SHARED_SUFFIX=.$(DLEXT)
81 endif
82
83else # Not building for Windows
84 DLEXT ?= so
85 EXEXT=
86 SHARED_SUFFIX=
Gilles Peskine21570cf2023-12-22 11:49:50 +010087 ifndef THREADING
88 # Auto-detect configurations with pthread.
Gilles Peskinef3316f12023-12-22 18:30:37 +010089 # If the call to remove_enabled_options returns "control", the symbols
Gilles Peskine2337a3b2023-12-22 13:25:18 +010090 # are confirmed set and we link with pthread.
91 # If the auto-detection fails, the result of the call is empty and
92 # we keep THREADING undefined.
Gilles Peskinef3316f12023-12-22 18:30:37 +010093 ifeq (control,$(call remove_enabled_options,control MBEDTLS_THREADING_C MBEDTLS_THREADING_PTHREAD))
Gilles Peskine21570cf2023-12-22 11:49:50 +010094 THREADING := pthread
95 endif
96 endif
Gilles Peskine076fd252023-12-22 11:45:53 +010097
98 ifeq ($(THREADING),pthread)
99 LOCAL_LDFLAGS += -lpthread
100 endif
101endif
102
103ifdef WINDOWS
104PYTHON ?= python
105else
106PYTHON ?= $(shell if type python3 >/dev/null 2>/dev/null; then echo python3; else echo python; fi)
107endif
108
109# See root Makefile
110GEN_FILES ?= yes
111ifdef GEN_FILES
112gen_file_dep =
113else
114gen_file_dep = |
115endif
Gilles Peskine4392fc12023-12-22 11:49:35 +0100116
117default: all
118
119$(MBEDLIBS):
Paul Elliott7ed1cf52024-01-05 18:10:44 +0000120 $(MAKE) -C $(MBEDTLS_PATH)/library
Gilles Peskine4392fc12023-12-22 11:49:35 +0100121
122neat: clean
123ifndef WINDOWS
124 rm -f $(GENERATED_FILES)
125else
126 for %f in ($(subst /,\,$(GENERATED_FILES))) if exist %f del /Q /F %f
127endif
Gilles Peskine0ae58dd2024-01-02 23:11:24 +0100128
129# Auxiliary modules used by tests and some sample programs
130MBEDTLS_CORE_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard \
131 ${MBEDTLS_TEST_PATH}/src/*.c \
132 ${MBEDTLS_TEST_PATH}/src/drivers/*.c \
133 ))
134# Additional auxiliary modules for TLS testing
135MBEDTLS_TLS_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard \
136 ${MBEDTLS_TEST_PATH}/src/test_helpers/*.c \
137 ))
138
139MBEDTLS_TEST_OBJS = $(MBEDTLS_CORE_TEST_OBJS) $(MBEDTLS_TLS_TEST_OBJS)