blob: a5e023e1782c164a6ba7a05efd184ab7c8b100ec [file] [log] [blame]
Tom Rini0344c602024-10-08 13:56:50 -06001ifndef MBEDTLS_PATH
2MBEDTLS_PATH := ..
3endif
4
5GENERATED_FILES := \
6 error.c version_features.c \
7 ssl_debug_helpers_generated.c \
8 psa_crypto_driver_wrappers.h \
9 psa_crypto_driver_wrappers_no_static.c
10
11ifneq ($(GENERATED_FILES),$(wildcard $(GENERATED_FILES)))
12 ifeq (,$(wildcard $(MBEDTLS_PATH)/framework/exported.make))
13 # Use the define keyword to get a multi-line message.
14 # GNU make appends ". Stop.", so tweak the ending of our message accordingly.
15 define error_message
16$(MBEDTLS_PATH)/framework/exported.make not found.
17Run `git submodule update --init` to fetch the submodule contents.
18This is a fatal error
19 endef
20 $(error $(error_message))
21 endif
22 include $(MBEDTLS_PATH)/framework/exported.make
23endif
24
25# Also see "include/mbedtls/mbedtls_config.h"
26
27CFLAGS ?= -O2
28WARNING_CFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral
29LDFLAGS ?=
30
31# Include ../include for public headers and . for private headers.
32# Note that . needs to be included explicitly for the sake of library
33# files that are not in the /library directory (which currently means
34# under /3rdparty).
35LOCAL_CFLAGS = $(WARNING_CFLAGS) -I. -I../include -D_FILE_OFFSET_BITS=64
36LOCAL_LDFLAGS =
37
38ifdef DEBUG
39LOCAL_CFLAGS += -g3
40endif
41
42# MicroBlaze specific options:
43# CFLAGS += -mno-xl-soft-mul -mxl-barrel-shift
44
45# To compile on Plan9:
46# CFLAGS += -D_BSD_EXTENSION
47
48PERL ?= perl
49
50ifdef WINDOWS
51PYTHON ?= python
52else
53PYTHON ?= $(shell if type python3 >/dev/null 2>/dev/null; then echo python3; else echo python; fi)
54endif
55
56# if were running on Windows build for Windows
57ifdef WINDOWS
58WINDOWS_BUILD=1
59else ifeq ($(shell uname -s),Darwin)
60ifeq ($(AR),ar)
61APPLE_BUILD ?= 1
62endif
63endif
64
65ifdef WINDOWS_BUILD
66LOCAL_LDFLAGS += -lbcrypt
67endif
68
69# To compile as a shared library:
70ifdef SHARED
71# all code is position-indep with mingw, avoid warning about useless flag
72ifndef WINDOWS_BUILD
73LOCAL_CFLAGS += -fPIC -fpic
74endif
75endif
76
77SOEXT_TLS?=so.21
78SOEXT_X509?=so.7
79SOEXT_CRYPTO?=so.16
80
81# Set AR_DASH= (empty string) to use an ar implementation that does not accept
82# the - prefix for command line options (e.g. llvm-ar)
83AR_DASH ?= -
84
85ARFLAGS = $(AR_DASH)src
86ifdef APPLE_BUILD
87ifneq ($(APPLE_BUILD),0)
88ARFLAGS = $(AR_DASH)Src
89RLFLAGS = -no_warning_for_no_symbols -c
90RL ?= ranlib
91endif
92endif
93
94DLEXT ?= so
95ifdef WINDOWS_BUILD
96# Windows shared library extension:
97DLEXT = dll
98else ifdef APPLE_BUILD
99ifneq ($(APPLE_BUILD),0)
100# Mac OS X shared library extension:
101DLEXT = dylib
102endif
103endif
104
105OBJS_CRYPTO= \
106 aes.o \
107 aesni.o \
108 aesce.o \
109 aria.o \
110 asn1parse.o \
111 asn1write.o \
112 base64.o \
113 bignum.o \
114 bignum_core.o \
115 bignum_mod.o \
116 bignum_mod_raw.o \
117 block_cipher.o \
118 camellia.o \
119 ccm.o \
120 chacha20.o \
121 chachapoly.o \
122 cipher.o \
123 cipher_wrap.o \
124 cmac.o \
125 constant_time.o \
126 ctr_drbg.o \
127 des.o \
128 dhm.o \
129 ecdh.o \
130 ecdsa.o \
131 ecjpake.o \
132 ecp.o \
133 ecp_curves.o \
134 ecp_curves_new.o \
135 entropy.o \
136 entropy_poll.o \
137 error.o \
138 gcm.o \
139 hkdf.o \
140 hmac_drbg.o \
141 lmots.o \
142 lms.o \
143 md.o \
144 md5.o \
145 memory_buffer_alloc.o \
146 nist_kw.o \
147 oid.o \
148 padlock.o \
149 pem.o \
150 pk.o \
151 pk_ecc.o \
152 pk_wrap.o \
153 pkcs12.o \
154 pkcs5.o \
155 pkparse.o \
156 pkwrite.o \
157 platform.o \
158 platform_util.o \
159 poly1305.o \
160 psa_crypto.o \
161 psa_crypto_aead.o \
162 psa_crypto_cipher.o \
163 psa_crypto_client.o \
164 psa_crypto_driver_wrappers_no_static.o \
165 psa_crypto_ecp.o \
166 psa_crypto_ffdh.o \
167 psa_crypto_hash.o \
168 psa_crypto_mac.o \
169 psa_crypto_pake.o \
170 psa_crypto_rsa.o \
171 psa_crypto_se.o \
172 psa_crypto_slot_management.o \
173 psa_crypto_storage.o \
174 psa_its_file.o \
175 psa_util.o \
176 ripemd160.o \
177 rsa.o \
178 rsa_alt_helpers.o \
179 sha1.o \
180 sha256.o \
181 sha512.o \
182 sha3.o \
183 threading.o \
184 timing.o \
185 version.o \
186 version_features.o \
187 # This line is intentionally left blank
188
189include ../3rdparty/Makefile.inc
190LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES)
191OBJS_CRYPTO+=$(THIRDPARTY_CRYPTO_OBJECTS)
192
193OBJS_X509= \
194 x509.o \
195 x509_create.o \
196 x509_crl.o \
197 x509_crt.o \
198 x509_csr.o \
199 x509write.o \
200 x509write_crt.o \
201 x509write_csr.o \
202 pkcs7.o \
203 # This line is intentionally left blank
204
205OBJS_TLS= \
206 debug.o \
207 mps_reader.o \
208 mps_trace.o \
209 net_sockets.o \
210 ssl_cache.o \
211 ssl_ciphersuites.o \
212 ssl_client.o \
213 ssl_cookie.o \
214 ssl_debug_helpers_generated.o \
215 ssl_msg.o \
216 ssl_ticket.o \
217 ssl_tls.o \
218 ssl_tls12_client.o \
219 ssl_tls12_server.o \
220 ssl_tls13_keys.o \
221 ssl_tls13_client.o \
222 ssl_tls13_server.o \
223 ssl_tls13_generic.o \
224 # This line is intentionally left blank
225
226.SILENT:
227
228.PHONY: all static shared clean
229
230ifndef SHARED
231all: static
232else
233all: shared static
234endif
235
236static: libmbedcrypto.a libmbedx509.a libmbedtls.a
237 cd ../tests && echo "This is a seedfile that contains 64 bytes (65 on Windows)......" > seedfile
238
239shared: libmbedcrypto.$(DLEXT) libmbedx509.$(DLEXT) libmbedtls.$(DLEXT)
240
241# Windows builds under Mingw can fail if make tries to create archives in the same
242# directory at the same time - see https://bugs.launchpad.net/gcc-arm-embedded/+bug/1848002.
243# This forces builds of the .a files to be serialised.
244ifdef WINDOWS
245libmbedtls.a: | libmbedx509.a
246libmbedx509.a: | libmbedcrypto.a
247endif
248
249# tls
250libmbedtls.a: $(OBJS_TLS)
251 echo " AR $@"
252 $(AR) $(ARFLAGS) $@ $(OBJS_TLS)
253ifdef APPLE_BUILD
254ifneq ($(APPLE_BUILD),0)
255 echo " RL $@"
256 $(RL) $(RLFLAGS) $@
257endif
258endif
259
260libmbedtls.$(SOEXT_TLS): $(OBJS_TLS) libmbedx509.so
261 echo " LD $@"
262 $(CC) -shared -Wl,-soname,$@ -o $@ $(OBJS_TLS) -L. -lmbedx509 -lmbedcrypto $(LOCAL_LDFLAGS) $(LDFLAGS)
263
264ifneq ($(SOEXT_TLS),so)
265libmbedtls.so: libmbedtls.$(SOEXT_TLS)
266 echo " LN $@ -> $<"
267 ln -sf $< $@
268endif
269
270libmbedtls.dylib: $(OBJS_TLS) libmbedx509.dylib
271 echo " LD $@"
272 $(CC) -dynamiclib -o $@ $(OBJS_TLS) -L. -lmbedx509 -lmbedcrypto $(LOCAL_LDFLAGS) $(LDFLAGS)
273
274libmbedtls.dll: $(OBJS_TLS) libmbedx509.dll
275 echo " LD $@"
276 $(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS_TLS) -lws2_32 -lwinmm -lgdi32 -L. -lmbedx509 -lmbedcrypto -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS)
277
278# x509
279libmbedx509.a: $(OBJS_X509)
280 echo " AR $@"
281 $(AR) $(ARFLAGS) $@ $(OBJS_X509)
282ifdef APPLE_BUILD
283ifneq ($(APPLE_BUILD),0)
284 echo " RL $@"
285 $(RL) $(RLFLAGS) $@
286endif
287endif
288
289libmbedx509.$(SOEXT_X509): $(OBJS_X509) libmbedcrypto.so
290 echo " LD $@"
291 $(CC) -shared -Wl,-soname,$@ -o $@ $(OBJS_X509) -L. -lmbedcrypto $(LOCAL_LDFLAGS) $(LDFLAGS)
292
293ifneq ($(SOEXT_X509),so)
294libmbedx509.so: libmbedx509.$(SOEXT_X509)
295 echo " LN $@ -> $<"
296 ln -sf $< $@
297endif
298
299libmbedx509.dylib: $(OBJS_X509) libmbedcrypto.dylib
300 echo " LD $@"
301 $(CC) -dynamiclib -o $@ $(OBJS_X509) -L. -lmbedcrypto $(LOCAL_LDFLAGS) $(LDFLAGS)
302
303libmbedx509.dll: $(OBJS_X509) libmbedcrypto.dll
304 echo " LD $@"
305 $(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS_X509) -lws2_32 -lwinmm -lgdi32 -L. -lmbedcrypto -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS)
306
307# crypto
308libmbedcrypto.a: $(OBJS_CRYPTO)
309 echo " AR $@"
310 $(AR) $(ARFLAGS) $@ $(OBJS_CRYPTO)
311ifdef APPLE_BUILD
312ifneq ($(APPLE_BUILD),0)
313 echo " RL $@"
314 $(RL) $(RLFLAGS) $@
315endif
316endif
317
318libmbedcrypto.$(SOEXT_CRYPTO): $(OBJS_CRYPTO)
319 echo " LD $@"
320 $(CC) -shared -Wl,-soname,$@ -o $@ $(OBJS_CRYPTO) $(LOCAL_LDFLAGS) $(LDFLAGS)
321
322ifneq ($(SOEXT_CRYPTO),so)
323libmbedcrypto.so: libmbedcrypto.$(SOEXT_CRYPTO)
324 echo " LN $@ -> $<"
325 ln -sf $< $@
326endif
327
328libmbedcrypto.dylib: $(OBJS_CRYPTO)
329 echo " LD $@"
330 $(CC) -dynamiclib -o $@ $(OBJS_CRYPTO) $(LOCAL_LDFLAGS) $(LDFLAGS)
331
332libmbedcrypto.dll: $(OBJS_CRYPTO)
333 echo " LD $@"
334 $(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS_CRYPTO) -lws2_32 -lwinmm -lgdi32 -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS)
335
336.c.o:
337 echo " CC $<"
338 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -o $@ -c $<
339
340.PHONY: generated_files
341generated_files: $(GENERATED_FILES)
342
343# See root Makefile
344GEN_FILES ?=
345ifdef GEN_FILES
346gen_file_dep =
347else
348gen_file_dep = |
349endif
350
351error.c: $(gen_file_dep) ../scripts/generate_errors.pl
352error.c: $(gen_file_dep) ../scripts/data_files/error.fmt
353error.c: $(gen_file_dep) $(filter-out %config%,$(wildcard ../include/mbedtls/*.h))
354error.c:
355 echo " Gen $@"
356 $(PERL) ../scripts/generate_errors.pl
357
358ssl_debug_helpers_generated.c: $(gen_file_dep) ../scripts/generate_ssl_debug_helpers.py
359ssl_debug_helpers_generated.c: $(gen_file_dep) $(filter-out %config%,$(wildcard ../include/mbedtls/*.h))
360ssl_debug_helpers_generated.c:
361 echo " Gen $@"
362 $(PYTHON) ../scripts/generate_ssl_debug_helpers.py --mbedtls-root .. .
363
364version_features.c: $(gen_file_dep) ../scripts/generate_features.pl
365version_features.c: $(gen_file_dep) ../scripts/data_files/version_features.fmt
366## The generated file only depends on the options that are present in mbedtls_config.h,
367## not on which options are set. To avoid regenerating this file all the time
368## when switching between configurations, don't declare mbedtls_config.h as a
369## dependency. Remove this file from your working tree if you've just added or
370## removed an option in mbedtls_config.h.
371#version_features.c: ../include/mbedtls/mbedtls_config.h
372version_features.c:
373 echo " Gen $@"
374 $(PERL) ../scripts/generate_features.pl
375
376GENERATED_WRAPPER_FILES = \
377 psa_crypto_driver_wrappers.h \
378 psa_crypto_driver_wrappers_no_static.c
379$(GENERATED_WRAPPER_FILES): ../scripts/generate_driver_wrappers.py
380$(GENERATED_WRAPPER_FILES): ../scripts/data_files/driver_templates/psa_crypto_driver_wrappers.h.jinja
381$(GENERATED_WRAPPER_FILES): ../scripts/data_files/driver_templates/psa_crypto_driver_wrappers_no_static.c.jinja
382$(GENERATED_WRAPPER_FILES):
383 echo " Gen $(GENERATED_WRAPPER_FILES)"
384 $(PYTHON) ../scripts/generate_driver_wrappers.py
385
386psa_crypto.o:psa_crypto_driver_wrappers.h
387
388clean:
389ifndef WINDOWS
390 rm -f *.o libmbed*
391 rm -f $(THIRDPARTY_CRYPTO_OBJECTS)
392else
393 if exist *.o del /Q /F *.o
394 if exist libmbed* del /Q /F libmbed*
395 del /Q /F del_errors_out_if_the_file_list_is_empty_but_not_if_a_file_does_not_exist $(subst /,\,$(THIRDPARTY_CRYPTO_OBJECTS))
396endif
397
398neat: clean
399ifndef WINDOWS
400 rm -f $(GENERATED_FILES)
401else
402 for %f in ($(subst /,\,$(GENERATED_FILES))) if exist %f del /Q /F %f
403endif