Bug 1679927 Part 1: Make AppleVTDecoder check color depth and use 10-bit YUV420 when...
[gecko.git] / moz.configure
blobe9488a6790af9f41841382aac2a5aea91a5613d5
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 set_config(
141     "MOZ_DIAGNOSTIC_ASSERT_ENABLED",
142     True,
143     when=moz_debug | milestone.is_early_beta_or_earlier,
145 set_define(
146     "MOZ_DIAGNOSTIC_ASSERT_ENABLED",
147     True,
148     when=moz_debug | milestone.is_early_beta_or_earlier,
151 option(
152     "--with-debug-label",
153     nargs="+",
154     help="Debug DEBUG_<value> for each comma-separated value given",
158 @depends(moz_debug, "--with-debug-label")
159 def debug_defines(debug, labels):
160     if debug:
161         return ["DEBUG"] + ["DEBUG_%s" % label for label in labels]
162     return ["NDEBUG", "TRIMMED"]
165 set_config("MOZ_DEBUG_DEFINES", debug_defines)
167 option(env="MOZ_PGO", help="Build with profile guided optimizations")
169 set_config("MOZ_PGO", depends("MOZ_PGO")(lambda x: bool(x)))
172 imply_option("--enable-release", mozilla_official)
173 imply_option("--enable-release", depends_if("MOZ_AUTOMATION")(lambda x: True))
175 option(
176     "--enable-release",
177     default=milestone.is_release_or_beta,
178     help="{Build|Do not build} with more conservative, release "
179     "engineering-oriented options.{ This may slow down builds.|}",
183 @depends("--enable-release")
184 def developer_options(value):
185     if not value:
186         return True
189 add_old_configure_assignment("DEVELOPER_OPTIONS", developer_options)
190 set_config("DEVELOPER_OPTIONS", developer_options)
193 # hybrid build handling
194 # ==============================================================
196 option(
197     "--disable-unified-build",
198     help="Enable building modules that are not marked with `REQUIRES_UNIFIED_BUILD` in non unified context",
201 set_config("ENABLE_UNIFIED_BUILD", True, when="--disable-unified-build")
204 include("build/moz.configure/bootstrap.configure")
206 # The execution model of the configure sandbox doesn't allow for
207 # check_prog to use bootstrap_search_path directly because check_prog
208 # comes first, so we use a trick to allow it. Uses of check_prog
209 # happening before here won't allow bootstrap.
210 @template
211 def check_prog(*args, **kwargs):
212     kwargs["bootstrap_search_path"] = bootstrap_search_path
213     return check_prog(*args, **kwargs)
216 check_prog("WGET", ("wget",), allow_missing=True)
219 include("build/moz.configure/toolchain.configure", when="--enable-compile-environment")
221 include("build/moz.configure/pkg.configure")
222 # Make this assignment here rather than in pkg.configure to avoid
223 # requiring this file in unit tests.
224 add_old_configure_assignment("PKG_CONFIG", pkg_config)
226 include("build/moz.configure/memory.configure", when="--enable-compile-environment")
227 include("build/moz.configure/headers.configure", when="--enable-compile-environment")
228 include("build/moz.configure/warnings.configure", when="--enable-compile-environment")
229 include("build/moz.configure/flags.configure", when="--enable-compile-environment")
230 include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment")
231 # rust.configure is included by js/moz.configure.
233 option("--enable-valgrind", help="Enable Valgrind integration hooks")
235 valgrind_h = check_header("valgrind/valgrind.h", when="--enable-valgrind")
238 @depends("--enable-valgrind", valgrind_h)
239 def check_valgrind(valgrind, valgrind_h):
240     if valgrind:
241         if not valgrind_h:
242             die("--enable-valgrind specified but Valgrind is not installed")
243         return True
246 set_define("MOZ_VALGRIND", check_valgrind)
247 set_config("MOZ_VALGRIND", check_valgrind)
250 @depends(target, host)
251 def is_openbsd(target, host):
252     return target.kernel == "OpenBSD" or host.kernel == "OpenBSD"
255 option(
256     env="SO_VERSION",
257     nargs=1,
258     default="1.0",
259     when=is_openbsd,
260     help="Shared library version for OpenBSD systems",
264 @depends("SO_VERSION", when=is_openbsd)
265 def so_version(value):
266     return value
269 @template
270 def library_name_info_template(host_or_target):
271     assert host_or_target in {host, target}
272     compiler = {
273         host: host_c_compiler,
274         target: c_compiler,
275     }[host_or_target]
277     @depends(host_or_target, compiler, so_version)
278     def library_name_info_impl(host_or_target, compiler, so_version):
279         if host_or_target.kernel == "WINNT":
280             # There aren't artifacts for mingw builds, so it's OK that the
281             # results are inaccurate in that case.
282             if compiler and compiler.type != "clang-cl":
283                 return namespace(
284                     dll=namespace(prefix="", suffix=".dll"),
285                     lib=namespace(prefix="lib", suffix="a"),
286                     import_lib=namespace(prefix="lib", suffix="a"),
287                     obj=namespace(prefix="", suffix="o"),
288                 )
290             return namespace(
291                 dll=namespace(prefix="", suffix=".dll"),
292                 lib=namespace(prefix="", suffix="lib"),
293                 import_lib=namespace(prefix="", suffix="lib"),
294                 obj=namespace(prefix="", suffix="obj"),
295             )
297         elif host_or_target.kernel == "Darwin":
298             return namespace(
299                 dll=namespace(prefix="lib", suffix=".dylib"),
300                 lib=namespace(prefix="lib", suffix="a"),
301                 import_lib=namespace(prefix=None, suffix=""),
302                 obj=namespace(prefix="", suffix="o"),
303             )
304         elif so_version:
305             so = ".so.%s" % so_version
306         else:
307             so = ".so"
309         return namespace(
310             dll=namespace(prefix="lib", suffix=so),
311             lib=namespace(prefix="lib", suffix="a"),
312             import_lib=namespace(prefix=None, suffix=""),
313             obj=namespace(prefix="", suffix="o"),
314         )
316     return library_name_info_impl
319 host_library_name_info = library_name_info_template(host)
320 library_name_info = library_name_info_template(target)
322 set_config("DLL_PREFIX", library_name_info.dll.prefix)
323 set_config("DLL_SUFFIX", library_name_info.dll.suffix)
324 set_config("HOST_DLL_PREFIX", host_library_name_info.dll.prefix)
325 set_config("HOST_DLL_SUFFIX", host_library_name_info.dll.suffix)
326 set_config("LIB_PREFIX", library_name_info.lib.prefix)
327 set_config("LIB_SUFFIX", library_name_info.lib.suffix)
328 set_config("OBJ_SUFFIX", library_name_info.obj.suffix)
329 # Lots of compilation tests depend on this variable being present.
330 add_old_configure_assignment("OBJ_SUFFIX", library_name_info.obj.suffix)
331 set_config("IMPORT_LIB_SUFFIX", library_name_info.import_lib.suffix)
332 set_define(
333     "MOZ_DLL_PREFIX", depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s)
335 set_define(
336     "MOZ_DLL_SUFFIX", depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s)
338 set_config("HOST_LIB_PREFIX", host_library_name_info.lib.prefix)
339 set_config("HOST_IMPORT_LIB_SUFFIX", host_library_name_info.import_lib.suffix)
340 set_config("WASM_OBJ_SUFFIX", "wasm")
342 # Make `profiling` available to this file even when js/moz.configure
343 # doesn't end up included.
344 profiling = dependable(False)
345 # Same for js_standalone
346 js_standalone = dependable(False)
347 js_shared = dependable(False)
348 moz_linker = dependable(False)
349 # Same for fold_libs
350 fold_libs = dependable(False)
352 include(include_project_configure)
355 @depends("--help")
356 @imports(_from="mozbuild.backend", _import="backends")
357 def build_backends_choices(_):
358     return tuple(backends)
361 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
362 def build_backend(backends):
363     if backends:
364         return tuple("+%s" % b for b in backends)
367 imply_option("--build-backends", build_backend)
370 @depends(
371     host,
372     target,
373     "--enable-artifact-builds",
374     "--disable-compile-environment",
375     "--enable-build-backend",
376     "--enable-project",
377     "--enable-application",
378     "--help",
380 @imports("sys")
381 def build_backend_defaults(
382     host,
383     target,
384     artifact_builds,
385     compile_environment,
386     requested_backends,
387     project,
388     application,
389     _,
391     if application:
392         project = application[0]
393     elif project:
394         project = project[0]
396     if "Tup" in requested_backends:
397         # As a special case, if Tup was requested, do not combine it with any
398         # Make based backend by default.
399         all_backends = []
400     elif artifact_builds:
401         all_backends = ["FasterMake+RecursiveMake"]
402     else:
403         all_backends = ["RecursiveMake", "FasterMake"]
404     if (
405         host.os == "WINNT"
406         and target.os == "WINNT"
407         and compile_environment
408         and project not in ("mobile/android", "memory", "tools/update-programs")
409     ):
410         all_backends.append("VisualStudio")
411     return tuple(all_backends) or None
414 option(
415     "--build-backends",
416     nargs="+",
417     default=build_backend_defaults,
418     choices=build_backends_choices,
419     help="Build backends to generate",
423 @depends("--build-backends")
424 def build_backends(backends):
425     return backends
428 set_config("BUILD_BACKENDS", build_backends)
431 @depends(build_environment, build_backends)
432 @imports("glob")
433 def check_objdir_backend_reuse(build_env, backends):
434     # "Make based" might be RecursiveMake or a hybrid backend, so "Make" is
435     # intentionally vague for use with the substring match below.
436     incompatible_backends = (("Tup", "Make"), ("Make", "Tup"))
437     for backend_file in glob.iglob(
438         os.path.join(build_env.topobjdir, "backend.*Backend")
439     ):
440         for prev, curr in incompatible_backends:
441             if prev in backend_file and any(curr in b for b in backends):
442                 die(
443                     "The active objdir, %s, was previously "
444                     "used to build with a %s based backend. "
445                     "Change objdirs (by setting MOZ_OBJDIR in "
446                     "your mozconfig) or clobber to continue.\n",
447                     build_env.topobjdir,
448                     prev,
449                 )
452 # Determine whether to build the gtest xul. This happens in automation
453 # on Android and Desktop platforms with the exception of:
454 #  - Windows PGO, where linking xul-gtest.dll takes too long;
455 #  - Android other than x86_64, where gtest is not required.
456 @depends(
457     build_project,
458     target,
459     "MOZ_AUTOMATION",
460     enable_tests,
461     when="--enable-compile-environment",
463 def build_gtest(build_project, target, automation, enable_tests):
464     return bool(
465         enable_tests
466         and automation
467         and build_project in ("browser", "comm/mail", "mobile/android")
468         and not (target.os == "Android" and target.cpu != "x86_64")
469     )
472 option(
473     "--enable-gtest-in-build",
474     default=build_gtest,
475     help="{Enable|Force disable} building the gtest libxul during the build.",
476     when="--enable-compile-environment",
479 set_config("LINK_GTEST_DURING_COMPILE", True, when="--enable-gtest-in-build")
481 # Localization
482 # ==============================================================
483 option(
484     "--enable-ui-locale",
485     default="en-US",
486     help="Select the user interface locale (default: en-US)",
489 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
491 option(
492     "--enable-icu4x",
493     help="An experiment to use ICU4X instead of ICU4C. See intl/ICU4X.md",
496 set_config("MOZ_ICU4X", True, when="--enable-icu4x")
498 # clang-plugin location
499 # ==============================================================
502 @depends(host_library_name_info, build_environment, when="--enable-clang-plugin")
503 def clang_plugin_path(library_name_info, build_env):
504     topobjdir = build_env.topobjdir
505     if topobjdir.endswith("/js/src"):
506         topobjdir = topobjdir[:-7]
507     return os.path.abspath(
508         os.path.join(
509             topobjdir,
510             "build",
511             "clang-plugin",
512             "%sclang-plugin%s"
513             % (library_name_info.dll.prefix, library_name_info.dll.suffix),
514         )
515     )
518 set_config("CLANG_PLUGIN", clang_plugin_path)
519 add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
522 # Awk detection
523 # ==============================================================
524 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"))
526 # Until the AWK variable is not necessary in old-configure
529 @depends(awk)
530 def awk_for_old_configure(value):
531     return value
534 add_old_configure_assignment("AWK", awk_for_old_configure)
537 # Perl detection
538 # ==============================================================
539 perl = check_prog("PERL", ("perl5", "perl"))
541 # Until the PERL variable is not necessary in old-configure
544 @depends(perl)
545 def perl_for_old_configure(value):
546     return value
549 add_old_configure_assignment("PERL", perl_for_old_configure)
552 @template
553 def perl_version_check(min_version):
554     @depends(perl)
555     @checking("for minimum required perl version >= %s" % min_version)
556     def get_perl_version(perl):
557         return Version(
558             check_cmd_output(
559                 perl,
560                 "-e",
561                 "print $]",
562                 onerror=lambda: die("Failed to get perl version."),
563             )
564         )
566     @depends(get_perl_version)
567     def check_perl_version(version):
568         if version < min_version:
569             die("Perl %s or higher is required.", min_version)
571     @depends(perl)
572     @checking("for full perl installation")
573     @imports("subprocess")
574     def has_full_perl_installation(perl):
575         ret = subprocess.call([perl, "-e", "use Config; exit(!-d $Config{archlib})"])
576         return ret == 0
578     @depends(has_full_perl_installation)
579     def require_full_perl_installation(has_full_perl_installation):
580         if not has_full_perl_installation:
581             die(
582                 "Cannot find Config.pm or $Config{archlib}. "
583                 "A full perl installation is required."
584             )
587 perl_version_check("5.006")
590 # GNU make detection
591 # ==============================================================
592 option(env="MAKE", nargs=1, help="Path to GNU make")
595 @depends("MAKE", host)
596 def possible_makes(make, host):
597     candidates = []
598     if host.kernel == "WINNT":
599         candidates.append("mingw32-make")
600     if make:
601         candidates.append(make[0])
602     if host.kernel == "WINNT":
603         candidates.extend(("mozmake", "make", "gmake"))
604     else:
605         candidates.extend(("gmake", "make"))
606     return candidates
609 check_prog("GMAKE", possible_makes, bootstrap="mozmake")
611 # watchman detection
612 # ==============================================================
614 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
617 @depends(host, "WATCHMAN")
618 @checking("for watchman", callback=lambda w: w.path if w else "not found")
619 def watchman(host, prog):
620     # On Windows, `watchman` is only supported on 64-bit hosts.
621     if host.os == "WINNT" and host.cpu != "x86_64":
622         return
624     if not prog:
625         prog = find_program("watchman")
627     if not prog:
628         return
630     # `watchman version` will talk to the Watchman daemon service.
631     # This can hang due to permissions problems. e.g.
632     # https://github.com/facebook/watchman/issues/376. So use
633     # `watchman --version` to prevent a class of failures.
634     out = check_cmd_output(prog, "--version", onerror=lambda: None)
635     if out is None:
636         return
638     return namespace(path=prog, version=Version(out.strip()))
641 @depends_if(watchman)
642 @checking("for watchman version")
643 def watchman_version(w):
644     return w.version
647 set_config("WATCHMAN", watchman.path)
650 @depends_all(hg_version, hg_config, watchman)
651 @checking("for watchman Mercurial integration")
652 @imports("os")
653 def watchman_hg(hg_version, hg_config, watchman):
654     if hg_version < Version("3.8"):
655         return "no (Mercurial 3.8+ required)"
657     ext_enabled = False
658     mode_disabled = False
660     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
661         if k in hg_config and hg_config[k] != "!":
662             ext_enabled = True
664     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
666     if not ext_enabled:
667         return "no (fsmonitor extension not enabled)"
668     if mode_disabled:
669         return "no (fsmonitor.mode=off disables fsmonitor)"
671     return True
674 # Miscellaneous programs
675 # ==============================================================
676 check_prog("XARGS", ("xargs",))
679 @depends(target)
680 def extra_programs(target):
681     if target.kernel == "Darwin":
682         return namespace(
683             DSYMUTIL=("dsymutil", "llvm-dsymutil"),
684             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
685             HFS_TOOL=("hfsplus",),
686         )
687     if target.os == "GNU" and target.kernel == "Linux":
688         return namespace(RPMBUILD=("rpmbuild",))
691 check_prog("DSYMUTIL", extra_programs.DSYMUTIL, allow_missing=True)
692 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
693 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
694 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
697 nsis = check_prog(
698     "MAKENSISU",
699     ("makensis",),
700     bootstrap="nsis/bin",
701     allow_missing=True,
702     when=target_is_windows,
705 # Make sure the version of makensis is up to date.
708 @depends_if(nsis)
709 @checking("for NSIS version")
710 @imports("re")
711 def nsis_version(nsis):
712     nsis_min_version = "3.0b1"
714     def onerror():
715         return die("Failed to get nsis version.")
717     out = check_cmd_output(nsis, "-version", onerror=onerror)
719     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
721     if not m:
722         raise FatalCheckError("Unknown version of makensis")
723     ver = Version(m.group(0))
725     # Versions comparisons don't quite work well with beta versions, so ensure
726     # it works for the non-beta version.
727     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
728         raise FatalCheckError(
729             "To build the installer you must have NSIS"
730             " version %s or greater in your path" % nsis_min_version
731         )
733     return ver
736 # And that makensis is 32-bit (but only on Windows).
737 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
738 @checking("for 32-bit NSIS")
739 def nsis_binary_type(nsis):
740     bin_type = windows_binary_type(nsis)
741     if bin_type != "win32":
742         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
744     return "yes"
747 # And any flags we have to give to makensis
748 @depends(host)
749 def nsis_flags(host):
750     if host.kernel != "WINNT":
751         return "-nocd"
752     return ""
755 set_config("MAKENSISU_FLAGS", nsis_flags)
757 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
758 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
761 @template
762 def llvm_tool(name):
763     @depends(host_c_compiler, c_compiler, bindgen_config_paths)
764     def llvm_tool(host_c_compiler, c_compiler, bindgen_config_paths):
765         clang = None
766         for compiler in (host_c_compiler, c_compiler):
767             if compiler and compiler.type == "clang":
768                 clang = compiler.compiler
769                 break
770             elif compiler and compiler.type == "clang-cl":
771                 clang = os.path.join(os.path.dirname(compiler.compiler), "clang")
772                 break
774         if not clang and bindgen_config_paths:
775             clang = bindgen_config_paths.clang_path
776         tool = name
777         if clang:
778             out = check_cmd_output(
779                 clang, "--print-prog-name=%s" % tool, onerror=lambda: None
780             )
781             if out:
782                 tool = out.rstrip()
783         return (tool,)
785     return llvm_tool
788 llvm_objdump = check_prog(
789     "LLVM_OBJDUMP",
790     llvm_tool("llvm-objdump"),
791     what="llvm-objdump",
792     when="--enable-compile-environment",
793     paths=clang_search_path,
796 add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)
799 @depends(llvm_tool("llvm-readelf"), toolchain_prefix)
800 def readelf(llvm_readelf, toolchain_prefix):
801     commands = [llvm_readelf[0], "readelf"]
802     for prefix in toolchain_prefix or ():
803         commands.insert(1, "%sreadelf" % prefix)
804     return tuple(commands)
807 def validate_readelf(path):
808     # llvm-readelf from llvm < 8 doesn't support the GNU binutils-compatible `-d`
809     # flag. We could try running `$path -d $some_binary` but we might be cross
810     # compiling and not have a binary at hand to run that against. `$path -d` alone
811     # would fail whether the flag is supported or not. So we resort to look for the
812     # option in the `--help` output, which fortunately, s compatible between
813     # llvm-readelf and readelf.
814     retcode, stdout, stderr = get_cmd_output(path, "--help")
815     return retcode == 0 and any(l.startswith("  -d ") for l in stdout.splitlines())
818 @depends("--enable-compile-environment", target, host)
819 def readelf_when(compile_env, target, host):
820     return compile_env and any(
821         x.kernel not in ("Darwin", "WINNT") for x in (target, host)
822     )
825 check_prog(
826     "READELF",
827     readelf,
828     what="readelf",
829     when=readelf_when,
830     paths=clang_search_path,
831     validate=validate_readelf,
834 option("--enable-dtrace", help="Build with dtrace support")
836 dtrace = check_header(
837     "sys/sdt.h",
838     when="--enable-dtrace",
839     onerror=lambda: die("dtrace enabled but sys/sdt.h not found"),
842 set_config("HAVE_DTRACE", True, when=dtrace)
843 set_define("INCLUDE_MOZILLA_DTRACE", True, when=dtrace)
844 add_old_configure_assignment("enable_dtrace", "yes", when=dtrace)
847 option("--disable-icf", help="Disable Identical Code Folding")
849 add_old_configure_assignment(
850     "MOZ_DISABLE_ICF", "1", when=depends("--enable-icf")(lambda x: not x)
854 option(
855     "--enable-strip",
856     when=compile_environment,
857     help="Enable stripping of libs & executables",
860 # This should be handled as a `when` once bug 1617793 is fixed.
863 @depends("--enable-strip", c_compiler, when=compile_environment)
864 def enable_strip(strip, c_compiler):
865     if strip and c_compiler.type != "clang-cl":
866         return True
869 set_config("ENABLE_STRIP", enable_strip)
871 option(
872     "--disable-install-strip",
873     when=compile_environment,
874     help="Enable stripping of libs & executables when packaging",
877 # This should be handled as a `when` once bug 1617793 is fixed.
880 @depends("--enable-install-strip", c_compiler, when=compile_environment)
881 def enable_install_strip(strip, c_compiler):
882     if strip and c_compiler.type != "clang-cl":
883         return True
886 set_config("PKG_STRIP", enable_install_strip)
889 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
890 def strip(strip, install_strip):
891     return strip or install_strip
894 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
897 @depends("STRIP_FLAGS", profiling, target, when=strip)
898 def strip_flags(flags, profiling, target):
899     if flags:
900         return flags[0].split()
901     if profiling:
902         # Only strip debug info and symbols when profiling is enabled, keeping
903         # local symbols.
904         if target.kernel == "Darwin":
905             return ["-S"]
906         elif target.os == "Android":
907             # The tooling we use with Android supports detached symbols, and the
908             # size increase caused by local symbols are too much for mobile. So,
909             # don't restrict the amount of stripping with a flag.
910             return
911         else:
912             return ["--strip-debug"]
913     # Otherwise strip everything we can, which happens without flags on non-Darwin.
914     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
915     elif target.kernel == "Darwin":
916         return ["-x", "-S"]
919 set_config("STRIP_FLAGS", strip_flags)
922 @depends(js_standalone, target)
923 def system_zlib_default(js_standalone, target):
924     return js_standalone and target.kernel not in ("WINNT", "Darwin")
927 option(
928     "--with-system-zlib",
929     nargs="?",
930     default=system_zlib_default,
931     help="{Use|Do not use} system libz",
935 @depends("--with-system-zlib")
936 def deprecated_system_zlib_path(value):
937     if len(value) == 1:
938         die(
939             "--with-system-zlib=PATH is not supported anymore. Please use "
940             "--with-system-zlib and set any necessary pkg-config environment variable."
941         )
944 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
946 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
949 @depends("--with-system-zlib", js_shared, moz_linker, target.os)
950 def zlib_in_mozglue(system_zlib, js_shared, linker, os):
951     if not system_zlib and (js_shared or linker or os == "Android"):
952         return True
955 set_config("ZLIB_IN_MOZGLUE", zlib_in_mozglue)
956 set_define("ZLIB_IN_MOZGLUE", zlib_in_mozglue)
959 # Please do not add configure checks from here on.
961 # Fallthrough to autoconf-based configure
962 include("build/moz.configure/old.configure")
964 # JS Subconfigure.
965 include("js/sub.configure", when=compile_environment & toolkit)
968 @depends(build_environment, build_project)
969 @imports("__sandbox__")
970 @imports("glob")
971 @imports(_from="os.path", _import="exists")
972 def config_status_deps(build_env, build_project):
974     topsrcdir = build_env.topsrcdir
975     topobjdir = build_env.topobjdir
977     if not topobjdir.endswith("js/src"):
978         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
979     else:
980         # mozconfig changes may impact js configure.
981         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
983     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
984     if exists(confvars):
985         extra_deps.append(confvars)
987     return (
988         list(__sandbox__._all_paths)
989         + extra_deps
990         + [
991             os.path.join(topsrcdir, "CLOBBER"),
992             os.path.join(topsrcdir, "configure.in"),
993             os.path.join(topsrcdir, "js", "src", "configure.in"),
994             os.path.join(topsrcdir, "nsprpub", "configure"),
995             os.path.join(topsrcdir, "config", "milestone.txt"),
996             os.path.join(topsrcdir, "browser", "config", "version.txt"),
997             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
998             os.path.join(topsrcdir, "build", "build_virtualenv_packages.txt"),
999             os.path.join(topsrcdir, "build", "common_virtualenv_packages.txt"),
1000             os.path.join(topsrcdir, "build", "mach_virtualenv_packages.txt"),
1001             os.path.join(topsrcdir, "python", "mach", "mach", "site.py"),
1002             os.path.join(topsrcdir, "aclocal.m4"),
1003             os.path.join(topsrcdir, "old-configure.in"),
1004             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
1005             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
1006         ]
1007         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
1008     )
1011 set_config("CONFIG_STATUS_DEPS", config_status_deps)
1012 # Please do not add anything after setting config_dep_paths.