buildenv.mk 6.3 KB

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