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')
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.
17 option('--enable-artifact-builds', env='MOZ_ARTIFACT_BUILDS',
18 help='Download and use prebuilt binary artifacts.')
20 @depends('--enable-artifact-builds')
21 def artifact_builds(value):
25 set_config('MOZ_ARTIFACT_BUILDS', artifact_builds)
27 imply_option('--enable-artifact-build-symbols',
28 depends(artifact_builds)(lambda v: False if v is None else None),
29 reason='--disable-artifact-builds')
31 option('--enable-artifact-build-symbols', nargs='?', choices=('full',),
32 help='Download symbols when artifact builds are enabled.')
34 @depends('--enable-artifact-build-symbols', 'MOZ_AUTOMATION', target)
35 def enable_artifact_build_symbols(value, automation, target):
39 if target.os == 'Android' and not automation:
44 set_config('MOZ_ARTIFACT_BUILD_SYMBOLS',
45 enable_artifact_build_symbols)
47 @depends('--enable-artifact-builds')
48 def imply_disable_compile_environment(value):
52 option(env='MOZ_COPY_PDBS',
53 help='For builds that do not support symbols in the normal fashion,'
54 ' generate and copy them into the resulting build archive.')
56 set_config('MOZ_COPY_PDBS', depends_if('MOZ_COPY_PDBS')(lambda _: True))
58 imply_option('--enable-compile-environment', imply_disable_compile_environment)
60 option('--disable-compile-environment',
61 help='Disable compiler/library checks')
63 @depends('--disable-compile-environment')
64 def compile_environment(compile_env):
68 set_config('COMPILE_ENVIRONMENT', compile_environment)
69 add_old_configure_assignment('COMPILE_ENVIRONMENT', compile_environment)
71 js_option('--disable-tests',
72 help='Do not build test libraries & programs')
74 @depends('--disable-tests')
75 def enable_tests(value):
79 set_config('ENABLE_TESTS', enable_tests)
80 set_define('ENABLE_TESTS', enable_tests)
82 @depends(enable_tests)
83 def gtest_has_rtti(value):
87 set_define('GTEST_HAS_RTTI', gtest_has_rtti)
89 @depends(target, enable_tests)
90 def linux_gtest_defines(target, enable_tests):
91 if enable_tests and target.os == 'Android':
92 return namespace(os_linux_android=True,
93 use_own_tr1_tuple=True,
96 set_define('GTEST_OS_LINUX_ANDROID',
97 linux_gtest_defines.os_linux_android)
98 set_define('GTEST_USE_OWN_TR1_TUPLE',
99 linux_gtest_defines.use_own_tr1_tuple)
100 set_define('GTEST_HAS_CLONE',
101 linux_gtest_defines.has_clone)
103 js_option('--enable-debug',
105 help='Enable building with developer debug info '
106 '(using the given compiler flags).')
108 @depends('--enable-debug')
109 def moz_debug(debug):
113 set_config('MOZ_DEBUG', moz_debug)
114 set_define('MOZ_DEBUG', moz_debug)
115 # Override any value MOZ_DEBUG may have from the environment when passing it
116 # down to old-configure.
117 add_old_configure_assignment('MOZ_DEBUG',
118 depends('--enable-debug')(lambda x: bool(x)))
120 js_option('--enable-rust-debug',
121 default=depends(when='--enable-debug')(lambda: True),
122 help='{Build|Do not build} Rust code with debug assertions turned '
125 @depends(when='--enable-rust-debug')
129 set_config('MOZ_DEBUG_RUST', debug_rust)
130 set_define('MOZ_DEBUG_RUST', debug_rust)
132 js_option(env='MOZ_PGO', help='Build with profile guided optimizations')
134 set_config('MOZ_PGO', depends('MOZ_PGO')(lambda x: bool(x)))
136 include('build/moz.configure/toolchain.configure',
137 when='--enable-compile-environment')
139 include('build/moz.configure/pkg.configure')
140 # Make this assignment here rather than in pkg.configure to avoid
141 # requiring this file in unit tests.
142 add_old_configure_assignment('PKG_CONFIG', pkg_config)
144 include('build/moz.configure/memory.configure',
145 when='--enable-compile-environment')
146 include('build/moz.configure/headers.configure',
147 when='--enable-compile-environment')
148 include('build/moz.configure/warnings.configure',
149 when='--enable-compile-environment')
150 include('build/moz.configure/flags.configure',
151 when='--enable-compile-environment')
152 # rust.configure is included by js/moz.configure.
154 js_option('--enable-valgrind',
155 help='Enable Valgrind integration hooks')
157 valgrind_h = check_header('valgrind/valgrind.h', when='--enable-valgrind')
159 @depends('--enable-valgrind', valgrind_h)
160 def check_valgrind(valgrind, valgrind_h):
163 die('--enable-valgrind specified but Valgrind is not installed')
166 set_define('MOZ_VALGRIND', check_valgrind)
167 set_config('MOZ_VALGRIND', check_valgrind)
169 @depends(target, host)
170 def is_openbsd(target, host):
171 return target.kernel == 'OpenBSD' or host.kernel == 'OpenBSD'
173 option(env='SO_VERSION', nargs=1, default='1.0', when=is_openbsd,
174 help='Shared library version for OpenBSD systems')
176 @depends('SO_VERSION', when=is_openbsd)
177 def so_version(value):
181 def library_name_info_template(host_or_target):
182 assert host_or_target in {host, target}
184 host: host_c_compiler,
188 @depends(host_or_target, compiler, so_version)
189 def library_name_info_impl(host_or_target, compiler, so_version):
190 if host_or_target.kernel == 'WINNT':
191 # There aren't artifacts for mingw builds, so it's OK that the
192 # results are inaccurate in that case.
193 if compiler and compiler.type != 'clang-cl':
195 dll=namespace(prefix='', suffix='.dll'),
196 lib=namespace(prefix='lib', suffix='a'),
197 import_lib=namespace(prefix='lib', suffix='a'),
198 rust_lib=namespace(prefix='', suffix='lib'),
199 obj=namespace(prefix='', suffix='o'),
203 dll=namespace(prefix='', suffix='.dll'),
204 lib=namespace(prefix='', suffix='lib'),
205 import_lib=namespace(prefix='', suffix='lib'),
206 rust_lib=namespace(prefix='', suffix='lib'),
207 obj=namespace(prefix='', suffix='obj'),
210 elif host_or_target.kernel == 'Darwin':
212 dll=namespace(prefix='lib', suffix='.dylib'),
213 lib=namespace(prefix='lib', suffix='a'),
214 import_lib=namespace(prefix=None, suffix=''),
215 rust_lib=namespace(prefix='lib', suffix='a'),
216 obj=namespace(prefix='', suffix='o'),
219 so = '.so.%s' % so_version
224 dll=namespace(prefix='lib', suffix=so),
225 lib=namespace(prefix='lib', suffix='a'),
226 import_lib=namespace(prefix=None, suffix=''),
227 rust_lib=namespace(prefix='lib', suffix='a'),
228 obj=namespace(prefix='', suffix='o'),
231 return library_name_info_impl
233 host_library_name_info = library_name_info_template(host)
234 library_name_info = library_name_info_template(target)
236 set_config('DLL_PREFIX', library_name_info.dll.prefix)
237 set_config('DLL_SUFFIX', library_name_info.dll.suffix)
238 set_config('HOST_DLL_PREFIX', host_library_name_info.dll.prefix)
239 set_config('HOST_DLL_SUFFIX', host_library_name_info.dll.suffix)
240 set_config('LIB_PREFIX', library_name_info.lib.prefix)
241 set_config('LIB_SUFFIX', library_name_info.lib.suffix)
242 set_config('RUST_LIB_PREFIX', library_name_info.rust_lib.prefix)
243 set_config('RUST_LIB_SUFFIX', library_name_info.rust_lib.suffix)
244 set_config('OBJ_SUFFIX', library_name_info.obj.suffix)
245 # Lots of compilation tests depend on this variable being present.
246 add_old_configure_assignment('OBJ_SUFFIX', library_name_info.obj.suffix)
247 set_config('IMPORT_LIB_SUFFIX', library_name_info.import_lib.suffix)
248 set_define('MOZ_DLL_PREFIX', depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s))
249 set_define('MOZ_DLL_SUFFIX', depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s))
251 include(include_project_configure)
254 @imports(_from='mozbuild.backend', _import='backends')
255 def build_backends_choices(_):
256 return tuple(backends)
259 @deprecated_option('--enable-build-backend', nargs='+',
260 choices=build_backends_choices)
261 def build_backend(backends):
263 return tuple('+%s' % b for b in backends)
265 imply_option('--build-backends', build_backend)
268 @depends('--enable-artifact-builds', '--disable-compile-environment',
269 '--enable-build-backend', '--help')
271 def build_backend_defaults(artifact_builds, compile_environment, requested_backends,
273 if 'Tup' in requested_backends:
274 # As a special case, if Tup was requested, do not combine it with any
275 # Make based backend by default.
277 elif artifact_builds:
278 all_backends = ['FasterMake+RecursiveMake']
280 all_backends = ['RecursiveMake', 'FasterMake']
281 # Normally, we'd use target.os == 'WINNT', but a dependency on target
282 # would require target to depend on --help, as well as host and shell,
283 # and this is not a can of worms we can open at the moment.
284 if sys.platform == 'win32' and compile_environment:
285 all_backends.append('VisualStudio')
286 return tuple(all_backends) or None
288 option('--build-backends', nargs='+', default=build_backend_defaults,
289 choices=build_backends_choices, help='Build backends to generate')
291 @depends('--build-backends')
292 def build_backends(backends):
295 set_config('BUILD_BACKENDS', build_backends)
298 @depends(check_build_environment, build_backends)
300 def check_objdir_backend_reuse(build_env, backends):
301 # "Make based" might be RecursiveMake or a hybrid backend, so "Make" is
302 # intentionally vague for use with the substring match below.
303 incompatible_backends = (
307 for backend_file in glob.iglob(os.path.join(build_env.topobjdir,
308 'backend.*Backend')):
309 for prev, curr in incompatible_backends:
310 if prev in backend_file and any(curr in b for b in backends):
311 die("The active objdir, %s, was previously "
312 "used to build with a %s based backend. "
313 "Change objdirs (by setting MOZ_OBJDIR in "
314 "your mozconfig) or clobber to continue.\n",
315 build_env.topobjdir, prev)
318 option('--disable-gtest-in-build',
319 help='Force disable building the gtest libxul during the build.',
320 when='--enable-compile-environment')
322 # Determine whether to build the gtest xul. This happens in automation
323 # on Android and Desktop platforms with the exception of:
324 # - Windows PGO, where linking xul-gtest.dll takes too long;
325 # - Android other than x86_64, where gtest is not required.
326 @depends('MOZ_PGO', build_project, target, 'MOZ_AUTOMATION', '--disable-gtest-in-build',
327 enable_tests, when='--enable-compile-environment')
328 def build_gtest(pgo, build_project, target, automation, enabled, enable_tests):
329 if not enable_tests or not enabled:
331 if (automation and build_project in ('browser', 'comm/mail', 'mobile/android') and
332 not ((pgo and target.os == 'WINNT') or (target.os == 'Android' and target.cpu != 'x86_64'))):
335 set_config('LINK_GTEST_DURING_COMPILE', build_gtest)
338 # ==============================================================
339 option('--enable-ui-locale', default='en-US',
340 help='Select the user interface locale (default: en-US)')
342 set_config('MOZ_UI_LOCALE', depends('--enable-ui-locale')(lambda x: x))
344 # clang-plugin location
345 # ==============================================================
346 @depends(host_library_name_info, check_build_environment,
347 when='--enable-clang-plugin')
348 def clang_plugin_path(library_name_info, build_env):
349 topobjdir = build_env.topobjdir
350 if topobjdir.endswith('/js/src'):
351 topobjdir = topobjdir[:-7]
352 return os.path.abspath(
353 os.path.join(topobjdir, 'build', 'clang-plugin',
354 '%sclang-plugin%s' % (library_name_info.dll.prefix,
355 library_name_info.dll.suffix))
358 add_old_configure_assignment('CLANG_PLUGIN', clang_plugin_path)
362 # ==============================================================
363 awk = check_prog('AWK', ('gawk', 'mawk', 'nawk', 'awk'))
365 # Until the AWK variable is not necessary in old-configure
367 def awk_for_old_configure(value):
370 add_old_configure_assignment('AWK', awk_for_old_configure)
374 # ==============================================================
375 perl = check_prog('PERL', ('perl5', 'perl'))
377 # Until the PERL variable is not necessary in old-configure
379 def perl_for_old_configure(value):
382 add_old_configure_assignment('PERL', perl_for_old_configure)
385 def perl_version_check(min_version):
387 @checking('for minimum required perl version >= %s' % min_version)
388 def get_perl_version(perl):
389 return Version(check_cmd_output(
390 perl, '-e', 'print $]',
391 onerror=lambda: die('Failed to get perl version.')
394 @depends(get_perl_version)
395 def check_perl_version(version):
396 if version < min_version:
397 die('Perl %s or higher is required.', min_version)
400 @checking('for full perl installation')
401 @imports('subprocess')
402 def has_full_perl_installation(perl):
403 ret = subprocess.call(
404 [perl, '-e', 'use Config; exit(!-d $Config{archlib})'])
407 @depends(has_full_perl_installation)
408 def require_full_perl_installation(has_full_perl_installation):
409 if not has_full_perl_installation:
410 die('Cannot find Config.pm or $Config{archlib}. '
411 'A full perl installation is required.')
413 perl_version_check('5.006')
417 # ==============================================================
418 option(env='MAKE', nargs=1, help='Path to GNU make')
420 @depends('MAKE', host)
421 def possible_makes(make, host):
423 if host.kernel == 'WINNT':
424 candidates.append('mingw32-make')
426 candidates.append(make[0])
427 if host.kernel == 'WINNT':
428 candidates.extend(('make', 'gmake'))
430 candidates.extend(('gmake', 'make'))
433 check_prog('GMAKE', possible_makes)
435 @depends(build_backends, build_project)
436 def tup_include(build_backends, build_project):
437 # We need to check the rustc version when building with tup, but
438 # rustc_info isn't available when configuring js (and build_backends isn't
439 # available from project-specific configure), so as a workaround we only
440 # include the file when we know we'll need it. This can be removed when
441 # we globally require a rustc recent enough to build with tup.
442 if build_project not in ('browser', 'mobile/android'):
444 for backend in build_backends:
446 return 'build/moz.configure/tup.configure'
451 # ==============================================================
453 option(env='WATCHMAN', nargs=1, help='Path to the watchman program')
455 @depends(host, 'WATCHMAN')
456 @checking('for watchman', callback=lambda w: w.path if w else 'not found')
457 def watchman(host, prog):
458 # On Windows, `watchman` is only supported on 64-bit hosts.
459 if host.os == 'WINNT' and host.cpu != 'x86_64':
463 prog = find_program('watchman')
468 # `watchman version` will talk to the Watchman daemon service.
469 # This can hang due to permissions problems. e.g.
470 # https://github.com/facebook/watchman/issues/376. So use
471 # `watchman --version` to prevent a class of failures.
472 out = check_cmd_output(prog, '--version', onerror=lambda: None)
476 return namespace(path=prog, version=Version(out.strip()))
478 @depends_if(watchman)
479 @checking('for watchman version')
480 def watchman_version(w):
483 set_config('WATCHMAN', watchman.path)
485 @depends_all(hg_version, hg_config, watchman)
486 @checking('for watchman Mercurial integration')
488 def watchman_hg(hg_version, hg_config, watchman):
489 if hg_version < Version('3.8'):
490 return 'no (Mercurial 3.8+ required)'
493 mode_disabled = False
495 for k in ('extensions.fsmonitor', 'extensions.hgext.fsmonitor'):
496 if k in hg_config and hg_config[k] != '!':
499 mode_disabled = hg_config.get('fsmonitor.mode') == 'off'
502 return 'no (fsmonitor extension not enabled)'
504 return 'no (fsmonitor.mode=off disables fsmonitor)'
508 # Miscellaneous programs
509 # ==============================================================
510 check_prog('XARGS', ('xargs',))
513 def extra_programs(target):
514 if target.kernel == 'Darwin':
516 DSYMUTIL=('dsymutil', 'llvm-dsymutil'),
517 MKFSHFS=('newfs_hfs', 'mkfs.hfsplus'),
518 HFS_TOOL=('hfsplus',)
520 if target.os == 'GNU' and target.kernel == 'Linux':
521 return namespace(RPMBUILD=('rpmbuild',))
523 check_prog('DSYMUTIL', extra_programs.DSYMUTIL,
525 check_prog('MKFSHFS', extra_programs.MKFSHFS,
527 check_prog('HFS_TOOL', extra_programs.HFS_TOOL,
529 check_prog('RPMBUILD', extra_programs.RPMBUILD,
535 def makensis_progs(target):
536 if target.kernel != 'WINNT':
546 # Look for nsis installed by msys environment. But only the 32-bit version.
547 # We use an absolute path and insert as the first entry so it is preferred
548 # over a 64-bit exe that may be in PATH.
549 if 'MSYSTEM_PREFIX' in os.environ:
550 prefix = os.path.dirname(os.environ['MSYSTEM_PREFIX'])
551 candidates.insert(0, os.path.join(prefix, 'mingw32', 'bin', 'makensis.exe'))
553 return tuple(candidates)
555 nsis = check_prog('MAKENSISU', makensis_progs, allow_missing=True)
557 # Make sure the version of makensis is up to date.
559 @checking('for NSIS version')
561 def nsis_version(nsis):
562 nsis_min_version = '3.0b1'
563 out = check_cmd_output(nsis, '-version',
564 onerror=lambda: die('Failed to get nsis version.'))
565 m = re.search(r'(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?', out)
568 raise FatalCheckError('Unknown version of makensis')
569 ver = Version(m.group(0))
571 # Versions comparisons don't quite work well with beta versions, so ensure
572 # it works for the non-beta version.
573 if ver < nsis_min_version and (ver >= '3.0a' or ver < '3'):
574 raise FatalCheckError('To build the installer you must have NSIS'
575 ' version %s or greater in your path'
580 # And that makensis is 32-bit (but only on Windows).
581 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == 'WINNT'))
582 @checking('for 32-bit NSIS')
583 def nsis_binary_type(nsis):
584 bin_type = windows_binary_type(nsis)
585 if bin_type != 'win32':
586 raise FatalCheckError('%s is not a 32-bit Windows application' % nsis)
590 # And any flags we have to give to makensis
592 def nsis_flags(host):
593 if host.kernel != 'WINNT':
597 set_config('MAKENSISU_FLAGS', nsis_flags)
599 check_prog('7Z', ('7z', '7za'), allow_missing=True, when=target_is_windows)
602 @depends(host_c_compiler, c_compiler, bindgen_config_paths)
603 def llvm_objdump(host_c_compiler, c_compiler, bindgen_config_paths):
605 for compiler in (host_c_compiler, c_compiler):
606 if compiler and compiler.type == 'clang':
607 clang = compiler.compiler
609 elif compiler and compiler.type == 'clang-cl':
610 clang = os.path.join(os.path.dirname(compiler.compiler), 'clang')
613 if not clang and bindgen_config_paths:
614 clang = bindgen_config_paths.clang_path
615 llvm_objdump = 'llvm-objdump'
617 out = check_cmd_output(clang, '--print-prog-name=llvm-objdump',
618 onerror=lambda: None)
620 llvm_objdump = out.rstrip()
621 return (llvm_objdump,)
624 llvm_objdump = check_prog('LLVM_OBJDUMP', llvm_objdump, what='llvm-objdump',
625 when='--enable-compile-environment',
626 paths=toolchain_search_path)
628 add_old_configure_assignment('LLVM_OBJDUMP', llvm_objdump)
631 # Please do not add configure checks from here on.
633 # Fallthrough to autoconf-based configure
634 include('build/moz.configure/old.configure')
637 include('js/sub.configure', when=compile_environment & toolkit)
640 @depends(check_build_environment, build_project)
641 @imports('__sandbox__')
643 @imports(_from='os.path', _import='exists')
644 def config_status_deps(build_env, build_project):
646 topsrcdir = build_env.topsrcdir
647 topobjdir = build_env.topobjdir
649 if not topobjdir.endswith('js/src'):
650 extra_deps = [os.path.join(topobjdir, '.mozconfig.json')]
652 # mozconfig changes may impact js configure.
653 extra_deps = [os.path.join(topobjdir[:-7], '.mozconfig.json')]
655 confvars = os.path.join(topsrcdir, build_project, 'confvars.sh')
657 extra_deps.append(confvars)
659 return list(__sandbox__._all_paths) + extra_deps + [
660 os.path.join(topsrcdir, 'CLOBBER'),
661 os.path.join(topsrcdir, 'configure'),
662 os.path.join(topsrcdir, 'js', 'src', 'configure'),
663 os.path.join(topsrcdir, 'configure.in'),
664 os.path.join(topsrcdir, 'js', 'src', 'configure.in'),
665 os.path.join(topsrcdir, 'nsprpub', 'configure'),
666 os.path.join(topsrcdir, 'config', 'milestone.txt'),
667 os.path.join(topsrcdir, 'browser', 'config', 'version.txt'),
668 os.path.join(topsrcdir, 'browser', 'config', 'version_display.txt'),
669 os.path.join(topsrcdir, 'build', 'virtualenv_packages.txt'),
670 os.path.join(topsrcdir, 'python', 'mozbuild', 'mozbuild', 'virtualenv.py'),
671 os.path.join(topsrcdir, 'testing', 'mozbase', 'packages.txt'),
672 os.path.join(topsrcdir, 'aclocal.m4'),
673 os.path.join(topsrcdir, 'old-configure.in'),
674 os.path.join(topsrcdir, 'js', 'src', 'aclocal.m4'),
675 os.path.join(topsrcdir, 'js', 'src', 'old-configure.in'),
676 ] + glob.glob(os.path.join(topsrcdir, 'build', 'autoconf', '*.m4'))
678 set_config('CONFIG_STATUS_DEPS', config_status_deps)
679 # Please do not add anything after setting config_dep_paths.