1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# -*- 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_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_cc & ~target_is_netbsd & ~target_is_openbsd,
)
set_define("HAVE_RES_NINIT", have_res_ninit)
|