buildenv.mk 6.0 KB

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