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