forked from pEp.foundation/pEpEngine
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
463 lines
15 KiB
Makefile
463 lines
15 KiB
Makefile
# Copyright 2017-2023, pEp Foundation
|
|
# This file is part of pEpEngine
|
|
# This file may be used under the terms of the GNU General Public License version 3
|
|
# see LICENSE.txt
|
|
|
|
# See `doc/build-<your platform>.md` for documentation on how to build, and customize your build.
|
|
|
|
# This file sets all the make variables that allow you to customize a build.
|
|
# There are 3 ways in which you can customize your build:
|
|
# 1) Edit the variable assignments in this file (this is a tracked file, so your repository will be dirty)
|
|
# 2) Create `local.conf` and fill it with variable assignments.
|
|
# 3) Set the environment variable `BUILD_CONFIG` to an absolute path.
|
|
# The variable assignments found in the make file at the path indicated by `BUILD_CONFIG` will be evaluated.
|
|
# Customization options are applied in the order given above. Later variable assignments take precedence over earlier ones.
|
|
# It is possible to use multiple variants simultaniously.
|
|
# If nothing is changed according to these 3 methods, a default configuration for your platform (specified below) will be used for the build.
|
|
|
|
######### Header #########
|
|
HERE:=$(dir $(lastword $(MAKEFILE_LIST)))
|
|
|
|
|
|
######### General #########
|
|
# To use (only) system libraries, set all the *_INC and *_LIB variables to the empty string.
|
|
# All the *_INC and *_LIB variables are command line flags, not paths.
|
|
# Thus, all *_INC variables' values must start with "-I", and all *_LIB variables' values must start with "-L".
|
|
|
|
BUILD_ON := $(shell uname)
|
|
|
|
# This variable specifies the platform that the engine should be cross-compiled
|
|
# for.
|
|
BUILD_FOR ?= $(BUILD_ON)
|
|
|
|
# Cross-compiling is currently not supported.
|
|
# Maybe you can hack something with `local.conf`.
|
|
ifneq ($(BUILD_ON),$(BUILD_FOR))
|
|
ifeq ($(BUILD_FOR),OS/390)
|
|
$(warning Generating sources for z/OS)
|
|
endif
|
|
ONLY_GENERATE=true
|
|
endif
|
|
|
|
# Installation path prefix for libraries and binaries, except for system.db
|
|
PREFIX ?= $(HOME)
|
|
|
|
# pEp files and directories
|
|
#
|
|
# the PER_USER_DIRECTORY will be in $(HOME), respectively
|
|
# in debug builds the PER_USER_DIRECTORY will be in $(PEP_HOME) instead if set
|
|
#
|
|
# PER_MACHINE_DIRECTORY is calculated depending on the platform; overwrite if
|
|
# necessary
|
|
|
|
PER_USER_DIRECTORY = .pEp
|
|
PER_MACHINE_DIRECTORY = $(PREFIX)/share/pEp
|
|
|
|
# Filename of the pEpEngine library
|
|
ifeq ($(BUILD_FOR),OS/390)
|
|
TARGET=libpEpEngine.so
|
|
else ifeq ($(BUILD_FOR),Linux)
|
|
TARGET=libpEpEngine.so
|
|
else ifeq ($(BUILD_FOR),Darwin)
|
|
TARGET=libpEpEngine.dylib
|
|
endif
|
|
|
|
# DEBUG can be set to:
|
|
# * release
|
|
# for a release build;
|
|
# * debug
|
|
# for a debug build (default);
|
|
# * maintainer
|
|
# for a maintainer build.
|
|
# See the comment in local.conf.example for more information. This definition
|
|
# is meant to be easy to override in local.conf .
|
|
DEBUG ?= debug
|
|
|
|
# If empty, suppress compiler warnings.
|
|
# Otherwise, print warnings.
|
|
# This variable is ineffective when set anywhere else but here.
|
|
WARN ?= placeholder
|
|
|
|
|
|
######### YML2 #########
|
|
YML2_PATH=$(HOME)/yml2
|
|
|
|
YML2_PROC=$(YML2_PATH)/yml2proc $(YML2_OPTS)
|
|
|
|
YML2_OPTS=--encoding=utf8
|
|
|
|
|
|
######### asn1c #########
|
|
# asn1c binary
|
|
ASN1C=asn1c
|
|
|
|
# asn1c include search flag
|
|
ASN1C_INC=
|
|
#ASN1C_INC=-I$(HOME)/include
|
|
|
|
|
|
######### sqlite3 #########
|
|
# If empty (or undefined), compile sqlite3 from the sources shipped with the pEp distribution.
|
|
# Otherwise, use an sqlite3 implementation found in the OS's include/library paths.
|
|
SQLITE3_FROM_OS=placeholder
|
|
|
|
|
|
######### MIME #########
|
|
|
|
######### pEp MIME #########
|
|
# Set pEpMIME= anything (there are ifdefs on it) in your local.conf if you want
|
|
# to compile built-in pEpMIME (requires a separate libppEpMIME source repo to be
|
|
# checked out elsewhere on the system - define or redefine these in local.conf
|
|
# if you want to use it; otherwise, we default to etpan. (This will eventually
|
|
# become the default, but not yet.
|
|
#
|
|
PEP_MIME=
|
|
PEP_MIME_SRC=$(HOME)/src/pEpMIME/src
|
|
|
|
|
|
######### libetpan #########
|
|
# libetpan library search flag
|
|
#
|
|
ETPAN_LIB =
|
|
#ETPAN_LIB=-L$(HOME)/lib
|
|
|
|
# libetpan include search flag
|
|
ETPAN_INC =
|
|
#ETPAN_INC=-I$(HOME)/include
|
|
|
|
# positron, early 2023: before my factoring this was included in the compilation
|
|
# flags on every platform; it is not needed on GNU/Linux as far as I can tell.
|
|
CPPFLAGS += $(ETPAN_INC)
|
|
|
|
######### OpenPGP #########
|
|
# Selects OpenPGP implementation.
|
|
ifeq ($(BUILD_FOR),OS/390)
|
|
OPENPGP=NETPGP
|
|
else
|
|
OPENPGP=SEQUOIA
|
|
endif
|
|
|
|
# Sequoia-specific variables
|
|
SEQUOIA_CFLAGS=
|
|
SEQUOIA_LDFLAGS=
|
|
SEQUOIA_LIB=
|
|
SEQUOIA_INC=
|
|
|
|
######### Engine internals #########
|
|
# C macros (not environment variables) that can be overridden:
|
|
# DEFAULT_KEYSERVER - string with default keyserver
|
|
# CRASHDUMP_DEFAULT_LINES - number of log lines to deliver for crashdumps
|
|
# Example:
|
|
# EXTRA_MACROS=-DDEFAULT_KEYSERVER=\"default-server.org\" -DCRASHDUMP_DEFAULT_LINES=23
|
|
EXTRA_MACROS =
|
|
|
|
|
|
######### C and C++ #########
|
|
|
|
# The following two variables will be appended to.
|
|
# You can thus not set them to a final, fixed value here.
|
|
ifeq ($(BUILD_FOR),Linux)
|
|
LDFLAGS +=
|
|
else ifeq ($(BUILD_FOR),Darwin)
|
|
# "-bind_at_load" helps find symbol resolution errors faster
|
|
LDFLAGS += -bind_at_load
|
|
endif
|
|
|
|
# Define C and C++ compilers.
|
|
ifeq ($(BUILD_FOR),OS/390)
|
|
CC = xlclang
|
|
CXX = xlclang++
|
|
else ifeq ($(BUILD_FOR),Linux)
|
|
CC = gcc
|
|
CXX = g++
|
|
else ifeq ($(BUILD_FOR),Darwin)
|
|
CC = clang
|
|
CXX = clang
|
|
# Notice that clang issues a warning when "-pthread" is used for linking;
|
|
# we do not want it as part of the compiler name expansion.
|
|
endif
|
|
|
|
# Almost all the options in CFLAGS and CXXFLAGS are the same. Define a single
|
|
# variable CORCXXFLAGS; we will use twice further down, to define CFLAGS and
|
|
# CXXFLAGS.
|
|
# Start defining some sensible CORCXXFLAGS and CPPFLAGS that are correct on
|
|
# every platform.
|
|
ifeq ($(DEBUG),release)
|
|
CORCXXFLAGS += -O3
|
|
# We can define this with no fear: the test suite does not work with NDEBUG
|
|
# defined, but its makefile will filter the option out.
|
|
CPPFLAGS += -DNDEBUG
|
|
# I believe that we can afford some extra cost in binary size in exchange for
|
|
# debugging symbols being available everywhere.
|
|
COMPILEWITHDEBUGGINGSYMBOLS = yes
|
|
else
|
|
CORCXXFLAGS += -O0
|
|
CPPFLAGS += -DDEBUG_ERRORSTACK
|
|
# Non-release build: include debug symbols.
|
|
COMPILEWITHDEBUGGINGSYMBOLS = yes
|
|
endif
|
|
ifdef WARN
|
|
CORCXXFLAGS+= -Wall
|
|
# I do *not* want -pedantic: for example I am currently using, on purpose,
|
|
# __PRETTY_FUNCTION__ only where supported.
|
|
# CORCXXFLAGS+= -pedantic
|
|
ifeq ($(BUILD_FOR),Linux)
|
|
CORCXXFLAGS += -Wstrict-aliasing=3
|
|
endif
|
|
else
|
|
# positron, early 2023: this has been there since before my time but I doubt
|
|
# it is a good idea. Let us suppress known-false-positive warnings, rather
|
|
# than all of them, blindly.
|
|
# CORCXXFLAGS+= -w
|
|
endif
|
|
|
|
# These options are needed everywhere to make #include paths work.
|
|
CPPFLAGS += -I../src -I../asn.1
|
|
|
|
# Extend with platform-specific options.
|
|
ifeq ($(BUILD_FOR),OS/390)
|
|
CORCXXFLAGS += -Wno-gnu-include-next -qnosearch -qlanglvl=NOLIBEXT
|
|
CORCXXFLAGS += -fdiagnostics-color=auto
|
|
CORCXXFLAGS += -Wno-gnu-include-next -qnosearch
|
|
CPPFLAGS += -I$(HERE) -I. -I/usr/include
|
|
CPPFLAGS += -I/usr/lpp/java/J8.0_64/include -I/usr/include
|
|
CPPFLAGS += -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200112L -qlanglvl=NOLIBEXT
|
|
CPPFLAGS+=-W "l,xplink,dll" -W "c,float(ieee),xplink,dll,exportall"
|
|
else ifeq ($(BUILD_FOR),Linux)
|
|
CORCXXFLAGS += -pthread -fPIC -fstrict-aliasing
|
|
CORCXXFLAGS += -fdiagnostics-color=auto
|
|
LDLIBS += -luuid
|
|
else ifeq ($(BUILD_FOR),Darwin)
|
|
CORCXXFLAGS += -pthread -fPIC -fstrict-aliasing
|
|
CORCXXFLAGS += -fcolor-diagnostics
|
|
CPPFLAGS+=-D_DARWIN_C_SOURCE
|
|
endif
|
|
|
|
# Additional flags used for compiling ASN1C-generated code
|
|
ifeq ($(BUILD_FOR),Linux)
|
|
# The '_DEFAULT_SOURCE' feature test macro is required to suppress the warning
|
|
# _BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE
|
|
# otherwise printed during the compilation of every asn1c-generated C file.
|
|
# It's a glibc specific warning, only present in few versions around ~2.19.
|
|
# See https://lwn.net/Articles/590381/ for a discussion.
|
|
CPPFLAGS_GENERATED = -D_DEFAULT_SOURCE
|
|
else ifeq ($(BUILD_FOR),Darwin)
|
|
CPPFLAGS_GENERATED =
|
|
endif
|
|
|
|
|
|
######### CFLAGS and CXXFLAGS #########
|
|
|
|
# We have essentially everything we need for both CFLAGS and CXXFLAGS in
|
|
# CORCXXFLAGS. Add the what ware still missing and is different, which is
|
|
# to say the language version.
|
|
CFLAGS = $(CORCXXFLAGS)
|
|
CXXFLAGS = $(CORCXXFLAGS)
|
|
ifeq ($(BUILD_FOR),Linux)
|
|
# We could actually use C17, but only recent compilers understand the option
|
|
# -std=c17; for example GCC 7, which dates back from 2017 and should work
|
|
# well, does not. The 2011 standard is almost identical to the 2017 version
|
|
# anyway.
|
|
# So here we could use -std=c11 . However when trying -std=c11 for a while
|
|
# GCC was bothering me all the time with warnings about the non-standard
|
|
# __PRETTY_FUNCTION__ , which are useless noise since we use that
|
|
# conditionally only where supported. Doing away with that, and using gnu11
|
|
# instead of c11 to silently allow GNU extension, while *not* using them
|
|
# except in conditional code when we also have a fallback alternative.
|
|
#
|
|
# If I use some unsupported C feature by mistake people will tell me
|
|
# --positron.
|
|
# At least on GNU/Linux, where culturally we are used to use environment
|
|
# variables, honor CC instead of unconditionally overriding it!
|
|
CFLAGS += -std=gnu11
|
|
CXXFLAGS += -std=c++11
|
|
else ifeq ($(BUILD_FOR),Darwin)
|
|
CXXFLAGS += -std=c++11
|
|
else ifeq ($(BUILD_FOR),OS/390)
|
|
CXXFLAGS += -std=c++11
|
|
endif
|
|
|
|
|
|
################################
|
|
# Include local.conf for any overrides and additional flags
|
|
################################
|
|
-include $(HERE)/local.conf
|
|
ifdef BUILD_CONFIG
|
|
include $(BUILD_CONFIG)
|
|
endif
|
|
# From now on we can keep into account user overrides.
|
|
|
|
|
|
######### Directories ########
|
|
|
|
# Notice the single quotes below: since user definitions can contain dollar
|
|
# signs it is important to prevent their expansion: shell variable references
|
|
# here must be expanded at run time, and not at compile time.
|
|
ifdef PER_USER_DIRECTORY
|
|
EXTRA_MACROS += -DPER_USER_DIRECTORY='"$(PER_USER_DIRECTORY)"'
|
|
endif
|
|
ifdef PER_MACHINE_DIRECTORY
|
|
EXTRA_MACROS += -DPER_MACHINE_DIRECTORY='"$(PER_MACHINE_DIRECTORY)"'
|
|
endif
|
|
|
|
# If sequoia has been set up and the SEQUOIA flags aren't defined, set them up.
|
|
# Otherwise, add them to the CFLAGS/CXXFLAGS/LDFLAGS and library/include variables
|
|
ifeq ($(OPENPGP),SEQUOIA)
|
|
# Overridable (default empty): SEQUOIA_CFLAGS
|
|
# Overridable (default empty): SEQUOIA_LDFLAGS
|
|
ifeq ($(SEQUOIA_LIB),)
|
|
SEQUOIA_LIB = -lpep_engine_sequoia_backend
|
|
endif
|
|
# Overridable (default empty): SEQUOIA_INC
|
|
|
|
# Use the Sequoia variables.
|
|
CORCXXFLAGS += $(SEQUOIA_CFLAGS)
|
|
CPPFLAGS += $(SEQUOIA_INC)
|
|
LD_FLAGS += $(SEQUOIA_LDFLAGS)
|
|
endif
|
|
|
|
# YML_PATH is needed in the environment of every call to a program of the YML2 distribution
|
|
export YML_PATH=$(YML2_PATH)
|
|
|
|
# Postprocess for pEpMIME
|
|
ifdef PEP_MIME
|
|
# Replace c++11 with c++14 for now (limiting the subst to the ++11 means it doesn't matter if gnu or not)
|
|
CXXFLAGS:=$(subst ++11,++14,$(CXXFLAGS)) -fPIC -fvisibility=hidden
|
|
endif
|
|
ifdef PEP_MIME
|
|
ifndef PEP_MIME_SRC
|
|
$(error "Compiling with the PEP_MIME option set requires the value of \
|
|
PEP_MIME_SRC to be set to the source directory for libpEpMIME")
|
|
else
|
|
CPPFLAGS+=-DPEP_BUILTIN_MIME
|
|
ifneq ($(BUILD_ON),OS/390)
|
|
LDLIBS+=-lstdc++
|
|
endif
|
|
ETPAN_LIB=
|
|
ETPAN_INC=
|
|
endif
|
|
endif
|
|
|
|
|
|
######### Append user-specified CPPFLAGS ########
|
|
|
|
CPPFLAGS += $(EXTRA_MACROS)
|
|
|
|
|
|
######### Handle COMPILEWITHDEBUGGINGSYMBOLS ########
|
|
|
|
# Add -g or equivalent if needed.
|
|
ifeq ($(COMPILEWITHDEBUGGINGSYMBOLS),yes)
|
|
ifeq ($(BUILD_FOR),Linux)
|
|
CORCXXFLAGS += -ggdb
|
|
else
|
|
CORCXXFLAGS += -g
|
|
endif
|
|
else ifeq ($(COMPILEWITHDEBUGGINGSYMBOLS),no)
|
|
# All good: do nothing.
|
|
else
|
|
$(error "COMPILEWITHDEBUGGINGSYMBOLS is defined as \
|
|
'$(COMPILEWITHDEBUGGINGSYMBOLS)' which is different from both \
|
|
'no' and 'yes'.")
|
|
endif
|
|
|
|
|
|
######### Handle DEBUG ########
|
|
|
|
# Set safety mode through a command-line preprocessor definition.
|
|
ifeq ($(DEBUG),release)
|
|
CPPFLAGS += -DPEP_SAFETY_MODE=PEP_SAFETY_MODE_RELEASE
|
|
else ifeq ($(DEBUG),debug)
|
|
CPPFLAGS += -DPEP_SAFETY_MODE=PEP_SAFETY_MODE_DEBUG
|
|
else ifeq ($(DEBUG),maintainer)
|
|
CPPFLAGS += -DPEP_SAFETY_MODE=PEP_SAFETY_MODE_MAINTAINER
|
|
else
|
|
$(error "DEBUG is defined as '$(DEBUG)' which is different from \
|
|
'release', 'debug' and 'maintainer'. Please read \
|
|
local.conf.example .")
|
|
endif
|
|
|
|
|
|
######### Handle MAXLOGLEVEL ########
|
|
|
|
# Set maximum log level through a command-line preprocessor definition.
|
|
ifndef MAXLOGLEVEL
|
|
ifeq ($(DEBUG),release)
|
|
MAXLOGLEVEL = PRODUCTION
|
|
else ifeq ($(DEBUG),debug)
|
|
MAXLOGLEVEL = FUNCTION
|
|
else ifeq ($(DEBUG),maintainer)
|
|
MAXLOGLEVEL = EVERYTHING
|
|
else
|
|
$(error "DEBUG is defined as '$(DEBUG)' which is different from \
|
|
'release', 'debug' and 'maintainer'. Please read \
|
|
local.conf.example .")
|
|
endif
|
|
endif
|
|
CPPFLAGS += -DPEP_LOG_LEVEL_MAXIMUM=PEP_LOG_LEVEL_$(MAXLOGLEVEL)
|
|
|
|
|
|
######### Handle LOGDESTINATIONS ########
|
|
|
|
# Set log destinations through a command-line preprocessor definition.
|
|
ifndef LOGDESTINATIONS
|
|
LOGDESTINATIONS = '(PEP_LOG_DESTINATION_STDERR|PEP_LOG_DESTINATION_DATABASE)'
|
|
endif
|
|
CPPFLAGS += -DPEP_LOG_DESTINATIONS=$(LOGDESTINATIONS)
|
|
|
|
|
|
######### Handle TRUSTWORDSXORCOMPATIBILITY ########
|
|
|
|
# Set xor-trustword compatibility through a command-line preprocessor
|
|
# definition.
|
|
ifdef TRUSTWORDSXORCOMPATIBILITY
|
|
CPPFLAGS += -DPEP_TRUSTWORDS_XOR_COMPATIBILITY=1
|
|
endif
|
|
|
|
|
|
######### Makefile debugging #########
|
|
|
|
# We are about to define the target, which (considering that Makefile.conf is
|
|
# included) will probably be the first of the Makefile. But we do not want that
|
|
# target to be the default target.
|
|
first: all
|
|
|
|
# Print the value of some make variables
|
|
dump-make-variables:
|
|
@echo "BUILD_ON: $(BUILD_FOR)"
|
|
@echo "BUILD_FOR: $(BUILD_FOR)"
|
|
@echo "DEBUG: $(DEBUG)"
|
|
@echo "CC: $(CC)"
|
|
@echo "CXX: $(CXX)"
|
|
@echo "CFLAGS: $(CFLAGS)"
|
|
@echo "CXXFLAGS: $(CXXFLAGS)"
|
|
@echo "CPPFLAGS: $(CPPFLAGS)"
|
|
@echo "SQLITE3_FROM_OS: $(SQLITE3_FROM_OS)"
|
|
|
|
######### Banner #########
|
|
|
|
ifneq ($(wildcard local.conf),)
|
|
LOCALCONFEXISTINGMESSAGE = local.conf
|
|
endif
|
|
|
|
ifdef BUILD_CONFIG
|
|
BUILD_CONFIGMESSAGE := BUILD_CONFIG used ($(BUILD_CONFIG))
|
|
endif
|
|
|
|
export BANNERPRINTED
|
|
ifndef BANNERPRINTED
|
|
BANNERPRINTED := yes
|
|
VERSION=$(shell cat $(HERE)src/pEpEngine_version.h | grep 'PEP_ENGINE_VERSION "' | awk '{print $$3}' | tr '"' ' ')
|
|
$(info ================================================)
|
|
$(info Building p≡p Engine $(VERSION))
|
|
$(info Safety mode '$(DEBUG)')
|
|
$(info Maximum log level '$(MAXLOGLEVEL)')
|
|
$(info Log desinations '$(LOGDESTINATIONS)')
|
|
$(info )
|
|
$(info CFLAGS: $(CFLAGS))
|
|
$(info CXXFLAGS: $(CXXFLAGS))
|
|
$(info CPPFLAGS: $(CPPFLAGS))
|
|
$(info Overrides: $(LOCALCONFEXISTINGMESSAGE) $(BUILD_CONFIGMESSAGE))
|
|
$(info ================================================)
|
|
endif
|