Makefile 11 KB

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