blob: 2714bcd32769fda5e5e47ffd84e147b4e8f33af0 [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 Peskinef3d1ae12023-12-22 11:40:58 +01007CFLAGS ?= -O2
8WARNING_CFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral
9WARNING_CXXFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral
10LDFLAGS ?=
11
Paul Elliott7ed1cf52024-01-05 18:10:44 +000012LOCAL_CFLAGS = $(WARNING_CFLAGS) -I$(MBEDTLS_TEST_PATH)/include -I$(MBEDTLS_PATH)/include -D_FILE_OFFSET_BITS=64
13LOCAL_CXXFLAGS = $(WARNING_CXXFLAGS) -I$(MBEDTLS_PATH)/include -I$(MBEDTLS_PATH)/tests/include -D_FILE_OFFSET_BITS=64
Gilles Peskinef3d1ae12023-12-22 11:40:58 +010014LOCAL_LDFLAGS = ${MBEDTLS_TEST_OBJS} \
Paul Elliott7ed1cf52024-01-05 18:10:44 +000015 -L$(MBEDTLS_PATH)/library \
Gilles Peskinef3d1ae12023-12-22 11:40:58 +010016 -lmbedtls$(SHARED_SUFFIX) \
17 -lmbedx509$(SHARED_SUFFIX) \
18 -lmbedcrypto$(SHARED_SUFFIX)
Gilles Peskine076fd252023-12-22 11:45:53 +010019
Paul Elliott7ed1cf52024-01-05 18:10:44 +000020include $(MBEDTLS_PATH)/3rdparty/Makefile.inc
Gilles Peskine076fd252023-12-22 11:45:53 +010021LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES)
22
23ifndef SHARED
Paul Elliott7ed1cf52024-01-05 18:10:44 +000024MBEDLIBS=$(MBEDTLS_PATH)/library/libmbedcrypto.a $(MBEDTLS_PATH)/library/libmbedx509.a $(MBEDTLS_PATH)/library/libmbedtls.a
Gilles Peskine076fd252023-12-22 11:45:53 +010025else
Paul Elliott7ed1cf52024-01-05 18:10:44 +000026MBEDLIBS=$(MBEDTLS_PATH)/library/libmbedcrypto.$(DLEXT) $(MBEDTLS_PATH)/library/libmbedx509.$(DLEXT) $(MBEDTLS_PATH)/library/libmbedtls.$(DLEXT)
Gilles Peskine076fd252023-12-22 11:45:53 +010027endif
28
29ifdef DEBUG
30LOCAL_CFLAGS += -g3
31endif
32
33# if we're running on Windows, build for Windows
34ifdef WINDOWS
35WINDOWS_BUILD=1
36endif
37
Gilles Peskinef3316f12023-12-22 18:30:37 +010038## Usage: $(call remove_enabled_options,PREPROCESSOR_INPUT)
39## Remove the preprocessor symbols that are set in the current configuration
Gilles Peskine21570cf2023-12-22 11:49:50 +010040## from PREPROCESSOR_INPUT. Also normalize whitespace.
41## Example:
Gilles Peskinecd06a812024-01-02 18:14:40 +010042## $(call remove_enabled_options,MBEDTLS_FOO MBEDTLS_BAR)
Gilles Peskine21570cf2023-12-22 11:49:50 +010043## This expands to an empty string "" if MBEDTLS_FOO and MBEDTLS_BAR are both
Gilles Peskinef3316f12023-12-22 18:30:37 +010044## enabled, to "MBEDTLS_FOO" if MBEDTLS_BAR is enabled but MBEDTLS_FOO is
Gilles Peskine21570cf2023-12-22 11:49:50 +010045## disabled, etc.
46##
47## This only works with a Unix-like shell environment (Bourne/POSIX-style shell
48## and standard commands) and a Unix-like compiler (supporting -E). In
49## other environments, the output is likely to be empty.
Gilles Peskinef3316f12023-12-22 18:30:37 +010050define remove_enabled_options
Gilles Peskine21570cf2023-12-22 11:49:50 +010051$(strip $(shell
52 exec 2>/dev/null;
53 { echo '#include <mbedtls/build_info.h>'; echo $(1); } |
54 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -E - |
55 tail -n 1
56))
57endef
58
Gilles Peskine076fd252023-12-22 11:45:53 +010059ifdef WINDOWS_BUILD
60 DLEXT=dll
61 EXEXT=.exe
62 LOCAL_LDFLAGS += -lws2_32 -lbcrypt
63 ifdef SHARED
64 SHARED_SUFFIX=.$(DLEXT)
65 endif
66
67else # Not building for Windows
68 DLEXT ?= so
69 EXEXT=
70 SHARED_SUFFIX=
Gilles Peskine21570cf2023-12-22 11:49:50 +010071 ifndef THREADING
72 # Auto-detect configurations with pthread.
Gilles Peskinef3316f12023-12-22 18:30:37 +010073 # If the call to remove_enabled_options returns "control", the symbols
Gilles Peskine2337a3b2023-12-22 13:25:18 +010074 # are confirmed set and we link with pthread.
75 # If the auto-detection fails, the result of the call is empty and
76 # we keep THREADING undefined.
Gilles Peskinef3316f12023-12-22 18:30:37 +010077 ifeq (control,$(call remove_enabled_options,control MBEDTLS_THREADING_C MBEDTLS_THREADING_PTHREAD))
Gilles Peskine21570cf2023-12-22 11:49:50 +010078 THREADING := pthread
79 endif
80 endif
Gilles Peskine076fd252023-12-22 11:45:53 +010081
82 ifeq ($(THREADING),pthread)
83 LOCAL_LDFLAGS += -lpthread
84 endif
85endif
86
87ifdef WINDOWS
88PYTHON ?= python
89else
90PYTHON ?= $(shell if type python3 >/dev/null 2>/dev/null; then echo python3; else echo python; fi)
91endif
92
93# See root Makefile
94GEN_FILES ?= yes
95ifdef GEN_FILES
96gen_file_dep =
97else
98gen_file_dep = |
99endif
Gilles Peskine4392fc12023-12-22 11:49:35 +0100100
101default: all
102
103$(MBEDLIBS):
Paul Elliott7ed1cf52024-01-05 18:10:44 +0000104 $(MAKE) -C $(MBEDTLS_PATH)/library
Gilles Peskine4392fc12023-12-22 11:49:35 +0100105
106neat: clean
107ifndef WINDOWS
108 rm -f $(GENERATED_FILES)
109else
110 for %f in ($(subst /,\,$(GENERATED_FILES))) if exist %f del /Q /F %f
111endif
Gilles Peskine0ae58dd2024-01-02 23:11:24 +0100112
113# Auxiliary modules used by tests and some sample programs
114MBEDTLS_CORE_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard \
115 ${MBEDTLS_TEST_PATH}/src/*.c \
116 ${MBEDTLS_TEST_PATH}/src/drivers/*.c \
117 ))
118# Additional auxiliary modules for TLS testing
119MBEDTLS_TLS_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard \
120 ${MBEDTLS_TEST_PATH}/src/test_helpers/*.c \
121 ))
122
123MBEDTLS_TEST_OBJS = $(MBEDTLS_CORE_TEST_OBJS) $(MBEDTLS_TLS_TEST_OBJS)