buildenv.mk 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. # -----------------------------------------------------------------------------
  32. # Function : parent-dir
  33. # Arguments: 1: path
  34. # Returns : Parent dir or path of $1, with final separator removed.
  35. # -----------------------------------------------------------------------------
  36. parent-dir = $(patsubst %/,%,$(dir $(1:%/=%)))
  37. # -----------------------------------------------------------------------------
  38. # Macro : my-dir
  39. # Returns : the directory of the current Makefile
  40. # Usage : $(my-dir)
  41. # -----------------------------------------------------------------------------
  42. my-dir = $(realpath $(call parent-dir,$(lastword $(MAKEFILE_LIST))))
  43. ROOT_DIR := $(call my-dir)
  44. COMMON_DIR := $(ROOT_DIR)/common
  45. LINUX_EXTERNAL_DIR := $(ROOT_DIR)/external
  46. LINUX_PSW_DIR := $(ROOT_DIR)/psw
  47. LINUX_SDK_DIR := $(ROOT_DIR)/sdk
  48. LINUX_UNITTESTS := $(ROOT_DIR)/unittests
  49. CP := /bin/cp -f
  50. MKDIR := mkdir -p
  51. STRIP := strip
  52. OBJCOPY := objcopy
  53. # clean the content of 'INCLUDE' - this variable will be set by vcvars32.bat
  54. # thus it will cause build error when this variable is used by our Makefile,
  55. # when compiling the code under Cygwin tainted by MSVC environment settings.
  56. INCLUDE :=
  57. # this will return the path to the file that included the buildenv.mk file
  58. CUR_DIR := $(realpath $(call parent-dir,$(lastword $(wordlist 2,$(words $(MAKEFILE_LIST)),x $(MAKEFILE_LIST)))))
  59. # turn on stack protector for SDK
  60. CC_BELOW_4_9 := $(shell expr "`$(CC) -dumpversion`" \< "4.9")
  61. ifeq ($(CC_BELOW_4_9), 1)
  62. COMMON_FLAGS += -fstack-protector
  63. else
  64. COMMON_FLAGS += -fstack-protector-strong
  65. endif
  66. ifdef DEBUG
  67. COMMON_FLAGS += -O0 -ggdb -DDEBUG -UNDEBUG
  68. COMMON_FLAGS += -DSE_DEBUG_LEVEL=SE_TRACE_DEBUG
  69. else
  70. COMMON_FLAGS += -O2 -D_FORTIFY_SOURCE=2 -UDEBUG -DNDEBUG
  71. endif
  72. ifdef SE_SIM
  73. COMMON_FLAGS += -DSE_SIM
  74. endif
  75. # Disable ref-LE build by default.
  76. # Users could enable the ref-LE build
  77. # by explicitly specifying 'BUILD_REF_LE=1'
  78. BUILD_REF_LE ?= 0
  79. ifeq ($(BUILD_REF_LE), 1)
  80. COMMON_FLAGS += -DREF_LE
  81. endif
  82. COMMON_FLAGS += -ffunction-sections -fdata-sections
  83. # turn on compiler warnings as much as possible
  84. COMMON_FLAGS += -Wall -Wextra -Winit-self -Wpointer-arith -Wreturn-type \
  85. -Waddress -Wsequence-point -Wformat-security \
  86. -Wmissing-include-dirs -Wfloat-equal -Wundef -Wshadow \
  87. -Wcast-align -Wconversion -Wredundant-decls
  88. # additional warnings flags for C
  89. CFLAGS += -Wjump-misses-init -Wstrict-prototypes -Wunsuffixed-float-constants
  90. # additional warnings flags for C++
  91. CXXFLAGS += -Wnon-virtual-dtor
  92. CXXFLAGS += -std=c++11
  93. .DEFAULT_GOAL := all
  94. # this turns off the RCS / SCCS implicit rules of GNU Make
  95. % : RCS/%,v
  96. % : RCS/%
  97. % : %,v
  98. % : s.%
  99. % : SCCS/s.%
  100. # If a rule fails, delete $@.
  101. .DELETE_ON_ERROR:
  102. HOST_FILE_PROGRAM := file
  103. UNAME := $(shell uname -m)
  104. ifneq (,$(findstring 86,$(UNAME)))
  105. HOST_ARCH := x86
  106. ifneq (,$(shell $(HOST_FILE_PROGRAM) -L $(SHELL) | grep 'x86[_-]64'))
  107. HOST_ARCH := x86_64
  108. endif
  109. else
  110. $(info Unknown host CPU arhitecture $(UNAME))
  111. $(error Aborting)
  112. endif
  113. BUILD_DIR := $(ROOT_DIR)/build/linux
  114. ifeq "$(findstring __INTEL_COMPILER, $(shell $(CC) -E -dM -xc /dev/null))" "__INTEL_COMPILER"
  115. ifeq ($(shell test -f /usr/bin/dpkg; echo $$?), 0)
  116. ADDED_INC := -I /usr/include/$(shell dpkg-architecture -qDEB_BUILD_MULTIARCH)
  117. endif
  118. endif
  119. ARCH := $(HOST_ARCH)
  120. ifeq "$(findstring -m32, $(CXXFLAGS))" "-m32"
  121. ARCH := x86
  122. endif
  123. ifeq ($(ARCH), x86)
  124. COMMON_FLAGS += -DITT_ARCH_IA32
  125. else
  126. COMMON_FLAGS += -DITT_ARCH_IA64
  127. endif
  128. CFLAGS += $(COMMON_FLAGS)
  129. CXXFLAGS += $(COMMON_FLAGS)
  130. # Enable the security flags
  131. COMMON_LDFLAGS := -Wl,-z,relro,-z,now,-z,noexecstack
  132. # Compiler and linker options for an Enclave
  133. #
  134. # We are using '--export-dynamic' so that `g_global_data_sim' etc.
  135. # will be exported to dynamic symbol table.
  136. #
  137. # When `pie' is enabled, the linker (both BFD and Gold) under Ubuntu 14.04
  138. # will hide all symbols from dynamic symbol table even if they are marked
  139. # as `global' in the LD version script.
  140. ENCLAVE_CFLAGS = -ffreestanding -nostdinc -fvisibility=hidden -fpie
  141. ENCLAVE_CXXFLAGS = $(ENCLAVE_CFLAGS) -nostdinc++
  142. ENCLAVE_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \
  143. -Wl,-pie,-eenclave_entry -Wl,--export-dynamic \
  144. -Wl,--defsym,__ImageBase=0
  145. # Choose to use the optimized libraries (IPP/String/Math) by default.
  146. # Users could also use the source code version (SGXSSL/String/Math) by
  147. # explicitly specifying 'USE_OPT_LIBS=0'
  148. USE_OPT_LIBS ?= 1
  149. ifeq ($(ARCH), x86_64)
  150. IPP_SUBDIR = intel64
  151. else
  152. IPP_SUBDIR = ia32
  153. endif
  154. SGX_IPP_DIR := $(ROOT_DIR)/external/ippcp_internal
  155. SGX_IPP_INC := $(SGX_IPP_DIR)/inc
  156. IPP_LIBS_DIR := $(SGX_IPP_DIR)/lib/linux/$(IPP_SUBDIR)
  157. LD_IPP := -lippcp -lippcore