test/Makefile
author Sofia Balicka <sofia@pep.foundation>
Tue, 11 Aug 2020 21:45:11 +0200
branchtest-README.md
changeset 4948 d666f66e20b8
parent 4920 0b584b77b1f6
permissions -rw-r--r--
adding info about creating test
     1 # Copyright 2019, pEp Foundation
     2 # This file is part of pEpEngine
     3 # This file may be used under the terms of the GNU General Public License version 3
     4 # see LICENSE.txt
     5 
     6 HERE:=$(CURDIR)
     7 
     8 GTEST_SRC_DIR:=/usr/src/gtest
     9 GTEST_INC_DIR:=$(GTEST_SRC_DIR)/include
    10 GTEST_PL:=$(HOME)/src/gtest-parallel/gtest_parallel.py
    11 
    12 include ../Makefile.conf # This should import changed values for the above from
    13                          # local.conf
    14 
    15 SRCS:=$(wildcard src/*.cc) $(wildcard src/*/*.cc)
    16 OBJS:=$(addsuffix .o,$(basename $(SRCS)))
    17 DEPS:=$(OBJS:.o=.d)
    18 
    19 LDFLAGS+= -L../asn.1 -L../src $(ETPAN_LIB) $(GTEST_LDFLAGS)
    20 
    21 TARGET:=EngineTests
    22 
    23 GTEST_SUITE_SYM:=test_suite_name
    24 
    25 ifeq ($(shell grep -c $(GTEST_SUITE_SYM) $(GTEST_SRC_DIR)/src/gtest.cc),0)
    26     GTEST_SUITE_SYM=test_case_name
    27 endif
    28 
    29 CXXFLAGS+= -DGTEST_SUITE_SYM=$(GTEST_SUITE_SYM)
    30 
    31 ifeq ($(OPENPGP),GPG)
    32     LDFLAGS+= $(GPGME_LIB)
    33 else ifeq ($(OPENPGP),NETPGP)
    34     LDFLAGS+= $(NETGPG_LIB)
    35 endif
    36 
    37 LDLIBS+= -letpan -lpEpEngine -lstdc++ -lasn1
    38 
    39 ifeq ($(BUILD_FOR),Linux)
    40     LDLIBS+= -luuid
    41 endif
    42 
    43 ifeq ($(OPENPGP),SEQUOIA)
    44     LDFLAGS+= $(SEQUOIA_LDFLAGS)
    45     LDLIBS+= $(SEQUOIA_LIB)
    46     CXXFLAGS+= $(SEQUOIA_CFLAGS) -DUSE_SEQUOIA
    47     INC_FLAGS+= $(SEQUOIA_INC)
    48 endif
    49 
    50 ifdef SQLITE3_FROM_OS
    51     LDLIBS+= -lsqlite3
    52 endif
    53 
    54 ifeq ($(OPENPGP),GPG)
    55     #LDLIBS+= -lgpgme
    56 else ifeq ($(OPENPGP),NETPGP)
    57     LDLIBS+= -lnetpgp
    58     ifeq ($(BUILD_FOR),Linux)
    59         LDLIBS+= -ltre
    60     endif
    61 endif
    62 
    63 CXXFLAGS:=-I$(GTEST_INC_DIR) $(filter-out -DNDEBUG,$(CXXFLAGS))
    64 
    65 # FIXME Possibly missing incdirs: ASN1C_INC
    66 CXXFLAGS+= -I./src -I../sync $(INC_FLAGS) -Wno-deprecated -Wno-unused-variable
    67 
    68 ifeq ($(OPENPGP),GPG)
    69     CXXFLAGS+= -DUSE_GPG $(GPGME_INC)
    70 else ifeq ($(OPENPGP),NETPGP)
    71     CXXFLAGS+= -DUSE_NETPGP $(NETPGP_INC)
    72 endif
    73 
    74 EXTRA_LIB_PATHS=.:../src:
    75 ifdef ETPAN_LIB
    76     EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(ETPAN_LIB)):
    77 endif
    78 ifdef GPGME_LIB
    79     EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(GPGME_LIB)):
    80 endif
    81 ifdef NETPGP_LIB
    82     EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(NETPGP_LIB)):
    83 endif
    84 
    85 # Remove trailing ':'
    86 EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS::=)
    87 
    88 ifeq ($(BUILD_FOR),Darwin)
    89     LIBPATH=DYLD_LIBRARY_PATH
    90 else
    91     LIBPATH=LD_LIBRARY_PATH
    92 endif
    93 
    94 # FIXME: this forces a path on execution which overrides system paths for
    95 #        libraries like iconv and causes runtime errors.
    96 #TEST_CMD_PFX=$(LIBPATH)=$(EXTRA_LIB_PATHS)
    97 TEST_CMD_PFX=
    98 
    99 .PHONY: all clean test
   100 
   101 all:
   102 	make $(TARGET)
   103 
   104 %.d: %.cc
   105 	$(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< | sed -e 's,\($*\)\.o[ :]*,\1.o $@: ,g' > $@
   106 
   107 $(TARGET): $(OBJS)
   108 	${CXX} ${LDFLAGS} -L${PREFIX}/lib -o $@ $^ -lpEpEngine -lgtest -lgtest_main -lsequoia_openpgp_ffi $(LDLIBS)
   109 
   110 
   111 test: all
   112 	$(RM) -rf ./pEp_test_home/*
   113 	$(TEST_CMD_PFX) $(TEST_DEBUGGER) GTEST_COLOR=no python3 $(GTEST_PL) --gtest_color=no ./$(TARGET)
   114 clean:
   115 	$(RM) $(TARGET) $(TARGET).o $(TARGET).d $(OBJS) $(notdir $(basename $(OBJS))) $(DEPS)
   116 	$(RM) -rf ./pEp_test_home/*
   117 # If only the goal 'clean' is given, do not generate and include the '%.d' files.¬
   118 ifneq ($(MAKECMDGOALS),clean)
   119     -include $(DEPS)
   120 endif