blob: 7e16bd8953022334afaf5bb19883f3d24ccd8a4a [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +00002# Also see "include/mbedtls/config.h"
Paul Bakker5121ce52009-01-03 21:22:43 +00003
Alon Bar-Levf7a9f302015-02-18 17:55:05 +02004CFLAGS ?= -O2
5WARNING_CFLAGS ?= -Wall -W -Wdeclaration-after-statement
Alon Bar-Levada41052015-02-18 17:47:52 +02006LDFLAGS ?=
Alon Bar-Levf7a9f302015-02-18 17:55:05 +02007
Arto Kinnunen5e639ed2019-09-25 17:08:39 +03008# Check test environment. If ../library is available then Mbed TLS is used.
9# Otherwise Mbed OS environment is used.
Arto Kinnunen83078022019-09-25 16:10:04 +030010DIR_FOR_MBED_TLS_ENV=../library
11ifneq "$(wildcard $(DIR_FOR_MBED_TLS_ENV) )" ""
Arto Kinnunenc0d2fa72019-09-26 10:33:56 +030012 # Set include dirs for Mbed TLS test environment
Arto Kinnunen83078022019-09-25 16:10:04 +030013 INCLUDE_DIRS=-I../include
14else
Arto Kinnunenc0d2fa72019-09-26 10:33:56 +030015 # Set include dirs for Mbed OS test environment
16 INCLUDE_DIRS=-I../inc
17 CFLAGS += "-DMBEDTLS_CONFIG_FILE=\"mbedtls/test_config.h\""
Arto Kinnunen83078022019-09-25 16:10:04 +030018endif
19
20LOCAL_CFLAGS = $(WARNING_CFLAGS) $(INCLUDE_DIRS) -D_FILE_OFFSET_BITS=64
Arto Kinnunen83078022019-09-25 16:10:04 +030021
Alon Bar-Levada41052015-02-18 17:47:52 +020022LOCAL_LDFLAGS =
Paul Bakker5121ce52009-01-03 21:22:43 +000023
Paul Bakkerc7ffd362012-04-05 12:08:29 +000024ifdef DEBUG
Alon Bar-Levf7a9f302015-02-18 17:55:05 +020025LOCAL_CFLAGS += -g3
Paul Bakkerc7ffd362012-04-05 12:08:29 +000026endif
27
Paul Bakkerad7eca22010-03-24 06:46:47 +000028# MicroBlaze specific options:
29# CFLAGS += -mno-xl-soft-mul -mxl-barrel-shift
Paul Bakker5121ce52009-01-03 21:22:43 +000030
Paul Bakkerad7eca22010-03-24 06:46:47 +000031# To compile on Plan9:
32# CFLAGS += -D_BSD_EXTENSION
Paul Bakker5121ce52009-01-03 21:22:43 +000033
Manuel Pégourié-Gonnard02ba5782015-02-18 13:42:26 +000034# if were running on Windows build for Windows
35ifdef WINDOWS
36WINDOWS_BUILD=1
Andres Amaya Garciac471cd72018-06-13 09:28:04 +010037else ifeq ($(shell uname -s),Darwin)
Andres Amaya Garciae3402ce2018-06-20 10:43:21 +010038ifeq ($(AR),ar)
Andres Amaya Garcia1d937592018-06-13 10:04:58 +010039APPLE_BUILD ?= 1
Manuel Pégourié-Gonnard02ba5782015-02-18 13:42:26 +000040endif
Manuel Pégourié-Gonnard02ba5782015-02-18 13:42:26 +000041endif
42
Paul Bakkerad7eca22010-03-24 06:46:47 +000043# To compile as a shared library:
Paul Bakker9a736322012-11-14 12:39:52 +000044ifdef SHARED
Manuel Pégourié-Gonnard3cfb3452015-02-13 13:34:08 +000045# all code is position-indep with mingw, avoid warning about useless flag
Manuel Pégourié-Gonnard02ba5782015-02-18 13:42:26 +000046ifndef WINDOWS_BUILD
Alon Bar-Levf7a9f302015-02-18 17:55:05 +020047LOCAL_CFLAGS += -fPIC -fpic
Paul Bakker9a736322012-11-14 12:39:52 +000048endif
Manuel Pégourié-Gonnard3cfb3452015-02-13 13:34:08 +000049endif
Paul Bakker5121ce52009-01-03 21:22:43 +000050
Simon Butcher4d075cd2018-08-31 15:59:10 +010051SOEXT_TLS=so.12
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +020052SOEXT_X509=so.0
Simon Butcher2fcd3e42018-06-18 14:39:06 +010053SOEXT_CRYPTO=so.3
Paul Bakker33aac372011-08-13 11:47:41 +000054
Antonin Décimod5f47592019-01-23 15:24:37 +010055# Set AR_DASH= (empty string) to use an ar implementation that does not accept
Andres Amaya Garciaceed91b2018-03-25 23:48:39 +010056# the - prefix for command line options (e.g. llvm-ar)
57AR_DASH ?= -
Paul Bakker5121ce52009-01-03 21:22:43 +000058
Andres Amaya Garciac51d6132018-06-19 17:25:34 +010059ARFLAGS = $(AR_DASH)src
Andres Amaya Garcia0e98e882018-05-23 09:19:54 +010060ifdef APPLE_BUILD
Andres Amaya Garciac51d6132018-06-19 17:25:34 +010061ifneq ($(APPLE_BUILD),0)
Andres Amaya Garcia0e98e882018-05-23 09:19:54 +010062ARFLAGS = $(AR_DASH)Src
63RLFLAGS = -no_warning_for_no_symbols -c
64RL ?= ranlib
Andres Amaya Garciac51d6132018-06-19 17:25:34 +010065endif
Andres Amaya Garcia0e98e882018-05-23 09:19:54 +010066endif
67
Andres Amaya Garciac51d6132018-06-19 17:25:34 +010068DLEXT ?= so
Alon Bar-Lev18ba0cc2015-02-14 01:04:58 +020069ifdef WINDOWS_BUILD
Andres Amaya Garcia0e98e882018-05-23 09:19:54 +010070# Windows shared library extension:
71DLEXT = dll
72else ifdef APPLE_BUILD
Andres Amaya Garciac51d6132018-06-19 17:25:34 +010073ifneq ($(APPLE_BUILD),0)
Andres Amaya Garcia0e98e882018-05-23 09:19:54 +010074# Mac OS X shared library extension:
75DLEXT = dylib
Paul Bakkercd5b5292012-05-10 20:49:10 +000076endif
Paul Bakker6083fd22011-12-03 21:45:14 +000077endif
Paul Bakkerbdb912d2012-02-13 23:11:30 +000078
Jarno Lamsa337dad92019-04-25 11:00:41 +030079VPATH = ../tinycrypt
80
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +020081OBJS_CRYPTO= aes.o aesni.o arc4.o \
Manuel Pégourié-Gonnard39b19042018-06-07 12:01:33 +020082 aria.o asn1parse.o asn1write.o \
83 base64.o bignum.o blowfish.o \
84 camellia.o ccm.o chacha20.o \
85 chachapoly.o cipher.o cipher_wrap.o \
Andrzej Kureke4f865d2020-08-08 18:07:40 -040086 cmac.o crc.o ctr_drbg.o \
87 des.o dhm.o ecdh.o \
88 ecdsa.o ecjpake.o ecp.o \
Manuel Pégourié-Gonnard463e09d2015-06-24 11:54:19 +020089 ecp_curves.o entropy.o entropy_poll.o \
90 error.o gcm.o havege.o \
Thomas Fossati656864b2016-07-17 08:51:22 +010091 hkdf.o \
Manuel Pégourié-Gonnard463e09d2015-06-24 11:54:19 +020092 hmac_drbg.o md.o md2.o \
Hanno Becker0e7fc312019-07-17 11:23:12 +010093 md4.o md5.o \
Ron Eldorcb349ac2018-07-15 09:29:47 +030094 memory_buffer_alloc.o nist_kw.o \
95 oid.o padlock.o pem.o \
Manuel Pégourié-Gonnard4ed179f2019-09-19 10:45:14 +020096 pk.o pkcs12.o \
Ron Eldorcb349ac2018-07-15 09:29:47 +030097 pkcs5.o pkparse.o pkwrite.o \
98 platform.o platform_util.o poly1305.o \
Daniel Kingadc32c02016-05-16 18:25:45 -030099 ripemd160.o rsa_internal.o rsa.o \
100 sha1.o sha256.o sha512.o \
101 threading.o timing.o version.o \
Andrzej Kureke4f865d2020-08-08 18:07:40 -0400102 version_features.o xtea.o
103
Manuel Pégourié-Gonnard463e09d2015-06-24 11:54:19 +0200104
Teppo Järvelinffaba552019-09-03 12:33:16 +0300105OBJS_X509= certs.o pkcs11.o x509.o
Manuel Pégourié-Gonnard463e09d2015-06-24 11:54:19 +0200106
Andres AG788aa4a2016-09-14 14:32:09 +0100107OBJS_TLS= debug.o net_sockets.o \
108 ssl_cache.o ssl_ciphersuites.o \
109 ssl_cli.o ssl_cookie.o \
110 ssl_srv.o ssl_ticket.o \
Manuel Pégourié-Gonnard463e09d2015-06-24 11:54:19 +0200111 ssl_tls.o
112
Simon Butcher96998872019-11-22 15:09:39 +0000113# Default to always build TinyCrypt
114ifndef TINYCRYPT_BUILD
115TINYCRYPT_BUILD=1
116endif
117
118ifeq ($(TINYCRYPT_BUILD),1)
119# Add TinyCrypt to the targets and Makefile path
120VPATH = ../tinycrypt
121OBJS_CRYPTO += ecc.o ecc_dh.o ecc_dsa.o
122endif
123
Paul Bakkerad7eca22010-03-24 06:46:47 +0000124.SILENT:
Paul Bakker5121ce52009-01-03 21:22:43 +0000125
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200126.PHONY: all static shared clean
127
Paul Bakker9a736322012-11-14 12:39:52 +0000128ifndef SHARED
Paul Bakker3783d6d2011-07-13 11:25:36 +0000129all: static
Paul Bakker9a736322012-11-14 12:39:52 +0000130else
Manuel Pégourié-Gonnard04a81d52015-01-27 11:24:05 +0100131all: shared static
Paul Bakker9a736322012-11-14 12:39:52 +0000132endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000133
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200134static: libmbedcrypto.a libmbedx509.a libmbedtls.a
Paul Bakker5121ce52009-01-03 21:22:43 +0000135
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200136shared: libmbedcrypto.$(DLEXT) libmbedx509.$(DLEXT) libmbedtls.$(DLEXT)
Manuel Pégourié-Gonnardc26a0922015-01-23 12:51:33 +0000137
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200138# tls
139libmbedtls.a: $(OBJS_TLS)
Paul Bakkerad7eca22010-03-24 06:46:47 +0000140 echo " AR $@"
Andres Amaya Garcia0e98e882018-05-23 09:19:54 +0100141 $(AR) $(ARFLAGS) $@ $(OBJS_TLS)
142ifdef APPLE_BUILD
Andres Amaya Garciac51d6132018-06-19 17:25:34 +0100143ifneq ($(APPLE_BUILD),0)
Paul Bakkerad7eca22010-03-24 06:46:47 +0000144 echo " RL $@"
Andres Amaya Garcia0e98e882018-05-23 09:19:54 +0100145 $(RL) $(RLFLAGS) $@
146endif
Andres Amaya Garciac51d6132018-06-19 17:25:34 +0100147endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000148
Manuel Pégourié-Gonnarded46c432015-08-10 10:17:32 +0200149libmbedtls.$(SOEXT_TLS): $(OBJS_TLS) libmbedx509.so
Paul Bakkerad7eca22010-03-24 06:46:47 +0000150 echo " LD $@"
Manuel Pégourié-Gonnarded46c432015-08-10 10:17:32 +0200151 $(CC) -shared -Wl,-soname,$@ -L. -lmbedcrypto -lmbedx509 $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_TLS)
Paul Bakker5121ce52009-01-03 21:22:43 +0000152
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +0200153libmbedtls.so: libmbedtls.$(SOEXT_TLS)
154 echo " LN $@ -> $<"
155 ln -sf $< $@
Paul Bakkerb0763142013-11-05 11:27:12 +0100156
Mitsuhiro Nakamura5ff2ee52018-02-20 11:58:19 +0900157libmbedtls.dylib: $(OBJS_TLS) libmbedx509.dylib
Paul Bakkerad7eca22010-03-24 06:46:47 +0000158 echo " LD $@"
Mitsuhiro Nakamura5ff2ee52018-02-20 11:58:19 +0900159 $(CC) -dynamiclib -L. -lmbedcrypto -lmbedx509 $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_TLS)
Paul Bakker5121ce52009-01-03 21:22:43 +0000160
Manuel Pégourié-Gonnard111ce9f2015-08-07 12:07:16 +0200161libmbedtls.dll: $(OBJS_TLS) libmbedx509.dll
Paul Bakkerb0763142013-11-05 11:27:12 +0100162 echo " LD $@"
Manuel Pégourié-Gonnard111ce9f2015-08-07 12:07:16 +0200163 $(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS_TLS) -lws2_32 -lwinmm -lgdi32 -L. -lmbedcrypto -lmbedx509 -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS)
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200164
165# x509
166libmbedx509.a: $(OBJS_X509)
167 echo " AR $@"
Andres Amaya Garcia0e98e882018-05-23 09:19:54 +0100168 $(AR) $(ARFLAGS) $@ $(OBJS_X509)
169ifdef APPLE_BUILD
Andres Amaya Garciac51d6132018-06-19 17:25:34 +0100170ifneq ($(APPLE_BUILD),0)
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200171 echo " RL $@"
Andres Amaya Garcia0e98e882018-05-23 09:19:54 +0100172 $(RL) $(RLFLAGS) $@
173endif
Andres Amaya Garciac51d6132018-06-19 17:25:34 +0100174endif
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200175
Manuel Pégourié-Gonnarded46c432015-08-10 10:17:32 +0200176libmbedx509.$(SOEXT_X509): $(OBJS_X509) libmbedcrypto.so
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200177 echo " LD $@"
Manuel Pégourié-Gonnarded46c432015-08-10 10:17:32 +0200178 $(CC) -shared -Wl,-soname,$@ -L. -lmbedcrypto $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_X509)
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200179
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +0200180libmbedx509.so: libmbedx509.$(SOEXT_X509)
181 echo " LN $@ -> $<"
182 ln -sf $< $@
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200183
Mitsuhiro Nakamura5ff2ee52018-02-20 11:58:19 +0900184libmbedx509.dylib: $(OBJS_X509) libmbedcrypto.dylib
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200185 echo " LD $@"
Mitsuhiro Nakamura5ff2ee52018-02-20 11:58:19 +0900186 $(CC) -dynamiclib -L. -lmbedcrypto $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_X509)
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200187
Manuel Pégourié-Gonnard111ce9f2015-08-07 12:07:16 +0200188libmbedx509.dll: $(OBJS_X509) libmbedcrypto.dll
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200189 echo " LD $@"
Manuel Pégourié-Gonnard111ce9f2015-08-07 12:07:16 +0200190 $(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS_X509) -lws2_32 -lwinmm -lgdi32 -L. -lmbedcrypto -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS)
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200191
192# crypto
193libmbedcrypto.a: $(OBJS_CRYPTO)
194 echo " AR $@"
Andres Amaya Garcia0e98e882018-05-23 09:19:54 +0100195 $(AR) $(ARFLAGS) $@ $(OBJS_CRYPTO)
196ifdef APPLE_BUILD
Andres Amaya Garciac51d6132018-06-19 17:25:34 +0100197ifneq ($(APPLE_BUILD),0)
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200198 echo " RL $@"
Andres Amaya Garcia0e98e882018-05-23 09:19:54 +0100199 $(RL) $(RLFLAGS) $@
200endif
Andres Amaya Garciac51d6132018-06-19 17:25:34 +0100201endif
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200202
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +0200203libmbedcrypto.$(SOEXT_CRYPTO): $(OBJS_CRYPTO)
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200204 echo " LD $@"
Manuel Pégourié-Gonnard574ae182015-06-25 14:30:22 +0200205 $(CC) -shared -Wl,-soname,$@ $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_CRYPTO)
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200206
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +0200207libmbedcrypto.so: libmbedcrypto.$(SOEXT_CRYPTO)
208 echo " LN $@ -> $<"
209 ln -sf $< $@
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200210
211libmbedcrypto.dylib: $(OBJS_CRYPTO)
212 echo " LD $@"
213 $(CC) -dynamiclib $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_CRYPTO)
214
215libmbedcrypto.dll: $(OBJS_CRYPTO)
216 echo " LD $@"
Manuel Pégourié-Gonnard8018c282015-08-07 11:55:56 +0200217 $(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS_CRYPTO) -lws2_32 -lwinmm -lgdi32 -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS)
Paul Bakkera585beb2011-06-21 08:59:44 +0000218
Paul Bakkerad7eca22010-03-24 06:46:47 +0000219.c.o:
Paul Bakker96d42da2012-04-05 13:22:07 +0000220 echo " CC $<"
Alon Bar-Levf7a9f302015-02-18 17:55:05 +0200221 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -c $<
Paul Bakker5121ce52009-01-03 21:22:43 +0000222
223clean:
Paul Bakker62f88dc2012-05-10 21:26:28 +0000224ifndef WINDOWS
Manuel Pégourié-Gonnard80eaddf2019-07-30 14:59:54 +0200225 rm -f *.o *.su libmbed*
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200226else
Manuel Pégourié-Gonnard80eaddf2019-07-30 14:59:54 +0200227 del /Q /F *.o *.su libmbed*
Paul Bakker62f88dc2012-05-10 21:26:28 +0000228endif