From 67ea61d31236130191d7f6b24c53c240e9c07ec2 Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 18 Mar 2022 01:07:08 +0100 Subject: [PATCH] Build: Add GNU Make based build for src/ and test/ using local.conf build config (pEp standard) --- Makefile | 24 ++++++++++++++++++++++++ Makefile.conf | 34 ++++++++++++++++++++++++++++++++++ local.conf.example | 13 +++++++++++++ src/Makefile | 38 ++++++++++++++++++++++++++++++++++++++ test/Makefile | 27 +++++++++++++++++++++++++++ 5 files changed, 136 insertions(+) create mode 100644 Makefile create mode 100644 Makefile.conf create mode 100644 local.conf.example create mode 100644 src/Makefile create mode 100644 test/Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6ba41fb --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +# Copyright 2021, pEp Foundation +# This file is part of +# This file may be used under the terms of the GNU General Public License version 3 +# see LICENSE + +.PHONY: all src test install uninstall clean + +all: src test + +src: + $(MAKE) -C src + +test: + $(MAKE) -C test + +clean: + $(MAKE) -C src clean + $(MAKE) -C test clean + +install: + $(MAKE) -C src install + +uninstall: + $(MAKE) -C src uninstall diff --git a/Makefile.conf b/Makefile.conf new file mode 100644 index 0000000..0e35052 --- /dev/null +++ b/Makefile.conf @@ -0,0 +1,34 @@ +# Copyright 2022, pEp Foundation +# This file is part of +# This file may be used under the terms of the GNU General Public License version 3 +# see LICENSE.txt + +HERE:=$(dir $(lastword $(MAKEFILE_LIST))) + +TARGET_NAME=pEpHelloWorld +TARGET_STATIC=lib$(TARGET_NAME).a + +# Build config +# Defaults +DEBUG=1 +PREFIX?=$(HOME) + +# Overrides +-include $(HERE)local.conf + +# Constants +CXXFLAGS+=-std=c++11 -fPIC -Wall -Wextra -ansi -pedantic +CXXFLAGS+=-I$(PREFIX)/include +LDFLAGS+=-L$(PREFIX)/lib + +ifneq (,$(findstring g++,$(CXX))) + CXXFLAGS+=-fdiagnostics-color=always +else ifneq (,$(findstring clang,$(CXX))) + CXXFLAGS+=-fcolor-diagnostics +endif + +ifeq ($(DEBUG),1) + CXXFLAGS+=-g -O0 +else + CXXFLAGS+=-DNDEBUG=1 -O3 +endif \ No newline at end of file diff --git a/local.conf.example b/local.conf.example new file mode 100644 index 0000000..f53ff09 --- /dev/null +++ b/local.conf.example @@ -0,0 +1,13 @@ +# This is an Example build config file (local.conf) +# you might not need this file, but if the defaults dont work for you +# You can override them here. +# Tweak the values to your needs and rename it to local.conf + +######### C++ Compiler ######### +# Should work with clang and g++ +# CXX=g++ +# DEBUG=1 # DEBUG Build (Default) +# DEBUG=0 # RELEASE Build + +############# DIRS ############# +# PREFIX=$(HOME)/local diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..ebd0491 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,38 @@ +# Copyright 2022, pEp Foundation +# This file is part of +# This file may be used under the terms of the GNU General Public License version 3 +# see LICENSE + +include ../Makefile.conf + +SOURCE=$(wildcard *.cc) +HEADERS=$(wildcard *.hh *.hxx) +OBJECTS=$(subst .cc,.o,$(SOURCE)) +DEPENDS=$(subst .cc,.d,$(SOURCE)) +CXXFLAGS+= -MMD -MP + +ifneq ($(MAKECMDGOALS),clean) + -include $(DEPENDS) +endif + +.PHONY: all install uninstall clean +.DEFAULT_GOAL := all + +all: $(TARGET_STATIC) + +$(TARGET_STATIC): $(OBJECTS) + $(AR) -rc $@ $^ + +clean: + rm -vf $(TARGET_STATIC) $(OBJECTS) $(DEPENDS) + rm -f *.d.* + +install: $(TARGET_STATIC) + mkdir -p $(PREFIX)/include/pEp + mkdir -p $(PREFIX)/lib + cp -v $(HEADERS) $(PREFIX)/include/pEp/ + cp -v $(TARGET_STATIC) $(PREFIX)/lib/ + +uninstall: + cd $(PREFIX)/include/pEp && rm -vf $(HEADERS) + cd $(PREFIX)/lib && rm -vf $(TARGET_STATIC) diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..15f0993 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,27 @@ +# Copyright 2022, pEp Foundation +# This file is part of +# This file may be used under the terms of the GNU General Public License version 3 +# see LICENSE + +include ../Makefile.conf + +CXXFLAGS:=-I../src $(CXXFLAGS) +LDFLAGS:=-L../src $(LDFLAGS) +LDLIBS=-lstdc++ -lpthread -lm -l$(TARGET_NAME) + +# Test +SRC_TEST=$(wildcard test_*.cc) +BIN_TEST=$(subst .cc,,$(SRC_TEST)) + +.PHONY: all, clean + +all: $(TARGET_STATIC) $(BIN_TEST) + +$(BIN_TEST) : ../src/$(TARGET_STATIC) + +$(TARGET_STATIC): + $(MAKE) -C ../src + +clean: + rm -Rf *.dSYM + rm -f $(BIN_TEST)