diff --git a/.gitignore b/.gitignore index 873d37a08ef1608090d954a72d39cfa29bc75064..513f97b408304df1895aaa686df4d0c4c71fd773 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *~ /target +/local.conf diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 388800237a87ebfa786132d6ea35dafc691739bc..cdcf07bf6778d7592d9fa8d7cbe8c10afbe5292f 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 0000000000000000000000000000000000000000..1ecad5c64c2ada6a85930a5029da77729fadf1f8 --- /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 0000000000000000000000000000000000000000..f255f17637487264648340d945213a0e78c5e96c --- /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 + +