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