From f6addca5fc7ef1bb870670e026f3c7cff037c981 Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 19 Jan 2023 23:32:35 +0530 Subject: [PATCH] add Makefile and CI support Add a Makefile so that pEpEngineSequoiaBackend can be build using the usual pEp style without directly invoking cargo, supporting the usual targets build, install, uninstall, test, clean, all. Make the project easy to install and uninstall, with a user-settable prefix. The Makefile is extensible with a local.conf file, of which we provide an example. Add CI support. Add a .gitignore file. Co-authored-by: Heck Co-authored-by: Neal H. Walfield Co-authored-by: Luca Saiu Co-authored-by: Devan Carpenter Co-authored-by: Volker Birk --- .gitignore | 1 + .gitlab-ci.yml | 18 ++++++++++ Makefile | 86 ++++++++++++++++++++++++++++++++++++++++++++++ local.conf.example | 17 +++++++++ 4 files changed, 122 insertions(+) create mode 100644 Makefile create mode 100644 local.conf.example diff --git a/.gitignore b/.gitignore index 873d37a..513f97b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *~ /target +/local.conf diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3888002..cdcf07b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -60,6 +60,24 @@ bookworm: CARGO_HOME: /cargo after_script: [] +makefile: + tags: + - linux + stage: build + image: registry.gitlab.com/sequoia-pgp/build-docker-image/bookworm-prebuild:latest + needs: + - codespell + script: + - make build + - make test + - make clean + - DEBUG=debug make test + variables: + BUILD: /target + CARGO_HOME: /cargo + CARGO_TARGET_DIR: + after_script: [] + all_commits: # Test each commit up to main, to facilitate bisecting. stage: test diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1ecad5c --- /dev/null +++ b/Makefile @@ -0,0 +1,86 @@ +# Copyright 2023, pEp Foundation +# This file is part of pEpEngineSequoiaBackend +# This file may be used under the terms of the GNU General Public License version 3 +# see COPYING + +# Build config defaults +DEBUG?=debug +PREFIX?=/usr/local +CARGO?=cargo +BUILD?=_build +# Build config overrides +-include ./local.conf + +# Make sure CARGO_TARGET_DIR is not set by the user -- it would be ignored. +CARGO_TARGET_DIR?= +ifneq ($(CARGO_TARGET_DIR),) + $(error "the user should not set 'CARGO_TARGET_DIR': 'BUILD' can be used \ + instead.") +endif + +#export as env var to sub-shells +export CARGO_TARGET_DIR=$(BUILD) + +# constants +LIB_NAME=libpep_engine_sequoia_backend + +# determine library file extension +PLATFORM:=$(shell uname) +ifeq ($(PLATFORM),Linux) + DYNLIB_EXT=so +else ifeq ($(PLATFORM),Darwin) + DYNLIB_EXT=dylib +else + $(error "Dont know how to build for '$(PLATFORM)'") +endif + +# DEBUG can be defined as "release", "debug" or "maintainer". +ifeq ($(DEBUG),maintainer) # For compatibility with other pEp repos. + VARIANT_NAME=debug + VARIANT_FLAGS= +else ifeq ($(DEBUG),debug) + VARIANT_NAME=debug + VARIANT_FLAGS= +else ifeq ($(DEBUG),release) + VARIANT_NAME=release + VARIANT_FLAGS=--release +else + $(error "build option 'DEBUG' must be 'release', 'debug' or 'maintainer'") +endif + +LIB_DYNAMIC_PATH=$(CARGO_TARGET_DIR)/$(VARIANT_NAME)/$(LIB_NAME).$(DYNLIB_EXT) +LIB_STATIC_PATH=$(CARGO_TARGET_DIR)/$(VARIANT_NAME)/$(LIB_NAME).a +PKGCONFIG_PATH=$(CARGO_TARGET_DIR)/$(VARIANT_NAME)/pep_engine_sequoia_backend.pc +LIB_DIR=$(PREFIX)/lib/ +PKGCONFIG_DIR=$(PREFIX)/share/pkgconfig/ + +CARGO_FLAGS+=$(VARIANT_FLAGS) + +ifneq ($(filter Darwin %BSD,$(shell uname -s)),) + INSTALL?=ginstall +else + INSTALL?=install +endif + +.PHONY: all build install uninstall test clean +all: build + +build: + $(CARGO) build $(CARGO_FLAGS) + +install: build + mkdir -p $(LIB_DIR) $(PKGCONFIG_DIR) + $(INSTALL) $(LIB_DYNAMIC_PATH) $(LIB_DIR) + $(INSTALL) $(LIB_STATIC_PATH) $(LIB_DIR) + $(INSTALL) $(PKGCONFIG_PATH) $(PKGCONFIG_DIR) + +uninstall: + rm -f $(LIB_DIR)/$(LIB_NAME).$(DYNLIB_EXT) + rm -f $(LIB_DIR)/$(LIB_NAME).a + rm -f $(PKGCONFIG_DIR)/pep_engine_sequoia_backend.pc + +test: + $(CARGO) test $(CARGO_FLAGS) + +clean: + $(CARGO) clean diff --git a/local.conf.example b/local.conf.example new file mode 100644 index 0000000..f255f17 --- /dev/null +++ b/local.conf.example @@ -0,0 +1,17 @@ +# This is an Example build config (local.conf) +# The values here reflect the defaults. +# If needed, copy this file into a file called +# `local.conf` and adjust the values + +# The dir where the build artifacts get installed into +# PREFIX=/usr/local + +# Build variant: one of release , debug , maintainer (maintainer exists for +# compatibility with other pEp projects: in this project maintainer and debug +# builds are the same). The default is debug . +# DEBUG=release + +# Defines the build dir. This can be a relative or an absolute path. +# BUILD=_build + + -- GitLab