Bug 1875768 - Call the appropriate postfork handler on MacOS r=glandium
[gecko.git] / build / moz.configure / libraries.configure
blob3c3c713a40f066c0a55087457b611bf93c6a3980
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/.
8 @template
9 def check_clock_monotonic_support(lib=None, when=None):
10     check_msg = "for clock_gettime(CLOCK_MONOTONIC)"
11     flags = []
13     if lib is not None:
14         check_msg += f" in {lib}"
15         flags.append(f"-l{lib}")
17     check_when = building_with_gnu_compatible_cc
18     if when is not None:
19         check_when &= when
21     return try_link(
22         includes=["time.h"],
23         body="struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts);",
24         check_msg=check_msg,
25         flags=flags,
26         when=check_when,
27     )
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
35 set_define(
36     "HAVE_CLOCK_MONOTONIC",
37     have_raw_clock_monotonic_support | have_rt_clock_monotonic_support,
39 set_config(
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")
64     set_define(
65         "HAVE_DLADDR", depends(dladdr_check)(lambda check: "1" if check.found else "0")
66     )
68     with only_when(~target_is_darwin):
69         check_header("dlfcn.h")
70         dlopen_check = check_symbol_in_libs(["dl", None], symbol="dlopen")
71         set_config(
72             "DL_LIBS", ["-ldl"], when=depends(dlopen_check)(lambda check: check.lib)
73         )
76 set_config(
77     "C_R_LIBS",
78     ["-lc_r"],
79     when=check_symbol_in_lib(
80         "c_r", symbol="gethostbyname_r", when=building_with_gnu_compatible_cc
81     ),
83 set_config(
84     "SOCKET_LIBS",
85     ["-lsocket"],
86     when=check_symbol_in_lib(
87         "socket", symbol="socket", when=building_with_gnu_compatible_cc
88     ),
91 moz_use_pthreads = (
92     target_is_darwin
93     | check_symbol_in_libs(
94         [None, "pthread"],
95         symbol="pthread_create",
96         when=building_with_gnu_compatible_cc & ~target_is_darwin,
97     ).found
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(
106         "-pthread",
107         pthread_flags,
108         ["-Werror", "-pthread"],
109         compiler=c_compiler,
110     )
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):
123     @template
124     def check_std_atomic_requirements(flag=None, when=None):
125         return try_link(
126             includes=["cstdint", "atomic"],
127             body="std::atomic<uint64_t> foo; foo = 1;",
128             flags=flag or [],
129             when=when,
130         )
132     is_libatomic_optional = check_std_atomic_requirements()
133     is_libatomic_required = check_std_atomic_requirements(
134         flag="-latomic", when=~is_libatomic_optional
135     )
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:
141             return False
142         if is_libatomic_required:
143             return True
144         return "do not know; assuming no"
146     set_config(
147         "LIBATOMIC_LIBS",
148         ["-latomic"],
149         when=depends(checking_needs_libatomic)(lambda c: c is True),
150     )