test/Makefile
author Krista Bennett <krista@pep-project.org>
Fri, 21 Dec 2018 11:14:10 +0100
branchmake-cleanup
changeset 3200 329005a93c6a
parent 3199 e16d89af41ad
child 3201 105b50dfaf15
permissions -rw-r--r--
Response to test/Makefile comments for damiano
krista@2637
     1
damiano@1960
     2
# Copyright 2017, pEp Foundation
damiano@1958
     3
# This file is part of pEpEngine
damiano@1958
     4
# This file may be used under the terms of the GNU General Public License version 3
vb@1513
     5
# see LICENSE.txt
vb@1513
     6
damiano@2210
     7
include ../default.conf
vb@2
     8
krista@3200
     9
# This is done this way because we presume that users who don't have python3 installed are also not bothering with the generated parts of the test suite (i.e. non-devs).
krista@3200
    10
# Tests will totally build and run without it.
krista@3200
    11
PY_ENV:=$(shell command -v python3 2> /dev/null)
krista@2642
    12
damiano@3199
    13
# Since you 'include' before evaluating CURDIR, I think it's possible that CURDIR does not have the value you think it might have. Yes, make is awkward.
krista@3200
    14
# KB: These are probably redundant anyway. But it is supposed to correspond to the directory in src/TestDriver.cc, which is whatever the cwd is that TestDriver is running in.
krista@3200
    15
#     It's a pretty trivial point anyway - it's only used in the clean target, and only really matters if tests were interrupted because of a seg fault or non-test assert;
krista@3200
    16
#     in that case, the test directory not being cleaned up *might* be problematic, but really probably isn't.
krista@2637
    17
HERE:=$(CURDIR)
krista@2639
    18
TEST_HOME=$(HERE)/pEp_test_home
damiano@1970
    19
krista@2638
    20
TARGET=TestDriver
krista@2638
    21
krista@2639
    22
SRCS := $(wildcard src/*.cc) $(wildcard src/*/*.cc)
krista@2637
    23
OBJS := $(addsuffix .o,$(basename $(SRCS)))
krista@2637
    24
DEPS := $(OBJS:.o=.d)
krista@2637
    25
damiano@3199
    26
# Using '/usr/local/include' is very much a "works on my machine" solution to the problem. Either, the compiler search paths are enough, otherwise define a BLA_INC and BLA_LIB path to make clear to other developers what you are looking for outside the standard paths.
krista@3200
    27
# KB: Sure. Then fix that - again, audience of 1-4, and we needed to make our tests work. This file tends to get hacked when settings from above don't end up in compilation.
krista@3170
    28
INC_DIRS := ./include /usr/local/include ../src ../sync ../asn.1
damiano@3199
    29
# Whoa dude... addprefix is brilliant. Why didn't I find this before!? This could make setting all the *_INC and *_LIB so much nicer!
damiano@2975
    30
INC_FLAGS := $(addprefix -I,$(INC_DIRS)) $(GPGME_INC) $(CPPUNIT_INC)
krista@2637
    31
damiano@3199
    32
# '+=' is a magic assignment operators. It ensures that there is exactly one space between the old value and the suffix. Yes, this means it might strip spaces. At any rate, there is no need to add a space after the operator.
krista@3200
    33
# KB: I doubt this was in any way intentional.
krista@3200
    34
LDFLAGS+=-L/usr/local/lib
krista@2637
    35
damiano@3199
    36
# For setting both C and C++ compiler flags, there is CPPFLAGS
krista@3200
    37
# KB: This was almost certainly desperation because something wasn't working as it should. 
krista@3200
    38
CFLAGS+=-Wno-deprecated
krista@3200
    39
CXXFLAGS+=-Wno-deprecated
krista@3170
    40
CFLAGS:=$(filter-out -Wall,$(CFLAGS))
damiano@1970
    41
damiano@2975
    42
LDFLAGS+= $(ETPAN_LIB) $(CPPUNIT_LIB) -L../asn.1 -L../src
damiano@1970
    43
LDLIBS+= -letpan -lpEpEngine -lstdc++ -lasn1
damiano@1970
    44
damiano@3199
    45
# Caution: you're using tab to indent here, but none of the lines from here to 60 are recipes. Indentation should be done with spaces. This only works because Make is such a gratious tool. (Yeah, right...)
krista@3200
    46
# KB: Feel free to change it.
krista@1989
    47
ifeq ($(BUILD_FOR),Linux)
krista@2637
    48
	LDLIBS+= -luuid
Edouard@178
    49
endif
Edouard@178
    50
damiano@1972
    51
ifeq ($(OPENPGP),NETPGP)
krista@2637
    52
	LDLIBS+= -lnetpgp
krista@3170
    53
	CFLAGS+= -DUSE_NETPGP
krista@3164
    54
ifeq ($(BUILD_FOR),Linux)
krista@3164
    55
	LDLIBS+= -ltre
krista@3164
    56
endif
edouard@1939
    57
endif
edouard@1939
    58
damiano@2002
    59
ifdef SQLITE3_FROM_OS
krista@2637
    60
	LDLIBS+= -lsqlite3
damiano@2002
    61
endif
damiano@2002
    62
damiano@3199
    63
# Looks like both LIBPATH and LLDB_BIN aren't needed any more.
krista@3200
    64
# KB: I don't know. Building on MacOS is tetchy, so if it works without it, feel free to remove it.
krista@3200
    65
#     But if you break Volker, prepare to hear about it :) Of all the Makefiles to be careful about optimising,
krista@3200
    66
#     this one is the worst, because it's the ones devs need to "just work" at all times.
damiano@1970
    67
ifeq ($(shell uname),Darwin)
krista@2637
    68
	LIBPATH=DYLD_LIBRARY_PATH
krista@2637
    69
	LLDB_BIN=/Applications/Xcode.app/Contents/Developer/usr/bin/lldb
damiano@1970
    70
else
krista@2637
    71
	LIBPATH=LD_LIBRARY_PATH
krista@2637
    72
	LLDB_BIN=lldb
damiano@1970
    73
endif
damiano@1970
    74
krista@2925
    75
LDLIBS+= -lcpptest
krista@2637
    76
damiano@3199
    77
# Probably everything from here to 81 is not needed any more either...
damiano@1972
    78
# 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
    79
# Note that += can not be used here, as it changes the amount of whitespace
krista@3200
    80
# KB: See above.
damiano@1970
    81
EXTRA_LIB_PATHS=../src:
damiano@1970
    82
ifdef ETPAN_LIB
krista@2637
    83
	EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(ETPAN_LIB)):
damiano@1970
    84
endif
damiano@1970
    85
ifdef GPGME_LIB
krista@2637
    86
	EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(GPGME_LIB)):
damiano@1970
    87
endif
damiano@1970
    88
ifdef NETPGP_LIB
krista@2637
    89
	EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(NETPGP_LIB)):
damiano@1970
    90
endif
krista@2637
    91
damiano@1970
    92
# Remove trailing ':'
damiano@1970
    93
EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS::=)
damiano@1970
    94
damiano@2074
    95
CFLAGS:=$(filter-out -DNDEBUG,$(CFLAGS))
damiano@2063
    96
ifneq ($(MAKECMDGOALS),clean)
krista@2637
    97
	ifneq (,$(findstring -DNDEBUG,$(CFLAGS)))
krista@2637
    98
		$(error The macro NDEBUG must not be defined for test compilation.)
krista@2637
    99
	endif
damiano@2062
   100
endif
damiano@2062
   101
damiano@2075
   102
CXXFLAGS:=$(filter-out -DNDEBUG,$(CXXFLAGS))
damiano@2075
   103
ifneq ($(MAKECMDGOALS),clean)
krista@2637
   104
	ifneq (,$(findstring -DNDEBUG,$(CXXFLAGS)))
krista@2637
   105
		$(error The macro NDEBUG must not be defined for test compilation.)
krista@2637
   106
	endif
damiano@2075
   107
endif
damiano@2075
   108
krista@2637
   109
CPPFLAGS += $(INC_FLAGS) -MMD -MP
roker@1659
   110
damiano@3199
   111
# Forgot the phony for all?
krista@3200
   112
# KB: I have no idea. Again, was just making it work. I bow to the master ;)
krista@2696
   113
all: suitemaker $(TARGET) test_home_ scripts
krista@2639
   114
	
damiano@3199
   115
# There is probably a built-in rules that makes this redundant. Unless we're not using '.cc' or 'CPPFLAGS' as is canon in GNU Make land.
krista@3200
   116
# KB: NOPE. This had to be readded because the built-in rules did NOT use them. Leave it unless you can fix that. I didn't have time to
krista@3200
   117
#     investigate why not, I needed the tests to run with the right flags.
krista@3200
   118
#     You can do what you want here, as long as I get all the flags I expect to see :)
krista@3170
   119
%.o: %.cc
krista@3170
   120
	$(CXX) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
krista@3170
   121
krista@2637
   122
$(TARGET): $(OBJS)
krista@3170
   123
	$(CXX) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(OBJS) $(LDFLAGS) $(LDLIBS) -o $@
edouard@1844
   124
krista@2642
   125
.PHONY: suitemaker
krista@2642
   126
suitemaker:
krista@2642
   127
ifndef PY_ENV
krista@2642
   128
	@echo "WARNING: Can't find python3 - this is fine unless you're adding test suites. If so, please install python3."
krista@2642
   129
else
krista@2941
   130
ifndef EXCLUDE
krista@2642
   131
	$(PY_ENV) gensuitemaker.py
krista@2941
   132
else
krista@2941
   133
	# Comma-separated list, no spaces
krista@2941
   134
	$(PY_ENV) gensuitemaker.py --exclude=$(EXCLUDE)
krista@2941
   135
endif
krista@2642
   136
endif
krista@2642
   137
		
damiano@3199
   138
# This target does nothing.
krista@2639
   139
.PHONY: test_home_
krista@2639
   140
test_home_: 
krista@2696
   141
	
krista@2696
   142
damiano@3199
   143
# So, if there is no python, then 'scripts' will trivially be up to date, because there is no recipe associated with this rule. That's probably not what you want.
krista@3200
   144
# KB: That is totally what I want here.
vb@2750
   145
.PHONY: scripts
krista@2696
   146
scripts: 
krista@2696
   147
ifdef PY_ENV
krista@2696
   148
	$(PY_ENV) genscripts.py
krista@2696
   149
endif
krista@2639
   150
damiano@3199
   151
# Ah, yes, here it is. Finally someone tripped over me introducing both Makefile.conf and default.conf. TEST_DEBUGGER is documented in one, but not the other Makefile. Yeah, I should clean this up, otherwise every time a new knob is added, it will only appear in either Makefile.conf or default.conf.
krista@3200
   152
# KB: Discuss with Volker and/or Neal. I don't use the TEST_DEBUGGER thing.
krista@2639
   153
.PHONY: test
krista@2639
   154
test: all
vb@2750
   155
	$(TEST_DEBUGGER) ./$(TARGET)
krista@2639
   156
	
damiano@1970
   157
.PHONY: clean
vb@2
   158
clean:
krista@2637
   159
	$(RM) $(TARGET) $(OBJS) $(DEPS)
vb@2831
   160
	$(RM) $(HERE)/*Tests msg_2.0.asc
vb@2
   161
krista@2639
   162
krista@2639
   163
damiano@3199
   164
# You know, I think we have this "compiler generates Makefiles" pattern in another makefile in the engine, but there it looks completly different. From reading just this makefile: are you sure, the compiler generated Makefiles are actually every generated? You don't have DEPS as a prerequisite anywhere. Is there some built-in rule that has %.d as a prerequisite? Without further investigation I am not convinced the %.d files are ever generated...
krista@3200
   165
# KB: This might be leftover.
krista@2637
   166
-include $(DEPS)
krista@2639
   167