Home | History | Annotate | Download | only in member
      1 #!/usr/bin/make -f
      2 
      3 #define path variables
      4 IPP_SRC_INCLUDE_DIR = ../../ext/ipp/sources/ippcp/src/
      5 IPP_INCLUDE_DIR = ../../ext/ipp/sources/include/
      6 GTEST_INCLUDE_DIR = ../../ext/
      7 
      8 LIB_INSTALL_DIR = $(epidinstalldir)/lib/posix-$(ARCH)/
      9 TEST_INSTALL_DIR = $(epidinstalldir)/test/
     10 HEADERS_INSTALL_DIR :=  $(epidinstalldir)/include/epid/member/
     11 
     12 API_HEADERS_INSTALL = $(wildcard ./*.h)
     13 
     14 MEMBER_INCLUDE_DIR = ../../
     15 TINY_MEMBER_INCLUDE_DIR = ./tiny/
     16 
     17 MEMBER_SRC =  $(wildcard ./src/*.c)
     18 TINY_MEMBER_SRC =  $(wildcard ./tiny/src/*.c)
     19 TINY_MEMBER_MATH_SRC =  $(wildcard ./tiny/math/src/*.c)
     20 TINY_STDLIB_MEMBER_SRC =  $(wildcard ./tiny/stdlib/src/*.c)
     21 MEMBER_TPM2_TSS_UTEST_SRC = $(wildcard ./tpm2/unittests/*.cc)
     22 ifneq ($(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
     29 else
     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))
     33 endif
     34 MEMBER_SRC += $(MEMBER_TPM2_SRC)
     35 MEMBER_LIB = ./libmember.a
     36 MATH_LIB = ./libmath.a
     37 STDLIB_LIB = ./libtiny_stdlib.a
     38 
     39 MEMBER_UTEST_EXE = ./member-utest$(EXE_EXTENSION)
     40 MEMBER_UTEST_SRC = $(wildcard ./unittests/*.cc) \
     41 	./tpm2/unittests/tpm2_wrapper-testhelper.cc
     42 TINY_MEMBER_UTEST_SRC = $(wildcard ./tiny/unittests/*.cc)
     43 TINY_MEMBER_MATH_UTEST_SRC = $(wildcard ./tiny/math/unittests/*.cc)
     44 ifneq ($(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)
     51 else
     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)
     55 endif
     56 
     57 LIB_MEMBER_DIR = .
     58 LIB_VERIFIER_DIR = ../verifier
     59 LIB_COMMON_TESTHELPER_DIR = ../common-testhelper
     60 LIB_COMMON_DIR = ../common
     61 LIB_IPPCP_DIR = ../../ext/ipp/sources/ippcp/src
     62 
     63 #set flags for linker
     64 LDFLAGS += -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 
     69 ifneq ($(TSS_PATH),)
     70 	LDFLAGS += -L$(TSS_PATH) -ltss -lcrypto
     71 endif
     72 
     73 ifneq ($(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
     87 endif
     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 
    104 ifneq ($(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 $^
    126 else
    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 $^
    134 endif
    135 
    136 build: all
    137 LIBS = $(MEMBER_LIB)
    138 ifneq ($(TINY),)
    139 	LIBS += $(STDLIB_LIB) $(MATH_LIB)
    140 endif
    141 all: $(LIBS)
    142 install:
    143 	mkdir -p '$(LIB_INSTALL_DIR)'
    144 	mkdir -p '$(HEADERS_INSTALL_DIR)'
    145 	cp $(MEMBER_LIB) '$(LIB_INSTALL_DIR)'
    146 ifneq ($(TINY),)
    147 	cp $(MATH_LIB) '$(LIB_INSTALL_DIR)'
    148 	cp $(STDLIB_LIB) '$(LIB_INSTALL_DIR)'
    149 endif
    150 	cp $(API_HEADERS_INSTALL) '$(HEADERS_INSTALL_DIR)'
    151 #install tests if they exist
    152 ifneq (,$(wildcard $(MEMBER_UTEST_EXE)))
    153 	mkdir -p '$(TEST_INSTALL_DIR)'
    154 	cp $(MEMBER_UTEST_EXE) '$(TEST_INSTALL_DIR)'
    155 endif
    156 ifneq ($(TINY),)
    157 	mkdir -p '$(TEST_INSTALL_DIR)'
    158 	cp $(TINY_MEMBER_MATH_UTEST_EXE) '$(TEST_INSTALL_DIR)'
    159 else
    160 	mkdir -p '$(TEST_INSTALL_DIR)'
    161 	cp $(MEMBER_TPM2_UTEST_EXE) '$(TEST_INSTALL_DIR)'
    162 endif
    163 
    164 utest: $(MEMBER_UTEST_EXE) $(MEMBER_TPM2_UTEST_EXE) $(TINY_MEMBER_MATH_UTEST_EXE)
    165 
    166 run_utest:
    167 	$(MEMBER_UTEST_EXE) $(GTEST_FLAGS)
    168 	$(MEMBER_TPM2_UTEST_EXE) $(GTEST_FLAGS)
    169 	$(TINY_MEMBER_MATH_UTEST_EXE) $(GTEST_FLAGS)
    170 
    171 check: utest run_utest
    172 
    173 clean:
    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