Makefile 4.0 KB

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