Bug 1747171 don't hold mutex while spinning nested event loop r=jesup
[gecko.git] / moz.configure
blob2f0187b4c597473e04952a3a934cbbad4ddb9ee7
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 js_shared = dependable(False)
335 moz_linker = dependable(False)
336 # Same for fold_libs
337 fold_libs = dependable(False)
339 include(include_project_configure)
342 @depends("--help")
343 @imports(_from="mozbuild.backend", _import="backends")
344 def build_backends_choices(_):
345     return tuple(backends)
348 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
349 def build_backend(backends):
350     if backends:
351         return tuple("+%s" % b for b in backends)
354 imply_option("--build-backends", build_backend)
357 @depends(
358     host,
359     target,
360     "--enable-artifact-builds",
361     "--disable-compile-environment",
362     "--enable-build-backend",
363     "--enable-project",
364     "--enable-application",
365     "--help",
367 @imports("sys")
368 def build_backend_defaults(
369     host,
370     target,
371     artifact_builds,
372     compile_environment,
373     requested_backends,
374     project,
375     application,
376     _,
378     if application:
379         project = application[0]
380     elif project:
381         project = project[0]
383     if "Tup" in requested_backends:
384         # As a special case, if Tup was requested, do not combine it with any
385         # Make based backend by default.
386         all_backends = []
387     elif artifact_builds:
388         all_backends = ["FasterMake+RecursiveMake"]
389     else:
390         all_backends = ["RecursiveMake", "FasterMake"]
391     if (
392         host.os == "WINNT"
393         and target.os == "WINNT"
394         and compile_environment
395         and project not in ("mobile/android", "memory", "tools/update-programs")
396     ):
397         all_backends.append("VisualStudio")
398     return tuple(all_backends) or None
401 option(
402     "--build-backends",
403     nargs="+",
404     default=build_backend_defaults,
405     choices=build_backends_choices,
406     help="Build backends to generate",
410 @depends("--build-backends")
411 def build_backends(backends):
412     return backends
415 set_config("BUILD_BACKENDS", build_backends)
418 @depends(build_environment, build_backends)
419 @imports("glob")
420 def check_objdir_backend_reuse(build_env, backends):
421     # "Make based" might be RecursiveMake or a hybrid backend, so "Make" is
422     # intentionally vague for use with the substring match below.
423     incompatible_backends = (("Tup", "Make"), ("Make", "Tup"))
424     for backend_file in glob.iglob(
425         os.path.join(build_env.topobjdir, "backend.*Backend")
426     ):
427         for prev, curr in incompatible_backends:
428             if prev in backend_file and any(curr in b for b in backends):
429                 die(
430                     "The active objdir, %s, was previously "
431                     "used to build with a %s based backend. "
432                     "Change objdirs (by setting MOZ_OBJDIR in "
433                     "your mozconfig) or clobber to continue.\n",
434                     build_env.topobjdir,
435                     prev,
436                 )
439 # Determine whether to build the gtest xul. This happens in automation
440 # on Android and Desktop platforms with the exception of:
441 #  - Windows PGO, where linking xul-gtest.dll takes too long;
442 #  - Android other than x86_64, where gtest is not required.
443 @depends(
444     build_project,
445     target,
446     "MOZ_AUTOMATION",
447     enable_tests,
448     when="--enable-compile-environment",
450 def build_gtest(build_project, target, automation, enable_tests):
451     return bool(
452         enable_tests
453         and automation
454         and build_project in ("browser", "comm/mail", "mobile/android")
455         and not (target.os == "Android" and target.cpu != "x86_64")
456     )
459 option(
460     "--enable-gtest-in-build",
461     default=build_gtest,
462     help="{Enable|Force disable} building the gtest libxul during the build.",
463     when="--enable-compile-environment",
466 set_config("LINK_GTEST_DURING_COMPILE", True, when="--enable-gtest-in-build")
468 # Localization
469 # ==============================================================
470 option(
471     "--enable-ui-locale",
472     default="en-US",
473     help="Select the user interface locale (default: en-US)",
476 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
478 option(
479     "--enable-icu4x",
480     help="An experiment to use ICU4X instead of ICU4C. See intl/ICU4X.md",
483 set_config("MOZ_ICU4X", True, when="--enable-icu4x")
485 # clang-plugin location
486 # ==============================================================
489 @depends(host_library_name_info, build_environment, when="--enable-clang-plugin")
490 def clang_plugin_path(library_name_info, build_env):
491     topobjdir = build_env.topobjdir
492     if topobjdir.endswith("/js/src"):
493         topobjdir = topobjdir[:-7]
494     return os.path.abspath(
495         os.path.join(
496             topobjdir,
497             "build",
498             "clang-plugin",
499             "%sclang-plugin%s"
500             % (library_name_info.dll.prefix, library_name_info.dll.suffix),
501         )
502     )
505 set_config("CLANG_PLUGIN", clang_plugin_path)
506 add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
509 # Awk detection
510 # ==============================================================
511 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"))
513 # Until the AWK variable is not necessary in old-configure
516 @depends(awk)
517 def awk_for_old_configure(value):
518     return value
521 add_old_configure_assignment("AWK", awk_for_old_configure)
524 # Perl detection
525 # ==============================================================
526 perl = check_prog("PERL", ("perl5", "perl"))
528 # Until the PERL variable is not necessary in old-configure
531 @depends(perl)
532 def perl_for_old_configure(value):
533     return value
536 add_old_configure_assignment("PERL", perl_for_old_configure)
539 @template
540 def perl_version_check(min_version):
541     @depends(perl)
542     @checking("for minimum required perl version >= %s" % min_version)
543     def get_perl_version(perl):
544         return Version(
545             check_cmd_output(
546                 perl,
547                 "-e",
548                 "print $]",
549                 onerror=lambda: die("Failed to get perl version."),
550             )
551         )
553     @depends(get_perl_version)
554     def check_perl_version(version):
555         if version < min_version:
556             die("Perl %s or higher is required.", min_version)
558     @depends(perl)
559     @checking("for full perl installation")
560     @imports("subprocess")
561     def has_full_perl_installation(perl):
562         ret = subprocess.call([perl, "-e", "use Config; exit(!-d $Config{archlib})"])
563         return ret == 0
565     @depends(has_full_perl_installation)
566     def require_full_perl_installation(has_full_perl_installation):
567         if not has_full_perl_installation:
568             die(
569                 "Cannot find Config.pm or $Config{archlib}. "
570                 "A full perl installation is required."
571             )
574 perl_version_check("5.006")
577 # GNU make detection
578 # ==============================================================
579 option(env="MAKE", nargs=1, help="Path to GNU make")
582 @depends("MAKE", host)
583 def possible_makes(make, host):
584     candidates = []
585     if host.kernel == "WINNT":
586         candidates.append("mingw32-make")
587     if make:
588         candidates.append(make[0])
589     if host.kernel == "WINNT":
590         candidates.extend(("mozmake", "make", "gmake"))
591     else:
592         candidates.extend(("gmake", "make"))
593     return candidates
596 check_prog("GMAKE", possible_makes, bootstrap="mozmake")
598 # watchman detection
599 # ==============================================================
601 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
604 @depends(host, "WATCHMAN")
605 @checking("for watchman", callback=lambda w: w.path if w else "not found")
606 def watchman(host, prog):
607     # On Windows, `watchman` is only supported on 64-bit hosts.
608     if host.os == "WINNT" and host.cpu != "x86_64":
609         return
611     if not prog:
612         prog = find_program("watchman")
614     if not prog:
615         return
617     # `watchman version` will talk to the Watchman daemon service.
618     # This can hang due to permissions problems. e.g.
619     # https://github.com/facebook/watchman/issues/376. So use
620     # `watchman --version` to prevent a class of failures.
621     out = check_cmd_output(prog, "--version", onerror=lambda: None)
622     if out is None:
623         return
625     return namespace(path=prog, version=Version(out.strip()))
628 @depends_if(watchman)
629 @checking("for watchman version")
630 def watchman_version(w):
631     return w.version
634 set_config("WATCHMAN", watchman.path)
637 @depends_all(hg_version, hg_config, watchman)
638 @checking("for watchman Mercurial integration")
639 @imports("os")
640 def watchman_hg(hg_version, hg_config, watchman):
641     if hg_version < Version("3.8"):
642         return "no (Mercurial 3.8+ required)"
644     ext_enabled = False
645     mode_disabled = False
647     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
648         if k in hg_config and hg_config[k] != "!":
649             ext_enabled = True
651     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
653     if not ext_enabled:
654         return "no (fsmonitor extension not enabled)"
655     if mode_disabled:
656         return "no (fsmonitor.mode=off disables fsmonitor)"
658     return True
661 # Miscellaneous programs
662 # ==============================================================
663 check_prog("XARGS", ("xargs",))
666 @depends(target)
667 def extra_programs(target):
668     if target.kernel == "Darwin":
669         return namespace(
670             DSYMUTIL=("dsymutil", "llvm-dsymutil"),
671             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
672             HFS_TOOL=("hfsplus",),
673         )
674     if target.os == "GNU" and target.kernel == "Linux":
675         return namespace(RPMBUILD=("rpmbuild",))
678 check_prog("DSYMUTIL", extra_programs.DSYMUTIL, allow_missing=True)
679 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
680 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
681 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
684 nsis = check_prog(
685     "MAKENSISU",
686     ("makensis",),
687     bootstrap="nsis/bin",
688     allow_missing=True,
689     when=target_is_windows,
692 # Make sure the version of makensis is up to date.
695 @depends_if(nsis)
696 @checking("for NSIS version")
697 @imports("re")
698 def nsis_version(nsis):
699     nsis_min_version = "3.0b1"
701     def onerror():
702         return die("Failed to get nsis version.")
704     out = check_cmd_output(nsis, "-version", onerror=onerror)
706     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
708     if not m:
709         raise FatalCheckError("Unknown version of makensis")
710     ver = Version(m.group(0))
712     # Versions comparisons don't quite work well with beta versions, so ensure
713     # it works for the non-beta version.
714     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
715         raise FatalCheckError(
716             "To build the installer you must have NSIS"
717             " version %s or greater in your path" % nsis_min_version
718         )
720     return ver
723 # And that makensis is 32-bit (but only on Windows).
724 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
725 @checking("for 32-bit NSIS")
726 def nsis_binary_type(nsis):
727     bin_type = windows_binary_type(nsis)
728     if bin_type != "win32":
729         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
731     return "yes"
734 # And any flags we have to give to makensis
735 @depends(host)
736 def nsis_flags(host):
737     if host.kernel != "WINNT":
738         return "-nocd"
739     return ""
742 set_config("MAKENSISU_FLAGS", nsis_flags)
744 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
745 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
748 @template
749 def llvm_tool(name):
750     @depends(host_c_compiler, c_compiler, bindgen_config_paths)
751     def llvm_tool(host_c_compiler, c_compiler, bindgen_config_paths):
752         clang = None
753         for compiler in (host_c_compiler, c_compiler):
754             if compiler and compiler.type == "clang":
755                 clang = compiler.compiler
756                 break
757             elif compiler and compiler.type == "clang-cl":
758                 clang = os.path.join(os.path.dirname(compiler.compiler), "clang")
759                 break
761         if not clang and bindgen_config_paths:
762             clang = bindgen_config_paths.clang_path
763         tool = name
764         if clang:
765             out = check_cmd_output(
766                 clang, "--print-prog-name=%s" % tool, onerror=lambda: None
767             )
768             if out:
769                 tool = out.rstrip()
770         return (tool,)
772     return llvm_tool
775 llvm_objdump = check_prog(
776     "LLVM_OBJDUMP",
777     llvm_tool("llvm-objdump"),
778     what="llvm-objdump",
779     when="--enable-compile-environment",
780     paths=clang_search_path,
783 add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)
786 @depends(llvm_tool("llvm-readelf"), toolchain_prefix)
787 def readelf(llvm_readelf, toolchain_prefix):
788     commands = [llvm_readelf[0], "readelf"]
789     for prefix in toolchain_prefix or ():
790         commands.insert(1, "%sreadelf" % prefix)
791     return tuple(commands)
794 def validate_readelf(path):
795     # llvm-readelf from llvm < 8 doesn't support the GNU binutils-compatible `-d`
796     # flag. We could try running `$path -d $some_binary` but we might be cross
797     # compiling and not have a binary at hand to run that against. `$path -d` alone
798     # would fail whether the flag is supported or not. So we resort to look for the
799     # option in the `--help` output, which fortunately, s compatible between
800     # llvm-readelf and readelf.
801     retcode, stdout, stderr = get_cmd_output(path, "--help")
802     return retcode == 0 and any(l.startswith("  -d ") for l in stdout.splitlines())
805 @depends("--enable-compile-environment", target, host)
806 def readelf_when(compile_env, target, host):
807     return compile_env and any(
808         x.kernel not in ("Darwin", "WINNT") for x in (target, host)
809     )
812 check_prog(
813     "READELF",
814     readelf,
815     what="readelf",
816     when=readelf_when,
817     paths=clang_search_path,
818     validate=validate_readelf,
821 option("--enable-dtrace", help="Build with dtrace support")
823 dtrace = check_header(
824     "sys/sdt.h",
825     when="--enable-dtrace",
826     onerror=lambda: die("dtrace enabled but sys/sdt.h not found"),
829 set_config("HAVE_DTRACE", True, when=dtrace)
830 set_define("INCLUDE_MOZILLA_DTRACE", True, when=dtrace)
831 add_old_configure_assignment("enable_dtrace", "yes", when=dtrace)
834 option("--disable-icf", help="Disable Identical Code Folding")
836 add_old_configure_assignment(
837     "MOZ_DISABLE_ICF", "1", when=depends("--enable-icf")(lambda x: not x)
841 option(
842     "--enable-strip",
843     when=compile_environment,
844     help="Enable stripping of libs & executables",
847 # This should be handled as a `when` once bug 1617793 is fixed.
850 @depends("--enable-strip", c_compiler, when=compile_environment)
851 def enable_strip(strip, c_compiler):
852     if strip and c_compiler.type != "clang-cl":
853         return True
856 set_config("ENABLE_STRIP", enable_strip)
858 option(
859     "--disable-install-strip",
860     when=compile_environment,
861     help="Enable stripping of libs & executables when packaging",
864 # This should be handled as a `when` once bug 1617793 is fixed.
867 @depends("--enable-install-strip", c_compiler, when=compile_environment)
868 def enable_install_strip(strip, c_compiler):
869     if strip and c_compiler.type != "clang-cl":
870         return True
873 set_config("PKG_STRIP", enable_install_strip)
876 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
877 def strip(strip, install_strip):
878     return strip or install_strip
881 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
884 @depends("STRIP_FLAGS", profiling, target, when=strip)
885 def strip_flags(flags, profiling, target):
886     if flags:
887         return flags[0].split()
888     if profiling:
889         # Only strip debug info and symbols when profiling is enabled, keeping
890         # local symbols.
891         if target.kernel == "Darwin":
892             return ["-S"]
893         elif target.os == "Android":
894             # The tooling we use with Android supports detached symbols, and the
895             # size increase caused by local symbols are too much for mobile. So,
896             # don't restrict the amount of stripping with a flag.
897             return
898         else:
899             return ["--strip-debug"]
900     # Otherwise strip everything we can, which happens without flags on non-Darwin.
901     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
902     elif target.kernel == "Darwin":
903         return ["-x", "-S"]
906 set_config("STRIP_FLAGS", strip_flags)
909 @depends(js_standalone, target)
910 def system_zlib_default(js_standalone, target):
911     return js_standalone and target.kernel not in ("WINNT", "Darwin")
914 option(
915     "--with-system-zlib",
916     nargs="?",
917     default=system_zlib_default,
918     help="{Use|Do not use} system libz",
922 @depends("--with-system-zlib")
923 def deprecated_system_zlib_path(value):
924     if len(value) == 1:
925         die(
926             "--with-system-zlib=PATH is not supported anymore. Please use "
927             "--with-system-zlib and set any necessary pkg-config environment variable."
928         )
931 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
933 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
936 @depends("--with-system-zlib", js_shared, moz_linker, target.os)
937 def zlib_in_mozglue(system_zlib, js_shared, linker, os):
938     if not system_zlib and (js_shared or linker or os == "Android"):
939         return True
942 set_config("ZLIB_IN_MOZGLUE", zlib_in_mozglue)
943 set_define("ZLIB_IN_MOZGLUE", zlib_in_mozglue)
946 # Please do not add configure checks from here on.
948 # Fallthrough to autoconf-based configure
949 include("build/moz.configure/old.configure")
951 # JS Subconfigure.
952 include("js/sub.configure", when=compile_environment & toolkit)
955 @depends(build_environment, build_project)
956 @imports("__sandbox__")
957 @imports("glob")
958 @imports(_from="os.path", _import="exists")
959 def config_status_deps(build_env, build_project):
961     topsrcdir = build_env.topsrcdir
962     topobjdir = build_env.topobjdir
964     if not topobjdir.endswith("js/src"):
965         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
966     else:
967         # mozconfig changes may impact js configure.
968         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
970     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
971     if exists(confvars):
972         extra_deps.append(confvars)
974     return (
975         list(__sandbox__._all_paths)
976         + extra_deps
977         + [
978             os.path.join(topsrcdir, "CLOBBER"),
979             os.path.join(topsrcdir, "configure.in"),
980             os.path.join(topsrcdir, "js", "src", "configure.in"),
981             os.path.join(topsrcdir, "nsprpub", "configure"),
982             os.path.join(topsrcdir, "config", "milestone.txt"),
983             os.path.join(topsrcdir, "browser", "config", "version.txt"),
984             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
985             os.path.join(topsrcdir, "build", "build_virtualenv_packages.txt"),
986             os.path.join(topsrcdir, "build", "common_virtualenv_packages.txt"),
987             os.path.join(topsrcdir, "build", "mach_virtualenv_packages.txt"),
988             os.path.join(topsrcdir, "python", "mach", "mach", "site.py"),
989             os.path.join(topsrcdir, "aclocal.m4"),
990             os.path.join(topsrcdir, "old-configure.in"),
991             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
992             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
993         ]
994         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
995     )
998 set_config("CONFIG_STATUS_DEPS", config_status_deps)
999 # Please do not add anything after setting config_dep_paths.