Makefile 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #
  2. # Copyright (C) 2011-2018 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. TOP_DIR = ../../../..
  32. include $(TOP_DIR)/buildenv.mk
  33. INCLUDES := -I.. \
  34. -I$(COMMON_DIR)/inc \
  35. -I$(COMMON_DIR)/inc/internal \
  36. -I$(LINUX_SDK_DIR)/tseal \
  37. -I$(LINUX_SDK_DIR)/simulation/tinst \
  38. -I$(LINUX_SDK_DIR)/simulation/urtssim \
  39. -I$(LINUX_EXTERNAL_DIR)/epid-sdk \
  40. -I$(LINUX_EXTERNAL_DIR)/rdrand/ \
  41. -I$(LINUX_PSW_DIR)/ae/inc \
  42. -I$(LINUX_PSW_DIR)/ae/inc/internal \
  43. -I$(LINUX_PSW_DIR)/ae/common
  44. CXXFLAGS += -Wall -fPIC $(INCLUDES) -Werror -g
  45. CFLAGS := $(filter-out -fPIC -Werror, $(CFLAGS)) -Wall $(INCLUDES)
  46. VERSION_SCRIPT = $(shell pwd)/uae_service_sim.linux.version
  47. LD_OPT = $(COMMON_LDFLAGS) -Wl,--version-script=$(VERSION_SCRIPT)
  48. RDRAND_LIBDIR := $(LINUX_EXTERNAL_DIR)/rdrand/src
  49. RDRAND_MAKEFILE := $(RDRAND_LIBDIR)/Makefile
  50. EXTERNAL_LIB += -L$(RDRAND_LIBDIR) -lrdrand
  51. EXTERNAL_LIB += -L$(RDRAND_LIBDIR) -lrt
  52. EXTERNAL_LIB += -ldl -lcrypto
  53. vpath %.cpp $(LINUX_PSW_DIR)/ae/common \
  54. $(LINUX_SDK_DIR)/simulation/urtssim \
  55. $(COMMON_DIR)/src
  56. vpath %.c $(COMMON_DIR)/src
  57. CPP_SRC := $(wildcard *.cpp ../*.cpp) se_sig_rl.cpp cpusvn_util.cpp sgx_read_rand.cpp
  58. CPP_SRC += crypto_evp_digest.cpp crypto_cmac_128.cpp
  59. C_SRC := se_trace.c se_thread.c
  60. OBJ := $(sort $(CPP_SRC:.cpp=.o)) \
  61. $(C_SRC:.c=.o)
  62. DLLNAME = libsgx_uae_service_sim.so
  63. DLLNAME_DEBUG = libsgx_uae_service_sim.so.debug
  64. LIBUAE_SERVICE_DEPLOY := libsgx_uae_service_deploy.so
  65. .PHONY: all
  66. all: $(DLLNAME) $(DLLNAME_DEBUG) $(LIBUAE_SERVICE_DEPLOY) | $(BUILD_DIR)
  67. $(CP) $(DLLNAME) $|
  68. $(CP) $(LIBUAE_SERVICE_DEPLOY) $|
  69. ifndef DEBUG
  70. $(CP) $(DLLNAME_DEBUG) $|
  71. endif
  72. $(DLLNAME): $(OBJ) -lrdrand
  73. $(CXX) $(CXXFLAGS) $(OBJ) -shared $(EXTERNAL_LIB) -o $@ $(LD_OPT)
  74. $(DLLNAME_DEBUG): $(DLLNAME)
  75. ifndef DEBUG
  76. $(CP) $(DLLNAME) $(DLLNAME).orig
  77. $(OBJCOPY) --only-keep-debug $(DLLNAME) $(DLLNAME_DEBUG)
  78. $(STRIP) -g $(DLLNAME)
  79. $(OBJCOPY) --add-gnu-debuglink=$(DLLNAME_DEBUG) $(DLLNAME)
  80. endif
  81. %.o: %.c
  82. $(CC) $(CFLAGS) -Werror -fPIC -c $< -o $@
  83. %.o: %.cpp
  84. $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@
  85. -lrdrand: $(RDRAND_MAKEFILE)
  86. $(MAKE) -C $(RDRAND_LIBDIR)
  87. $(RDRAND_MAKEFILE):
  88. ifeq ($(ARCH), x86)
  89. @cd $(RDRAND_LIBDIR);./configure
  90. else
  91. @cd $(RDRAND_LIBDIR);./configure CFLAGS=-fPIC
  92. endif
  93. $(LIBUAE_SERVICE_DEPLOY): ../uae_service_deploy.c
  94. $(CC) -fPIC -shared -Wl,-soname=libsgx_uae_service.so $< -o $@
  95. $(BUILD_DIR):
  96. @$(MKDIR) $@
  97. .PHONY: clean
  98. clean:
  99. @$(RM) *.o
  100. @$(RM) ../*.o $(DLLNAME).orig
  101. @$(RM) $(DLLNAME) $(BUILD_DIR)/$(DLLNAME)
  102. @$(RM) $(DLLNAME_DEBUG) $(BUILD_DIR)/$(DLLNAME_DEBUG)
  103. @$(RM) $(LIBUAE_SERVICE_DEPLOY) $(BUILD_DIR)/$(LIBUAE_SERVICE_DEPLOY)
  104. ifeq ($(RDRAND_MAKEFILE), $(wildcard $(RDRAND_MAKEFILE)))
  105. @$(MAKE) distclean -C $(RDRAND_LIBDIR)
  106. endif
  107. .PHONY: rebuild
  108. rebuild:
  109. $(MAKE) clean
  110. $(MAKE) all