Makefile 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. include ../src/Makefile.Host
  2. CC = gcc
  3. CFLAGS = -Wall -O2 -std=c11 -fno-builtin -nostdlib \
  4. -I../include/pal -I../lib -I../src
  5. preloads = $(patsubst %.c,%,$(wildcard *.so.c))
  6. executables = $(filter-out $(preloads),$(patsubst %.c,%,$(wildcard *.c))) ..Bootstrap
  7. manifests = manifest $(patsubst %.manifest.template,%.manifest,$(wildcard *.manifest.template))
  8. target = $(executables) $(manifests)
  9. graphene_lib = .lib/graphene-lib.a
  10. pal_lib = ../../Runtime/libpal-$(PAL_HOST).so
  11. .PHONY: default
  12. default: all
  13. include ../../Makefile.configs
  14. include ../../Makefile.rules
  15. include ../src/Makefile.Test
  16. RUNTIME_DIR = $(CURDIR)/../../Runtime
  17. export PAL_LOADER = $(RUNTIME_DIR)/pal-$(PAL_HOST)
  18. .PHONY: all
  19. all: $(call expand_target,$(target)) $(preloads)
  20. .PHONY: sgx-tokens
  21. sgx-tokens: $(call expand_target_to_token,$(target))
  22. ifeq ($(DEBUG),1)
  23. CC += -g
  24. endif
  25. export DEBUG
  26. ifeq ($(WERROR),1)
  27. CFLAGS += -Werror
  28. endif
  29. # To enable tests for remote attestation, please provide RA_CLIENT_SPID and RA_CLIENT_KEY
  30. # in the environment variables.
  31. # To obtain a SPID, register in the Intel API portal:
  32. # https://api.portal.trustedservices.intel.com/EPID-attestation
  33. manifest_rules = \
  34. -e 's:\$$(PAL):$(abspath ../../Runtime/pal_loader):g' \
  35. -e 's:\$$(PWD):$(shell pwd)/:g' \
  36. -e 's:\$$(RA_CLIENT_SPID):$(RA_CLIENT_SPID):g' \
  37. -e 's:\$$(RA_CLIENT_KEY):$(RA_CLIENT_KEY):g' \
  38. -e 's:\$$(RA_CLIENT_LINKABLE):$(if $(RA_CLIENT_LINKABLE),$(RA_CLIENT_LINKABLE),0):g' \
  39. $(extra_rules)
  40. manifest: manifest.template
  41. sed $(manifest_rules) $< >$@
  42. %.manifest: %.manifest.template $(executables) $(pal_lib)
  43. sed $(manifest_rules) $< >$@
  44. (grep -q "#\!" $@ && chmod +x $@) || true
  45. ../src/user_shared_start.o ../src/user_start.o: ../src/user_start.S
  46. $(MAKE) -C ../src $(notdir $@)
  47. CFLAGS-AvxDisable += -mavx
  48. ifeq ($(findstring x86_64,$(SYS))$(findstring linux,$(SYS)),x86_64linux)
  49. LDLIBS-preloads = ../src/user_shared_start.o $(graphene_lib) $(pal_lib)
  50. $(preloads): CFLAGS += -shared -fPIC
  51. $(preloads): LDLIBS = $(LDLIBS-preloads)
  52. $(preloads): %.so: %.so.c $(LDLIBS-preloads)
  53. $(call cmd,csingle)
  54. LDLIBS-executables = ../src/user_start.o $(graphene_lib) $(pal_lib) $(preloads)
  55. $(executables): CFLAGS += -no-pie
  56. $(executables): LDLIBS = $(LDLIBS-executables)
  57. $(executables): %: %.c $(LDLIBS-executables)
  58. $(call cmd,csingle)
  59. ifeq ($(filter clean,$(MAKECMDGOALS)),)
  60. include $(wildcard *.d)
  61. ifeq ($(SGX), 1)
  62. # Bootstrap5.manifest doesn't have main executable, but only preloaded
  63. # libraries. Static pattern rule is needed to override the implicit pattern
  64. # rule defined in Pal/src/host/Linux-SGX/Makefile.Test.
  65. Bootstrap5.manifest.sgx.d: %.manifest.sgx.d: %.manifest
  66. $(call cmd,sgx_sign_depend)
  67. include $(addsuffix .manifest.sgx.d,$(executables))
  68. endif
  69. endif
  70. .lib/host_endian.h: ../src/host/$(PAL_HOST)/host_endian.h
  71. @mkdir -p .lib
  72. cp -f $< $@
  73. $(graphene_lib): .lib/host_endian.h
  74. $(MAKE) -C ../lib target=$(abspath .lib)/
  75. else
  76. .IGNORE: $(preloads) $(executables)
  77. $(preloads) $(executables):
  78. endif
  79. export PYTHONPATH=../../Scripts
  80. .PHONY: regression
  81. regression:
  82. $(RM) pal-regression.xml
  83. $(MAKE) pal-regression.xml
  84. pal-regression.xml: test_pal.py $(call expand_target_to_token,$(target))
  85. python3 -m pytest --junit-xml $@ -v test_pal.py
  86. .PHONY: clean
  87. clean:
  88. rm -rf $(call expand_target,$(target)) $(preloads) *.tmp .lib *.cached *.sig *.d .output.* *.token .*.d .*.sig .*.token __pycache__ .cache pal-regression.xml