Source code

Revision control

Copy as Markdown

Other Tools

# -*- 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",
when=use_pkg_config,
)
@depends("--with-system-nspr", when=use_pkg_config)
def with_system_nspr_option(with_system_nspr):
return with_system_nspr
@depends(enable_nspr_build, with_system_nspr_option, 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_option, js_standalone)
def js_without_nspr(build_nspr, system_nspr, js_standalone):
if js_standalone:
return not build_nspr and not system_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_option, 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,
)
# Avoid using obsolete NSPR features
set_define("NO_NSPR_10_SUPPORT", True)
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)