test/Makefile
author Edouard Tisserant <edouard@pep-project.org>
Thu, 20 Jul 2017 15:09:34 +0200
changeset 1932 1bbe9e6435b7
parent 1929 bad90979fd7e
child 1934 c59a9b6e9f40
permissions -rw-r--r--
re-started gpg-agent killings - it doesn't hurt
     1 
     2 # This file is under GNU General Public License 3.0
     3 # see LICENSE.txt
     4 
     5 HERE := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
     6 
     7 include ../Makefile.conf
     8 
     9 CC?=g++ -std=gnu++11 -pthread
    10 CXX?=g++ -std=gnu++11 -pthread
    11 LD?=$(CXX)
    12 LDFLAGS?=-L$(HOME)/lib
    13 LDLIBS?=-letpan -lpEpEngine -lstdc++ -L../asn.1 -lasn1
    14 ifeq ($(BUILD_FOR),Linux)
    15 	LDLIBS+= -luuid
    16 endif
    17 CXXFLAGS?=-std=c++11 -g -O0 -I../src -I../asn.1
    18 # CXXFLAGS=-O3 -DNDEBUG
    19 
    20 ifeq ("$(OPENPGP)","NETPGP")
    21 	LDLIBS+= -lnetpgp
    22 endif
    23 
    24 TARGET=pEpEngineTest
    25 
    26 UNIT_TESTS_SOURCE=$(wildcard *_test.cc)
    27 UNIT_TESTS=$(subst .cc,,$(UNIT_TESTS_SOURCE))
    28 UNIT_TESTS_RUN=$(subst .cc,_run,$(UNIT_TESTS_SOURCE))
    29 
    30 all: $(TARGET) $(UNIT_TESTS)
    31 
    32 .PHONY: clean
    33 
    34 # don't delete .o files!
    35 .PRECIOUS: %.o
    36 
    37 unexport GNUPGHOME;
    38 TEST_HOME=$(HERE)/test_home
    39 TEST_HOME_SKEL=$(TEST_HOME)_skel
    40 TEST_GNUPGHOME_SKEL=$(TEST_HOME)_skel/.gnupg
    41 
    42 ifeq ($(shell which gpg2), )
    43     GPG_CMD = gpg
    44 else
    45     GPG_CMD = gpg2
    46 endif
    47 
    48 ifeq ($(shell uname), Darwin)
    49     LIBPATH = DYLD_LIBRARY_PATH
    50     LLDB_BIN = /Applications/Xcode.app/Contents/Developer/usr/bin/lldb
    51 else
    52     LIBPATH = LD_LIBRARY_PATH
    53     LLDB_BIN = lldb
    54 endif
    55 
    56 TEST_CMD_PFX = $(LIBPATH)=$(HOME)/lib:../src HOME=$(TEST_HOME)
    57 
    58 define killgpg =
    59 	gpgconf --kill gpg-agent
    60 	HOME=$(TEST_HOME) gpgconf --kill gpg-agent
    61 	HOME=$(TEST_HOME_SKEL) gpgconf --kill gpg-agent
    62 endef
    63 ifeq ("$(OPENPGP)","NETPGP")
    64     killgpg_if_using_it =
    65 else
    66     killgpg_if_using_it = $(killgpg)
    67 endif
    68 
    69 test_home_skel:
    70 	$(killgpg)
    71 	mkdir -p test_home_skel
    72 	mkdir -p $(TEST_GNUPGHOME_SKEL)/private-keys-v1.d
    73 	$(GPG_CMD) --import --batch --homedir $(TEST_GNUPGHOME_SKEL) 0x*.asc *_sec.asc
    74 	$(killgpg)
    75 
    76 test_home_: test_home_skel
    77 	$(killgpg_if_using_it)
    78 	rm -rf test_home
    79 	cp -a test_home_skel test_home
    80 
    81 clean:
    82 	rm -f *.o $(TARGET) *.a *~ $(UNIT_TESTS) pep_Dokument_Titel.pdf msg4.asc
    83 	rm -Rf *.dSYM test_home test_home_skel pubring.gpg secring.gpg random_seed *.conf trustdb.gpg
    84 
    85 test: pEpEngineTest test_home_
    86 	$(TEST_CMD_PFX) ./pEpEngineTest
    87 
    88 %_test : %_test.o test_util.o
    89 	 $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
    90 
    91 %_run : % test_home_
    92 	$(TEST_CMD_PFX) ./$<
    93 
    94 %_lldb : % test_home_
    95 	$(TEST_CMD_PFX) $(LLDB_BIN) ./$<
    96 
    97 %_valgrind : % test_home_
    98 	$(TEST_CMD_PFX) valgrind --leak-check=yes ./$<
    99 
   100 %_gdb : % test_home_
   101 	$(TEST_CMD_PFX) gdb ./$<
   102 
   103 unit_tests: $(UNIT_TESTS) $(UNIT_TESTS_RUN)
   104 
   105 install:
   106 	make -C .. install