buildenv.mk 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. # clean the content of 'INCLUDE' - this variable will be set by vcvars32.bat
  52. # thus it will cause build error when this variable is used by our Makefile,
  53. # when compiling the code under Cygwin tainted by MSVC environment settings.
  54. INCLUDE :=
  55. # this will return the path to the file that included the buildenv.mk file
  56. CUR_DIR := $(realpath $(call parent-dir,$(lastword $(wordlist 2,$(words $(MAKEFILE_LIST)),x $(MAKEFILE_LIST)))))
  57. # turn on stack protector for SDK
  58. COMMON_FLAGS += -fstack-protector
  59. ifdef DEBUG
  60. COMMON_FLAGS += -ggdb -DDEBUG -UNDEBUG
  61. COMMON_FLAGS += -DSE_DEBUG_LEVEL=SE_TRACE_DEBUG
  62. else
  63. COMMON_FLAGS += -O2 -UDEBUG -DNDEBUG
  64. endif
  65. ifdef SE_SIM
  66. COMMON_FLAGS += -DSE_SIM
  67. endif
  68. # turn on compiler warnings as much as possible
  69. COMMON_FLAGS += -Wall -Wextra -Winit-self -Wpointer-arith -Wreturn-type \
  70. -Waddress -Wsequence-point -Wformat-security \
  71. -Wmissing-include-dirs -Wfloat-equal -Wundef -Wshadow \
  72. -Wcast-align -Wconversion -Wredundant-decls
  73. # additional warnings flags for C
  74. CFLAGS += -Wjump-misses-init -Wstrict-prototypes -Wunsuffixed-float-constants
  75. # additional warnings flags for C++
  76. CXXFLAGS += -Wnon-virtual-dtor
  77. # for static_assert()
  78. CXXFLAGS += -std=c++0x
  79. .DEFAULT_GOAL := all
  80. # this turns off the RCS / SCCS implicit rules of GNU Make
  81. % : RCS/%,v
  82. % : RCS/%
  83. % : %,v
  84. % : s.%
  85. % : SCCS/s.%
  86. # If a rule fails, delete $@.
  87. .DELETE_ON_ERROR:
  88. HOST_FILE_PROGRAM := file
  89. UNAME := $(shell uname -m)
  90. ifneq (,$(findstring 86,$(UNAME)))
  91. HOST_ARCH := x86
  92. ifneq (,$(shell $(HOST_FILE_PROGRAM) -L $(SHELL) | grep 'x86[_-]64'))
  93. HOST_ARCH := x86_64
  94. endif
  95. else
  96. $(info Unknown host CPU arhitecture $(UNAME))
  97. $(error Aborting)
  98. endif
  99. BUILD_DIR := $(ROOT_DIR)/build/linux
  100. ifeq "$(findstring __INTEL_COMPILER, $(shell $(CC) -E -dM -xc /dev/null))" "__INTEL_COMPILER"
  101. ifeq ($(shell test -f /usr/bin/dpkg; echo $$?), 0)
  102. ADDED_INC := -I /usr/include/$(shell dpkg-architecture -qDEB_BUILD_MULTIARCH)
  103. endif
  104. endif
  105. ARCH := $(HOST_ARCH)
  106. ifeq "$(findstring -m32, $(CXXFLAGS))" "-m32"
  107. ARCH := x86
  108. endif
  109. ifeq ($(ARCH), x86)
  110. COMMON_FLAGS += -DITT_ARCH_IA32
  111. else
  112. COMMON_FLAGS += -DITT_ARCH_IA64
  113. endif
  114. CFLAGS += $(COMMON_FLAGS)
  115. CXXFLAGS += $(COMMON_FLAGS)
  116. # Compiler and linker options for an Enclave
  117. #
  118. # We are using '--export-dynamic' so that `g_global_data_sim' etc.
  119. # will be exported to dynamic symbol table.
  120. #
  121. # When `pie' is enabled, the linker (both BFD and Gold) under Ubuntu 14.04
  122. # will hide all symbols from dynamic symbol table even if they are marked
  123. # as `global' in the LD version script.
  124. ENCLAVE_CFLAGS = -ffreestanding -nostdinc -fvisibility=hidden -fpie
  125. ENCLAVE_CXXFLAGS = $(ENCLAVE_CFLAGS) -nostdinc++
  126. ENCLAVE_LDFLAGS = -Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \
  127. -Wl,-pie,-eenclave_entry -Wl,--export-dynamic \
  128. -Wl,--defsym,__ImageBase=0