Makefile 3.6 KB

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