Makefile 3.8 KB

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