test/Makefile
author Damiano Boppart <damiano@pep-security.net>
Mon, 18 Sep 2017 16:09:57 +0200
branchENGINE-259
changeset 2064 c222d7d481ad
parent 2063 fc8e786b8b0d
child 2073 b4126ce1af67
permissions -rw-r--r--
Make bracket usage consistent
damiano@1960
     1
# Copyright 2017, pEp Foundation
damiano@1958
     2
# This file is part of pEpEngine
damiano@1958
     3
# This file may be used under the terms of the GNU General Public License version 3
vb@1517
     4
# see LICENSE.txt
vb@1517
     5
damiano@1958
     6
HERE:=$(CURDIR)
vb@2
     7
edouard@1844
     8
include ../Makefile.conf
vb@1422
     9
damiano@1970
    10
TARGET=pEpEngineTest
damiano@1970
    11
damiano@1970
    12
unexport GNUPGHOME
damiano@1970
    13
TEST_HOME=$(HERE)/test_home
damiano@1970
    14
TEST_GNUPGHOME=$(TEST_HOME)/.gnupg
damiano@1970
    15
damiano@1970
    16
LDFLAGS+= $(ETPAN_LIB) -L../asn.1 -L../src
damiano@1970
    17
LDLIBS+= -letpan -lpEpEngine -lstdc++ -lasn1
damiano@1970
    18
krista@1989
    19
ifeq ($(BUILD_FOR),Linux)
damiano@1970
    20
    LDLIBS+= -luuid
krista@1989
    21
endif
krista@1988
    22
damiano@1972
    23
ifeq ($(OPENPGP),NETPGP)
damiano@1970
    24
    LDLIBS+= -lnetpgp
Edouard@178
    25
endif
Edouard@178
    26
damiano@2002
    27
ifdef SQLITE3_FROM_OS
damiano@2002
    28
    LDLIBS+= -lsqlite3
damiano@2002
    29
endif
damiano@2002
    30
damiano@1970
    31
ifeq ($(shell uname),Darwin)
damiano@1970
    32
    LIBPATH=DYLD_LIBRARY_PATH
damiano@1970
    33
    LLDB_BIN=/Applications/Xcode.app/Contents/Developer/usr/bin/lldb
damiano@1970
    34
else
damiano@1970
    35
    LIBPATH=LD_LIBRARY_PATH
damiano@1970
    36
    LLDB_BIN=lldb
Edouard@178
    37
endif
Edouard@178
    38
damiano@1972
    39
# Create a list of the extra library paths for the loader. I do not assume that the engine (and its dependencies) are installed for testing.
damiano@1970
    40
# Note that += can not be used here, as it changes the amount of whitespace
damiano@1970
    41
EXTRA_LIB_PATHS=../src:
damiano@1970
    42
ifdef ETPAN_LIB
damiano@1970
    43
    EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(ETPAN_LIB)):
damiano@1970
    44
endif
damiano@1970
    45
ifdef GPGME_LIB
damiano@1970
    46
    EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(GPGME_LIB)):
damiano@1970
    47
endif
damiano@1970
    48
ifdef NETPGP_LIB
damiano@1970
    49
    EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(NETPGP_LIB)):
damiano@1970
    50
endif
damiano@1970
    51
# Remove trailing ':'
damiano@1970
    52
EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS::=)
damiano@1970
    53
damiano@1970
    54
TEST_CMD_PFX=$(LIBPATH)=$(EXTRA_LIB_PATHS) HOME=$(TEST_HOME)
vb@2
    55
vb@50
    56
UNIT_TESTS_SOURCE=$(wildcard *_test.cc)
vb@50
    57
UNIT_TESTS=$(subst .cc,,$(UNIT_TESTS_SOURCE))
krista@1617
    58
UNIT_TESTS_RUN=$(subst .cc,_run,$(UNIT_TESTS_SOURCE))
vb@2
    59
damiano@2063
    60
ifneq ($(MAKECMDGOALS),clean)
damiano@2064
    61
    ifneq (,$(findstring -DNDEBUG,$(CFLAGS)))
damiano@2063
    62
        $(error The macro NDEBUG must not be defined for test compilation.)
damiano@2063
    63
    endif
damiano@2062
    64
endif
damiano@2062
    65
damiano@1970
    66
.PHONY: all
vb@48
    67
all: $(TARGET) $(UNIT_TESTS)
vb@2
    68
roker@1659
    69
# don't delete .o files!
roker@1659
    70
.PRECIOUS: %.o
roker@1659
    71
damiano@1970
    72
.PHONY: test_home_
edouard@1934
    73
test_home_: 
edouard@1941
    74
	-gpgconf --kill gpg-agent
edouard@1941
    75
	-HOME=$(TEST_HOME) gpgconf --kill gpg-agent
edouard@1941
    76
	-killall gpg-agent
edouard@1934
    77
	rm -rf $(TEST_HOME)
edouard@1934
    78
	mkdir -p $(TEST_GNUPGHOME)/private-keys-v1.d
edouard@1934
    79
	$(GPG_CMD) --import --batch --homedir $(TEST_GNUPGHOME) 0x*.asc *_sec.asc
edouard@1844
    80
damiano@1970
    81
.PHONY: clean
vb@2
    82
clean:
vb@458
    83
	rm -f *.o $(TARGET) *.a *~ $(UNIT_TESTS) pep_Dokument_Titel.pdf msg4.asc
edouard@1934
    84
	rm -Rf *.dSYM $(TEST_HOME) pubring.gpg secring.gpg random_seed *.conf trustdb.gpg
vb@2
    85
damiano@1970
    86
.PHONY: test
damiano@1970
    87
test: $(TARGET) test_home_
damiano@1970
    88
	$(TEST_CMD_PFX) ./$<
vb@2
    89
roker@1656
    90
%_test : %_test.o test_util.o
damiano@1994
    91
	$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)
roker@1656
    92
edouard@1844
    93
%_run : % test_home_
edouard@1844
    94
	$(TEST_CMD_PFX) ./$<
Edouard@699
    95
edouard@1844
    96
%_lldb : % test_home_
edouard@1851
    97
	$(TEST_CMD_PFX) $(LLDB_BIN) ./$<
roker@1656
    98
edouard@1844
    99
%_valgrind : % test_home_
edouard@1844
   100
	$(TEST_CMD_PFX) valgrind --leak-check=yes ./$<
Edouard@745
   101
edouard@1844
   102
%_gdb : % test_home_
edouard@1844
   103
	$(TEST_CMD_PFX) gdb ./$<
Edouard@770
   104
damiano@1970
   105
.PHONY: unit_tests
Edouard@699
   106
unit_tests: $(UNIT_TESTS) $(UNIT_TESTS_RUN)
vb@142
   107
damiano@1994
   108
.PHONY: compile
damiano@1994
   109
compile: $(UNIT_TESTS) $(TARGET)
damiano@1994
   110
damiano@1970
   111
# Installs the engine, not the test binaries
damiano@1970
   112
.PHONY: install
vb@142
   113
install:
damiano@1970
   114
	$(MAKE) -C .. install