Makefile 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. include ../../Scripts/Makefile.configs
  2. include ../../Scripts/Makefile.rules
  3. include ../src/host/$(PAL_HOST)/Makefile.am
  4. CFLAGS += -I../include/lib -I../include -I../include/pal -Icrypto/mbedtls/include -I../include/host/$(PAL_HOST)
  5. CRYPTO_PROVIDER ?= mbedtls
  6. # Select which crypto adpater you want to use here. This has to match
  7. # the #define in pal_crypto.h.
  8. #
  9. # Unfortunately, we cannot use just one .c file for the adapter. The LibOS
  10. # shim links against the crypto library, but it doesn't use Diffie-Hellman.
  11. # If the Diffie-Hellman stubs are in the same .o file as the SHA1 stubs,
  12. # this pulls Diffie-Hellman code into LibOS shim, resulting in unsatisfied
  13. # symbols.
  14. ifeq ($(CRYPTO_PROVIDER),mbedtls)
  15. crypto_mbedtls_library_objs = \
  16. crypto/mbedtls/library/aes.o \
  17. crypto/mbedtls/library/aesni.o \
  18. crypto/mbedtls/library/asn1parse.o \
  19. crypto/mbedtls/library/base64.o \
  20. crypto/mbedtls/library/bignum.o \
  21. crypto/mbedtls/library/cipher.o \
  22. crypto/mbedtls/library/cipher_wrap.o \
  23. crypto/mbedtls/library/cmac.o \
  24. crypto/mbedtls/library/ctr_drbg.o \
  25. crypto/mbedtls/library/dhm.o \
  26. crypto/mbedtls/library/entropy.o \
  27. crypto/mbedtls/library/gcm.o \
  28. crypto/mbedtls/library/md.o \
  29. crypto/mbedtls/library/md_wrap.o \
  30. crypto/mbedtls/library/oid.o \
  31. crypto/mbedtls/library/platform_util.o \
  32. crypto/mbedtls/library/rsa.o \
  33. crypto/mbedtls/library/rsa_internal.o \
  34. crypto/mbedtls/library/sha256.o \
  35. crypto/mbedtls/library/ssl_ciphersuites.o \
  36. crypto/mbedtls/library/ssl_cli.o \
  37. crypto/mbedtls/library/ssl_srv.o \
  38. crypto/mbedtls/library/ssl_tls.o
  39. objs += $(crypto_mbedtls_library_objs)
  40. endif
  41. MBEDTLS_VERSION ?= 2.16.3
  42. MBEDTLS_SRC ?= mbedtls-$(MBEDTLS_VERSION).tar.gz
  43. MBEDTLS_URI ?= https://github.com/ARMmbed/mbedtls/archive/
  44. MBEDTLS_CHECKSUM ?= ec72ecf39275327f52b5ee9787271313a0d2960e7342b488d223a118ba164caa
  45. crypto/$(MBEDTLS_SRC):
  46. ../../Scripts/download --output $@ --url $(MBEDTLS_URI)/$(MBEDTLS_SRC) --sha256 $(MBEDTLS_CHECKSUM)
  47. ifeq ($(DEBUG),1)
  48. MBED_BUILD_TYPE=Debug
  49. else
  50. MBED_BUILD_TYPE=Release
  51. endif
  52. # First, build mbedtls library against system's glibc and install in ../install. This library is
  53. # used by, for example, LibOS test cases. Second, prepare mbedtls directory to be used during PAL
  54. # build. A custom config.h header replaces libc dependencies with PAL-specific alternatives.
  55. crypto/mbedtls/CMakeLists.txt: crypto/$(MBEDTLS_SRC)
  56. cd crypto && tar -mxzf $(MBEDTLS_SRC)
  57. mv crypto/mbedtls-mbedtls-$(MBEDTLS_VERSION) crypto/mbedtls
  58. mkdir crypto/mbedtls/install
  59. cd crypto/mbedtls && ./scripts/config.pl set MBEDTLS_CMAC_C && make DESTDIR=install install .
  60. $(RM) crypto/mbedtls/include/mbedtls/config.h
  61. crypto/mbedtls/include/mbedtls/config.h: crypto/config.h crypto/mbedtls/CMakeLists.txt
  62. cp crypto/config.h crypto/mbedtls/include/mbedtls
  63. crypto/mbedtls/library/aes.c: crypto/mbedtls/CMakeLists.txt crypto/mbedtls/include/mbedtls/config.h
  64. $(filter-out crypto/mbedtls/library/aes.c,$(patsubst %.o,%.c,$(crypto_mbedtls_library_objs))): crypto/mbedtls/library/aes.c
  65. objs += \
  66. crypto/udivmodti4.o \
  67. graphene/config.o \
  68. graphene/path.o \
  69. network/hton.o \
  70. network/inet_pton.o \
  71. stdlib/printfmt.o \
  72. string/atoi.o \
  73. string/memcmp.o \
  74. string/memcpy.o \
  75. string/memset.o \
  76. string/strchr.o \
  77. string/strcmp.o \
  78. string/strendswith.o \
  79. string/strlen.o \
  80. string/wordcopy.o
  81. $(addprefix $(target),crypto/adapters/mbedtls_adapter.o crypto/adapters/mbedtls_dh.o crypto/adapters/mbedtls_encoding.o): crypto/mbedtls/library/aes.c
  82. ifeq ($(CRYPTO_PROVIDER),mbedtls)
  83. CFLAGS += -DCRYPTO_USE_MBEDTLS -mrdrnd
  84. objs += crypto/adapters/mbedtls_adapter.o
  85. objs += crypto/adapters/mbedtls_dh.o
  86. objs += crypto/adapters/mbedtls_encoding.o
  87. endif
  88. .PHONY: all
  89. all: $(target)graphene-lib.a
  90. $(target)graphene-lib.a: $(addprefix $(target),$(objs))
  91. @mkdir -p $(dir $@)
  92. $(call cmd,ar_a_o)
  93. $(target)%.o: %.c
  94. @mkdir -p $(dir $@)
  95. $(call cmd,cc_o_c)
  96. ifeq ($(filter %clean,$(MAKECMDGOALS)),)
  97. -include $(patsubst %.o,%.d,$(addprefix $(target),$(objs)))
  98. endif
  99. .PHONY: clean
  100. clean:
  101. $(RM) $(objs) graphene-lib.a
  102. .PHONY: distclean
  103. distclean: clean
  104. $(RM) -r crypto/$(MBEDTLS_SRC) crypto/mbedtls