test/Makefile
author Damiano Boppart <damiano@pep-security.net>
Mon, 18 Sep 2017 15:47:30 +0200
branchENGINE-259
changeset 2062 4a97ad19141e
parent 2021 c15acce7cee9
child 2063 fc8e786b8b0d
permissions -rw-r--r--
test/Makefile fails if NDEBUG macro is defined
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@2062
    60
ifneq (,$(findstring -DNDEBUG,${CFLAGS}))
damiano@2062
    61
    $(error The macro NDEBUG must not be defined for test compilation.)
damiano@2062
    62
endif
damiano@2062
    63
damiano@1970
    64
.PHONY: all
vb@48
    65
all: $(TARGET) $(UNIT_TESTS)
vb@2
    66
roker@1659
    67
# don't delete .o files!
roker@1659
    68
.PRECIOUS: %.o
roker@1659
    69
damiano@1970
    70
.PHONY: test_home_
edouard@1934
    71
test_home_: 
edouard@1941
    72
	-gpgconf --kill gpg-agent
edouard@1941
    73
	-HOME=$(TEST_HOME) gpgconf --kill gpg-agent
edouard@1941
    74
	-killall gpg-agent
edouard@1934
    75
	rm -rf $(TEST_HOME)
edouard@1934
    76
	mkdir -p $(TEST_GNUPGHOME)/private-keys-v1.d
edouard@1934
    77
	$(GPG_CMD) --import --batch --homedir $(TEST_GNUPGHOME) 0x*.asc *_sec.asc
edouard@1844
    78
damiano@1970
    79
.PHONY: clean
vb@2
    80
clean:
vb@458
    81
	rm -f *.o $(TARGET) *.a *~ $(UNIT_TESTS) pep_Dokument_Titel.pdf msg4.asc
edouard@1934
    82
	rm -Rf *.dSYM $(TEST_HOME) pubring.gpg secring.gpg random_seed *.conf trustdb.gpg
vb@2
    83
damiano@1970
    84
.PHONY: test
damiano@1970
    85
test: $(TARGET) test_home_
damiano@1970
    86
	$(TEST_CMD_PFX) ./$<
vb@2
    87
roker@1656
    88
%_test : %_test.o test_util.o
damiano@1994
    89
	$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)
roker@1656
    90
edouard@1844
    91
%_run : % test_home_
edouard@1844
    92
	$(TEST_CMD_PFX) ./$<
Edouard@699
    93
edouard@1844
    94
%_lldb : % test_home_
edouard@1851
    95
	$(TEST_CMD_PFX) $(LLDB_BIN) ./$<
roker@1656
    96
edouard@1844
    97
%_valgrind : % test_home_
edouard@1844
    98
	$(TEST_CMD_PFX) valgrind --leak-check=yes ./$<
Edouard@745
    99
edouard@1844
   100
%_gdb : % test_home_
edouard@1844
   101
	$(TEST_CMD_PFX) gdb ./$<
Edouard@770
   102
damiano@1970
   103
.PHONY: unit_tests
Edouard@699
   104
unit_tests: $(UNIT_TESTS) $(UNIT_TESTS_RUN)
vb@142
   105
damiano@1994
   106
.PHONY: compile
damiano@1994
   107
compile: $(UNIT_TESTS) $(TARGET)
damiano@1994
   108
damiano@1970
   109
# Installs the engine, not the test binaries
damiano@1970
   110
.PHONY: install
vb@142
   111
install:
damiano@1970
   112
	$(MAKE) -C .. install