summaryrefslogtreecommitdiffstats
path: root/build/moz.configure/nspr.configure
blob: 5c7358ca507c6649d1cbc10fbd852b3de90c535d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# -*- 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/.

# Top-level configure defaults to building NSPR from source. Standalone JS
# doesn't.
option(
    "--enable-nspr-build",
    when=js_standalone,
    help="{Build|Do not build} NSPR from source tree",
)


@depends("--enable-nspr-build", when=js_standalone)
def enable_nspr_build(enable):
    if enable:
        return enable


system_lib_option("--with-system-nspr", help="Use system NSPR")


@depends(enable_nspr_build, "--with-system-nspr", js_standalone)
def build_nspr(nspr_build, system_nspr, js_standalone):
    if nspr_build is not None and nspr_build.origin != "default":
        if nspr_build and system_nspr:
            die("Cannot use both --enable-nspr-build and --with-system-nspr")
    if js_standalone:
        return nspr_build
    return not system_nspr


set_config("MOZ_BUILD_NSPR", True, when=build_nspr)
set_config("MOZ_SYSTEM_NSPR", True, when="--with-system-nspr")


@depends(build_nspr, "--with-system-nspr", js_standalone)
def js_without_nspr(build_nspr, system_nspr, js_standalone):
    if js_standalone:
        return not build_nspr and not system_nspr


set_config("JS_WITHOUT_NSPR", True, when=js_without_nspr)
set_define("JS_WITHOUT_NSPR", True, when=js_without_nspr)


@depends(js_standalone)
def nspr_minver(js_standalone):
    if js_standalone:
        return "nspr >= 4.10"
    return "nspr >= 4.32"


nspr_pkg = pkg_check_modules("NSPR", nspr_minver, when="--with-system-nspr")


@depends_if(nspr_pkg)
def nspr_pkg(nspr_pkg):
    def extract(prefix, list):
        for item in list:
            if item.startswith(prefix):
                return item[len(prefix) :]
        return ""

    include_dir = extract("-I", nspr_pkg.cflags)
    lib_dir = extract("-L", nspr_pkg.libs)
    return namespace(
        cflags=nspr_pkg.cflags,
        include_dir=include_dir,
        libs=nspr_pkg.libs,
        lib_dir=lib_dir,
    )


@depends("--with-system-nspr", nspr_minver)
def pkgconf_requires_private(system_nspr, nspr_minver):
    if not system_nspr:
        return ""
    return "Requires.private: %s" % nspr_minver


set_config("PKGCONF_REQUIRES_PRIVATE", pkgconf_requires_private)

# pkg_check_modules takes care of NSPR_CFLAGS and NSPR_LIBS when using --with-system-nspr.
@depends(build_environment, c_compiler, fold_libs, when=build_nspr)
def nspr_config(build_env, c_compiler, fold_libs):
    libs = ["nspr4", "plc4", "plds4"]
    if c_compiler.type == "clang-cl":
        lib_dir = os.path.join(build_env.dist, "lib")
        libs = [os.path.join(lib_dir, "%s.lib" % lib) for lib in libs]
    else:
        lib_dir = os.path.join(build_env.dist, "lib" if fold_libs else "bin")
        libs = ["-L%s" % lib_dir] + ["-l%s" % lib for lib in libs]

    include_dir = os.path.join(build_env.dist, "include", "nspr")
    return namespace(
        cflags=["-I%s" % include_dir],
        include_dir=include_dir,
        libs=libs,
        lib_dir=lib_dir,
    )


set_config("NSPR_CFLAGS", nspr_config.cflags, when=nspr_config)
set_config("NSPR_LIBS", nspr_config.libs, when=nspr_config)

set_config("NSPR_INCLUDE_DIR", nspr_config.include_dir, when=nspr_config)
set_config("NSPR_LIB_DIR", nspr_config.lib_dir, when=nspr_config)
set_config("NSPR_INCLUDE_DIR", nspr_pkg.include_dir, when=nspr_pkg)
set_config("NSPR_LIB_DIR", nspr_pkg.lib_dir, when=nspr_pkg)

add_old_configure_assignment("NSPR_LIBS", nspr_config.libs, when=nspr_config)
add_old_configure_assignment("NSPR_LIBS", nspr_pkg.libs, when=nspr_pkg)