buildenv.mk 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. # -----------------------------------------------------------------------------
  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 += -ggdb -DDEBUG -UNDEBUG
  68. COMMON_FLAGS += -DSE_DEBUG_LEVEL=SE_TRACE_DEBUG
  69. else
  70. COMMON_FLAGS += -O2 -UDEBUG -DNDEBUG
  71. endif
  72. ifdef SE_SIM
  73. COMMON_FLAGS += -DSE_SIM
  74. endif
  75. COMMON_FLAGS += -ffunction-sections -fdata-sections
  76. # turn on compiler warnings as much as possible
  77. COMMON_FLAGS += -Wall -Wextra -Winit-self -Wpointer-arith -Wreturn-type \
  78. -Waddress -Wsequence-point -Wformat-security \
  79. -Wmissing-include-dirs -Wfloat-equal -Wundef -Wshadow \
  80. -Wcast-align -Wconversion -Wredundant-decls
  81. # additional warnings flags for C
  82. CFLAGS += -Wjump-misses-init -Wstrict-prototypes -Wunsuffixed-float-constants
  83. # additional warnings flags for C++
  84. CXXFLAGS += -Wnon-virtual-dtor
  85. # for static_assert()
  86. CXXFLAGS += -std=c++0x
  87. .DEFAULT_GOAL := all
  88. # this turns off the RCS / SCCS implicit rules of GNU Make
  89. % : RCS/%,v
  90. % : RCS/%
  91. % : %,v
  92. % : s.%
  93. % : SCCS/s.%
  94. # If a rule fails, delete $@.
  95. .DELETE_ON_ERROR:
  96. HOST_FILE_PROGRAM := file
  97. UNAME := $(shell uname -m)
  98. ifneq (,$(findstring 86,$(UNAME)))
  99. HOST_ARCH := x86
  100. ifneq (,$(shell $(HOST_FILE_PROGRAM) -L $(SHELL) | grep 'x86[_-]64'))
  101. HOST_ARCH := x86_64
  102. endif
  103. else
  104. $(info Unknown host CPU arhitecture $(UNAME))
  105. $(error Aborting)
  106. endif
  107. BUILD_DIR := $(ROOT_DIR)/build/linux
  108. ifeq "$(findstring __INTEL_COMPILER, $(shell $(CC) -E -dM -xc /dev/null))" "__INTEL_COMPILER"
  109. ifeq ($(shell test -f /usr/bin/dpkg; echo $$?), 0)
  110. ADDED_INC := -I /usr/include/$(shell dpkg-architecture -qDEB_BUILD_MULTIARCH)
  111. endif
  112. endif
  113. ARCH := $(HOST_ARCH)
  114. ifeq "$(findstring -m32, $(CXXFLAGS))" "-m32"
  115. ARCH := x86
  116. endif
  117. ifeq ($(ARCH), x86)
  118. COMMON_FLAGS += -DITT_ARCH_IA32
  119. else
  120. COMMON_FLAGS += -DITT_ARCH_IA64
  121. endif
  122. CFLAGS += $(COMMON_FLAGS)
  123. CXXFLAGS += $(COMMON_FLAGS)
  124. # Compiler and linker options for an Enclave
  125. #
  126. # We are using '--export-dynamic' so that `g_global_data_sim' etc.
  127. # will be exported to dynamic symbol table.
  128. #
  129. # When `pie' is enabled, the linker (both BFD and Gold) under Ubuntu 14.04
  130. # will hide all symbols from dynamic symbol table even if they are marked
  131. # as `global' in the LD version script.
  132. ENCLAVE_CFLAGS = -ffreestanding -nostdinc -fvisibility=hidden -fpie
  133. ENCLAVE_CXXFLAGS = $(ENCLAVE_CFLAGS) -nostdinc++
  134. ENCLAVE_LDFLAGS = -Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \
  135. -Wl,-pie,-eenclave_entry -Wl,--export-dynamic \
  136. -Wl,--defsym,__ImageBase=0
  137. # Choose to use the optimized libraries (IPP/String/Math) by default.
  138. # Users could also use the non-optimized source code version by
  139. # explicitly specifying 'USE_OPT_LIBS=0'
  140. USE_OPT_LIBS ?= 1
  141. ifeq ($(ARCH), x86_64)
  142. IPP_SUBDIR = intel64
  143. else
  144. IPP_SUBDIR = ia32
  145. endif
  146. ifneq ($(USE_OPT_LIBS), 0)
  147. SGX_IPP_DIR := $(ROOT_DIR)/external/ippcp_internal
  148. SGX_IPP_INC := $(SGX_IPP_DIR)/inc
  149. IPP_LIBS_DIR := $(SGX_IPP_DIR)/lib/linux/$(IPP_SUBDIR)
  150. LD_IPP := -lippcp -lippcore
  151. else
  152. SGX_IPP_DIR := $(ROOT_DIR)/external/crypto_px
  153. SGX_IPP_INC := $(SGX_IPP_DIR)/include
  154. IPP_LIBS_DIR := $(SGX_IPP_DIR)
  155. LD_IPP := -lcrypto_px
  156. endif