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
     1 
     2 # Copyright 2017, pEp Foundation
     3 # This file is part of pEpEngine
     4 # This file may be used under the terms of the GNU General Public License version 3
     5 # see LICENSE.txt
     6 
     7 include ../default.conf
     8 
     9 # I tend to not use spacing around assignment operators in Make. Sometimes weird things happen.
    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.
    11 PY_ENV := $(shell command -v python3 2> /dev/null)
    12 
    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.
    14 HERE:=$(CURDIR)
    15 TEST_HOME=$(HERE)/pEp_test_home
    16 
    17 TARGET=TestDriver
    18 
    19 SRCS := $(wildcard src/*.cc) $(wildcard src/*/*.cc)
    20 OBJS := $(addsuffix .o,$(basename $(SRCS)))
    21 DEPS := $(OBJS:.o=.d)
    22 
    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.
    24 INC_DIRS := ./include /usr/local/include ../src ../sync ../asn.1
    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!
    26 INC_FLAGS := $(addprefix -I,$(INC_DIRS)) $(GPGME_INC) $(CPPUNIT_INC)
    27 
    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.
    29 LDFLAGS += -L/usr/local/lib
    30 
    31 # For setting both C and C++ compiler flags, there is CPPFLAGS
    32 CFLAGS += -Wno-deprecated
    33 CXXFLAGS += -Wno-deprecated
    34 CFLAGS:=$(filter-out -Wall,$(CFLAGS))
    35 
    36 LDFLAGS+= $(ETPAN_LIB) $(CPPUNIT_LIB) -L../asn.1 -L../src
    37 LDLIBS+= -letpan -lpEpEngine -lstdc++ -lasn1
    38 
    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...)
    40 ifeq ($(BUILD_FOR),Linux)
    41 	LDLIBS+= -luuid
    42 endif
    43 
    44 ifeq ($(OPENPGP),NETPGP)
    45 	LDLIBS+= -lnetpgp
    46 	CFLAGS+= -DUSE_NETPGP
    47 ifeq ($(BUILD_FOR),Linux)
    48 	LDLIBS+= -ltre
    49 endif
    50 endif
    51 
    52 ifdef SQLITE3_FROM_OS
    53 	LDLIBS+= -lsqlite3
    54 endif
    55 
    56 # Looks like both LIBPATH and LLDB_BIN aren't needed any more.
    57 ifeq ($(shell uname),Darwin)
    58 	LIBPATH=DYLD_LIBRARY_PATH
    59 	LLDB_BIN=/Applications/Xcode.app/Contents/Developer/usr/bin/lldb
    60 else
    61 	LIBPATH=LD_LIBRARY_PATH
    62 	LLDB_BIN=lldb
    63 endif
    64 
    65 LDLIBS+= -lcpptest
    66 
    67 # Probably everything from here to 81 is not needed any more either...
    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.
    69 # Note that += can not be used here, as it changes the amount of whitespace
    70 EXTRA_LIB_PATHS=../src:
    71 ifdef ETPAN_LIB
    72 	EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(ETPAN_LIB)):
    73 endif
    74 ifdef GPGME_LIB
    75 	EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(GPGME_LIB)):
    76 endif
    77 ifdef NETPGP_LIB
    78 	EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(NETPGP_LIB)):
    79 endif
    80 
    81 # Remove trailing ':'
    82 EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS::=)
    83 
    84 CFLAGS:=$(filter-out -DNDEBUG,$(CFLAGS))
    85 ifneq ($(MAKECMDGOALS),clean)
    86 	ifneq (,$(findstring -DNDEBUG,$(CFLAGS)))
    87 		$(error The macro NDEBUG must not be defined for test compilation.)
    88 	endif
    89 endif
    90 
    91 CXXFLAGS:=$(filter-out -DNDEBUG,$(CXXFLAGS))
    92 ifneq ($(MAKECMDGOALS),clean)
    93 	ifneq (,$(findstring -DNDEBUG,$(CXXFLAGS)))
    94 		$(error The macro NDEBUG must not be defined for test compilation.)
    95 	endif
    96 endif
    97 
    98 CPPFLAGS += $(INC_FLAGS) -MMD -MP
    99 
   100 # Forgot the phony for all?
   101 all: suitemaker $(TARGET) test_home_ scripts
   102 	
   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.
   104 %.o: %.cc
   105 	$(CXX) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
   106 
   107 $(TARGET): $(OBJS)
   108 	$(CXX) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(OBJS) $(LDFLAGS) $(LDLIBS) -o $@
   109 
   110 .PHONY: suitemaker
   111 suitemaker:
   112 ifndef PY_ENV
   113 	@echo "WARNING: Can't find python3 - this is fine unless you're adding test suites. If so, please install python3."
   114 else
   115 ifndef EXCLUDE
   116 	$(PY_ENV) gensuitemaker.py
   117 else
   118 	# Comma-separated list, no spaces
   119 	$(PY_ENV) gensuitemaker.py --exclude=$(EXCLUDE)
   120 endif
   121 endif
   122 		
   123 # This target does nothing.
   124 .PHONY: test_home_
   125 test_home_: 
   126 	
   127 
   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.
   129 .PHONY: scripts
   130 scripts: 
   131 ifdef PY_ENV
   132 	$(PY_ENV) genscripts.py
   133 endif
   134 
   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.
   136 .PHONY: test
   137 test: all
   138 	$(TEST_DEBUGGER) ./$(TARGET)
   139 	
   140 .PHONY: clean
   141 clean:
   142 	$(RM) $(TARGET) $(OBJS) $(DEPS)
   143 	$(RM) $(HERE)/*Tests msg_2.0.asc
   144 
   145 
   146 
   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...
   148 -include $(DEPS)
   149