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