Makefile 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #!/usr/bin/make -f
  2. #define path variables
  3. IPP_SRC_INCLUDE_DIR = ../../ext/ipp/sources/ippcp/src/
  4. IPP_INCLUDE_DIR = ../../ext/ipp/sources/include/
  5. GTEST_INCLUDE_DIR = ../../ext/
  6. LIB_INSTALL_DIR = $(epidinstalldir)/lib/posix-$(ARCH)/
  7. TEST_INSTALL_DIR = $(epidinstalldir)/test/
  8. HEADERS_INSTALL_DIR := $(epidinstalldir)/include/epid/member/
  9. API_HEADERS_INSTALL = $(wildcard ./*.h)
  10. MEMBER_INCLUDE_DIR = ../../
  11. TINY_MEMBER_INCLUDE_DIR = ./tiny/
  12. MEMBER_SRC = $(wildcard ./src/*.c)
  13. TINY_MEMBER_SRC = $(wildcard ./tiny/src/*.c)
  14. TINY_MEMBER_MATH_SRC = $(wildcard ./tiny/math/src/*.c)
  15. TINY_STDLIB_MEMBER_SRC = $(wildcard ./tiny/stdlib/src/*.c)
  16. MEMBER_TPM2_TSS_UTEST_SRC = $(wildcard ./tpm2/unittests/*.cc)
  17. ifneq ($(TSS_PATH),)
  18. MEMBER_TPM2_SRC = $(wildcard ./tpm2/ibm_tss/*.c)
  19. MEMBER_TPM2_UTEST_SRC = $(filter-out $(wildcard ./tpm2/unittests/*-simulator-test.cc), \
  20. $(MEMBER_TPM2_TSS_UTEST_SRC))
  21. MEMBER_INCLUDE_DIR += -I$(TSS_PATH)
  22. CFLAGS += -DTPM_TSS
  23. CXXFLAGS += -DTPM_TSS
  24. else
  25. MEMBER_TPM2_SRC = $(wildcard ./tpm2/src/*.c)
  26. MEMBER_TPM2_UTEST_SRC = $(filter-out $(wildcard ./tpm2/unittests/*-tss-test.cc), \
  27. $(MEMBER_TPM2_TSS_UTEST_SRC))
  28. endif
  29. MEMBER_SRC += $(MEMBER_TPM2_SRC)
  30. MEMBER_LIB = ./libmember.a
  31. MATH_LIB = ./libmath.a
  32. STDLIB_LIB = ./libtiny_stdlib.a
  33. MEMBER_UTEST_EXE = ./member-utest$(EXE_EXTENSION)
  34. MEMBER_UTEST_SRC = $(wildcard ./unittests/*.cc) \
  35. ./tpm2/unittests/tpm2_wrapper-testhelper.cc
  36. TINY_MEMBER_UTEST_SRC = $(wildcard ./tiny/unittests/*.cc)
  37. TINY_MEMBER_MATH_UTEST_SRC = $(wildcard ./tiny/math/unittests/*.cc)
  38. ifneq ($(TINY),)
  39. MEMBER_OBJ = $(TINY_MEMBER_SRC:.c=.o)
  40. MATH_OBJ = $(TINY_MEMBER_MATH_SRC:.c=.o)
  41. STDLIB_OBJ = $(TINY_STDLIB_MEMBER_SRC:.c=.o)
  42. MEMBER_UTEST_OBJ = $(TINY_MEMBER_UTEST_SRC:.cc=.o)
  43. TINY_MEMBER_MATH_UTEST_OBJ = $(TINY_MEMBER_MATH_UTEST_SRC:.cc=.o)
  44. MEMBER_INCLUDE_DIR += -I$(TINY_MEMBER_INCLUDE_DIR)
  45. else
  46. MEMBER_OBJ = $(MEMBER_SRC:.c=.o)
  47. MEMBER_UTEST_OBJ = $(MEMBER_UTEST_SRC:.cc=.o)
  48. MEMBER_TPM2_UTEST_OBJ = $(MEMBER_TPM2_UTEST_SRC:.cc=.o)
  49. endif
  50. LIB_MEMBER_DIR = .
  51. LIB_VERIFIER_DIR = ../verifier
  52. LIB_COMMON_TESTHELPER_DIR = ../common-testhelper
  53. LIB_COMMON_DIR = ../common
  54. LIB_IPPCP_DIR = ../../ext/ipp/sources/ippcp/src
  55. #set flags for linker
  56. LDFLAGS += -L$(GTEST_INCLUDE_DIR)/gtest -L$(LIB_COMMON_TESTHELPER_DIR) \
  57. -L$(LIB_MEMBER_DIR) -L$(LIB_VERIFIER_DIR) -L$(LIB_COMMON_DIR) \
  58. -L$(LIB_IPPCP_DIR) -lgtest -lcommon-testhelper \
  59. -lmember -lverifier -lcommon -lippcp
  60. ifneq ($(TSS_PATH),)
  61. LDFLAGS += -L$(TSS_PATH) -ltss -lcrypto
  62. endif
  63. ifneq ($(TINY),)
  64. CPPDEFINES := -DNDEBUG
  65. LDFLAGS += -lmath -ltiny_stdlib
  66. CFLAGS := -Os -fno-builtin -fno-stack-protector -fomit-frame-pointer -fno-asynchronous-unwind-tables \
  67. -fdata-sections -ffunction-sections -fvisibility=hidden -Werror -Wall -Wextra
  68. ifneq ($(OS),Windows_NT)
  69. CFLAGS += -fPIC
  70. endif
  71. ifeq ($(findstring gcc,$(CC)),gcc)
  72. CFLAGS += -Wno-missing-braces
  73. endif
  74. ifeq ($(ARCH), x86)
  75. CFLAGS += -m32
  76. endif
  77. endif
  78. $(MEMBER_OBJ): %.o: %.c
  79. $(CC) $(CFLAGS) -I$(IPP_INCLUDE_DIR) -I$(IPP_SRC_INCLUDE_DIR) \
  80. -I$(MEMBER_INCLUDE_DIR) -c $^ -o $@
  81. $(MEMBER_LIB): $(MEMBER_OBJ)
  82. $(AR) rc $(MEMBER_LIB) $(MEMBER_OBJ)
  83. $(RANLIB) $(MEMBER_LIB)
  84. $(MEMBER_UTEST_EXE): $(MEMBER_UTEST_OBJ)
  85. $(CXX) -o $@ $^ $(LDFLAGS)
  86. $(MEMBER_UTEST_OBJ): %.o: %.cc
  87. $(CXX) -o $@ $(CXXFLAGS) $(GTEST_DEFINES) -I$(MEMBER_INCLUDE_DIR) \
  88. -I$(GTEST_INCLUDE_DIR) -c $^
  89. ifneq ($(TINY),)
  90. $(MATH_OBJ): %.o: %.c
  91. $(CC) $(CFLAGS) -I$(MEMBER_INCLUDE_DIR) -c $^ -o $@
  92. $(STDLIB_OBJ): %.o: %.c
  93. $(CC) $(CFLAGS) -I$(MEMBER_INCLUDE_DIR) -c $^ -o $@
  94. $(MATH_LIB): $(MATH_OBJ)
  95. $(AR) rc $(MATH_LIB) $(MATH_OBJ)
  96. $(RANLIB) $(MATH_LIB)
  97. $(STDLIB_LIB): $(STDLIB_OBJ)
  98. $(AR) rc $(STDLIB_LIB) $(STDLIB_OBJ)
  99. $(RANLIB) $(STDLIB_LIB)
  100. TINY_MEMBER_MATH_UTEST_EXE = ./member.math-utest$(EXE_EXTENSION)
  101. $(TINY_MEMBER_MATH_UTEST_EXE): $(TINY_MEMBER_MATH_UTEST_OBJ)
  102. $(CXX) -o $@ $^ $(LDFLAGS)
  103. $(TINY_MEMBER_MATH_UTEST_OBJ): %.o: %.cc
  104. $(CXX) -o $@ $(CXXFLAGS) $(GTEST_DEFINES) -I$(MEMBER_INCLUDE_DIR) \
  105. -I$(GTEST_INCLUDE_DIR) -c $^
  106. else
  107. MEMBER_TPM2_UTEST_EXE = ./member.tpm2-utest$(EXE_EXTENSION)
  108. $(MEMBER_TPM2_UTEST_EXE): $(MEMBER_TPM2_UTEST_OBJ)
  109. $(CXX) -o $@ $^ $(LDFLAGS)
  110. $(MEMBER_TPM2_UTEST_OBJ): %.o: %.cc
  111. $(CXX) -o $@ $(CXXFLAGS) $(GTEST_DEFINES) -I$(MEMBER_INCLUDE_DIR) \
  112. -I$(GTEST_INCLUDE_DIR) -c $^
  113. endif
  114. build: all
  115. LIBS = $(MEMBER_LIB)
  116. ifneq ($(TINY),)
  117. LIBS += $(STDLIB_LIB) $(MATH_LIB)
  118. endif
  119. all: $(LIBS)
  120. install:
  121. mkdir -p '$(LIB_INSTALL_DIR)'
  122. mkdir -p '$(HEADERS_INSTALL_DIR)'
  123. cp $(MEMBER_LIB) '$(LIB_INSTALL_DIR)'
  124. ifneq ($(TINY),)
  125. cp $(MATH_LIB) '$(LIB_INSTALL_DIR)'
  126. cp $(STDLIB_LIB) '$(LIB_INSTALL_DIR)'
  127. endif
  128. cp $(API_HEADERS_INSTALL) '$(HEADERS_INSTALL_DIR)'
  129. #install tests if they exist
  130. ifneq (,$(wildcard $(MEMBER_UTEST_EXE)))
  131. mkdir -p '$(TEST_INSTALL_DIR)'
  132. cp $(MEMBER_UTEST_EXE) '$(TEST_INSTALL_DIR)'
  133. endif
  134. ifneq ($(TINY),)
  135. mkdir -p '$(TEST_INSTALL_DIR)'
  136. cp $(TINY_MEMBER_MATH_UTEST_EXE) '$(TEST_INSTALL_DIR)'
  137. else
  138. mkdir -p '$(TEST_INSTALL_DIR)'
  139. cp $(MEMBER_TPM2_UTEST_EXE) '$(TEST_INSTALL_DIR)'
  140. endif
  141. utest: $(MEMBER_UTEST_EXE) $(MEMBER_TPM2_UTEST_EXE) $(TINY_MEMBER_MATH_UTEST_EXE)
  142. run_utest:
  143. $(MEMBER_UTEST_EXE) $(GTEST_FLAGS)
  144. $(MEMBER_TPM2_UTEST_EXE) $(GTEST_FLAGS)
  145. $(TINY_MEMBER_MATH_UTEST_EXE) $(GTEST_FLAGS)
  146. check: utest run_utest
  147. clean:
  148. rm -f $(MEMBER_OBJ) \
  149. $(MEMBER_LIB) \
  150. $(MATH_OBJ) \
  151. $(MATH_LIB) \
  152. $(STDLIB_OBJ) \
  153. $(STDLIB_LIB) \
  154. $(MEMBER_UTEST_OBJ) \
  155. $(MEMBER_UTEST_EXE) \
  156. $(MEMBER_TPM2_UTEST_OBJ) \
  157. $(MEMBER_TPM2_UTEST_EXE) \
  158. $(TINY_MEMBER_MATH_UTEST_OBJ) \
  159. $(TINY_MEMBER_MATH_UTEST_EXE) \
  160. *.xml