From b0f32bd2141711d4482e4ab0ef00dedacf01dc70 Mon Sep 17 00:00:00 2001 From: heck Date: Mon, 28 Feb 2022 23:05:16 +0100 Subject: [PATCH] Build: add basic makefile build --- Makefile | 24 ++++++++++++++++++++++++ Makefile.conf | 35 +++++++++++++++++++++++++++++++++++ local.conf.example | 12 ++++++++++++ src/Makefile | 38 ++++++++++++++++++++++++++++++++++++++ test/Makefile | 24 ++++++++++++++++++++++++ 5 files changed, 133 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..26ab972 --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +# Copyright 2022, pEp Foundation +# This file is part of libpEpCxx11 +# 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 + +src: + $(MAKE) -C src + +test: src + $(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..f32ac26 --- /dev/null +++ b/Makefile.conf @@ -0,0 +1,35 @@ +# Copyright 2022, pEp Foundation +# This file is part of libpEpCxx11 +# This file may be used under the terms of the GNU General Public License version 3 +# see LICENSE + +HERE:=$(dir $(lastword $(MAKEFILE_LIST))) + +TARGET=libpEpCxx11.a + +# Defaults +DEBUG=1 +PREFIX?=$(HOME) +LANG_VERSION=c++11 +CXXFLAGS+=-fPIC -Wall -Wextra -ansi -pedantic + +ifneq (,$(findstring g++,$(CXX))) + CXXFLAGS+=-fdiagnostics-color=always +else ifneq (,$(findstring clang,$(CXX))) + CXXFLAGS+=-fcolor-diagnostics +endif + + +######### Overrides ######### +-include $(HERE)local.conf + +CXXFLAGS+=-std=$(LANG_VERSION) + +ifeq ($(DEBUG),1) + CXXFLAGS+=-g -O0 +else + CXXFLAGS+=-DNDEBUG=1 -O3 +endif + +CXXFLAGS+=-I$(PREFIX)/include +LDFLAGS=-L$(PREFIX)/lib \ No newline at end of file diff --git a/local.conf.example b/local.conf.example new file mode 100644 index 0000000..6ed7024 --- /dev/null +++ b/local.conf.example @@ -0,0 +1,12 @@ +# 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++ +# DEBUG=1 # DEBUG Build (Default) +# DEBUG=0 # RELEASE Build + +############# DIRS ############# +# PREFIX=$(HOME)/local \ No newline at end of file diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..4558513 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,38 @@ +# Copyright 2022, pEp Foundation +# This file is part of libpEpCxx11 +# 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) + +$(TARGET): $(OBJECTS) + $(AR) -rc $@ $^ + +clean: + rm -vf $(TARGET) $(OBJECTS) $(DEPENDS) + rm -f *.d.* + +install: $(TARGET) + mkdir -p $(PREFIX)/include/pEp + mkdir -p $(PREFIX)/lib + cp -v $(HEADERS) $(PREFIX)/include/pEp/ + cp -v $(TARGET) $(PREFIX)/lib/ + +uninstall: + cd $(PREFIX)/include/pEp && rm -vf $(HEADERS) + cd $(PREFIX)/lib && rm -vf $(TARGET) diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..03836a5 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,24 @@ +# Copyright 2022, pEp Foundation +# This file is part of libpEpCxx11 +# 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++ -lpEpAdapter #-lpthread -ldl -lm +CXXFLAGS:=-I../src $(CXXFLAGS) + +# Test +SRC_TEST=$(wildcard test_*.cc) +BIN_TEST=$(subst .cc,,$(SRC_TEST)) + +.PHONY: tests, all, clean + +all: $(BIN_TEST) + + +clean: + rm -Rf *.dSYM + rm -f $(BIN_TEST)