Bug 1732409 let fake:true getUserMedia() parameter override loopback prefs r=jib
[gecko.git] / moz.configure
blobe7a37cd89e3498cf07a6284d738b2f5165c26d16
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 include("build/moz.configure/init.configure")
9 # Note:
10 # - Gecko-specific options and rules should go in toolkit/moz.configure.
11 # - Firefox-specific options and rules should go in browser/moz.configure.
12 # - Fennec-specific options and rules should go in
13 #   mobile/android/moz.configure.
14 # - Spidermonkey-specific options and rules should go in js/moz.configure.
15 # - etc.
17 option(
18     "--enable-artifact-builds",
19     env="MOZ_ARTIFACT_BUILDS",
20     help="Download and use prebuilt binary artifacts.",
24 @depends("--enable-artifact-builds")
25 def artifact_builds(value):
26     if value:
27         return True
30 set_config("MOZ_ARTIFACT_BUILDS", artifact_builds)
32 imply_option(
33     "--enable-artifact-build-symbols",
34     depends(artifact_builds)(lambda v: False if v is None else None),
35     reason="--disable-artifact-builds",
38 option(
39     "--enable-artifact-build-symbols",
40     nargs="?",
41     choices=("full",),
42     help="Download symbols when artifact builds are enabled.",
46 @depends("--enable-artifact-build-symbols", "MOZ_AUTOMATION", target)
47 def enable_artifact_build_symbols(value, automation, target):
48     if len(value):
49         return value[0]
50     if bool(value):
51         if target.os == "Android" and not automation:
52             return "full"
53         return True
54     return None
57 set_config("MOZ_ARTIFACT_BUILD_SYMBOLS", enable_artifact_build_symbols)
60 @depends("--enable-artifact-builds")
61 def imply_disable_compile_environment(value):
62     if value:
63         return False
66 option(
67     env="MOZ_COPY_PDBS",
68     help="For builds that do not support symbols in the normal fashion,"
69     " generate and copy them into the resulting build archive.",
72 set_config("MOZ_COPY_PDBS", depends_if("MOZ_COPY_PDBS")(lambda _: True))
74 imply_option("--enable-compile-environment", imply_disable_compile_environment)
76 option("--disable-compile-environment", help="Disable compiler/library checks")
79 @depends("--disable-compile-environment")
80 def compile_environment(compile_env):
81     if compile_env:
82         return True
85 set_config("COMPILE_ENVIRONMENT", compile_environment)
86 add_old_configure_assignment("COMPILE_ENVIRONMENT", compile_environment)
88 option("--disable-tests", help="Do not build test libraries & programs")
91 @depends("--disable-tests")
92 def enable_tests(value):
93     if value:
94         return True
97 set_config("ENABLE_TESTS", enable_tests)
98 set_define("ENABLE_TESTS", enable_tests)
101 @depends(enable_tests)
102 def gtest_has_rtti(value):
103     if value:
104         return "0"
107 set_define("GTEST_HAS_RTTI", gtest_has_rtti)
110 @depends(target, enable_tests)
111 def linux_gtest_defines(target, enable_tests):
112     if enable_tests and target.os == "Android":
113         return namespace(os_linux_android=True, use_own_tr1_tuple=True, has_clone="0")
116 set_define("GTEST_OS_LINUX_ANDROID", linux_gtest_defines.os_linux_android)
117 set_define("GTEST_USE_OWN_TR1_TUPLE", linux_gtest_defines.use_own_tr1_tuple)
118 set_define("GTEST_HAS_CLONE", linux_gtest_defines.has_clone)
120 option(
121     "--enable-debug",
122     nargs="?",
123     help="Enable building with developer debug info "
124     "(using the given compiler flags).",
128 @depends("--enable-debug")
129 def moz_debug(debug):
130     if debug:
131         return bool(debug)
134 set_config("MOZ_DEBUG", moz_debug)
135 set_define("MOZ_DEBUG", moz_debug)
136 # Override any value MOZ_DEBUG may have from the environment when passing it
137 # down to old-configure.
138 add_old_configure_assignment("MOZ_DEBUG", depends("--enable-debug")(lambda x: bool(x)))
140 option(
141     "--with-debug-label",
142     nargs="+",
143     help="Debug DEBUG_<value> for each comma-separated value given",
147 @depends(moz_debug, "--with-debug-label")
148 def debug_defines(debug, labels):
149     if debug:
150         return ["DEBUG"] + ["DEBUG_%s" % label for label in labels]
151     return ["NDEBUG", "TRIMMED"]
154 set_config("MOZ_DEBUG_DEFINES", debug_defines)
156 option(env="MOZ_PGO", help="Build with profile guided optimizations")
158 set_config("MOZ_PGO", depends("MOZ_PGO")(lambda x: bool(x)))
161 imply_option("--enable-release", mozilla_official)
162 imply_option("--enable-release", depends_if("MOZ_AUTOMATION")(lambda x: True))
164 option(
165     "--enable-release",
166     default=milestone.is_release_or_beta,
167     help="{Build|Do not build} with more conservative, release "
168     "engineering-oriented options.{ This may slow down builds.|}",
172 @depends("--enable-release")
173 def developer_options(value):
174     if not value:
175         return True
178 add_old_configure_assignment("DEVELOPER_OPTIONS", developer_options)
179 set_config("DEVELOPER_OPTIONS", developer_options)
182 # hybrid build handling
183 # ==============================================================
185 option(
186     "--disable-unified-build",
187     help="Enable building modules that are not marked with `REQUIRES_UNIFIED_BUILD` in non unified context",
190 set_config("ENABLE_UNIFIED_BUILD", True, when="--disable-unified-build")
193 include("build/moz.configure/bootstrap.configure")
195 # The execution model of the configure sandbox doesn't allow for
196 # check_prog to use bootstrap_search_path directly because check_prog
197 # comes first, so we use a trick to allow it. Uses of check_prog
198 # happening before here won't allow bootstrap.
199 @template
200 def check_prog(*args, **kwargs):
201     kwargs["bootstrap_search_path"] = bootstrap_search_path
202     return check_prog(*args, **kwargs)
205 check_prog("WGET", ("wget",), allow_missing=True)
208 include("build/moz.configure/toolchain.configure", when="--enable-compile-environment")
210 include("build/moz.configure/pkg.configure")
211 # Make this assignment here rather than in pkg.configure to avoid
212 # requiring this file in unit tests.
213 add_old_configure_assignment("PKG_CONFIG", pkg_config)
215 include("build/moz.configure/memory.configure", when="--enable-compile-environment")
216 include("build/moz.configure/headers.configure", when="--enable-compile-environment")
217 include("build/moz.configure/warnings.configure", when="--enable-compile-environment")
218 include("build/moz.configure/flags.configure", when="--enable-compile-environment")
219 include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment")
220 # rust.configure is included by js/moz.configure.
222 option("--enable-valgrind", help="Enable Valgrind integration hooks")
224 valgrind_h = check_header("valgrind/valgrind.h", when="--enable-valgrind")
227 @depends("--enable-valgrind", valgrind_h)
228 def check_valgrind(valgrind, valgrind_h):
229     if valgrind:
230         if not valgrind_h:
231             die("--enable-valgrind specified but Valgrind is not installed")
232         return True
235 set_define("MOZ_VALGRIND", check_valgrind)
236 set_config("MOZ_VALGRIND", check_valgrind)
239 @depends(target, host)
240 def is_openbsd(target, host):
241     return target.kernel == "OpenBSD" or host.kernel == "OpenBSD"
244 option(
245     env="SO_VERSION",
246     nargs=1,
247     default="1.0",
248     when=is_openbsd,
249     help="Shared library version for OpenBSD systems",
253 @depends("SO_VERSION", when=is_openbsd)
254 def so_version(value):
255     return value
258 @template
259 def library_name_info_template(host_or_target):
260     assert host_or_target in {host, target}
261     compiler = {
262         host: host_c_compiler,
263         target: c_compiler,
264     }[host_or_target]
266     @depends(host_or_target, compiler, so_version)
267     def library_name_info_impl(host_or_target, compiler, so_version):
268         if host_or_target.kernel == "WINNT":
269             # There aren't artifacts for mingw builds, so it's OK that the
270             # results are inaccurate in that case.
271             if compiler and compiler.type != "clang-cl":
272                 return namespace(
273                     dll=namespace(prefix="", suffix=".dll"),
274                     lib=namespace(prefix="lib", suffix="a"),
275                     import_lib=namespace(prefix="lib", suffix="a"),
276                     obj=namespace(prefix="", suffix="o"),
277                 )
279             return namespace(
280                 dll=namespace(prefix="", suffix=".dll"),
281                 lib=namespace(prefix="", suffix="lib"),
282                 import_lib=namespace(prefix="", suffix="lib"),
283                 obj=namespace(prefix="", suffix="obj"),
284             )
286         elif host_or_target.kernel == "Darwin":
287             return namespace(
288                 dll=namespace(prefix="lib", suffix=".dylib"),
289                 lib=namespace(prefix="lib", suffix="a"),
290                 import_lib=namespace(prefix=None, suffix=""),
291                 obj=namespace(prefix="", suffix="o"),
292             )
293         elif so_version:
294             so = ".so.%s" % so_version
295         else:
296             so = ".so"
298         return namespace(
299             dll=namespace(prefix="lib", suffix=so),
300             lib=namespace(prefix="lib", suffix="a"),
301             import_lib=namespace(prefix=None, suffix=""),
302             obj=namespace(prefix="", suffix="o"),
303         )
305     return library_name_info_impl
308 host_library_name_info = library_name_info_template(host)
309 library_name_info = library_name_info_template(target)
311 set_config("DLL_PREFIX", library_name_info.dll.prefix)
312 set_config("DLL_SUFFIX", library_name_info.dll.suffix)
313 set_config("HOST_DLL_PREFIX", host_library_name_info.dll.prefix)
314 set_config("HOST_DLL_SUFFIX", host_library_name_info.dll.suffix)
315 set_config("LIB_PREFIX", library_name_info.lib.prefix)
316 set_config("LIB_SUFFIX", library_name_info.lib.suffix)
317 set_config("OBJ_SUFFIX", library_name_info.obj.suffix)
318 # Lots of compilation tests depend on this variable being present.
319 add_old_configure_assignment("OBJ_SUFFIX", library_name_info.obj.suffix)
320 set_config("IMPORT_LIB_SUFFIX", library_name_info.import_lib.suffix)
321 set_define(
322     "MOZ_DLL_PREFIX", depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s)
324 set_define(
325     "MOZ_DLL_SUFFIX", depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s)
327 set_config("WASM_OBJ_SUFFIX", "wasm")
329 # Make `profiling` available to this file even when js/moz.configure
330 # doesn't end up included.
331 profiling = dependable(False)
332 # Same for js_standalone
333 js_standalone = dependable(False)
334 # Same for fold_libs
335 fold_libs = dependable(False)
337 include(include_project_configure)
340 @depends("--help")
341 @imports(_from="mozbuild.backend", _import="backends")
342 def build_backends_choices(_):
343     return tuple(backends)
346 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
347 def build_backend(backends):
348     if backends:
349         return tuple("+%s" % b for b in backends)
352 imply_option("--build-backends", build_backend)
355 @depends(
356     "--enable-artifact-builds",
357     "--disable-compile-environment",
358     "--enable-build-backend",
359     "--enable-project",
360     "--enable-application",
361     "--help",
363 @imports("sys")
364 def build_backend_defaults(
365     artifact_builds, compile_environment, requested_backends, project, application, _
367     if application:
368         project = application[0]
369     elif project:
370         project = project[0]
372     if "Tup" in requested_backends:
373         # As a special case, if Tup was requested, do not combine it with any
374         # Make based backend by default.
375         all_backends = []
376     elif artifact_builds:
377         all_backends = ["FasterMake+RecursiveMake"]
378     else:
379         all_backends = ["RecursiveMake", "FasterMake"]
380     # Normally, we'd use target.os == 'WINNT', but a dependency on target
381     # would require target to depend on --help, as well as host and shell,
382     # and this is not a can of worms we can open at the moment.
383     if (
384         sys.platform == "win32"
385         and compile_environment
386         and project not in ("mobile/android", "memory", "tools/update-programs")
387     ):
388         all_backends.append("VisualStudio")
389     return tuple(all_backends) or None
392 option(
393     "--build-backends",
394     nargs="+",
395     default=build_backend_defaults,
396     choices=build_backends_choices,
397     help="Build backends to generate",
401 @depends("--build-backends")
402 def build_backends(backends):
403     return backends
406 set_config("BUILD_BACKENDS", build_backends)
409 @depends(check_build_environment, build_backends)
410 @imports("glob")
411 def check_objdir_backend_reuse(build_env, backends):
412     # "Make based" might be RecursiveMake or a hybrid backend, so "Make" is
413     # intentionally vague for use with the substring match below.
414     incompatible_backends = (("Tup", "Make"), ("Make", "Tup"))
415     for backend_file in glob.iglob(
416         os.path.join(build_env.topobjdir, "backend.*Backend")
417     ):
418         for prev, curr in incompatible_backends:
419             if prev in backend_file and any(curr in b for b in backends):
420                 die(
421                     "The active objdir, %s, was previously "
422                     "used to build with a %s based backend. "
423                     "Change objdirs (by setting MOZ_OBJDIR in "
424                     "your mozconfig) or clobber to continue.\n",
425                     build_env.topobjdir,
426                     prev,
427                 )
430 # Determine whether to build the gtest xul. This happens in automation
431 # on Android and Desktop platforms with the exception of:
432 #  - Windows PGO, where linking xul-gtest.dll takes too long;
433 #  - Android other than x86_64, where gtest is not required.
434 @depends(
435     build_project,
436     target,
437     "MOZ_AUTOMATION",
438     enable_tests,
439     when="--enable-compile-environment",
441 def build_gtest(build_project, target, automation, enable_tests):
442     return bool(
443         enable_tests
444         and automation
445         and build_project in ("browser", "comm/mail", "mobile/android")
446         and not (target.os == "Android" and target.cpu != "x86_64")
447     )
450 option(
451     "--enable-gtest-in-build",
452     default=build_gtest,
453     help="{Enable|Force disable} building the gtest libxul during the build.",
454     when="--enable-compile-environment",
457 set_config("LINK_GTEST_DURING_COMPILE", True, when="--enable-gtest-in-build")
459 # Localization
460 # ==============================================================
461 option(
462     "--enable-ui-locale",
463     default="en-US",
464     help="Select the user interface locale (default: en-US)",
467 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
469 option(
470     "--enable-icu4x",
471     help="An experiment to use ICU4X instead of ICU4C. See intl/ICU4X.md",
474 set_config("MOZ_ICU4X", True, when="--enable-icu4x")
476 # clang-plugin location
477 # ==============================================================
480 @depends(host_library_name_info, check_build_environment, when="--enable-clang-plugin")
481 def clang_plugin_path(library_name_info, build_env):
482     topobjdir = build_env.topobjdir
483     if topobjdir.endswith("/js/src"):
484         topobjdir = topobjdir[:-7]
485     return os.path.abspath(
486         os.path.join(
487             topobjdir,
488             "build",
489             "clang-plugin",
490             "%sclang-plugin%s"
491             % (library_name_info.dll.prefix, library_name_info.dll.suffix),
492         )
493     )
496 set_config("CLANG_PLUGIN", clang_plugin_path)
497 add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
500 # Awk detection
501 # ==============================================================
502 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"))
504 # Until the AWK variable is not necessary in old-configure
507 @depends(awk)
508 def awk_for_old_configure(value):
509     return value
512 add_old_configure_assignment("AWK", awk_for_old_configure)
515 # Perl detection
516 # ==============================================================
517 perl = check_prog("PERL", ("perl5", "perl"))
519 # Until the PERL variable is not necessary in old-configure
522 @depends(perl)
523 def perl_for_old_configure(value):
524     return value
527 add_old_configure_assignment("PERL", perl_for_old_configure)
530 @template
531 def perl_version_check(min_version):
532     @depends(perl)
533     @checking("for minimum required perl version >= %s" % min_version)
534     def get_perl_version(perl):
535         return Version(
536             check_cmd_output(
537                 perl,
538                 "-e",
539                 "print $]",
540                 onerror=lambda: die("Failed to get perl version."),
541             )
542         )
544     @depends(get_perl_version)
545     def check_perl_version(version):
546         if version < min_version:
547             die("Perl %s or higher is required.", min_version)
549     @depends(perl)
550     @checking("for full perl installation")
551     @imports("subprocess")
552     def has_full_perl_installation(perl):
553         ret = subprocess.call([perl, "-e", "use Config; exit(!-d $Config{archlib})"])
554         return ret == 0
556     @depends(has_full_perl_installation)
557     def require_full_perl_installation(has_full_perl_installation):
558         if not has_full_perl_installation:
559             die(
560                 "Cannot find Config.pm or $Config{archlib}. "
561                 "A full perl installation is required."
562             )
565 perl_version_check("5.006")
568 # GNU make detection
569 # ==============================================================
570 option(env="MAKE", nargs=1, help="Path to GNU make")
573 @depends("MAKE", host)
574 def possible_makes(make, host):
575     candidates = []
576     if host.kernel == "WINNT":
577         candidates.append("mingw32-make")
578     if make:
579         candidates.append(make[0])
580     if host.kernel == "WINNT":
581         candidates.extend(("mozmake", "make", "gmake"))
582     else:
583         candidates.extend(("gmake", "make"))
584     return candidates
587 check_prog("GMAKE", possible_makes, bootstrap="mozmake")
589 # watchman detection
590 # ==============================================================
592 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
595 @depends(host, "WATCHMAN")
596 @checking("for watchman", callback=lambda w: w.path if w else "not found")
597 def watchman(host, prog):
598     # On Windows, `watchman` is only supported on 64-bit hosts.
599     if host.os == "WINNT" and host.cpu != "x86_64":
600         return
602     if not prog:
603         prog = find_program("watchman")
605     if not prog:
606         return
608     # `watchman version` will talk to the Watchman daemon service.
609     # This can hang due to permissions problems. e.g.
610     # https://github.com/facebook/watchman/issues/376. So use
611     # `watchman --version` to prevent a class of failures.
612     out = check_cmd_output(prog, "--version", onerror=lambda: None)
613     if out is None:
614         return
616     return namespace(path=prog, version=Version(out.strip()))
619 @depends_if(watchman)
620 @checking("for watchman version")
621 def watchman_version(w):
622     return w.version
625 set_config("WATCHMAN", watchman.path)
628 @depends_all(hg_version, hg_config, watchman)
629 @checking("for watchman Mercurial integration")
630 @imports("os")
631 def watchman_hg(hg_version, hg_config, watchman):
632     if hg_version < Version("3.8"):
633         return "no (Mercurial 3.8+ required)"
635     ext_enabled = False
636     mode_disabled = False
638     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
639         if k in hg_config and hg_config[k] != "!":
640             ext_enabled = True
642     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
644     if not ext_enabled:
645         return "no (fsmonitor extension not enabled)"
646     if mode_disabled:
647         return "no (fsmonitor.mode=off disables fsmonitor)"
649     return True
652 # Miscellaneous programs
653 # ==============================================================
654 check_prog("XARGS", ("xargs",))
657 @depends(target)
658 def extra_programs(target):
659     if target.kernel == "Darwin":
660         return namespace(
661             DSYMUTIL=("dsymutil", "llvm-dsymutil"),
662             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
663             HFS_TOOL=("hfsplus",),
664         )
665     if target.os == "GNU" and target.kernel == "Linux":
666         return namespace(RPMBUILD=("rpmbuild",))
669 check_prog("DSYMUTIL", extra_programs.DSYMUTIL, allow_missing=True)
670 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
671 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
672 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
675 nsis = check_prog(
676     "MAKENSISU",
677     ("makensis",),
678     bootstrap="nsis/bin",
679     allow_missing=True,
680     when=target_is_windows,
683 # Make sure the version of makensis is up to date.
686 @depends_if(nsis)
687 @checking("for NSIS version")
688 @imports("re")
689 def nsis_version(nsis):
690     nsis_min_version = "3.0b1"
692     def onerror():
693         return die("Failed to get nsis version.")
695     out = check_cmd_output(nsis, "-version", onerror=onerror)
697     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
699     if not m:
700         raise FatalCheckError("Unknown version of makensis")
701     ver = Version(m.group(0))
703     # Versions comparisons don't quite work well with beta versions, so ensure
704     # it works for the non-beta version.
705     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
706         raise FatalCheckError(
707             "To build the installer you must have NSIS"
708             " version %s or greater in your path" % nsis_min_version
709         )
711     return ver
714 # And that makensis is 32-bit (but only on Windows).
715 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
716 @checking("for 32-bit NSIS")
717 def nsis_binary_type(nsis):
718     bin_type = windows_binary_type(nsis)
719     if bin_type != "win32":
720         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
722     return "yes"
725 # And any flags we have to give to makensis
726 @depends(host)
727 def nsis_flags(host):
728     if host.kernel != "WINNT":
729         return "-nocd"
730     return ""
733 set_config("MAKENSISU_FLAGS", nsis_flags)
735 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
736 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
739 @template
740 def llvm_tool(name):
741     @depends(host_c_compiler, c_compiler, bindgen_config_paths)
742     def llvm_tool(host_c_compiler, c_compiler, bindgen_config_paths):
743         clang = None
744         for compiler in (host_c_compiler, c_compiler):
745             if compiler and compiler.type == "clang":
746                 clang = compiler.compiler
747                 break
748             elif compiler and compiler.type == "clang-cl":
749                 clang = os.path.join(os.path.dirname(compiler.compiler), "clang")
750                 break
752         if not clang and bindgen_config_paths:
753             clang = bindgen_config_paths.clang_path
754         tool = name
755         if clang:
756             out = check_cmd_output(
757                 clang, "--print-prog-name=%s" % tool, onerror=lambda: None
758             )
759             if out:
760                 tool = out.rstrip()
761         return (tool,)
763     return llvm_tool
766 llvm_objdump = check_prog(
767     "LLVM_OBJDUMP",
768     llvm_tool("llvm-objdump"),
769     what="llvm-objdump",
770     when="--enable-compile-environment",
771     paths=clang_search_path,
774 add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)
777 @depends(llvm_tool("llvm-readelf"), toolchain_prefix)
778 def readelf(llvm_readelf, toolchain_prefix):
779     commands = [llvm_readelf[0], "readelf"]
780     for prefix in toolchain_prefix or ():
781         commands.insert(1, "%sreadelf" % prefix)
782     return tuple(commands)
785 def validate_readelf(path):
786     # llvm-readelf from llvm < 8 doesn't support the GNU binutils-compatible `-d`
787     # flag. We could try running `$path -d $some_binary` but we might be cross
788     # compiling and not have a binary at hand to run that against. `$path -d` alone
789     # would fail whether the flag is supported or not. So we resort to look for the
790     # option in the `--help` output, which fortunately, s compatible between
791     # llvm-readelf and readelf.
792     retcode, stdout, stderr = get_cmd_output(path, "--help")
793     return retcode == 0 and any(l.startswith("  -d ") for l in stdout.splitlines())
796 @depends("--enable-compile-environment", target, host)
797 def readelf_when(compile_env, target, host):
798     return compile_env and any(
799         x.kernel not in ("Darwin", "WINNT") for x in (target, host)
800     )
803 check_prog(
804     "READELF",
805     readelf,
806     what="readelf",
807     when=readelf_when,
808     paths=clang_search_path,
809     validate=validate_readelf,
812 option("--enable-dtrace", help="Build with dtrace support")
814 dtrace = check_header(
815     "sys/sdt.h",
816     when="--enable-dtrace",
817     onerror=lambda: die("dtrace enabled but sys/sdt.h not found"),
820 set_config("HAVE_DTRACE", True, when=dtrace)
821 set_define("INCLUDE_MOZILLA_DTRACE", True, when=dtrace)
822 add_old_configure_assignment("enable_dtrace", "yes", when=dtrace)
825 option("--disable-icf", help="Disable Identical Code Folding")
827 add_old_configure_assignment(
828     "MOZ_DISABLE_ICF", "1", when=depends("--enable-icf")(lambda x: not x)
832 option(
833     "--enable-strip",
834     when=compile_environment,
835     help="Enable stripping of libs & executables",
838 # This should be handled as a `when` once bug 1617793 is fixed.
841 @depends("--enable-strip", c_compiler, when=compile_environment)
842 def enable_strip(strip, c_compiler):
843     if strip and c_compiler.type != "clang-cl":
844         return True
847 set_config("ENABLE_STRIP", enable_strip)
849 option(
850     "--disable-install-strip",
851     when=compile_environment,
852     help="Enable stripping of libs & executables when packaging",
855 # This should be handled as a `when` once bug 1617793 is fixed.
858 @depends("--enable-install-strip", c_compiler, when=compile_environment)
859 def enable_install_strip(strip, c_compiler):
860     if strip and c_compiler.type != "clang-cl":
861         return True
864 set_config("PKG_STRIP", enable_install_strip)
867 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
868 def strip(strip, install_strip):
869     return strip or install_strip
872 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
875 @depends("STRIP_FLAGS", profiling, target, when=strip)
876 def strip_flags(flags, profiling, target):
877     if flags:
878         return flags[0].split()
879     if profiling:
880         # Only strip debug info and symbols when profiling is enabled, keeping
881         # local symbols.
882         if target.kernel == "Darwin":
883             return ["-S"]
884         elif target.os == "Android":
885             # The tooling we use with Android supports detached symbols, and the
886             # size increase caused by local symbols are too much for mobile. So,
887             # don't restrict the amount of stripping with a flag.
888             return
889         else:
890             return ["--strip-debug"]
891     # Otherwise strip everything we can, which happens without flags on non-Darwin.
892     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
893     elif target.kernel == "Darwin":
894         return ["-x", "-S"]
897 set_config("STRIP_FLAGS", strip_flags)
900 @depends(js_standalone, target)
901 def system_zlib_default(js_standalone, target):
902     return js_standalone and target.kernel not in ("WINNT", "Darwin")
905 option(
906     "--with-system-zlib",
907     nargs="?",
908     default=system_zlib_default,
909     help="{Use|Do not use} system libz",
913 @depends("--with-system-zlib")
914 def deprecated_system_zlib_path(value):
915     if len(value) == 1:
916         die(
917             "--with-system-zlib=PATH is not supported anymore. Please use "
918             "--with-system-zlib and set any necessary pkg-config environment variable."
919         )
922 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
924 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
925 add_old_configure_assignment("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
928 # Please do not add configure checks from here on.
930 # Fallthrough to autoconf-based configure
931 include("build/moz.configure/old.configure")
933 # JS Subconfigure.
934 include("js/sub.configure", when=compile_environment & toolkit)
937 @depends(check_build_environment, build_project)
938 @imports("__sandbox__")
939 @imports("glob")
940 @imports(_from="os.path", _import="exists")
941 def config_status_deps(build_env, build_project):
943     topsrcdir = build_env.topsrcdir
944     topobjdir = build_env.topobjdir
946     if not topobjdir.endswith("js/src"):
947         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
948     else:
949         # mozconfig changes may impact js configure.
950         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
952     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
953     if exists(confvars):
954         extra_deps.append(confvars)
956     return (
957         list(__sandbox__._all_paths)
958         + extra_deps
959         + [
960             os.path.join(topsrcdir, "CLOBBER"),
961             os.path.join(topsrcdir, "configure.in"),
962             os.path.join(topsrcdir, "js", "src", "configure.in"),
963             os.path.join(topsrcdir, "nsprpub", "configure"),
964             os.path.join(topsrcdir, "config", "milestone.txt"),
965             os.path.join(topsrcdir, "browser", "config", "version.txt"),
966             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
967             os.path.join(topsrcdir, "build", "build_virtualenv_packages.txt"),
968             os.path.join(topsrcdir, "build", "common_virtualenv_packages.txt"),
969             os.path.join(topsrcdir, "build", "mach_virtualenv_packages.txt"),
970             os.path.join(topsrcdir, "python", "mach", "mach", "site.py"),
971             os.path.join(topsrcdir, "aclocal.m4"),
972             os.path.join(topsrcdir, "old-configure.in"),
973             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
974             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
975         ]
976         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
977     )
980 set_config("CONFIG_STATUS_DEPS", config_status_deps)
981 # Please do not add anything after setting config_dep_paths.