damiano@1960: # Copyright 2017, pEp Foundation damiano@1958: # This file is part of pEpEngine damiano@1958: # This file may be used under the terms of the GNU General Public License version 3 vb@1517: # see LICENSE.txt vb@1517: damiano@1958: HERE:=$(CURDIR) vb@2: damiano@2252: include ../default.conf vb@1422: damiano@1970: TARGET=pEpEngineTest damiano@1970: damiano@1970: unexport GNUPGHOME damiano@2246: TEST_HOME=$(HERE)test_home krista@2144: TEST_GNUPGHOME=$(TEST_HOME)/gnupg damiano@1970: damiano@1970: LDFLAGS+= $(ETPAN_LIB) -L../asn.1 -L../src damiano@1970: LDLIBS+= -letpan -lpEpEngine -lstdc++ -lasn1 damiano@1970: krista@1989: ifeq ($(BUILD_FOR),Linux) damiano@1970: LDLIBS+= -luuid krista@1989: endif krista@1988: damiano@1972: ifeq ($(OPENPGP),NETPGP) damiano@1970: LDLIBS+= -lnetpgp Edouard@178: endif Edouard@178: damiano@2002: ifdef SQLITE3_FROM_OS damiano@2002: LDLIBS+= -lsqlite3 damiano@2002: endif damiano@2002: damiano@1970: ifeq ($(shell uname),Darwin) damiano@1970: LIBPATH=DYLD_LIBRARY_PATH damiano@1970: LLDB_BIN=/Applications/Xcode.app/Contents/Developer/usr/bin/lldb damiano@1970: else damiano@1970: LIBPATH=LD_LIBRARY_PATH damiano@1970: LLDB_BIN=lldb Edouard@178: endif Edouard@178: damiano@1972: # 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: # Note that += can not be used here, as it changes the amount of whitespace damiano@1970: EXTRA_LIB_PATHS=../src: damiano@1970: ifdef ETPAN_LIB damiano@1970: EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(ETPAN_LIB)): damiano@1970: endif damiano@1970: ifdef GPGME_LIB damiano@1970: EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(GPGME_LIB)): damiano@1970: endif damiano@1970: ifdef NETPGP_LIB damiano@1970: EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(NETPGP_LIB)): damiano@1970: endif damiano@1970: # Remove trailing ':' damiano@1970: EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS::=) damiano@1970: krista@2144: TEST_CMD_PFX=$(LIBPATH)=$(EXTRA_LIB_PATHS) HOME=$(TEST_HOME) GNUPGHOME=$(TEST_GNUPGHOME) vb@2: vb@50: UNIT_TESTS_SOURCE=$(wildcard *_test.cc) vb@50: UNIT_TESTS=$(subst .cc,,$(UNIT_TESTS_SOURCE)) krista@1617: UNIT_TESTS_RUN=$(subst .cc,_run,$(UNIT_TESTS_SOURCE)) vb@2: damiano@2074: CFLAGS:=$(filter-out -DNDEBUG,$(CFLAGS)) damiano@2063: ifneq ($(MAKECMDGOALS),clean) damiano@2064: ifneq (,$(findstring -DNDEBUG,$(CFLAGS))) damiano@2063: $(error The macro NDEBUG must not be defined for test compilation.) damiano@2063: endif damiano@2062: endif damiano@2062: damiano@2075: CXXFLAGS:=$(filter-out -DNDEBUG,$(CXXFLAGS)) damiano@2075: ifneq ($(MAKECMDGOALS),clean) damiano@2075: ifneq (,$(findstring -DNDEBUG,$(CXXFLAGS))) damiano@2075: $(error The macro NDEBUG must not be defined for test compilation.) damiano@2075: endif damiano@2075: endif damiano@2075: damiano@1970: .PHONY: all vb@48: all: $(TARGET) $(UNIT_TESTS) vb@2: roker@1659: # don't delete .o files! roker@1659: .PRECIOUS: %.o roker@1659: damiano@1970: .PHONY: test_home_ edouard@1934: test_home_: krista@2144: -GNUPGHOME=$(TEST_GNUPGHOME) gpgconf --kill gpg-agent edouard@1934: rm -rf $(TEST_HOME) edouard@1934: mkdir -p $(TEST_GNUPGHOME)/private-keys-v1.d edouard@1934: $(GPG_CMD) --import --batch --homedir $(TEST_GNUPGHOME) 0x*.asc *_sec.asc edouard@1844: damiano@1970: .PHONY: clean vb@2: clean: damiano@2244: rm -f *.o $(TARGET) *.a *~ $(UNIT_TESTS) pep_Dokument_Titel.pdf msg4.asc msg_encrypt_for_self.asc edouard@1934: rm -Rf *.dSYM $(TEST_HOME) pubring.gpg secring.gpg random_seed *.conf trustdb.gpg vb@2: damiano@1970: .PHONY: test damiano@1970: test: $(TARGET) test_home_ damiano@1970: $(TEST_CMD_PFX) ./$< vb@2: roker@1656: %_test : %_test.o test_util.o damiano@2261: $(CXX) $^ $(LDFLAGS) $(LDLIBS) -o $@ roker@1656: edouard@1844: %_run : % test_home_ edouard@1844: $(TEST_CMD_PFX) ./$< Edouard@699: edouard@1844: %_lldb : % test_home_ edouard@1851: $(TEST_CMD_PFX) $(LLDB_BIN) ./$< roker@1656: edouard@1844: %_valgrind : % test_home_ edouard@1844: $(TEST_CMD_PFX) valgrind --leak-check=yes ./$< Edouard@745: edouard@1844: %_gdb : % test_home_ edouard@1844: $(TEST_CMD_PFX) gdb ./$< Edouard@770: damiano@1970: .PHONY: unit_tests Edouard@699: unit_tests: $(UNIT_TESTS) $(UNIT_TESTS_RUN) vb@142: damiano@1994: .PHONY: compile damiano@1994: compile: $(UNIT_TESTS) $(TARGET) damiano@1994: damiano@1970: # Installs the engine, not the test binaries damiano@1970: .PHONY: install vb@142: install: damiano@1970: $(MAKE) -C .. install