Makefile 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 cipher_wrap cmac dhm md md_wrap oid rsa rsa_internal sha256 platform_util)
  31. endif
  32. MBEDTLS_VERSION ?= 2.16.3
  33. MBEDTLS_SRC ?= mbedtls-$(MBEDTLS_VERSION).tar.gz
  34. MBEDTLS_URI ?= https://github.com/ARMmbed/mbedtls/archive/
  35. MBEDTLS_CHECKSUM ?= ec72ecf39275327f52b5ee9787271313a0d2960e7342b488d223a118ba164caa
  36. crypto/$(MBEDTLS_SRC):
  37. wget --timeout=10 $(MBEDTLS_URI)/$(MBEDTLS_SRC) -O tmp
  38. @[ "`sha256sum tmp`" = "$(MBEDTLS_CHECKSUM) tmp" ] || \
  39. (echo "*** $@ has a wrong checksum ***"; rm -f tmp; exit 255)
  40. mv -f tmp $@
  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. cp crypto/config.h crypto/mbedtls/include/mbedtls
  55. crypto/mbedtls/library/aes.c: crypto/mbedtls/CMakeLists.txt
  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
  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