1 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2 # vim: set filetype=python:
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 # Top-level configure defaults to building NSPR from source. Standalone JS
10 "--enable-nspr-build",
12 help="{Build|Do not build} NSPR from source tree",
16 @depends("--enable-nspr-build", when=js_standalone)
17 def enable_nspr_build(enable):
22 system_lib_option("--with-system-nspr", help="Use system NSPR")
25 @depends(enable_nspr_build, "--with-system-nspr", js_standalone)
26 def build_nspr(nspr_build, system_nspr, js_standalone):
27 if nspr_build is not None and nspr_build.origin != "default":
28 if nspr_build and system_nspr:
29 die("Cannot use both --enable-nspr-build and --with-system-nspr")
32 return not system_nspr
35 set_config("MOZ_BUILD_NSPR", True, when=build_nspr)
36 set_config("MOZ_SYSTEM_NSPR", True, when="--with-system-nspr")
39 @depends(build_nspr, "--with-system-nspr", js_standalone)
40 def js_without_nspr(build_nspr, system_nspr, js_standalone):
42 return not build_nspr and not system_nspr
45 set_config("JS_WITHOUT_NSPR", True, when=js_without_nspr)
46 set_define("JS_WITHOUT_NSPR", True, when=js_without_nspr)
49 @depends(js_standalone)
50 def nspr_minver(js_standalone):
56 nspr_pkg = pkg_check_modules("NSPR", nspr_minver, when="--with-system-nspr")
60 def nspr_pkg(nspr_pkg):
61 def extract(prefix, list):
63 if item.startswith(prefix):
64 return item[len(prefix) :]
67 include_dir = extract("-I", nspr_pkg.cflags)
68 lib_dir = extract("-L", nspr_pkg.libs)
70 cflags=nspr_pkg.cflags,
71 include_dir=include_dir,
77 @depends("--with-system-nspr", nspr_minver)
78 def pkgconf_requires_private(system_nspr, nspr_minver):
81 return "Requires.private: %s" % nspr_minver
84 set_config("PKGCONF_REQUIRES_PRIVATE", pkgconf_requires_private)
86 # pkg_check_modules takes care of NSPR_CFLAGS and NSPR_LIBS when using --with-system-nspr.
87 @depends(build_environment, c_compiler, fold_libs, when=build_nspr)
88 def nspr_config(build_env, c_compiler, fold_libs):
89 libs = ["nspr4", "plc4", "plds4"]
90 if c_compiler.type == "clang-cl":
91 lib_dir = os.path.join(build_env.dist, "lib")
92 libs = [os.path.join(lib_dir, "%s.lib" % lib) for lib in libs]
94 lib_dir = os.path.join(build_env.dist, "lib" if fold_libs else "bin")
95 libs = ["-L%s" % lib_dir] + ["-l%s" % lib for lib in libs]
97 include_dir = os.path.join(build_env.dist, "include", "nspr")
99 cflags=["-I%s" % include_dir],
100 include_dir=include_dir,
106 set_config("NSPR_CFLAGS", nspr_config.cflags, when=nspr_config)
107 set_config("NSPR_LIBS", nspr_config.libs, when=nspr_config)
109 set_config("NSPR_INCLUDE_DIR", nspr_config.include_dir, when=nspr_config)
110 set_config("NSPR_LIB_DIR", nspr_config.lib_dir, when=nspr_config)
111 set_config("NSPR_INCLUDE_DIR", nspr_pkg.include_dir, when=nspr_pkg)
112 set_config("NSPR_LIB_DIR", nspr_pkg.lib_dir, when=nspr_pkg)
114 add_old_configure_assignment("NSPR_LIBS", nspr_config.libs, when=nspr_config)
115 add_old_configure_assignment("NSPR_LIBS", nspr_pkg.libs, when=nspr_pkg)