mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
46b1ffeb92
Original patch by Simon McVittie <smcv@debian.org> Differential Revision: https://phabricator.services.mozilla.com/D220988
151 lines
4.6 KiB
Python
151 lines
4.6 KiB
Python
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
|
|
# vim: set filetype=python:
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
@template
|
|
def check_clock_monotonic_support(lib=None, when=None):
|
|
check_msg = "for clock_gettime(CLOCK_MONOTONIC)"
|
|
flags = []
|
|
|
|
if lib is not None:
|
|
check_msg += f" in {lib}"
|
|
flags.append(f"-l{lib}")
|
|
|
|
check_when = building_with_gnu_compatible_cc
|
|
if when is not None:
|
|
check_when &= when
|
|
|
|
return try_link(
|
|
includes=["time.h"],
|
|
body="struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts);",
|
|
check_msg=check_msg,
|
|
flags=flags,
|
|
when=check_when,
|
|
)
|
|
|
|
|
|
have_raw_clock_monotonic_support = check_clock_monotonic_support()
|
|
have_rt_clock_monotonic_support = check_clock_monotonic_support(
|
|
lib="rt", when=~have_raw_clock_monotonic_support
|
|
)
|
|
|
|
set_define(
|
|
"HAVE_CLOCK_MONOTONIC",
|
|
have_raw_clock_monotonic_support | have_rt_clock_monotonic_support,
|
|
)
|
|
set_config(
|
|
"HAVE_CLOCK_MONOTONIC",
|
|
have_raw_clock_monotonic_support | have_rt_clock_monotonic_support,
|
|
)
|
|
|
|
set_config("REALTIME_LIBS", ["-lrt"], when=have_rt_clock_monotonic_support)
|
|
|
|
|
|
have_res_ninit = try_link(
|
|
includes=["sys/types.h", "netinet/in.h", "arpa/nameser.h", "resolv.h"],
|
|
body="int foo = res_ninit(&_res);",
|
|
check_msg="for res_ninit()",
|
|
flags=depends(when=building_linux)(["-D_BSD_SOURCE=1"]),
|
|
when=building_with_gnu_compatible_cc & ~target_is_netbsd & ~target_is_openbsd,
|
|
)
|
|
|
|
set_define("HAVE_RES_NINIT", have_res_ninit)
|
|
|
|
# We don't want to link with libdl even if it's present on OS X, since
|
|
# it's not used and not part of the default installation.
|
|
# We don't want to link against libm or libpthread on Darwin since
|
|
# they both are just symlinks to libSystem and explicitly linking
|
|
# against libSystem causes issues when debugging (see bug 299601).
|
|
with only_when(building_with_gnu_compatible_cc):
|
|
dladdr_check = check_symbol_in_libs([None, "dl"], symbol="dladdr")
|
|
set_define(
|
|
"HAVE_DLADDR", depends(dladdr_check)(lambda check: "1" if check.found else "0")
|
|
)
|
|
|
|
with only_when(~target_is_darwin):
|
|
check_header("dlfcn.h")
|
|
dlopen_check = check_symbol_in_libs(["dl", None], symbol="dlopen")
|
|
set_config(
|
|
"DL_LIBS", ["-ldl"], when=depends(dlopen_check)(lambda check: check.lib)
|
|
)
|
|
|
|
|
|
set_config(
|
|
"C_R_LIBS",
|
|
["-lc_r"],
|
|
when=check_symbol_in_lib(
|
|
"c_r", symbol="gethostbyname_r", when=building_with_gnu_compatible_cc
|
|
),
|
|
)
|
|
set_config(
|
|
"SOCKET_LIBS",
|
|
["-lsocket"],
|
|
when=check_symbol_in_lib(
|
|
"socket", symbol="socket", when=building_with_gnu_compatible_cc
|
|
),
|
|
)
|
|
|
|
moz_use_pthreads = (
|
|
target_is_darwin
|
|
| check_symbol_in_libs(
|
|
[None, "pthread"],
|
|
symbol="pthread_create",
|
|
when=building_with_gnu_compatible_cc & ~target_is_darwin,
|
|
).found
|
|
)
|
|
|
|
with only_when(moz_use_pthreads):
|
|
check_header("pthread.h")
|
|
|
|
pthread_flags = dependable(lambda: namespace(cflags=[]))
|
|
|
|
(have_pthread_cflag,) = check_and_add_flags(
|
|
"-pthread",
|
|
pthread_flags,
|
|
["-Werror", "-pthread"],
|
|
compiler=c_compiler,
|
|
)
|
|
|
|
@depends(pthread_flags, compilation_flags)
|
|
def add_pthread_linker_flags(pthread_flags, compilation_flags):
|
|
# Handle compilation flags update
|
|
compilation_flags.cflags.extend(pthread_flags.cflags)
|
|
compilation_flags.cxxflags.extend(pthread_flags.cflags)
|
|
|
|
set_config("MOZ_USE_PTHREADS", True)
|
|
|
|
|
|
with only_when(building_with_gnu_compatible_cc):
|
|
|
|
@template
|
|
def check_std_atomic_requirements(flag=None, when=None):
|
|
return try_link(
|
|
includes=["cstdint", "atomic"],
|
|
body="std::atomic<uint64_t> foo; foo = 1;",
|
|
flags=flag or [],
|
|
when=when,
|
|
)
|
|
|
|
is_libatomic_optional = check_std_atomic_requirements()
|
|
is_libatomic_required = check_std_atomic_requirements(
|
|
flag=["-latomic"], when=~is_libatomic_optional
|
|
)
|
|
|
|
@depends(is_libatomic_optional, is_libatomic_required)
|
|
@checking("whether 64-bits std::atomic requires -latomic")
|
|
def checking_needs_libatomic(is_libatomic_optional, is_libatomic_required):
|
|
if is_libatomic_optional:
|
|
return False
|
|
if is_libatomic_required:
|
|
return True
|
|
return "do not know; assuming no"
|
|
|
|
set_config(
|
|
"LIBATOMIC_LIBS",
|
|
["-latomic"],
|
|
when=depends(checking_needs_libatomic)(lambda c: c is True),
|
|
)
|