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