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