nspr.configure (3774B)
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/. 6 7 # Top-level configure defaults to building NSPR from source. Standalone JS 8 # doesn't. 9 option( 10 "--enable-nspr-build", 11 when=js_standalone, 12 help="{Build|Do not build} NSPR from source tree", 13 ) 14 15 16 @depends("--enable-nspr-build", when=js_standalone) 17 def enable_nspr_build(enable): 18 if enable: 19 return enable 20 21 22 system_lib_option( 23 "--with-system-nspr", 24 help="Use system NSPR", 25 when=use_pkg_config, 26 ) 27 28 29 @depends("--with-system-nspr", when=use_pkg_config) 30 def with_system_nspr_option(with_system_nspr): 31 return with_system_nspr 32 33 34 @depends(enable_nspr_build, with_system_nspr_option, js_standalone) 35 def build_nspr(nspr_build, system_nspr, js_standalone): 36 if nspr_build is not None and nspr_build.origin != "default": 37 if nspr_build and system_nspr: 38 die("Cannot use both --enable-nspr-build and --with-system-nspr") 39 if js_standalone: 40 return nspr_build 41 return not system_nspr 42 43 44 set_config("MOZ_BUILD_NSPR", True, when=build_nspr) 45 set_config("MOZ_SYSTEM_NSPR", True, when="--with-system-nspr") 46 47 48 @depends(build_nspr, with_system_nspr_option, js_standalone) 49 def js_without_nspr(build_nspr, system_nspr, js_standalone): 50 if js_standalone: 51 return not build_nspr and not system_nspr 52 53 54 set_define("JS_WITHOUT_NSPR", True, when=js_without_nspr) 55 56 57 @depends(js_standalone) 58 def nspr_minver(js_standalone): 59 if js_standalone: 60 return "nspr >= 4.10" 61 return "nspr >= 4.32" 62 63 64 nspr_pkg = pkg_check_modules("NSPR", nspr_minver, when="--with-system-nspr") 65 66 67 @depends_if(nspr_pkg) 68 def nspr_pkg(nspr_pkg): 69 def extract(prefix, list): 70 for item in list: 71 if item.startswith(prefix): 72 return item[len(prefix) :] 73 return "" 74 75 include_dir = extract("-I", nspr_pkg.cflags) 76 lib_dir = extract("-L", nspr_pkg.libs) 77 return namespace( 78 cflags=nspr_pkg.cflags, 79 include_dir=include_dir, 80 libs=nspr_pkg.libs, 81 lib_dir=lib_dir, 82 ) 83 84 85 @depends(with_system_nspr_option, nspr_minver) 86 def pkgconf_requires_private(system_nspr, nspr_minver): 87 if not system_nspr: 88 return "" 89 return "Requires.private: %s" % nspr_minver 90 91 92 set_config("PKGCONF_REQUIRES_PRIVATE", pkgconf_requires_private) 93 94 95 # pkg_check_modules takes care of NSPR_CFLAGS and NSPR_LIBS when using --with-system-nspr. 96 @depends(build_environment, c_compiler, fold_libs, when=build_nspr) 97 def nspr_config(build_env, c_compiler, fold_libs): 98 libs = ["nspr4", "plc4", "plds4"] 99 if c_compiler.type == "clang-cl": 100 lib_dir = os.path.join(build_env.dist, "lib") 101 libs = [os.path.join(lib_dir, "%s.lib" % lib) for lib in libs] 102 else: 103 lib_dir = os.path.join(build_env.dist, "lib" if fold_libs else "bin") 104 libs = ["-L%s" % lib_dir] + ["-l%s" % lib for lib in libs] 105 106 include_dir = os.path.join(build_env.dist, "include", "nspr") 107 return namespace( 108 cflags=["-I%s" % include_dir], 109 include_dir=include_dir, 110 libs=libs, 111 lib_dir=lib_dir, 112 ) 113 114 115 # Avoid using obsolete NSPR features 116 set_define("NO_NSPR_10_SUPPORT", True) 117 118 set_config("NSPR_CFLAGS", nspr_config.cflags, when=nspr_config) 119 set_config("NSPR_LIBS", nspr_config.libs, when=nspr_config) 120 121 set_config("NSPR_INCLUDE_DIR", nspr_config.include_dir, when=nspr_config) 122 set_config("NSPR_LIB_DIR", nspr_config.lib_dir, when=nspr_config) 123 set_config("NSPR_INCLUDE_DIR", nspr_pkg.include_dir, when=nspr_pkg) 124 set_config("NSPR_LIB_DIR", nspr_pkg.lib_dir, when=nspr_pkg)