From 9b41720bd014cf8b9024abc548061130a6502605 Mon Sep 17 00:00:00 2001 From: Damiano Boppart Date: Sat, 15 Dec 2018 17:48:57 +0100 Subject: [PATCH 1/6] First attempt at makefile cleanup --- Makefile | 70 +++++++++++++++++++++++++++++++++++---------------- Makefile.conf | 48 ++++++++++++++++++++++++++++++++--- 2 files changed, 94 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index e99669d..4676b74 100644 --- a/Makefile +++ b/Makefile @@ -1,49 +1,77 @@ -# this file is under GNU GPL 3.0, see LICENSE.txt +# Copyright 2018, pEp Foundation +# This file is part of lib pEp Adapter +# This file may be used under the terms of the GNU General Public License version 3 # see LICENSE.txt include Makefile.conf --include local.conf -CXXFLAGS += -I$(HOME)/include -std=c++14 -O0 -g +ifneq ($(wildcard local.conf),) + $(info ================================================) + $(info Overrides in \`local.conf\` are used.) + $(info ================================================) +endif + +ifdef BUILD_CONFIG + $(info ================================================) + $(info Overrides in \`$(BUILD_CONFIG)\` are used.) + $(info ================================================) +endif SOURCE=$(wildcard *.cc) HEADERS=$(wildcard *.hh *.hxx) OBJECTS=$(subst .cc,.o,$(SOURCE)) WITHOUT_TESTS=$(patsubst test%.o,,$(OBJECTS)) +TARGET=libpEpAdapter.a +EXTRA_LIB_PATHS=.: +ifdef ENGINE_LIB + EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(ENGINE_LIB)): +endif + +# Remove trailing ':' +EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS::=) + +ifeq ($(BUILD_FOR),Darwin) + LIBPATH=DYLD_LIBRARY_PATH +else + LIBPATH=LD_LIBRARY_PATH +endif + +$(TEST_CMD_PFX)=$(LIBPATH)=$(EXTRA_LIB_PATHS) + + +.PHONY: all all: $(TARGET) +# Rule copied from make's built-in rules %.o: %.cc %.hh - $(CXX) $(CXXFLAGS) -c $< + $(COMPILE.cc) $(OUTPUT_OPTION) $< $(TARGET): $(WITHOUT_TESTS) ar -rc $@ $^ -.PHONY: clean distclean test install uninstall - +.PHONY: clean clean: - rm -f $(TARGET) $(OBJECTS) *.a test_adapter lib + rm -f $(TARGET) $(OBJECTS) *.a test_adapter test_library lib +.PHONY: distclean distclean: clean rm -Rf .gnupg .pEp_management* +# $$(pwd) will return the incorrect directory, if make is run with `make -C ...`. +.PHONY: test test: test_adapter test_library -ifeq ($(HOME),$(PREFIX)) - -ln -fs $$HOME/lib -endif - HOME=$$(pwd) ./test_adapter - -test_adapter: test_adapter.o $(TARGET) - $(CXX) -o $@ -L$(PEP)/lib -lpEpEngine -L. -lpEpAdapter $< + $(TEST_CMD_PFX) HOME=$$(pwd) ./test_adapter -test_library: test_library.o $(TARGET) - $(CXX) -o $@ -L$(PEP)/lib -lpEpEngine -L. -lpEpAdapter $< +test_%: test_%.o $(TARGET) +.PHONY: install install: $(TARGET) - -mkdir -p $(PEP)/include/pEp - cp $(HEADERS) $(PEP)/include/pEp/ - cp $(TARGET) $(PEP)/lib/ + -mkdir -p $(PREFIX)/include/pEp + cp $(HEADERS) $(PREFIX)/include/pEp/ + cp $(TARGET) $(PREFIX)/lib/ +.PHONY: uninstall uninstall: - cd $(PEP)/include && rm -f $(HEADERS) - cd $(PEP)/lib && rm -f $(TARGET) + cd $(PREFIX)/include/pEp && rm -f $(HEADERS) + cd $(PREFIX)/lib && rm -f $(TARGET) diff --git a/Makefile.conf b/Makefile.conf index b409f75..f49b165 100644 --- a/Makefile.conf +++ b/Makefile.conf @@ -1,7 +1,49 @@ -# this file is under GNU GPL 3.0, see LICENSE.txt +# Copyright 2018, pEp Foundation +# This file is part of lib pEp Adapter +# This file may be used under the terms of the GNU General Public License version 3 # see LICENSE.txt -TARGET=libpEpAdapter.a +######### Header ######### +HERE:=$(dir $(lastword $(MAKEFILE_LIST))) + + +######### General ######### +BUILD_FOR:=$(shell uname) + PREFIX=$(HOME) -PEP=$(HOME) + +######### C and C++ ######### +LDFLAGS=$(ENGINE_LIB) + +LDLIBS=-lstdc++ -lpEpEngine -lpEpAdapter + + +######### C++ ######### +ifeq ($(BUILD_FOR),Linux) + CXX=g++ -std=c++14 +else ifeq ($(BUILD_FOR),Darwin) + CXX=clang -std=c++14 +endif + +ifeq ($(BUILD_FOR),Linux) + CXXFLAGS=-fdiagnostics-color=always -O0 -g $(ENGINE_INC) +else ifeq ($(BUILD_FOR),Darwin) + CXXFLAGS=-fcolor-diagnostics -O0 -g $(ENGINE_INC) +endif + + +######### Engine ######### +ENGINE_LIB=-L$(HOME)/code/engine/build/lib +#ENGINE_LIB=-L$(HOME)/local/lib + +ENGINE_INC=-I$(HOME)/code/engine/build/include +#ENGINE_INC=-I$(HOME)/local/inc + + +######### Footer ######### +-include $(HERE)/local.conf + +ifdef BUILD_CONFIG + include $(BUILD_CONFIG) +endif From 81599ce27df4526f251920a2c07778fb8b6c85e5 Mon Sep 17 00:00:00 2001 From: Damiano Boppart Date: Mon, 17 Dec 2018 13:07:21 +0100 Subject: [PATCH 2/6] Fix variable definition syntax --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4676b74..b86e080 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ else LIBPATH=LD_LIBRARY_PATH endif -$(TEST_CMD_PFX)=$(LIBPATH)=$(EXTRA_LIB_PATHS) +TEST_CMD_PFX=$(LIBPATH)=$(EXTRA_LIB_PATHS) .PHONY: all From 63b2c2f5ccaf108af733d8aa9f9ea318fd0abc81 Mon Sep 17 00:00:00 2001 From: Damiano Boppart Date: Tue, 18 Dec 2018 14:06:13 +0100 Subject: [PATCH 3/6] Fix clean target, and library search paths --- Makefile | 2 ++ Makefile.conf | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b86e080..90d8bf9 100644 --- a/Makefile +++ b/Makefile @@ -53,6 +53,8 @@ $(TARGET): $(WITHOUT_TESTS) .PHONY: clean clean: rm -f $(TARGET) $(OBJECTS) *.a test_adapter test_library lib + rm -rf test_adapter.dSYM + rm -rf test_library.dSYM .PHONY: distclean distclean: clean diff --git a/Makefile.conf b/Makefile.conf index f49b165..50d2386 100644 --- a/Makefile.conf +++ b/Makefile.conf @@ -14,7 +14,7 @@ PREFIX=$(HOME) ######### C and C++ ######### -LDFLAGS=$(ENGINE_LIB) +LDFLAGS=$(ENGINE_LIB) -L. LDLIBS=-lstdc++ -lpEpEngine -lpEpAdapter From 69a69265cafbc62a964b38d5a99f89e56ef96173 Mon Sep 17 00:00:00 2001 From: Damiano Boppart Date: Thu, 17 Jan 2019 16:06:31 +0100 Subject: [PATCH 4/6] Fix clean target --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 90d8bf9..865a87f 100644 --- a/Makefile +++ b/Makefile @@ -55,6 +55,8 @@ clean: rm -f $(TARGET) $(OBJECTS) *.a test_adapter test_library lib rm -rf test_adapter.dSYM rm -rf test_library.dSYM + rm -rf .gnupg/ + rm -f .pEp_management.db* .PHONY: distclean distclean: clean From a24311cb18b52c3cf26f16694f103d24a902d15b Mon Sep 17 00:00:00 2001 From: Damiano Boppart Date: Thu, 17 Jan 2019 16:19:04 +0100 Subject: [PATCH 5/6] Create all required folders when installing --- .hgignore | 1 + Makefile | 1 + 2 files changed, 2 insertions(+) diff --git a/.hgignore b/.hgignore index 8b280d8..9b4c464 100644 --- a/.hgignore +++ b/.hgignore @@ -8,3 +8,4 @@ test_adapter .pEp* lib local.conf +build/ diff --git a/Makefile b/Makefile index 865a87f..ebd0a76 100644 --- a/Makefile +++ b/Makefile @@ -72,6 +72,7 @@ test_%: test_%.o $(TARGET) .PHONY: install install: $(TARGET) -mkdir -p $(PREFIX)/include/pEp + -mkdir -p $(PREFIX)/lib cp $(HEADERS) $(PREFIX)/include/pEp/ cp $(TARGET) $(PREFIX)/lib/ From 859527e2497adad48727d049b667e98295f8b6a0 Mon Sep 17 00:00:00 2001 From: Damiano Boppart Date: Thu, 17 Jan 2019 16:22:02 +0100 Subject: [PATCH 6/6] Add basic build instructions --- readme.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 readme.md diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..cbc9b7d --- /dev/null +++ b/readme.md @@ -0,0 +1,23 @@ +# How to build + +To customize your build, you may change several variables that are consumed by make. + +These variables, along with some explanations can be found in Makefile.conf. + +You can edit that file, or create a file `local.conf` in the root of the repository, which will also be parsed by make. + +A sample `local.conf` looks like this: + +~~~ +PREFIX=$(HOME)/code/libad/build + +ENGINE_LIB=-L$(HOME)/code/engine/build/lib +ENGINE_INC=-I$(HOME)/code/engine/build/include +~~~ + +Now, run: + +~~~ +make all +make install +~~~