Makefile 4.0 KB

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