third_party/openpgp.configure
author Mozilla Releng Treescript <release+treescript@mozilla.org>
Mon, 22 Mar 2021 08:37:38 +0000
changeset 41418 469750840b63d92271fd91b5db4e7ec0e75c6eef
parent 40374 f9cf8c5973a6ca4ad8365732d057f6ba7d25ecc3
child 42537 568b56686fdf18c592291d86b63ec9612071e20b
permissions -rw-r--r--
no bug - Bumping Thunderbird l10n changesets r=release a=l10n-bump DONTBUILD ar -> 0d19f1c07ecedb196ed5c462afe8355025d8d3c8 be -> 5c1ac7b2253fd6cc99416c5d171bb80457db5b55 bg -> 7289260eb00ffb5ebff28ace31eb1fb0a928f151 br -> a3c4e6b8ebe164b8b22be083df33f467338f324a ca -> 2bddd90cfca3259922b866c0095cddcb1e4a8cf6 cak -> 34d0c578939190cc6b08a1ea1405ab89ce8664da cs -> 7174ed1d41e8d3df28f6c9155654b31d1bd81ded cy -> 6ec17b2c9cfe627746c5e8c4d442b71ccb98511a da -> 2a0039c127a50242b19970479d06ffdd950f392b de -> fe1727679c5aa251f0b6d7ecdb55f274c48979fd dsb -> a8c9b2534c7c3a954a68e20abda112dbb0f168af el -> ddbeee1744d24b919c3d5fca8a56eff6042d871a en-CA -> cca41d76480b2b8e24bfb0946c18a9edc1e5c529 en-GB -> a57fae2878b776ee7bac53014f19585f6360475d es-AR -> ae2899c5c38f470ce3bff11df852c9dc72e71a0e es-ES -> 997fb8029ff2489ae1f826dec67a320c42ab9ae1 et -> a96e92052387c16bbcffe4cc25a942781a5060b9 eu -> 87240f51b7c640dfafdd439109e63b1f536c6086 fi -> e78ce6c8fafcd3eed25a7af6769593798154d5e0 fr -> f7df0eecd20d13d619adead8807c62ec9006389f fy-NL -> 46c116c82b236f195569f1cfcb92e1d5090ee3fe gl -> 40a0f16a7b9a184315798855ad71cef8fad6d3a1 he -> a65128376cf46c8b8ee11639a5d10ce9981699a8 hr -> 077a56b125d981426c84c9ad28e12497ef8c75cf hsb -> 70118d5baf56d1c4ecb9a91eaba48e15bef8dc1a hu -> 5e38454153738bdc3da1016a10d9435b8e856374 hy-AM -> 4cf6e3aa30586f358d74dabe872dc69f0ff893e5 id -> 727c0157707a480934ecdfae18ba991fee79e985 it -> 23cb1b9403df55510feadb7ccf6970690ce6f5ba ja -> 29ecefce0a748f46d7848b6682bede44a564a3c0 ja-JP-mac -> 5f0d96ca9de50ca47d9b1a58efe8ec8288678986 ka -> 7902ab45bc6521652763ca9117d361b55f5444ec kab -> fe2ad176fe41fb8c0b900eb46fa8920b21e66204 kk -> 15134e1e5e1248731ca56ee77da9205cfa3d60cb ko -> a72bee782fb4adc994c1ed33fa44d21c95d053a0 lt -> ebe9a3160739e04a77a9a0e3cd1fc54bf71eb2bf nb-NO -> e6367352d009f5d41c6d92d803b326c7750a91b5 nl -> c22b1ab43765214c112e87a83a3e7780695a6c70 nn-NO -> dcb52465dcc0742896c372191040b4ed67c84a0e pa-IN -> 2435f2e9153899a6a9ce714c3e2f3e185e326da1 pl -> 7563545e97325d80aba09cacc08156b3a546c04d pt-BR -> b924fc058102089db90b55512f307a5a2d31dee5 pt-PT -> 3208f934f658e1514ebfc44732b3ffc69ba7dfcb rm -> 3c8e4cd74d81aa664f17b9b2ac6982e7a3415f00 ro -> 6d580dc761bf6bfbc291fdb1f27341cffc7c9735 ru -> f663d08ee0931a5938812c638b1354514e478d94 sk -> bd2e8286afe6cb86cce9ea69487d29742dbed3b0 sl -> 5c0add6445e2ba0fa55c6b64754893d2d924fe9f sq -> 45cf8fd3abbf58a8f2da229b317a77ade02926d5 sr -> 0badca946680876e5e8588600b76df7bc777283c sv-SE -> b403b5f2c2b79ec7ddcd7df4b5f6ae7d3d066d1a th -> 16dfd654e3588349b9624c119db856ed064e4541 tr -> 0b2c1304f8be28eecc2c0a08a6ea425f9fc6ced7 uk -> 7222454c1d8a5829554db24fbc6aa636e8963f7a uz -> edb10ef52b2c242b8c96a98a5e1a7ef13f3fcd21 vi -> 8a095a6f0becde32de0023df775dadbc5be4a1ff zh-CN -> 9400573eda1af97cd311f611740cbab50279d6c4 zh-TW -> a9d71057d605be2537ed0704849e5d5c4cd44683

# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
#  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/.


@template
def noset_check_header(
    header, language="C++", flags=None, includes=None, when=None, onerror=lambda: None
):
    if when is None:
        when = always

    if includes:
        includes = includes[:]
    else:
        includes = []
    includes.append(header)

    return try_compile(
        includes=includes,
        language=language,
        flags=flags,
        check_msg="for %s" % header,
        when=when,
        onerror=onerror,
    )


@template
def check_symbol_exists(
    symbol,
    header,
    language="C",
    flags=None,
    includes=None,
    when=None,
    onerror=lambda: None,
):
    if when is None:
        when = always

    if includes:
        includes = includes[:]
    else:
        includes = []
    includes.append("stdio.h")

    if isinstance(header, str):
        header = [header]
    includes.extend(header)

    body = """#ifndef %s
(void) %s;
#endif
""" % (
        symbol,
        symbol,
    )

    return try_compile(
        includes,
        body,
        language=language,
        flags=flags,
        check_msg="for %s" % symbol,
        when=when,
        onerror=onerror,
    )


with only_when("--enable-compile-environment"):
    # Use system libraries when building librnp
    # ZLIB honors --with-system-zlib

    # JSON-C --with-system-json
    option(
        "--with-system-jsonc",
        help="Use system JSON-C for librnp (located with pkgconfig)",
    )

    jsonc_pkg = pkg_check_modules(
        "MZLA_JSONC", "json-c >= 0.11", when="--with-system-jsonc"
    )
    set_config("MZLA_SYSTEM_JSONC", depends_if(jsonc_pkg)(lambda _: True))

    @depends("--with-system-jsonc")
    def in_tree_jsonc(system_jsonc):
        if not system_jsonc:
            return True

    # Bzip2 --with-system-bz2
    option(
        "--with-system-bz2",
        nargs="?",
        help="Use system Bzip2 for librnp (pkgconfig/given prefix)",
    )
    set_config("MZLA_SYSTEM_BZIP2", True, when="--with-system-bz2")

    # Bzip2 does not include a pkgconfig file, but some Linux distributions add one
    bzip2_pkg = pkg_check_modules(
        "MZLA_BZIP2",
        "bzip2 >= 1.0.6",
        when="--with-system-bz2",
        allow_missing=True,
        config=False,
    )

    @depends_if("--with-system-bz2", bzip2_pkg)
    def bzip2_flags(value, bzip2_pkg):
        if len(value):
            # A path (eg. /usr/local was given)
            return namespace(
                cflags=("-I%s/include" % value[0],),
                ldflags=("-L%s/lib" % value[0], "-lbz2"),
            )
        if bzip2_pkg:
            cflags = list(bzip2_pkg.cflags)
            libs = bzip2_pkg.libs
            return namespace(
                cflags=cflags,
                libs=libs,
                path=(value[0]),
            )
        # Fallback
        return namespace(
            ldflags=["-lbz2"],
        )

    with only_when("--with-system-bz2"):
        check_symbol(
            "BZ2_bzread",
            flags=bzip2_flags.ldflags,
            onerror=lambda: die(
                "--with-system-bz2 requested but symbol " "BZ2_bzread not found."
            ),
        )
        c_compiler.try_compile(
            includes=[
                "stdio.h",
                "sys/types.h",
                "bzlib.h",
            ],
            body="""
                #ifndef _BZLIB_H
                #error _BZLIB_H bzlib.h not found
                #endif
            """,
            flags=bzip2_flags.cflags,
            check_msg="for bzlib.h",
            onerror=lambda: die("bzlib.h header not found"),
        )
        set_config("MZLA_BZIP2_CFLAGS", bzip2_flags.cflags)
        set_config("MZLA_BZIP2_LIBS", bzip2_flags.ldflags)

    # BOTAN --with-system-botan
    option(
        "--with-system-botan",
        help="Use system Botan for librnp (located with pkgconfig)",
    )

    botan_pkg = pkg_check_modules(
        "MZLA_BOTAN", "botan-2 >= 2.8.0", when="--with-system-botan"
    )
    set_config("MZLA_SYSTEM_BOTAN", depends_if(botan_pkg)(lambda _: True))

    # Checks for building librnp itself
    # =================================
    have_fcntl_h = check_header("fcntl.h")
    have_string_h = check_header("string.h")
    check_headers(
        "limits.h",
        "sys/auxv.h",
        "sys/cdefs.h",
        "sys/resource.h",
        "sys/param.h",
        "sys/stat.h",
        "sys/wait.h",
    )

    set_define("HAVE_MKDTEMP", check_symbol_exists("mkdtemp", ["stdlib.h", "unistd.h"]))
    set_define("HAVE_MKSTEMP", check_symbol_exists("mkstemp", ["stdlib.h", "unistd.h"]))
    set_define("HAVE_REALPATH", check_symbol_exists("realpath", "stdlib.h"))
    set_define("HAVE_O_BINARY", check_symbol_exists("O_BINARY", "fcntl.h"))
    set_define("HAVE__O_BINARY", check_symbol_exists("_O_BINARY", "fcntl.h"))

    # Checks when building JSON-C from tree sources
    # =============================================
    with only_when(in_tree_jsonc):
        have_stdlib_h = check_header("stdlib.h")
        have_locale_h = check_header("locale.h")
        have_strings_h = check_header("strings.h")

        check_headers("stdarg.h", "dlfcn.h", "endian.h", "memory.h", "xlocale.h")

        set_define("JSON_C_HAVE_INTTYPES_H", noset_check_header("inttypes.h"))

        set_define("HAVE_DECL__ISNAN", check_symbol_exists("_isnan", "float.h"))

        set_define("HAVE_DECL__FINITE", check_symbol_exists("_finite", "float.h"))
        set_define("HAVE_DECL_INFINITY", check_symbol_exists("INFINITY", "math.h"))
        set_define("HAVE_DECL_ISINF", check_symbol_exists("isinf", "math.h"))
        set_define("HAVE_DECL_ISNAN", check_symbol_exists("isnan", "math.h"))
        set_define("HAVE_DECL_NAN", check_symbol_exists("nan", "math.h"))

        set_define("HAVE_DOPRNT", check_symbol_exists("_doprnt", "stdio.h"))
        set_define("HAVE_SNPRINTF", check_symbol_exists("snprintf", "stdio.h"))
        set_define(
            "HAVE_VASPRINTF",
            check_symbol_exists("vasprintf", "stdio.h", flags=["-D_GNU_SOURCE"]),
        )
        set_define("HAVE_VSNPRINTF", check_symbol_exists("vsnprintf", "stdio.h"))
        set_define("HAVE_VPRINTF", check_symbol_exists("vprintf", "stdio.h"))

        set_define(
            "HAVE_OPEN", check_symbol_exists("open", "fcntl.h", when=have_fcntl_h)
        )
        set_define(
            "HAVE_REALLOC",
            check_symbol_exists("realloc", "stdlib.h", when=have_stdlib_h),
        )
        set_define(
            "HAVE_SETLOCALE",
            check_symbol_exists("setlocale", "locale.h", when=have_locale_h),
        )
        set_define(
            "HAVE_USELOCALE",
            check_symbol_exists("uselocale", "locale.h", when=have_locale_h),
        )
        set_define(
            "HAVE_STRCASECMP",
            check_symbol_exists("strcasecmp", "strings.h", when=have_strings_h),
        )
        set_define(
            "HAVE_STRNCASECMP",
            check_symbol_exists("strncasecmp", "strings.h", when=have_strings_h),
        )
        set_define(
            "HAVE_STRDUP", check_symbol_exists("strdup", "string.h", when=have_string_h)
        )


@depends(c_compiler, target, when=compile_environment)
@checking("for clang_rt.builtins path", lambda x: x if x is None else x.clang_rt_lib)
@imports(_from="os", _import="pathsep")
@imports(_from="os.path", _import="isdir")
@imports(_from="os.path", _import="exists")
@imports(_from="os.path", _import="join")
def clang_rt_builtins(compiler_info, target):
    if compiler_info.type == "clang-cl":
        if target.raw_cpu in ["i686"]:
            rt_arch = "i386"
        else:
            rt_arch = target.raw_cpu

        clang_rt_builtins = "clang_rt.builtins-{}".format(rt_arch)
        clang_cl = compiler_info.compiler
        flags = []
        flags.extend(compiler_info.flags)
        flags.append("-clang:-print-search-dirs")
        clang_search_dirs = check_cmd_output(clang_cl, *flags)
        for line in clang_search_dirs.splitlines():
            name, _, value = line.partition(": =")
            if name == "libraries":
                for dir in value.split(pathsep):
                    if dir.endswith(compiler_info.version.vstring):
                        clang_rt_dir = join(dir, "lib/windows")
                        clang_rt_lib = join(clang_rt_dir, clang_rt_builtins)
                        if isdir(clang_rt_dir):
                            if exists("{}.lib".format(clang_rt_lib)):
                                return namespace(
                                    clang_rt_path=clang_rt_dir,
                                    clang_rt_lib=clang_rt_lib,
                                )
        die("Cannot find clang_rt.builtins path.")


set_config("COMPILER_RT_BUILTIN_PATH", clang_rt_builtins.clang_rt_path, when=is_windows)
set_config("COMPILER_RT_BUILTIN_LIB", clang_rt_builtins.clang_rt_lib, when=is_windows)


@depends(c_compiler, cxx_compiler, when=compile_environment)
def rnp_compiler(c_compiler, cxx_compiler):
    # Replace -std=gnu++17 or -std=c++17 with -std=gnu++11 or -std=c++11
    _cxxflags = []
    for f in cxx_compiler.flags:
        if f == "-std=c++17":
            _cxxflags.append("-std=c++14")
        elif f == "-std=gnu++17":
            _cxxflags.append("-std=gnu++11")
        else:
            _cxxflags.append(f)

    rnp_cc = " ".join(
        list(c_compiler.wrapper) + [c_compiler.compiler] + c_compiler.flags
    )
    rnp_cxx = " ".join(list(cxx_compiler.wrapper) + [cxx_compiler.compiler] + _cxxflags)

    return namespace(rnp_cc=rnp_cc, rnp_cxx=rnp_cxx)


set_config("MZLA_RNP_CC", rnp_compiler.rnp_cc)
set_config("MZLA_RNP_CXX", rnp_compiler.rnp_cxx)