blob: 2da58d00e3e1b7308cfc292da95ac1d5b6247eb4 [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 Peskine469f7812024-02-29 18:19:56 +01007include $(MBEDTLS_PATH)/framework/exported.make
8
Gilles Peskinef3d1ae12023-12-22 11:40:58 +01009CFLAGS ?= -O2
10WARNING_CFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral
11WARNING_CXXFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral
12LDFLAGS ?=
13
Paul Elliott7ed1cf52024-01-05 18:10:44 +000014LOCAL_CFLAGS = $(WARNING_CFLAGS) -I$(MBEDTLS_TEST_PATH)/include -I$(MBEDTLS_PATH)/include -D_FILE_OFFSET_BITS=64
15LOCAL_CXXFLAGS = $(WARNING_CXXFLAGS) -I$(MBEDTLS_PATH)/include -I$(MBEDTLS_PATH)/tests/include -D_FILE_OFFSET_BITS=64
Gilles Peskinef3d1ae12023-12-22 11:40:58 +010016LOCAL_LDFLAGS = ${MBEDTLS_TEST_OBJS} \
Paul Elliott7ed1cf52024-01-05 18:10:44 +000017 -L$(MBEDTLS_PATH)/library \
Gilles Peskinef3d1ae12023-12-22 11:40:58 +010018 -lmbedtls$(SHARED_SUFFIX) \
19 -lmbedx509$(SHARED_SUFFIX) \
20 -lmbedcrypto$(SHARED_SUFFIX)
Gilles Peskine076fd252023-12-22 11:45:53 +010021
Paul Elliott7ed1cf52024-01-05 18:10:44 +000022include $(MBEDTLS_PATH)/3rdparty/Makefile.inc
Gilles Peskine076fd252023-12-22 11:45:53 +010023LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES)
24
25ifndef SHARED
Paul Elliott7ed1cf52024-01-05 18:10:44 +000026MBEDLIBS=$(MBEDTLS_PATH)/library/libmbedcrypto.a $(MBEDTLS_PATH)/library/libmbedx509.a $(MBEDTLS_PATH)/library/libmbedtls.a
Gilles Peskine076fd252023-12-22 11:45:53 +010027else
Paul Elliott7ed1cf52024-01-05 18:10:44 +000028MBEDLIBS=$(MBEDTLS_PATH)/library/libmbedcrypto.$(DLEXT) $(MBEDTLS_PATH)/library/libmbedx509.$(DLEXT) $(MBEDTLS_PATH)/library/libmbedtls.$(DLEXT)
Gilles Peskine076fd252023-12-22 11:45:53 +010029endif
30
31ifdef DEBUG
32LOCAL_CFLAGS += -g3
33endif
34
35# if we're running on Windows, build for Windows
36ifdef WINDOWS
37WINDOWS_BUILD=1
38endif
39
Gilles Peskinef3316f12023-12-22 18:30:37 +010040## Usage: $(call remove_enabled_options,PREPROCESSOR_INPUT)
41## Remove the preprocessor symbols that are set in the current configuration
Gilles Peskine21570cf2023-12-22 11:49:50 +010042## from PREPROCESSOR_INPUT. Also normalize whitespace.
43## Example:
Gilles Peskinecd06a812024-01-02 18:14:40 +010044## $(call remove_enabled_options,MBEDTLS_FOO MBEDTLS_BAR)
Gilles Peskine21570cf2023-12-22 11:49:50 +010045## This expands to an empty string "" if MBEDTLS_FOO and MBEDTLS_BAR are both
Gilles Peskinef3316f12023-12-22 18:30:37 +010046## enabled, to "MBEDTLS_FOO" if MBEDTLS_BAR is enabled but MBEDTLS_FOO is
Gilles Peskine21570cf2023-12-22 11:49:50 +010047## disabled, etc.
48##
49## This only works with a Unix-like shell environment (Bourne/POSIX-style shell
50## and standard commands) and a Unix-like compiler (supporting -E). In
51## other environments, the output is likely to be empty.
Gilles Peskinef3316f12023-12-22 18:30:37 +010052define remove_enabled_options
Gilles Peskine21570cf2023-12-22 11:49:50 +010053$(strip $(shell
54 exec 2>/dev/null;
55 { echo '#include <mbedtls/build_info.h>'; echo $(1); } |
56 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -E - |
57 tail -n 1
58))
59endef
60
Gilles Peskine076fd252023-12-22 11:45:53 +010061ifdef WINDOWS_BUILD
62 DLEXT=dll
63 EXEXT=.exe
64 LOCAL_LDFLAGS += -lws2_32 -lbcrypt
65 ifdef SHARED
66 SHARED_SUFFIX=.$(DLEXT)
67 endif
68
69else # Not building for Windows
70 DLEXT ?= so
71 EXEXT=
72 SHARED_SUFFIX=
Gilles Peskine21570cf2023-12-22 11:49:50 +010073 ifndef THREADING
74 # Auto-detect configurations with pthread.
Gilles Peskinef3316f12023-12-22 18:30:37 +010075 # If the call to remove_enabled_options returns "control", the symbols
Gilles Peskine2337a3b2023-12-22 13:25:18 +010076 # are confirmed set and we link with pthread.
77 # If the auto-detection fails, the result of the call is empty and
78 # we keep THREADING undefined.
Gilles Peskinef3316f12023-12-22 18:30:37 +010079 ifeq (control,$(call remove_enabled_options,control MBEDTLS_THREADING_C MBEDTLS_THREADING_PTHREAD))
Gilles Peskine21570cf2023-12-22 11:49:50 +010080 THREADING := pthread
81 endif
82 endif
Gilles Peskine076fd252023-12-22 11:45:53 +010083
84 ifeq ($(THREADING),pthread)
85 LOCAL_LDFLAGS += -lpthread
86 endif
87endif
88
89ifdef WINDOWS
90PYTHON ?= python
91else
92PYTHON ?= $(shell if type python3 >/dev/null 2>/dev/null; then echo python3; else echo python; fi)
93endif
94
95# See root Makefile
96GEN_FILES ?= yes
97ifdef GEN_FILES
98gen_file_dep =
99else
100gen_file_dep = |
101endif
Gilles Peskine4392fc12023-12-22 11:49:35 +0100102
103default: all
104
105$(MBEDLIBS):
Paul Elliott7ed1cf52024-01-05 18:10:44 +0000106 $(MAKE) -C $(MBEDTLS_PATH)/library
Gilles Peskine4392fc12023-12-22 11:49:35 +0100107
108neat: clean
109ifndef WINDOWS
110 rm -f $(GENERATED_FILES)
111else
112 for %f in ($(subst /,\,$(GENERATED_FILES))) if exist %f del /Q /F %f
113endif
Gilles Peskine0ae58dd2024-01-02 23:11:24 +0100114
115# Auxiliary modules used by tests and some sample programs
116MBEDTLS_CORE_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard \
117 ${MBEDTLS_TEST_PATH}/src/*.c \
118 ${MBEDTLS_TEST_PATH}/src/drivers/*.c \
119 ))
120# Additional auxiliary modules for TLS testing
121MBEDTLS_TLS_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard \
122 ${MBEDTLS_TEST_PATH}/src/test_helpers/*.c \
123 ))
124
125MBEDTLS_TEST_OBJS = $(MBEDTLS_CORE_TEST_OBJS) $(MBEDTLS_TLS_TEST_OBJS)