2018-07-17 21:26:39 +03:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
import os
|
2019-05-01 00:44:59 +03:00
|
|
|
import sys
|
2018-07-17 21:26:39 +03:00
|
|
|
import SCons
|
|
|
|
|
|
|
|
opts = Variables()
|
|
|
|
opts.AddVariables(
|
2018-08-30 07:51:44 +03:00
|
|
|
BoolVariable("DEBUG", "Make debug build", 0),
|
2018-10-02 22:13:39 +03:00
|
|
|
BoolVariable("SANITIZE", "Use AddressSanitizer and UBSanitizer", 0),
|
2020-04-23 14:35:51 +03:00
|
|
|
BoolVariable("FUZZING", "Build with libFuzzer instrumentation and targets", 0),
|
2019-05-01 00:44:59 +03:00
|
|
|
BoolVariable("VERBOSE", "Show full build information", 0),
|
|
|
|
)
|
2018-07-17 21:26:39 +03:00
|
|
|
|
2019-05-01 00:44:59 +03:00
|
|
|
env = Environment(options=opts, ENV=os.environ)
|
2018-08-30 07:21:31 +03:00
|
|
|
|
2019-05-01 00:44:59 +03:00
|
|
|
env.Tool("clang")
|
2018-08-30 07:21:31 +03:00
|
|
|
|
2018-09-11 01:18:06 +03:00
|
|
|
# Add extra compiler flags from the environment
|
2018-09-12 07:34:21 +03:00
|
|
|
for flag in ["CCFLAGS", "CFLAGS", "CPPFLAGS", "CXXFLAGS", "LINKFLAGS"]:
|
2019-05-01 00:44:59 +03:00
|
|
|
if flag in os.environ:
|
|
|
|
env.Append(**{flag: SCons.Util.CLVar(os.getenv(flag))})
|
2018-07-17 21:26:39 +03:00
|
|
|
|
2019-05-01 00:44:59 +03:00
|
|
|
if env["DEBUG"]:
|
2018-09-11 01:18:06 +03:00
|
|
|
print("DEBUG MODE!")
|
2019-05-01 00:44:59 +03:00
|
|
|
env.Append(CCFLAGS=["-g", "-DDEBUG"])
|
2018-10-02 22:13:39 +03:00
|
|
|
|
|
|
|
if env["SANITIZE"]:
|
2019-05-01 00:44:59 +03:00
|
|
|
sanitizers = [
|
|
|
|
"-fsanitize=address,undefined",
|
|
|
|
"-fno-sanitize-recover=undefined,integer,nullability",
|
|
|
|
]
|
2020-04-23 14:30:13 +03:00
|
|
|
if not env["DEBUG"]:
|
|
|
|
sanitizers += ["-gline-tables-only"]
|
2019-05-01 00:44:59 +03:00
|
|
|
env.Append(CCFLAGS=sanitizers, LINKFLAGS=sanitizers)
|
2018-07-17 21:26:39 +03:00
|
|
|
|
2020-04-23 14:35:51 +03:00
|
|
|
if env["FUZZING"]:
|
2020-07-17 02:57:40 +03:00
|
|
|
fuzzing = ["-fsanitize=fuzzer-no-link"]
|
2020-04-23 14:35:51 +03:00
|
|
|
if not env["DEBUG"]:
|
|
|
|
fuzzing += ["-gline-tables-only"]
|
|
|
|
env.Append(CCFLAGS=fuzzing, LINKFLAGS=fuzzing)
|
|
|
|
|
2019-05-01 00:44:59 +03:00
|
|
|
if sys.platform == "darwin":
|
2020-07-17 02:57:40 +03:00
|
|
|
env.Append(
|
|
|
|
LINKFLAGS=[
|
|
|
|
"-L/usr/local/opt/nss/lib",
|
|
|
|
"-L/usr/local/opt/nspr/lib",
|
|
|
|
"-L/usr/local/opt/msgpack/lib",
|
|
|
|
],
|
|
|
|
# NOTE: this may be necessary on other platforms
|
|
|
|
CFLAGS=["-I/usr/local/opt/msgpack/include"],
|
|
|
|
)
|
2019-05-01 00:44:59 +03:00
|
|
|
include_pattern = "-I/usr/local/opt/{0}/include/{0}"
|
2020-07-17 02:57:40 +03:00
|
|
|
elif (
|
|
|
|
sys.platform.startswith("dragonfly")
|
|
|
|
or sys.platform.startswith("freebsd")
|
|
|
|
or sys.platform.startswith("openbsd")
|
|
|
|
):
|
2020-05-20 07:14:01 +03:00
|
|
|
env.Append(LINKFLAGS=["-L/usr/local/lib"])
|
|
|
|
env.Append(CFLAGS=["-isystem/usr/local/include"])
|
|
|
|
include_pattern = "-isystem/usr/local/include/{0}"
|
2019-05-01 00:44:59 +03:00
|
|
|
else:
|
|
|
|
include_pattern = "-I/usr/include/{0}"
|
2018-07-17 21:26:39 +03:00
|
|
|
|
2019-05-01 00:44:59 +03:00
|
|
|
env.Append(
|
|
|
|
LIBS=["mprio", "mpi", "nss3", "nspr4"],
|
|
|
|
LIBPATH=["#build/prio", "#build/mpi"],
|
|
|
|
CFLAGS=[
|
|
|
|
"-Wall",
|
|
|
|
"-Werror",
|
|
|
|
"-Wextra",
|
|
|
|
"-O3",
|
|
|
|
"-std=c99",
|
|
|
|
"-Wvla",
|
|
|
|
include_pattern.format("nss"),
|
|
|
|
include_pattern.format("nspr"),
|
|
|
|
"-Impi",
|
|
|
|
"-DDO_PR_CLEANUP",
|
2020-05-20 18:56:53 +03:00
|
|
|
"-DNSS_PKCS11_2_0_COMPAT",
|
2019-05-01 00:44:59 +03:00
|
|
|
],
|
|
|
|
)
|
2018-07-17 21:26:39 +03:00
|
|
|
|
2019-05-01 00:44:59 +03:00
|
|
|
env.Append(CPPPATH=["#include", "#."])
|
|
|
|
Export("env")
|
2018-07-17 21:26:39 +03:00
|
|
|
|
2019-05-01 00:44:59 +03:00
|
|
|
SConscript("mpi/SConscript", variant_dir="build/mpi")
|
|
|
|
SConscript("pclient/SConscript", variant_dir="build/pclient")
|
2020-05-23 21:11:23 +03:00
|
|
|
SConscript("pclient_uint/SConscript", variant_dir="build/pclient_uint")
|
2019-05-01 00:44:59 +03:00
|
|
|
SConscript("prio/SConscript", variant_dir="build/prio")
|
|
|
|
SConscript("ptest/SConscript", variant_dir="build/ptest")
|
2020-04-23 14:35:51 +03:00
|
|
|
|
|
|
|
if env["FUZZING"]:
|
|
|
|
SConscript("pfuzz/SConscript", variant_dir="build/pfuzz")
|