test/Makefile
author Damiano Boppart <damiano.boppart@pep.security>
Thu, 20 Dec 2018 21:47:52 +0100
branchmake-cleanup
changeset 3199 e16d89af41ad
parent 3180 f7ce02c58571
child 3200 329005a93c6a
permissions -rw-r--r--
Add comments on test/Makefile cleanup
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@1517
     5
# see LICENSE.txt
vb@1517
     6
damiano@2210
     7
include ../default.conf
vb@1422
     8
damiano@3199
     9
# I tend to not use spacing around assignment operators in Make. Sometimes weird things happen.
damiano@3199
    10
# Also -- this is very much a matter of taste -- my python scripts all have '#!/usr/bin/env python3' as the first line, and it's the user's job for there to always be an appropriate python3. I wouldn't add any business logic in the makefile regarding finding the python interpreter, if I just run my own python scripts.
krista@2645
    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@2637
    14
HERE:=$(CURDIR)
krista@2639
    15
TEST_HOME=$(HERE)/pEp_test_home
krista@2637
    16
krista@2638
    17
TARGET=TestDriver
krista@2638
    18
krista@2639
    19
SRCS := $(wildcard src/*.cc) $(wildcard src/*/*.cc)
krista@2637
    20
OBJS := $(addsuffix .o,$(basename $(SRCS)))
krista@2637
    21
DEPS := $(OBJS:.o=.d)
damiano@1970
    22
damiano@3199
    23
# 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@3170
    24
INC_DIRS := ./include /usr/local/include ../src ../sync ../asn.1
damiano@3199
    25
# 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
    26
INC_FLAGS := $(addprefix -I,$(INC_DIRS)) $(GPGME_INC) $(CPPUNIT_INC)
krista@2637
    27
damiano@3199
    28
# '+=' 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@2637
    29
LDFLAGS += -L/usr/local/lib
krista@2637
    30
damiano@3199
    31
# For setting both C and C++ compiler flags, there is CPPFLAGS
krista@2637
    32
CFLAGS += -Wno-deprecated
krista@2637
    33
CXXFLAGS += -Wno-deprecated
krista@3170
    34
CFLAGS:=$(filter-out -Wall,$(CFLAGS))
damiano@1970
    35
damiano@2975
    36
LDFLAGS+= $(ETPAN_LIB) $(CPPUNIT_LIB) -L../asn.1 -L../src
damiano@1970
    37
LDLIBS+= -letpan -lpEpEngine -lstdc++ -lasn1
damiano@1970
    38
damiano@3199
    39
# 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@1989
    40
ifeq ($(BUILD_FOR),Linux)
krista@2637
    41
	LDLIBS+= -luuid
krista@1989
    42
endif
krista@1988
    43
damiano@1972
    44
ifeq ($(OPENPGP),NETPGP)
krista@2637
    45
	LDLIBS+= -lnetpgp
krista@3170
    46
	CFLAGS+= -DUSE_NETPGP
krista@3164
    47
ifeq ($(BUILD_FOR),Linux)
krista@3164
    48
	LDLIBS+= -ltre
krista@3164
    49
endif
Edouard@178
    50
endif
Edouard@178
    51
damiano@2002
    52
ifdef SQLITE3_FROM_OS
krista@2637
    53
	LDLIBS+= -lsqlite3
damiano@2002
    54
endif
damiano@2002
    55
damiano@3199
    56
# Looks like both LIBPATH and LLDB_BIN aren't needed any more.
damiano@1970
    57
ifeq ($(shell uname),Darwin)
krista@2637
    58
	LIBPATH=DYLD_LIBRARY_PATH
krista@2637
    59
	LLDB_BIN=/Applications/Xcode.app/Contents/Developer/usr/bin/lldb
damiano@1970
    60
else
krista@2637
    61
	LIBPATH=LD_LIBRARY_PATH
krista@2637
    62
	LLDB_BIN=lldb
Edouard@178
    63
endif
Edouard@178
    64
krista@2925
    65
LDLIBS+= -lcpptest
krista@2637
    66
damiano@3199
    67
# Probably everything from here to 81 is not needed any more either...
damiano@1972
    68
# 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
    69
# Note that += can not be used here, as it changes the amount of whitespace
damiano@1970
    70
EXTRA_LIB_PATHS=../src:
damiano@1970
    71
ifdef ETPAN_LIB
krista@2637
    72
	EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(ETPAN_LIB)):
damiano@1970
    73
endif
damiano@1970
    74
ifdef GPGME_LIB
krista@2637
    75
	EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(GPGME_LIB)):
damiano@1970
    76
endif
damiano@1970
    77
ifdef NETPGP_LIB
krista@2637
    78
	EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(NETPGP_LIB)):
damiano@1970
    79
endif
krista@2637
    80
damiano@1970
    81
# Remove trailing ':'
damiano@1970
    82
EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS::=)
damiano@1970
    83
damiano@2074
    84
CFLAGS:=$(filter-out -DNDEBUG,$(CFLAGS))
damiano@2063
    85
ifneq ($(MAKECMDGOALS),clean)
krista@2637
    86
	ifneq (,$(findstring -DNDEBUG,$(CFLAGS)))
krista@2637
    87
		$(error The macro NDEBUG must not be defined for test compilation.)
krista@2637
    88
	endif
damiano@2062
    89
endif
damiano@2062
    90
damiano@2075
    91
CXXFLAGS:=$(filter-out -DNDEBUG,$(CXXFLAGS))
damiano@2075
    92
ifneq ($(MAKECMDGOALS),clean)
krista@2637
    93
	ifneq (,$(findstring -DNDEBUG,$(CXXFLAGS)))
krista@2637
    94
		$(error The macro NDEBUG must not be defined for test compilation.)
krista@2637
    95
	endif
damiano@2075
    96
endif
damiano@2075
    97
krista@2637
    98
CPPFLAGS += $(INC_FLAGS) -MMD -MP
roker@1659
    99
damiano@3199
   100
# Forgot the phony for all?
krista@2703
   101
all: suitemaker $(TARGET) test_home_ scripts
krista@2639
   102
	
damiano@3199
   103
# 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@3170
   104
%.o: %.cc
krista@3170
   105
	$(CXX) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
krista@3170
   106
krista@2637
   107
$(TARGET): $(OBJS)
krista@3170
   108
	$(CXX) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(OBJS) $(LDFLAGS) $(LDLIBS) -o $@
krista@2639
   109
krista@2642
   110
.PHONY: suitemaker
krista@2642
   111
suitemaker:
krista@2642
   112
ifndef PY_ENV
krista@2642
   113
	@echo "WARNING: Can't find python3 - this is fine unless you're adding test suites. If so, please install python3."
krista@2642
   114
else
krista@2941
   115
ifndef EXCLUDE
krista@2642
   116
	$(PY_ENV) gensuitemaker.py
krista@2941
   117
else
krista@2941
   118
	# Comma-separated list, no spaces
krista@2941
   119
	$(PY_ENV) gensuitemaker.py --exclude=$(EXCLUDE)
krista@2941
   120
endif
krista@2642
   121
endif
krista@2642
   122
		
damiano@3199
   123
# This target does nothing.
krista@2639
   124
.PHONY: test_home_
krista@2639
   125
test_home_: 
krista@2703
   126
	
krista@2703
   127
damiano@3199
   128
# 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.
vb@2750
   129
.PHONY: scripts
krista@2703
   130
scripts: 
krista@2703
   131
ifdef PY_ENV
krista@2703
   132
	$(PY_ENV) genscripts.py
krista@2703
   133
endif
edouard@1844
   134
damiano@3199
   135
# 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@2639
   136
.PHONY: test
krista@2639
   137
test: all
vb@2750
   138
	$(TEST_DEBUGGER) ./$(TARGET)
krista@2639
   139
	
damiano@1970
   140
.PHONY: clean
vb@2
   141
clean:
krista@2637
   142
	$(RM) $(TARGET) $(OBJS) $(DEPS)
vb@2831
   143
	$(RM) $(HERE)/*Tests msg_2.0.asc
vb@2
   144
roker@1656
   145
roker@1656
   146
damiano@3199
   147
# 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@2639
   148
-include $(DEPS)
krista@2639
   149