Makefile 4.0 KB

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