Makefile 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #
  2. # Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions
  6. # are met:
  7. #
  8. # * Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. # * Redistributions in binary form must reproduce the above copyright
  11. # notice, this list of conditions and the following disclaimer in
  12. # the documentation and/or other materials provided with the
  13. # distribution.
  14. # * Neither the name of Intel Corporation nor the names of its
  15. # contributors may be used to endorse or promote products derived
  16. # from this software without specific prior written permission.
  17. #
  18. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. #
  30. #
  31. include ../../../../buildenv.mk
  32. CPPFLAGS += -I$(COMMON_DIR)/inc/ \
  33. -I$(COMMON_DIR)/inc/tlibc/ \
  34. -I$(COMMON_DIR)/inc/internal \
  35. -I$(LINUX_SDK_DIR)/trts/
  36. CFLAGS += $(ENCLAVE_CFLAGS)
  37. ASFLAGS := -DSE_SIM -Werror $(CFLAGS)
  38. CFLAGS += -DSE_SIM -Werror -fasynchronous-unwind-tables
  39. CXXFLAGS += -DSE_SIM -Werror $(ENCLAVE_CXXFLAGS)\
  40. -fno-exceptions -fno-rtti
  41. SIM_DIR := $(CUR_DIR)/../..
  42. # The sources from tRTS - shared by both Sim/HW mode
  43. TRTS_DIR := $(LINUX_SDK_DIR)/trts/
  44. # The sources for SE0 instruction simulation
  45. TINST_DIR := $(SIM_DIR)/tinst/
  46. # The sources for low-level API used by instruction simulation
  47. LOWLIB_DIR := $(SIM_DIR)/assembly/linux/
  48. # The sources for TLS support
  49. TLS_DIR := $(SIM_DIR)/uinst/linux/
  50. # The source for trusted loader
  51. TLDR_DIR := $(LINUX_SDK_DIR)/trts/linux/
  52. # Support for platform dependent 'setcontext'
  53. SC_DIR := $(LINUX_SDK_DIR)/trts/linux/$(ARCH)/
  54. # The source for xsave/xrstor
  55. XSAVE_DIR := $(COMMON_DIR)/src/linux/
  56. TRTS1_OBJS := init_enclave.o \
  57. trts.o \
  58. trts_ecall.o \
  59. trts_ocall.o \
  60. trts_util.o \
  61. trts_veh.o \
  62. trts_xsave.o \
  63. init_optimized_lib.o \
  64. trts_emodpr.o \
  65. trts_add_trim.o
  66. TRTS2_OBJS := trts_nsp.o
  67. TRTS_OBJS := $(TRTS1_OBJS) $(TRTS2_OBJS)
  68. TINST_OBJS := t_instructions.o \
  69. deriv.o
  70. LOWLIB_OBJS := lowlib.o
  71. TLS_OBJS := get_tcs.o \
  72. restore_tls.o
  73. TLDR_ASM_OBJS := trts_pic.o \
  74. metadata_sec.o \
  75. xsave_gnu.o
  76. TLDR_C_OBJS := elf_parser.o \
  77. global_init.o \
  78. tls_support.o
  79. TLDR_OBJS := $(TLDR_ASM_OBJS) $(TLDR_C_OBJS)
  80. SC_OBJ := setcontext.o
  81. LIBTRTS := libsgx_trts_sim.a
  82. vpath %.cpp $(TRTS_DIR):$(TINST_DIR)
  83. vpath %.S $(LOWLIB_DIR):$(TLDR_DIR):$(SC_DIR):$(XSAVE_DIR)
  84. vpath %.c $(TLS_DIR):$(TLDR_DIR)
  85. # ------------------------------------------------------------
  86. .PHONY: all
  87. all: $(LIBTRTS) | $(BUILD_DIR)
  88. $(CP) $< $|
  89. $(LIBTRTS): $(TRTS_OBJS) $(TINST_OBJS) $(LOWLIB_OBJS) $(TLS_OBJS) $(TLDR_OBJS) $(SC_OBJ)
  90. $(AR) rcsD $@ $(TRTS_OBJS) $(TINST_OBJS) $(LOWLIB_OBJS) $(TLS_OBJS) $(TLDR_OBJS) $(SC_OBJ)
  91. # ------------------------------------------------------------
  92. $(TRTS1_OBJS): CPPFLAGS += -I$(COMMON_DIR)/inc/tlibc \
  93. -I$(SIM_DIR)/tinst/
  94. $(TRTS2_OBJS): %.o:%.cpp
  95. $(CXX) -c $(filter-out -fstack-protector-strong, $(CXXFLAGS)) -I$(SIM_DIR)/tinst/ $(CPPFLAGS) $< -o $@
  96. # Explicitly disable optimization for tRTS simulation library,
  97. # since the '_SE3' function has assumptions on stack layout.
  98. # c.f. ../../tinst/Makefile
  99. $(TINST_OBJS): CPPFLAGS += -I$(SIM_DIR)/assembly/ \
  100. -I$(SIM_DIR)/assembly/linux \
  101. -I$(SIM_DIR)/uinst/ \
  102. -I$(LINUX_SDK_DIR)/selib/ \
  103. -O0
  104. $(TLS_OBJS): CPPFLAGS += -I$(SIM_DIR)/assembly/ \
  105. -I$(SIM_DIR)/assembly/linux \
  106. -I$(SIM_DIR)/uinst/
  107. $(TLDR_C_OBJS): CPPFLAGS += -I$(COMMON_DIR)/inc/internal/linux/ \
  108. -I$(SIM_DIR)/assembly/
  109. $(TLDR_ASM_OBJS): ASFLAGS += -I$(SIM_DIR)/assembly/
  110. $(SC_OBJ): ASFLAGS += -I$(LINUX_SDK_DIR)/cpprt/linux/libunwind/src/$(ARCH) -DISE=1
  111. $(BUILD_DIR):
  112. $(MKDIR) $@
  113. .PHONY: clean
  114. clean:
  115. @$(RM) *.o $(LIBTRTS) $(BUILD_DIR)/$(LIBTRTS)
  116. .PHONY: rebuild
  117. rebuild:
  118. $(MAKE) clean
  119. $(MAKE) all