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