From ac2f2c943acf27338d51440974d446de0190b8d2 Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Wed, 28 Feb 2024 11:11:17 +0000 Subject: [PATCH] Bug 1880424 - Move clock_monotonic check to moz.configure r=glandium Differential Revision: https://phabricator.services.mozilla.com/D201942 --- build/moz.configure/libraries.configure | 44 +++++++++++++++++++++++++ js/src/old-configure.in | 26 --------------- moz.configure | 1 + old-configure.in | 23 ------------- 4 files changed, 45 insertions(+), 49 deletions(-) create mode 100644 build/moz.configure/libraries.configure diff --git a/build/moz.configure/libraries.configure b/build/moz.configure/libraries.configure new file mode 100644 index 000000000000..1d74475936b1 --- /dev/null +++ b/build/moz.configure/libraries.configure @@ -0,0 +1,44 @@ +# -*- 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) diff --git a/js/src/old-configure.in b/js/src/old-configure.in index f6bdd14e0ba4..0c9581121270 100644 --- a/js/src/old-configure.in +++ b/js/src/old-configure.in @@ -601,32 +601,6 @@ then fi -dnl Checks for library functions. -dnl ======================================================== - -dnl check for clock_gettime(), the CLOCK_MONOTONIC clock -AC_CACHE_CHECK(for clock_gettime(CLOCK_MONOTONIC), - ac_cv_clock_monotonic, - [for libs in "" -lrt; do - _SAVE_LIBS="$LIBS" - LIBS="$LIBS $libs" - AC_TRY_LINK([#include ], - [ struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); ], - ac_cv_clock_monotonic=$libs - LIBS="$_SAVE_LIBS" - break, - ac_cv_clock_monotonic=no) - LIBS="$_SAVE_LIBS" - done]) -if test "$ac_cv_clock_monotonic" != "no"; then - HAVE_CLOCK_MONOTONIC=1 - REALTIME_LIBS=$ac_cv_clock_monotonic - AC_DEFINE(HAVE_CLOCK_MONOTONIC) - AC_SUBST(HAVE_CLOCK_MONOTONIC) - AC_SUBST_LIST(REALTIME_LIBS) -fi - dnl Checks for math functions. dnl ======================================================== AC_CHECK_LIB(m, sin) diff --git a/moz.configure b/moz.configure index 4d1ccee36e03..fc6563d07570 100755 --- a/moz.configure +++ b/moz.configure @@ -208,6 +208,7 @@ include("build/moz.configure/toolchain.configure", when="--enable-compile-enviro include("build/moz.configure/pkg.configure") include("build/moz.configure/memory.configure", when="--enable-compile-environment") include("build/moz.configure/headers.configure", when="--enable-compile-environment") +include("build/moz.configure/libraries.configure", when="--enable-compile-environment") include("build/moz.configure/warnings.configure", when="--enable-compile-environment") include("build/moz.configure/flags.configure", when="--enable-compile-environment") include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment") diff --git a/old-configure.in b/old-configure.in index 27d741cb9255..802fa8db5917 100644 --- a/old-configure.in +++ b/old-configure.in @@ -637,29 +637,6 @@ fi dnl Checks for library functions. dnl ======================================================== -dnl check for clock_gettime(), the CLOCK_MONOTONIC clock -AC_CACHE_CHECK(for clock_gettime(CLOCK_MONOTONIC), - ac_cv_clock_monotonic, - [for libs in "" -lrt; do - _SAVE_LIBS="$LIBS" - LIBS="$LIBS $libs" - AC_TRY_LINK([#include ], - [ struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); ], - ac_cv_clock_monotonic=$libs - LIBS="$_SAVE_LIBS" - break, - ac_cv_clock_monotonic=no) - LIBS="$_SAVE_LIBS" - done]) -if test "$ac_cv_clock_monotonic" != "no"; then - HAVE_CLOCK_MONOTONIC=1 - REALTIME_LIBS=$ac_cv_clock_monotonic - AC_DEFINE(HAVE_CLOCK_MONOTONIC) - AC_SUBST(HAVE_CLOCK_MONOTONIC) - AC_SUBST_LIST(REALTIME_LIBS) -fi - AC_CACHE_CHECK( [for res_ninit()], ac_cv_func_res_ninit,