blob: 6d2fbc3e2b019a79257f402156d5dd760984d97a [file] [log] [blame]
Gilles Peskinef3d1ae12023-12-22 11:40:58 +01001# To compile on SunOS: add "-lsocket -lnsl" to LDFLAGS
2
3CFLAGS ?= -O2
4WARNING_CFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral
5WARNING_CXXFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral
6LDFLAGS ?=
7
8LOCAL_CFLAGS = $(WARNING_CFLAGS) -I../tests/include -I../include -D_FILE_OFFSET_BITS=64
9LOCAL_CXXFLAGS = $(WARNING_CXXFLAGS) -I../include -I../tests/include -D_FILE_OFFSET_BITS=64
10LOCAL_LDFLAGS = ${MBEDTLS_TEST_OBJS} \
11 -L../library \
12 -lmbedtls$(SHARED_SUFFIX) \
13 -lmbedx509$(SHARED_SUFFIX) \
14 -lmbedcrypto$(SHARED_SUFFIX)
Gilles Peskine076fd252023-12-22 11:45:53 +010015
16include ../3rdparty/Makefile.inc
17LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES)
18
19ifndef SHARED
20MBEDLIBS=../library/libmbedcrypto.a ../library/libmbedx509.a ../library/libmbedtls.a
21else
22MBEDLIBS=../library/libmbedcrypto.$(DLEXT) ../library/libmbedx509.$(DLEXT) ../library/libmbedtls.$(DLEXT)
23endif
24
25ifdef DEBUG
26LOCAL_CFLAGS += -g3
27endif
28
29# if we're running on Windows, build for Windows
30ifdef WINDOWS
31WINDOWS_BUILD=1
32endif
33
Gilles Peskine21570cf2023-12-22 11:49:50 +010034## Usage: $(call remove_unset_options,PREPROCESSOR_INPUT)
35## Remove the preprocessor symbols that are not set in the current configuration
36## from PREPROCESSOR_INPUT. Also normalize whitespace.
37## Example:
38## $(call remove_unset_options,MBEDTLS_FOO MBEDTLS_BAR)
39## This expands to an empty string "" if MBEDTLS_FOO and MBEDTLS_BAR are both
40## disabled, to "MBEDTLS_FOO" if MBEDTLS_BAR is enabled but MBEDTLS_FOO is
41## disabled, etc.
42##
43## This only works with a Unix-like shell environment (Bourne/POSIX-style shell
44## and standard commands) and a Unix-like compiler (supporting -E). In
45## other environments, the output is likely to be empty.
46define remove_unset_options
47$(strip $(shell
48 exec 2>/dev/null;
49 { echo '#include <mbedtls/build_info.h>'; echo $(1); } |
50 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -E - |
51 tail -n 1
52))
53endef
54
Gilles Peskine076fd252023-12-22 11:45:53 +010055ifdef WINDOWS_BUILD
56 DLEXT=dll
57 EXEXT=.exe
58 LOCAL_LDFLAGS += -lws2_32 -lbcrypt
59 ifdef SHARED
60 SHARED_SUFFIX=.$(DLEXT)
61 endif
62
63else # Not building for Windows
64 DLEXT ?= so
65 EXEXT=
66 SHARED_SUFFIX=
Gilles Peskine21570cf2023-12-22 11:49:50 +010067 ifndef THREADING
68 # Auto-detect configurations with pthread.
Gilles Peskine2337a3b2023-12-22 13:25:18 +010069 # If the call to remove_unset_options returns "control", the symbols
70 # are confirmed set and we link with pthread.
71 # If the auto-detection fails, the result of the call is empty and
72 # we keep THREADING undefined.
Gilles Peskine21570cf2023-12-22 11:49:50 +010073 ifeq (control,$(call remove_unset_options,control MBEDTLS_THREADING_C MBEDTLS_THREADING_PTHREAD))
74 THREADING := pthread
75 endif
76 endif
Gilles Peskine076fd252023-12-22 11:45:53 +010077
78 ifeq ($(THREADING),pthread)
79 LOCAL_LDFLAGS += -lpthread
80 endif
81endif
82
83ifdef WINDOWS
84PYTHON ?= python
85else
86PYTHON ?= $(shell if type python3 >/dev/null 2>/dev/null; then echo python3; else echo python; fi)
87endif
88
89# See root Makefile
90GEN_FILES ?= yes
91ifdef GEN_FILES
92gen_file_dep =
93else
94gen_file_dep = |
95endif
Gilles Peskine4392fc12023-12-22 11:49:35 +010096
97default: all
98
99$(MBEDLIBS):
100 $(MAKE) -C ../library
101
102neat: clean
103ifndef WINDOWS
104 rm -f $(GENERATED_FILES)
105else
106 for %f in ($(subst /,\,$(GENERATED_FILES))) if exist %f del /Q /F %f
107endif