Minor doc cleanup, and revamp test/Makefile make-cleanup
authorDamiano Boppart <damiano.boppart@pep.security>
Sat, 22 Dec 2018 00:32:04 +0100
branchmake-cleanup
changeset 32023f440e46823c
parent 3201 105b50dfaf15
child 3203 47bb3a01f2e1
Minor doc cleanup, and revamp test/Makefile
Makefile
Makefile.conf
src/Makefile
test/Makefile
     1.1 --- a/Makefile	Fri Dec 21 16:05:05 2018 +0100
     1.2 +++ b/Makefile	Sat Dec 22 00:32:04 2018 +0100
     1.3 @@ -51,7 +51,7 @@
     1.4  
     1.5  .PHONY: test
     1.6  test: all
     1.7 -	$(MAKE) -C test test
     1.8 +	$(MAKE) -C test all
     1.9  
    1.10  .PHONY: package
    1.11  package: clean
     2.1 --- a/Makefile.conf	Fri Dec 21 16:05:05 2018 +0100
     2.2 +++ b/Makefile.conf	Sat Dec 22 00:32:04 2018 +0100
     2.3 @@ -51,12 +51,12 @@
     2.4  
     2.5  # If empty, create a release build.
     2.6  # Otherwise, create a debug build.
     2.7 -# This variable is ineffective in your local.conf file.
     2.8 +# This variable is ineffective when set anywhere else but here.
     2.9  DEBUG=placeholder
    2.10  
    2.11  # If empty, suppress compiler warnings.
    2.12  # Otherwise, print warnings.
    2.13 -# This variable is ineffective in your local.conf file.
    2.14 +# This variable is ineffective when set anywhere else but here.
    2.15  WARN=placeholder
    2.16  
    2.17  
    2.18 @@ -64,7 +64,7 @@
    2.19  TARGET_ARCH=
    2.20  
    2.21  # The following two variables will be appended to.
    2.22 -# You can thus not set them to a fixed value here.
    2.23 +# You can thus not set them to a final, fixed value here.
    2.24  ifeq ($(BUILD_FOR),Linux)
    2.25      LDFLAGS=
    2.26  else ifeq ($(BUILD_FOR),Darwin)
    2.27 @@ -174,7 +174,7 @@
    2.28  ######### YML2 #########
    2.29  YML2_PATH=$(HOME)/yml2
    2.30  
    2.31 -YML2_PROC=$(YML2_PATH)/yml2proc
    2.32 +YML2_PROC=$(YML2_PATH)/yml2proc $(YML2_OPTS)
    2.33  
    2.34  YML2_OPTS=--encoding=utf8
    2.35  
    2.36 @@ -185,17 +185,17 @@
    2.37  
    2.38  # asn1c include search flag
    2.39  ASN1C_INC=
    2.40 -#ASN1C_INC=-I$(PREFIX)/include
    2.41 +#ASN1C_INC=-I$(HOME)/include
    2.42  
    2.43  
    2.44  ######### libetpan #########
    2.45  # libetpan library search flag
    2.46  ETPAN_LIB=
    2.47 -#ETPAN_LIB=-L$(PREFIX)/lib
    2.48 +#ETPAN_LIB=-L$(HOME)/lib
    2.49  
    2.50  # libetpan include search flag
    2.51  ETPAN_INC=
    2.52 -#ETPAN_INC=-I$(PREFIX)/include
    2.53 +#ETPAN_INC=-I$(HOME)/include
    2.54  
    2.55  
    2.56  ######### sqlite3 #########
    2.57 @@ -213,10 +213,12 @@
    2.58  OPENPGP=GPG
    2.59  
    2.60  # libGPGME filename
    2.61 -ifeq ($(BUILD_FOR),Linux)
    2.62 -    LIBGPGME=libgpgme.so.11
    2.63 -else ifeq ($(BUILD_FOR),Darwin)
    2.64 -    LIBGPGME=libgpgme.11.dylib
    2.65 +ifeq ($(OPENPGP),GPG)
    2.66 +    ifeq ($(BUILD_FOR),Linux)
    2.67 +        LIBGPGME=libgpgme.so.11
    2.68 +    else ifeq ($(BUILD_FOR),Darwin)
    2.69 +        LIBGPGME=libgpgme.11.dylib
    2.70 +    endif
    2.71  endif
    2.72  
    2.73  # libGPGME library search flag
    2.74 @@ -229,11 +231,11 @@
    2.75  
    2.76  # NETPGP library search flag
    2.77  NETPGP_LIB=
    2.78 -#NETPGP_LIB=-L$(PREFIX)/lib
    2.79 +#NETPGP_LIB=-L$(HOME)/lib
    2.80  
    2.81  # libGPGME include search flag
    2.82  NETPGP_INC=
    2.83 -#NETPGP_INC=-I$(PREFIX)/include
    2.84 +#NETPGP_INC=-I$(HOME)/include
    2.85  
    2.86  
    2.87  ######### CppUnit #########
    2.88 @@ -256,10 +258,11 @@
    2.89  
    2.90  
    2.91  ######### Misc #########
    2.92 -#LLDB_BIN
    2.93 +# Add this for running tests in debugger
    2.94 +#TEST_DEBUGGER=lldb --batch -o r
    2.95  
    2.96 -# add this for running tests in debugger
    2.97 -#TEST_DEBUGGER=lldb --batch -o r
    2.98 +# comma-separated list of tests to exclude from gensuite (relevant for running tests only)
    2.99 +EXCLUDE=
   2.100  
   2.101  
   2.102  ######### Footer #########
     3.1 --- a/src/Makefile	Fri Dec 21 16:05:05 2018 +0100
     3.2 +++ b/src/Makefile	Sat Dec 22 00:32:04 2018 +0100
     3.3 @@ -92,7 +92,7 @@
     3.4  	      timestamp.h identity_list.h bloblist.h stringpair.h message.h mime.h \
     3.5  	      cryptotech.h sync_api.h blacklist.h pEp_string.h openpgp_compat.h \
     3.6  	      labeled_int_list.h key_reset.h base64.h sync_codec.h \
     3.7 -		  ../asn.1/*.h $(PREFIX)/include/pEp/
     3.8 +	      ../asn.1/*.h $(PREFIX)/include/pEp/
     3.9  
    3.10  .PHONY: uninstall
    3.11  uninstall:
     4.1 --- a/test/Makefile	Fri Dec 21 16:05:05 2018 +0100
     4.2 +++ b/test/Makefile	Sat Dec 22 00:32:04 2018 +0100
     4.3 @@ -1,126 +1,73 @@
     4.4 -
     4.5  # Copyright 2017, pEp Foundation
     4.6  # This file is part of pEpEngine
     4.7  # This file may be used under the terms of the GNU General Public License version 3
     4.8  # see LICENSE.txt
     4.9  
    4.10 +HERE:=$(CURDIR)
    4.11 +
    4.12  include ../Makefile.conf
    4.13  
    4.14 -# 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).
    4.15 -# Tests will totally build and run without it.
    4.16 +# User's without python3 will skip the generated parts of the test suite. That's OK.
    4.17  PY_ENV:=$(shell command -v python3 2> /dev/null)
    4.18  
    4.19 -# 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.
    4.20 -# 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.
    4.21 -#     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;
    4.22 -#     in that case, the test directory not being cleaned up *might* be problematic, but really probably isn't.
    4.23 -HERE:=$(CURDIR)
    4.24  TEST_HOME=$(HERE)/pEp_test_home
    4.25  
    4.26  TARGET=TestDriver
    4.27  
    4.28 -SRCS := $(wildcard src/*.cc) $(wildcard src/*/*.cc)
    4.29 -OBJS := $(addsuffix .o,$(basename $(SRCS)))
    4.30 -DEPS := $(OBJS:.o=.d)
    4.31 +SRCS:=$(wildcard src/*.cc) $(wildcard src/*/*.cc)
    4.32 +OBJS:=$(addsuffix .o,$(basename $(SRCS)))
    4.33 +DEPS:=$(OBJS:.o=.d)
    4.34  
    4.35 -# 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.
    4.36 -# 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.
    4.37 -INC_DIRS := ./include /usr/local/include ../src ../sync ../asn.1
    4.38 -# Whoa dude... addprefix is brilliant. Why didn't I find this before!? This could make setting all the *_INC and *_LIB so much nicer!
    4.39 -INC_FLAGS := $(addprefix -I,$(INC_DIRS)) $(GPGME_INC) $(CPPUNIT_INC)
    4.40  
    4.41 -# '+=' 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.
    4.42 -# KB: I doubt this was in any way intentional.
    4.43 -LDFLAGS+=-L/usr/local/lib
    4.44 +LDFLAGS+= -L../asn.1 -L../src $(ETPAN_LIB) $(CPPUNIT_LIB)
    4.45  
    4.46 -# For setting both C and C++ compiler flags, there is CPPFLAGS
    4.47 -# KB: This was almost certainly desperation because something wasn't working as it should. 
    4.48 -CFLAGS+=-Wno-deprecated
    4.49 -CXXFLAGS+=-Wno-deprecated
    4.50 -CFLAGS:=$(filter-out -Wall,$(CFLAGS))
    4.51 -
    4.52 -LDFLAGS+= $(ETPAN_LIB) $(CPPUNIT_LIB) -L../asn.1 -L../src
    4.53 -LDLIBS+= -letpan -lpEpEngine -lstdc++ -lasn1
    4.54 -
    4.55 -# 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...)
    4.56 -# KB: Feel free to change it.
    4.57 -ifeq ($(BUILD_FOR),Linux)
    4.58 -	LDLIBS+= -luuid
    4.59 +ifeq ($(OPENPGP),GPG)
    4.60 +    LDFLAGS+= $(GPGME_LIB)
    4.61 +else ifeq ($(OPENPGP),NETPGP)
    4.62 +    LDFLAGS+= $(NETGPG_LIB)
    4.63  endif
    4.64  
    4.65 -ifeq ($(OPENPGP),NETPGP)
    4.66 -	LDLIBS+= -lnetpgp
    4.67 -	CFLAGS+= -DUSE_NETPGP
    4.68 +
    4.69 +LDLIBS+= -letpan -lpEpEngine -lstdc++ -lasn1 -lcpptest
    4.70 +
    4.71  ifeq ($(BUILD_FOR),Linux)
    4.72 -	LDLIBS+= -ltre
    4.73 -endif
    4.74 +    LDLIBS+= -luuid
    4.75  endif
    4.76  
    4.77  ifdef SQLITE3_FROM_OS
    4.78 -	LDLIBS+= -lsqlite3
    4.79 +    LDLIBS+= -lsqlite3
    4.80  endif
    4.81  
    4.82 -# Looks like both LIBPATH and LLDB_BIN aren't needed any more.
    4.83 -# KB: I don't know. Building on MacOS is tetchy, so if it works without it, feel free to remove it.
    4.84 -#     But if you break Volker, prepare to hear about it :) Of all the Makefiles to be careful about optimising,
    4.85 -#     this one is the worst, because it's the ones devs need to "just work" at all times.
    4.86 -ifeq ($(shell uname),Darwin)
    4.87 -	LIBPATH=DYLD_LIBRARY_PATH
    4.88 -	LLDB_BIN=/Applications/Xcode.app/Contents/Developer/usr/bin/lldb
    4.89 -else
    4.90 -	LIBPATH=LD_LIBRARY_PATH
    4.91 -	LLDB_BIN=lldb
    4.92 +ifeq ($(OPENPGP),GPG)
    4.93 +    #LDLIBS+= -lgpgme
    4.94 +else ifeq ($(OPENPGP),NETPGP)
    4.95 +    LDLIBS+= -lnetpgp
    4.96 +    ifeq ($(BUILD_FOR),Linux)
    4.97 +        LDLIBS+= -ltre
    4.98 +    endif
    4.99  endif
   4.100  
   4.101 -LDLIBS+= -lcpptest
   4.102  
   4.103 -# Probably everything from here to 81 is not needed any more either...
   4.104 -# 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.
   4.105 -# Note that += can not be used here, as it changes the amount of whitespace
   4.106 -# KB: See above.
   4.107 -EXTRA_LIB_PATHS=../src:
   4.108 -ifdef ETPAN_LIB
   4.109 -	EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(ETPAN_LIB)):
   4.110 -endif
   4.111 -ifdef GPGME_LIB
   4.112 -	EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(GPGME_LIB)):
   4.113 -endif
   4.114 -ifdef NETPGP_LIB
   4.115 -	EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(NETPGP_LIB)):
   4.116 +CXXFLAGS:=$(filter-out -DNDEBUG,$(CXXFLAGS))
   4.117 +
   4.118 +# FIXME Possibly missing incdirs: ASN1C_INC
   4.119 +CXXFLAGS+= -I./include -I../sync $(CPPUNIT_INC) -Wno-deprecated
   4.120 +
   4.121 +ifeq ($(OPENPGP),GPG)
   4.122 +    CXXFLAGS+= -DUSE_GPG $(GPGME_INC)
   4.123 +else ifeq ($(OPENPGP),NETPGP)
   4.124 +    CXXFLAGS+= -DUSE_NETPGP $(NETPGP_INC)
   4.125  endif
   4.126  
   4.127 -# Remove trailing ':'
   4.128 -EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS::=)
   4.129  
   4.130 -CFLAGS:=$(filter-out -DNDEBUG,$(CFLAGS))
   4.131 -ifneq ($(MAKECMDGOALS),clean)
   4.132 -	ifneq (,$(findstring -DNDEBUG,$(CFLAGS)))
   4.133 -		$(error The macro NDEBUG must not be defined for test compilation.)
   4.134 -	endif
   4.135 -endif
   4.136 +.PHONY: all
   4.137 +all: suitemaker $(TARGET) scripts
   4.138  
   4.139 -CXXFLAGS:=$(filter-out -DNDEBUG,$(CXXFLAGS))
   4.140 -ifneq ($(MAKECMDGOALS),clean)
   4.141 -	ifneq (,$(findstring -DNDEBUG,$(CXXFLAGS)))
   4.142 -		$(error The macro NDEBUG must not be defined for test compilation.)
   4.143 -	endif
   4.144 -endif
   4.145 -
   4.146 -CPPFLAGS += $(INC_FLAGS) -MMD -MP
   4.147 -
   4.148 -# Forgot the phony for all?
   4.149 -# KB: I have no idea. Again, was just making it work. I bow to the master ;)
   4.150 -all: suitemaker $(TARGET) test_home_ scripts
   4.151 -	
   4.152 -# 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.
   4.153 -# 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
   4.154 -#     investigate why not, I needed the tests to run with the right flags.
   4.155 -#     You can do what you want here, as long as I get all the flags I expect to see :)
   4.156 -%.o: %.cc
   4.157 -	$(CXX) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
   4.158 +%.d: %.cc
   4.159 +	$(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< | sed -e 's,\($*\)\.o[ :]*,\1.o $@: ,g' > $@
   4.160  
   4.161  $(TARGET): $(OBJS)
   4.162 -	$(CXX) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(OBJS) $(LDFLAGS) $(LDLIBS) -o $@
   4.163 +	$(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $@
   4.164  
   4.165  .PHONY: suitemaker
   4.166  suitemaker:
   4.167 @@ -134,16 +81,9 @@
   4.168  	$(PY_ENV) gensuitemaker.py --exclude=$(EXCLUDE)
   4.169  endif
   4.170  endif
   4.171 -		
   4.172 -# This target does nothing.
   4.173 -.PHONY: test_home_
   4.174 -test_home_: 
   4.175 -	
   4.176  
   4.177 -# 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.
   4.178 -# KB: That is totally what I want here.
   4.179  .PHONY: scripts
   4.180 -scripts: 
   4.181 +scripts:
   4.182  ifdef PY_ENV
   4.183  	$(PY_ENV) genscripts.py
   4.184  endif
   4.185 @@ -151,15 +91,13 @@
   4.186  .PHONY: test
   4.187  test: all
   4.188  	$(TEST_DEBUGGER) ./$(TARGET)
   4.189 -	
   4.190 +
   4.191  .PHONY: clean
   4.192  clean:
   4.193  	$(RM) $(TARGET) $(OBJS) $(DEPS)
   4.194  	$(RM) $(HERE)/*Tests msg_2.0.asc
   4.195  
   4.196 -
   4.197 -
   4.198 -# 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...
   4.199 -# KB: This might be leftover.
   4.200 --include $(DEPS)
   4.201 - 
   4.202 +# If only the goal 'clean' is given, do not generate and include the '%.d' files.¬
   4.203 +ifneq ($(MAKECMDGOALS),clean)
   4.204 +    -include $(DEPS)
   4.205 +endif