1 # -*- Mode: python; c-basic-offset: 4; 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/.
9 def check_clock_monotonic_support(lib=None, when=None):
10 check_msg = "for clock_gettime(CLOCK_MONOTONIC)"
14 check_msg += f" in {lib}"
15 flags.append(f"-l{lib}")
17 check_when = building_with_gnu_compatible_cc
23 body="struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts);",
30 have_raw_clock_monotonic_support = check_clock_monotonic_support()
31 have_rt_clock_monotonic_support = check_clock_monotonic_support(
32 lib="rt", when=~have_raw_clock_monotonic_support
36 "HAVE_CLOCK_MONOTONIC",
37 have_raw_clock_monotonic_support | have_rt_clock_monotonic_support,
40 "HAVE_CLOCK_MONOTONIC",
41 have_raw_clock_monotonic_support | have_rt_clock_monotonic_support,
44 set_config("REALTIME_LIBS", ["-lrt"], when=have_rt_clock_monotonic_support)
47 have_res_ninit = try_link(
48 includes=["sys/types.h", "netinet/in.h", "arpa/nameser.h", "resolv.h"],
49 body="int foo = res_ninit(&_res);",
50 check_msg="for res_ninit()",
51 flags=depends(when=building_linux)(["-D_BSD_SOURCE=1"]),
52 when=building_with_gnu_compatible_cc & ~target_is_netbsd & ~target_is_openbsd,
55 set_define("HAVE_RES_NINIT", have_res_ninit)
57 # We don't want to link with libdl even if it's present on OS X, since
58 # it's not used and not part of the default installation.
59 # We don't want to link against libm or libpthread on Darwin since
60 # they both are just symlinks to libSystem and explicitly linking
61 # against libSystem causes issues when debugging (see bug 299601).
62 with only_when(building_with_gnu_compatible_cc):
63 dladdr_check = check_symbol_in_libs([None, "dl"], symbol="dladdr")
65 "HAVE_DLADDR", depends(dladdr_check)(lambda check: "1" if check.found else "0")
68 with only_when(~target_is_darwin):
69 check_header("dlfcn.h")
70 dlopen_check = check_symbol_in_libs(["dl", None], symbol="dlopen")
72 "DL_LIBS", ["-ldl"], when=depends(dlopen_check)(lambda check: check.lib)
79 when=check_symbol_in_lib(
80 "c_r", symbol="gethostbyname_r", when=building_with_gnu_compatible_cc
86 when=check_symbol_in_lib(
87 "socket", symbol="socket", when=building_with_gnu_compatible_cc
93 | check_symbol_in_libs(
95 symbol="pthread_create",
96 when=building_with_gnu_compatible_cc & ~target_is_darwin,
100 with only_when(moz_use_pthreads):
101 check_header("pthread.h")
103 pthread_flags = dependable(lambda: namespace(cflags=[]))
105 (have_pthread_cflag,) = check_and_add_flags(
108 ["-Werror", "-pthread"],
112 @depends(pthread_flags, compilation_flags)
113 def add_pthread_linker_flags(pthread_flags, compilation_flags):
114 # Handle compilation flags update
115 compilation_flags.cflags.extend(pthread_flags.cflags)
116 compilation_flags.cxxflags.extend(pthread_flags.cflags)
118 set_config("MOZ_USE_PTHREADS", True)
121 with only_when(building_with_gnu_compatible_cc):
124 def check_std_atomic_requirements(flag=None, when=None):
126 includes=["cstdint", "atomic"],
127 body="std::atomic<uint64_t> foo; foo = 1;",
132 is_libatomic_optional = check_std_atomic_requirements()
133 is_libatomic_required = check_std_atomic_requirements(
134 flag=["-latomic"], when=~is_libatomic_optional
137 @depends(is_libatomic_optional, is_libatomic_required)
138 @checking("whether 64-bits std::atomic requires -latomic")
139 def checking_needs_libatomic(is_libatomic_optional, is_libatomic_required):
140 if is_libatomic_optional:
142 if is_libatomic_required:
144 return "do not know; assuming no"
149 when=depends(checking_needs_libatomic)(lambda c: c is True),