On 3/1/22 17:22, Lars Ingebrigtsen wrote:

--- a/lib/gnulib.mk.in
+++ b/lib/gnulib.mk.in
@@ -129,6 +129,7 @@
  #  minmax \
  #  mkostemp \
  #  mktime \
+#  nanosleep \
  #  nproc \
  #  nstrftime \
  #  pathmax \
@@ -2497,6 +2498,16 @@ EXTRA_libgnu_a_SOURCES += mktime.c
  endif
  ## end   gnulib module mktime-internal
+## begin gnulib module nanosleep
+ifeq (,$(OMIT_GNULIB_MODULE_nanosleep))
+
+ifneq (,$(GL_COND_OBJ_NANOSLEEP_CONDITION))
+libgnu_a_SOURCES += nanosleep.c
+endif
+
+endif
+## end   gnulib module nanosleep
+
  ## begin gnulib module nproc
  ifeq (,$(OMIT_GNULIB_MODULE_nproc))

This diff is wrong, as it omits a line "GL_COND_OBJ_NANOSLEEP_CONDITION = @GL_COND_OBJ_NANOSLEEP_CONDITION@".

I ran what should have been something like your commands and got the attached patch. One way forward is for you to simply install the attached patch and move on from there. Or we can continue to look into why things work for me and not for you. I suppose it could be an Autoconf bug on your platform, but it'd be an odd one.

Here's a shell transcript of what I did to get the attached patch, on Fedora 35 x86-64:

  $ git clone master master-tmp
  Cloning into 'master-tmp'...
  done.
  Updating files: 100% (4608/4608), done.
  $ cd master-tmp
  $ git log HEAD^!
commit 689a34e2153ec558dbf406809a5e58489250fe1a (HEAD -> master, origin/master, origin/HEAD)
  Author: Po Lu <[email protected]>
  Date:   Wed Mar 2 09:46:44 2022 +0800

      Dismiss help text when item becomes unactivated on oldXMenu

      * oldXMenu/Activate.c (XMenuActivate): Dismiss help text when
      leaving an item.
  $ (cd ../gnulib && git log HEAD^! )
commit 8c4f4d7a3c28f88b64fce2fb1d0dc0e570d1a482 (HEAD -> master, origin/master, origin/HEAD)
  Author: Paul Eggert <[email protected]>
  Date:   Tue Mar 1 10:01:22 2022 -0800

      Create lib/Makefile.am after gnulib-comp.m4

      * gnulib-tool (func_import): Create library makefile after
      creating gnulib-comp.m4.  With --gnu-make, the latter depends on
      the former.  See <https://bugs.gnu.org/32452#109>.
  $ sed -i 's/nproc nstrftime/nanosleep &/' admin/merge-gnulib
  $ admin/merge-gnulib
  Checking whether you have the necessary tools...
  (Read INSTALL.REPO for more details on building Emacs)
  Checking for autoconf (need at least version 2.65) ... ok
  Your system has the required tools.
  Building aclocal.m4 ...
  Running 'autoreconf -fi -I m4' ...
  Configuring local git repository...
  '.git/config' -> '.git/config.~1~'
  git config transfer.fsckObjects 'true'
git config diff.cpp.xfuncname '!^[ \t]*[A-Za-z_][A-Za-z_0-9]*:[[:space:]]*($|/[/*])
  ^((::[[:space:]]*)?[A-Za-z_][A-Za-z_0-9]*[[:space:]]*\(.*)$
  ^((#define[[:space:]]|DEFUN).*)$'
git config diff.elisp.xfuncname '^\([^[:space:]]*def[^[:space:]]+[[:space:]]+([^()[:space:]]+)'
  git config diff.m4.xfuncname '^((m4_)?define|A._DEFUN(_ONCE)?)\([^),]*'
git config diff.make.xfuncname '^([$.[:alnum:]_].*:|[[:alnum:]_]+[[:space:]]*([*:+]?[:?]?|!?)=|define .*)' git config diff.shell.xfuncname '^([[:space:]]*[[:alpha:]_][[:alnum:]_]*[[:space:]]*\(\)|[[:alpha:]_][[:alnum:]_]*=)' git config diff.texinfo.xfuncname '^@node[[:space:]]+([^,[:space:]][^,]+)'
  Installing git hooks...
  'build-aux/git-hooks/commit-msg' -> '.git/hooks/commit-msg'
  'build-aux/git-hooks/pre-commit' -> '.git/hooks/pre-commit'
'build-aux/git-hooks/prepare-commit-msg' -> '.git/hooks/prepare-commit-msg'
  '.git/hooks/applypatch-msg.sample' -> '.git/hooks/applypatch-msg'
  '.git/hooks/pre-applypatch.sample' -> '.git/hooks/pre-applypatch'
  You can now run './configure'.
  Module list with included dependencies (indented):
      absolute-header
      acl-permissions
    alloca-opt
      allocator
      at-internal
      attribute
    binary-io
      builtin-expect
    byteswap
    c-ctype
    c-strcase
      c99
    canonicalize-lgpl
    careadlinkat
      clock-time
      cloexec
    close-stream
    copy-file-range
    count-leading-zeros
    count-one-bits
    count-trailing-zeros
    crypto/md5
    crypto/md5-buffer
    crypto/sha1-buffer
    crypto/sha256-buffer
    crypto/sha512-buffer
    d-type
    diffseq
      dirent
      dirfd
    double-slash-root
    dtoastr
    dtotimespec
    dup2
      dynarray
      eloop-threshold
    environ
      errno
      euidaccess
    execinfo
    explicit_bzero
      extensions
      extern-inline
    faccessat
    fchmodat
    fcntl
    fcntl-h
    fdopendir
    file-has-acl
    filemode
    filename
    filevercmp
    flexmember
      fpending
    fpieee
    free-posix
    fstatat
    fsusage
    fsync
    futimens
      gen-header
      getdtablesize
      getgroups
    getloadavg
    getopt-gnu
      getopt-posix
    getrandom
      gettext-h
    gettime
    gettimeofday
    gitlog-to-changelog
      group-member
      idx
    ieee754-h
    ignore-value
      include_next
    intprops
      inttypes-incomplete
    largefile
      lchmod
      libc-config
    libgmp
      limits-h
    lstat
      malloc-gnu
      malloc-posix
    manywarnings
    memmem-simple
    mempcpy
    memrchr
    minmax
    mkostemp
    mktime
      mktime-internal
      multiarch
    nanosleep
      nocrash
    nproc
    nstrftime
      open
      openat-h
    pathmax
    pipe2
    pselect
    pthread_sigmask
    qcopy-acl
      rawmemchr
    readlink
    readlinkat
      realloc-gnu
      realloc-posix
    regex
      root-uid
      scratch_buffer
    sig2str
    sigdescr_np
      signal-h
      snippet/_Noreturn
      snippet/arg-nonnull
      snippet/c++defs
      snippet/warn-on-use
    socklen
      ssize_t
    stat-time
    std-gnu11
    stdalign
    stddef
      stdint
    stdio
      stdlib
    stpcpy
      string
    strnlen
    strtoimax
      strtoll
    symlink
      sys_random
      sys_select
    sys_stat
    sys_time
      sys_types
    tempname
    time
    time_r
    time_rz
    timegm
    timer-time
      timespec
    timespec-add
    timespec-sub
      u64
      unistd
    unlocked-io
      unlocked-io-internal
    update-copyright
      utimens
    utimensat
      vararrays
      verify
    vla
    warnings
      xalloc-oversized
  File list:
    build-aux/gitlog-to-changelog
    build-aux/update-copyright
    lib/_Noreturn.h
    lib/acl-errno-valid.c
    lib/acl-internal.c
    lib/acl-internal.h
    lib/acl.h
    lib/acl_entries.c
    lib/alloca.in.h
    lib/allocator.c
    lib/allocator.h
    lib/arg-nonnull.h
    lib/at-func.c
    lib/attribute.h
    lib/binary-io.c
    lib/binary-io.h
    lib/byteswap.in.h
    lib/c++defs.h
    lib/c-ctype.c
    lib/c-ctype.h
    lib/c-strcase.h
    lib/c-strcasecmp.c
    lib/c-strncasecmp.c
    lib/canonicalize-lgpl.c
    lib/careadlinkat.c
    lib/careadlinkat.h
    lib/cdefs.h
    lib/cloexec.c
    lib/cloexec.h
    lib/close-stream.c
    lib/close-stream.h
    lib/copy-file-range.c
    lib/count-leading-zeros.c
    lib/count-leading-zeros.h
    lib/count-one-bits.c
    lib/count-one-bits.h
    lib/count-trailing-zeros.c
    lib/count-trailing-zeros.h
    lib/diffseq.h
    lib/dirent.in.h
    lib/dirfd.c
    lib/dtoastr.c
    lib/dtotimespec.c
    lib/dup2.c
    lib/dynarray.h
    lib/eloop-threshold.h
    lib/errno.in.h
    lib/euidaccess.c
    lib/execinfo.c
    lib/execinfo.in.h
    lib/explicit_bzero.c
    lib/faccessat.c
    lib/fchmodat.c
    lib/fcntl.c
    lib/fcntl.in.h
    lib/fdopendir.c
    lib/file-has-acl.c
    lib/filemode.c
    lib/filemode.h
    lib/filename.h
    lib/filevercmp.c
    lib/filevercmp.h
    lib/flexmember.h
    lib/fpending.c
    lib/fpending.h
    lib/free.c
    lib/fstatat.c
    lib/fsusage.c
    lib/fsusage.h
    lib/fsync.c
    lib/ftoastr.c
    lib/ftoastr.h
    lib/futimens.c
    lib/get-permissions.c
    lib/getdtablesize.c
    lib/getgroups.c
    lib/getloadavg.c
    lib/getopt-cdefs.in.h
    lib/getopt-core.h
    lib/getopt-ext.h
    lib/getopt-pfx-core.h
    lib/getopt-pfx-ext.h
    lib/getopt.c
    lib/getopt.in.h
    lib/getopt1.c
    lib/getopt_int.h
    lib/getrandom.c
    lib/gettext.h
    lib/gettime.c
    lib/gettimeofday.c
    lib/gl_openssl.h
    lib/group-member.c
    lib/idx.h
    lib/ieee754.in.h
    lib/ignore-value.h
    lib/intprops.h
    lib/inttypes.in.h
    lib/lchmod.c
    lib/libc-config.h
    lib/limits.in.h
    lib/lstat.c
    lib/malloc.c
    lib/malloc/dynarray-skeleton.c
    lib/malloc/dynarray.h
    lib/malloc/dynarray_at_failure.c
    lib/malloc/dynarray_emplace_enlarge.c
    lib/malloc/dynarray_finalize.c
    lib/malloc/dynarray_resize.c
    lib/malloc/dynarray_resize_clear.c
    lib/malloc/scratch_buffer.h
    lib/malloc/scratch_buffer_dupfree.c
    lib/malloc/scratch_buffer_grow.c
    lib/malloc/scratch_buffer_grow_preserve.c
    lib/malloc/scratch_buffer_set_array_size.c
    lib/md5-stream.c
    lib/md5.c
    lib/md5.h
    lib/memmem.c
    lib/mempcpy.c
    lib/memrchr.c
    lib/mini-gmp-gnulib.c
    lib/mini-gmp.c
    lib/mini-gmp.h
    lib/minmax.h
    lib/mkostemp.c
    lib/mktime-internal.h
    lib/mktime.c
    lib/nanosleep.c
    lib/nproc.c
    lib/nproc.h
    lib/nstrftime.c
    lib/open.c
    lib/openat-priv.h
    lib/openat-proc.c
    lib/openat.h
    lib/pathmax.h
    lib/pipe2.c
    lib/pselect.c
    lib/pthread_sigmask.c
    lib/qcopy-acl.c
    lib/rawmemchr.c
    lib/rawmemchr.valgrind
    lib/readlink.c
    lib/readlinkat.c
    lib/realloc.c
    lib/regcomp.c
    lib/regex.c
    lib/regex.h
    lib/regex_internal.c
    lib/regex_internal.h
    lib/regexec.c
    lib/root-uid.h
    lib/scratch_buffer.h
    lib/set-permissions.c
    lib/sha1.c
    lib/sha1.h
    lib/sha256.c
    lib/sha256.h
    lib/sha512.c
    lib/sha512.h
    lib/sig2str.c
    lib/sig2str.h
    lib/sigdescr_np.c
    lib/signal.in.h
    lib/stat-time.c
    lib/stat-time.h
    lib/stdalign.in.h
    lib/stddef.in.h
    lib/stdint.in.h
    lib/stdio-impl.h
    lib/stdio-read.c
    lib/stdio-write.c
    lib/stdio.in.h
    lib/stdlib.in.h
    lib/stpcpy.c
    lib/str-two-way.h
    lib/strftime.h
    lib/string.in.h
    lib/strnlen.c
    lib/strtoimax.c
    lib/strtol.c
    lib/strtoll.c
    lib/symlink.c
    lib/sys_random.in.h
    lib/sys_select.in.h
    lib/sys_stat.in.h
    lib/sys_time.in.h
    lib/sys_types.in.h
    lib/tempname.c
    lib/tempname.h
    lib/time-internal.h
    lib/time.in.h
    lib/time_r.c
    lib/time_rz.c
    lib/timegm.c
    lib/timespec-add.c
    lib/timespec-sub.c
    lib/timespec.c
    lib/timespec.h
    lib/u64.c
    lib/u64.h
    lib/unistd.c
    lib/unistd.in.h
    lib/unlocked-io.h
    lib/utimens.c
    lib/utimens.h
    lib/utimensat.c
    lib/verify.h
    lib/vla.h
    lib/warn-on-use.h
    lib/xalloc-oversized.h
    m4/00gnulib.m4
    m4/__inline.m4
    m4/absolute-header.m4
    m4/acl.m4
    m4/alloca.m4
    m4/builtin-expect.m4
    m4/byteswap.m4
    m4/canonicalize.m4
    m4/clock_time.m4
    m4/copy-file-range.m4
    m4/d-type.m4
    m4/dirent_h.m4
    m4/dirfd.m4
    m4/double-slash-root.m4
    m4/dup2.m4
    m4/eealloc.m4
    m4/environ.m4
    m4/errno_h.m4
    m4/euidaccess.m4
    m4/execinfo.m4
    m4/explicit_bzero.m4
    m4/extensions.m4
    m4/extern-inline.m4
    m4/faccessat.m4
    m4/fchmodat.m4
    m4/fcntl-o.m4
    m4/fcntl.m4
    m4/fcntl_h.m4
    m4/fdopendir.m4
    m4/filemode.m4
    m4/flexmember.m4
    m4/fpending.m4
    m4/fpieee.m4
    m4/free.m4
    m4/fstatat.m4
    m4/fsusage.m4
    m4/fsync.m4
    m4/futimens.m4
    m4/getdtablesize.m4
    m4/getgroups.m4
    m4/getloadavg.m4
    m4/getopt.m4
    m4/getrandom.m4
    m4/gettime.m4
    m4/gettimeofday.m4
    m4/gl-openssl.m4
    m4/gnulib-common.m4
    m4/group-member.m4
    m4/ieee754-h.m4
    m4/include_next.m4
    m4/inttypes.m4
    m4/largefile.m4
    m4/lchmod.m4
    m4/libgmp.m4
    m4/limits-h.m4
    m4/lstat.m4
    m4/malloc.m4
    m4/manywarnings-c++.m4
    m4/manywarnings.m4
    m4/mbstate_t.m4
    m4/md5.m4
    m4/memmem.m4
    m4/mempcpy.m4
    m4/memrchr.m4
    m4/minmax.m4
    m4/mkostemp.m4
    m4/mktime.m4
    m4/mode_t.m4
    m4/multiarch.m4
    m4/nanosleep.m4
    m4/nocrash.m4
    m4/nproc.m4
    m4/nstrftime.m4
    m4/off_t.m4
    m4/open-cloexec.m4
    m4/open-slash.m4
    m4/open.m4
    m4/pathmax.m4
    m4/pid_t.m4
    m4/pipe2.m4
    m4/pselect.m4
    m4/pthread_sigmask.m4
    m4/rawmemchr.m4
    m4/readlink.m4
    m4/readlinkat.m4
    m4/realloc.m4
    m4/regex.m4
    m4/sha1.m4
    m4/sha256.m4
    m4/sha512.m4
    m4/sig2str.m4
    m4/sigdescr_np.m4
    m4/signal_h.m4
    m4/socklen.m4
    m4/ssize_t.m4
    m4/stat-time.m4
    m4/std-gnu11.m4
    m4/stdalign.m4
    m4/stddef_h.m4
    m4/stdint.m4
    m4/stdio_h.m4
    m4/stdlib_h.m4
    m4/stpcpy.m4
    m4/string_h.m4
    m4/strnlen.m4
    m4/strtoimax.m4
    m4/strtoll.m4
    m4/symlink.m4
    m4/sys_random_h.m4
    m4/sys_select_h.m4
    m4/sys_socket_h.m4
    m4/sys_stat_h.m4
    m4/sys_time_h.m4
    m4/sys_types_h.m4
    m4/tempname.m4
    m4/time_h.m4
    m4/time_r.m4
    m4/time_rz.m4
    m4/timegm.m4
    m4/timer_time.m4
    m4/timespec.m4
    m4/tm_gmtoff.m4
    m4/unistd_h.m4
    m4/unlocked-io.m4
    m4/utimens.m4
    m4/utimensat.m4
    m4/utimes.m4
    m4/vararrays.m4
    m4/warn-on-use.m4
    m4/warnings.m4
    m4/wchar_t.m4
    m4/wint_t.m4
    m4/year2038.m4
    m4/zzgnulib.m4
  Copying file lib/gl_openssl.h
  Copying file lib/nanosleep.c
  Copying file lib/stdio-read.c
  Copying file lib/stdio-write.c
  Copying file m4/fcntl-o.m4
  Copying file m4/gl-openssl.m4
  Copying file m4/gnulib-tool.m4
  Copying file m4/manywarnings-c++.m4
  Copying file m4/nanosleep.m4
  Copying file m4/warn-on-use.m4
  Copying file m4/wint_t.m4
  Creating m4/gnulib-cache.m4
  Updating m4/gnulib-comp.m4 (backup in m4/gnulib-comp.m4~)
  Updating lib/gnulib.mk.in (backup in lib/gnulib.mk.in~)
  Finished.

  You may need to add #include directives for the following .h files.
    #include <alloca.h>
    #include <byteswap.h>
    #include <dirent.h>
    #include <execinfo.h>
    #include <fcntl.h>
    #include <getopt.h>
    #include <gmp.h>
    #include <ieee754.h>
    #include <inttypes.h>
    #include <regex.h>
    #include <signal.h>
    #include <stdalign.h>
    #include <stddef.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <sys/random.h>
    #include <sys/select.h>
    #include <sys/stat.h>
    #include <sys/time.h>
    #include <time.h>
    #include <unistd.h>
    #include "acl.h"
    #include "binary-io.h"
    #include "c-ctype.h"
    #include "c-strcase.h"
    #include "careadlinkat.h"
    #include "close-stream.h"
    #include "count-leading-zeros.h"
    #include "count-one-bits.h"
    #include "count-trailing-zeros.h"
    #include "diffseq.h"
    #include "filemode.h"
    #include "filename.h"
    #include "filevercmp.h"
    #include "fsusage.h"
    #include "ftoastr.h"
    #include "ignore-value.h"
    #include "intprops.h"
    #include "md5.h"
    #include "minmax.h"
    #include "nproc.h"
    #include "pathmax.h"
    #include "sha1.h"
    #include "sha256.h"
    #include "sha512.h"
    #include "sig2str.h"
    #include "stat-time.h"
    #include "strftime.h"
    #include "tempname.h"
    #include "timespec.h"
    #include "unlocked-io.h"
    #include <sys/types.h>
    #if HAVE_SYS_SOCKET_H
    # include <sys/socket.h>
    #elif HAVE_WS2TCPIP_H
    # include <ws2tcpip.h>
    #endif

  You may need to use the following Makefile variables when linking.
  Use them in <program>_LDADD when linking a program, or
  in <library>_a_LDFLAGS or <library>_la_LDFLAGS when linking a library.
    $(GETLOADAVG_LIBS)
    $(LIBTHREAD)
    $(LIB_ACL)
    $(LIB_CLOCK_GETTIME)
    $(LIB_CRYPTO)
    $(LIB_EACCESS)
    $(LIB_EXECINFO)
    $(LIB_GETRANDOM)
    $(LIB_HAS_ACL)
    $(LIB_MBRTOWC)
    $(LIB_NANOSLEEP)
    $(LIB_PTHREAD_SIGMASK)
    $(LIB_SELECT)
    $(LIB_TIMER_TIME)
    $(LTLIBGMP) when linking with libtool, $(LIBGMP) otherwise
    $(LTLIBINTL) when linking with libtool, $(LIBINTL) otherwise

  Don't forget to
    - "include gnulib.mk.in" from within "lib/Makefile.am",
    - mention "-I m4" in ACLOCAL_AMFLAGS in Makefile.am
      or add an AC_CONFIG_MACRO_DIRS([m4]) invocation in ./configure.ac,
    - mention "m4/gnulib-cache.m4" in EXTRA_DIST in Makefile.am,
    - invoke gl_EARLY in ./configure.ac, right after AC_PROG_CC,
    - invoke gl_INIT in ./configure.ac.
  Checking whether you have the necessary tools...
  (Read INSTALL.REPO for more details on building Emacs)
  Checking for autoconf (need at least version 2.65) ... ok
  Your system has the required tools.
  Building aclocal.m4 ...
  Running 'autoreconf -fi -I m4' ...
  You can now run './configure'.
  $ git status
  On branch master
  Your branch is up to date with 'origin/master'.

  Changes not staged for commit:
    (use "git add <file>..." to update what will be committed)
    (use "git restore <file>..." to discard changes in working directory)
          modified:   admin/merge-gnulib
          modified:   lib/gnulib.mk.in
          modified:   m4/gnulib-comp.m4

  Untracked files:
    (use "git add <file>..." to include in what will be committed)
          lib/nanosleep.c
          m4/nanosleep.m4
          merge-gnulib.diff

  no changes added to commit (use "git add" and/or "git commit -a")
  $ git checkout -b for-larsi
  Switched to a new branch 'for-larsi'
$ git add lib/nanosleep.c m4/nanosleep.m4 admin/merge-gnulib lib/gnulib.mk.in m4/gnulib-comp.m4
  $ git commit -m'Add Gnulib nanosleep module'
  [for-larsi 2020d4fc91] Add Gnulib nanosleep module
   5 files changed, 355 insertions(+), 1 deletion(-)
   create mode 100644 lib/nanosleep.c
   create mode 100644 m4/nanosleep.m4
  $ git format-patch -1
  0001-Add-Gnulib-nanosleep-module.patch
  $
From 2020d4fc91bf704a2572e7b68baca615f88a9144 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Tue, 1 Mar 2022 18:04:38 -0800
Subject: [PATCH] Add Gnulib nanosleep module

---
 admin/merge-gnulib |   2 +-
 lib/gnulib.mk.in   |  13 +++
 lib/nanosleep.c    | 195 +++++++++++++++++++++++++++++++++++++++++++++
 m4/gnulib-comp.m4  |   7 ++
 m4/nanosleep.m4    | 139 ++++++++++++++++++++++++++++++++
 5 files changed, 355 insertions(+), 1 deletion(-)
 create mode 100644 lib/nanosleep.c
 create mode 100644 m4/nanosleep.m4

diff --git a/admin/merge-gnulib b/admin/merge-gnulib
index fec469c017..ea3d23686f 100755
--- a/admin/merge-gnulib
+++ b/admin/merge-gnulib
@@ -40,7 +40,7 @@ GNULIB_MODULES=
   getloadavg getopt-gnu getrandom gettime gettimeofday gitlog-to-changelog
   ieee754-h ignore-value intprops largefile libgmp lstat
   manywarnings memmem-simple mempcpy memrchr minmax mkostemp mktime
-  nproc nstrftime
+  nanosleep nproc nstrftime
   pathmax pipe2 pselect pthread_sigmask
   qcopy-acl readlink readlinkat regex
   sig2str sigdescr_np socklen stat-time std-gnu11 stdalign stddef stdio
diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in
index 3a9f5b9818..3deeca98be 100644
--- a/lib/gnulib.mk.in
+++ b/lib/gnulib.mk.in
@@ -129,6 +129,7 @@
 #  minmax \
 #  mkostemp \
 #  mktime \
+#  nanosleep \
 #  nproc \
 #  nstrftime \
 #  pathmax \
@@ -207,6 +208,7 @@ CPP = @CPP@
 CPPFLAGS = @CPPFLAGS@
 CRYPTOLIB = @CRYPTOLIB@
 CXX = @CXX@
+CXXCPP = @CXXCPP@
 CXXFLAGS = @CXXFLAGS@
 CYGWIN_OBJ = @CYGWIN_OBJ@
 C_SWITCH_MACHINE = @C_SWITCH_MACHINE@
@@ -283,6 +285,7 @@ GL_COND_OBJ_MEMPCPY_CONDITION = @GL_COND_OBJ_MEMPCPY_CONDITION@
 GL_COND_OBJ_MEMRCHR_CONDITION = @GL_COND_OBJ_MEMRCHR_CONDITION@
 GL_COND_OBJ_MINI_GMP_GNULIB_CONDITION = @GL_COND_OBJ_MINI_GMP_GNULIB_CONDITION@
 GL_COND_OBJ_MKOSTEMP_CONDITION = @GL_COND_OBJ_MKOSTEMP_CONDITION@
+GL_COND_OBJ_NANOSLEEP_CONDITION = @GL_COND_OBJ_NANOSLEEP_CONDITION@
 GL_COND_OBJ_OPEN_CONDITION = @GL_COND_OBJ_OPEN_CONDITION@
 GL_COND_OBJ_PSELECT_CONDITION = @GL_COND_OBJ_PSELECT_CONDITION@
 GL_COND_OBJ_PTHREAD_SIGMASK_CONDITION = @GL_COND_OBJ_PTHREAD_SIGMASK_CONDITION@
@@ -2497,6 +2500,16 @@ EXTRA_libgnu_a_SOURCES += mktime.c
 endif
 ## end   gnulib module mktime-internal
 
+## begin gnulib module nanosleep
+ifeq (,$(OMIT_GNULIB_MODULE_nanosleep))
+
+ifneq (,$(GL_COND_OBJ_NANOSLEEP_CONDITION))
+libgnu_a_SOURCES += nanosleep.c
+endif
+
+endif
+## end   gnulib module nanosleep
+
 ## begin gnulib module nproc
 ifeq (,$(OMIT_GNULIB_MODULE_nproc))
 
diff --git a/lib/nanosleep.c b/lib/nanosleep.c
new file mode 100644
index 0000000000..446794edc0
--- /dev/null
+++ b/lib/nanosleep.c
@@ -0,0 +1,195 @@
+/* Provide a replacement for the POSIX nanosleep function.
+
+   Copyright (C) 1999-2000, 2002, 2004-2022 Free Software Foundation, Inc.
+
+   This file is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   This file is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* written by Jim Meyering
+   and Bruno Haible for the native Windows part */
+
+#include <config.h>
+
+#include <time.h>
+
+#include "intprops.h"
+#include "verify.h"
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/select.h>
+#include <signal.h>
+
+#include <errno.h>
+
+#include <unistd.h>
+
+
+enum { BILLION = 1000 * 1000 * 1000 };
+
+#if HAVE_BUG_BIG_NANOSLEEP
+
+int
+nanosleep (const struct timespec *requested_delay,
+           struct timespec *remaining_delay)
+# undef nanosleep
+{
+  /* nanosleep mishandles large sleeps due to internal overflow problems.
+     The worst known case of this is Linux 2.6.9 with glibc 2.3.4, which
+     can't sleep more than 24.85 days (2^31 milliseconds).  Similarly,
+     cygwin 1.5.x, which can't sleep more than 49.7 days (2^32 milliseconds).
+     Solve this by breaking the sleep up into smaller chunks.  */
+
+  if (requested_delay->tv_nsec < 0 || BILLION <= requested_delay->tv_nsec)
+    {
+      errno = EINVAL;
+      return -1;
+    }
+
+  {
+    /* Verify that time_t is large enough.  */
+    verify (TYPE_MAXIMUM (time_t) / 24 / 24 / 60 / 60);
+    const time_t limit = 24 * 24 * 60 * 60;
+    time_t seconds = requested_delay->tv_sec;
+    struct timespec intermediate;
+    intermediate.tv_nsec = requested_delay->tv_nsec;
+
+    while (limit < seconds)
+      {
+        int result;
+        intermediate.tv_sec = limit;
+        result = nanosleep (&intermediate, remaining_delay);
+        seconds -= limit;
+        if (result)
+          {
+            if (remaining_delay)
+              remaining_delay->tv_sec += seconds;
+            return result;
+          }
+        intermediate.tv_nsec = 0;
+      }
+    intermediate.tv_sec = seconds;
+    return nanosleep (&intermediate, remaining_delay);
+  }
+}
+
+#elif defined _WIN32 && ! defined __CYGWIN__
+/* Native Windows platforms.  */
+
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+
+/* The Windows API function Sleep() has a resolution of about 15 ms and takes
+   at least 5 ms to execute.  We use this function for longer time periods.
+   Additionally, we use busy-looping over short time periods, to get a
+   resolution of about 0.01 ms.  In order to measure such short timespans,
+   we use the QueryPerformanceCounter() function.  */
+
+int
+nanosleep (const struct timespec *requested_delay,
+           struct timespec *remaining_delay)
+{
+  static bool initialized;
+  /* Number of performance counter increments per nanosecond,
+     or zero if it could not be determined.  */
+  static double ticks_per_nanosecond;
+
+  if (requested_delay->tv_nsec < 0 || BILLION <= requested_delay->tv_nsec)
+    {
+      errno = EINVAL;
+      return -1;
+    }
+
+  /* For requested delays of one second or more, 15ms resolution is
+     sufficient.  */
+  if (requested_delay->tv_sec == 0)
+    {
+      if (!initialized)
+        {
+          /* Initialize ticks_per_nanosecond.  */
+          LARGE_INTEGER ticks_per_second;
+
+          if (QueryPerformanceFrequency (&ticks_per_second))
+            ticks_per_nanosecond =
+              (double) ticks_per_second.QuadPart / 1000000000.0;
+
+          initialized = true;
+        }
+      if (ticks_per_nanosecond)
+        {
+          /* QueryPerformanceFrequency worked.  We can use
+             QueryPerformanceCounter.  Use a combination of Sleep and
+             busy-looping.  */
+          /* Number of milliseconds to pass to the Sleep function.
+             Since Sleep can take up to 8 ms less or 8 ms more than requested
+             (or maybe more if the system is loaded), we subtract 10 ms.  */
+          int sleep_millis = (int) requested_delay->tv_nsec / 1000000 - 10;
+          /* Determine how many ticks to delay.  */
+          LONGLONG wait_ticks = requested_delay->tv_nsec * ticks_per_nanosecond;
+          /* Start.  */
+          LARGE_INTEGER counter_before;
+          if (QueryPerformanceCounter (&counter_before))
+            {
+              /* Wait until the performance counter has reached this value.
+                 We don't need to worry about overflow, because the performance
+                 counter is reset at reboot, and with a frequency of 3.6E6
+                 ticks per second 63 bits suffice for over 80000 years.  */
+              LONGLONG wait_until = counter_before.QuadPart + wait_ticks;
+              /* Use Sleep for the longest part.  */
+              if (sleep_millis > 0)
+                Sleep (sleep_millis);
+              /* Busy-loop for the rest.  */
+              for (;;)
+                {
+                  LARGE_INTEGER counter_after;
+                  if (!QueryPerformanceCounter (&counter_after))
+                    /* QueryPerformanceCounter failed, but succeeded earlier.
+                       Should not happen.  */
+                    break;
+                  if (counter_after.QuadPart >= wait_until)
+                    /* The requested time has elapsed.  */
+                    break;
+                }
+              goto done;
+            }
+        }
+    }
+  /* Implementation for long delays and as fallback.  */
+  Sleep (requested_delay->tv_sec * 1000 + requested_delay->tv_nsec / 1000000);
+
+ done:
+  /* Sleep is not interruptible.  So there is no remaining delay.  */
+  if (remaining_delay != NULL)
+    {
+      remaining_delay->tv_sec = 0;
+      remaining_delay->tv_nsec = 0;
+    }
+  return 0;
+}
+
+#else
+/* Other platforms lacking nanosleep.
+   It's not clear whether these are still practical porting targets.
+   For now, just fall back on pselect.  */
+
+/* Suspend execution for at least *REQUESTED_DELAY seconds.  The
+   *REMAINING_DELAY part isn't implemented yet.  */
+
+int
+nanosleep (const struct timespec *requested_delay,
+           struct timespec *remaining_delay)
+{
+  return pselect (0, NULL, NULL, NULL, requested_delay, NULL);
+}
+#endif
diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4
index 1d31239d2d..fb5f1b52a4 100644
--- a/m4/gnulib-comp.m4
+++ b/m4/gnulib-comp.m4
@@ -140,6 +140,7 @@ AC_DEFUN
   # Code from module mktime:
   # Code from module mktime-internal:
   # Code from module multiarch:
+  # Code from module nanosleep:
   # Code from module nocrash:
   # Code from module nproc:
   # Code from module nstrftime:
@@ -430,6 +431,10 @@ AC_DEFUN
   fi
   gl_TIME_MODULE_INDICATOR([mktime])
   gl_MULTIARCH
+  gl_FUNC_NANOSLEEP
+  gl_CONDITIONAL([GL_COND_OBJ_NANOSLEEP],
+                 [test $HAVE_NANOSLEEP = 0 || test $REPLACE_NANOSLEEP = 1])
+  gl_TIME_MODULE_INDICATOR([nanosleep])
   gl_NPROC
   gl_FUNC_GNU_STRFTIME
   gl_PATHMAX
@@ -1304,6 +1309,7 @@ AC_DEFUN
   lib/mkostemp.c
   lib/mktime-internal.h
   lib/mktime.c
+  lib/nanosleep.c
   lib/nproc.c
   lib/nproc.h
   lib/nstrftime.c
@@ -1456,6 +1462,7 @@ AC_DEFUN
   m4/mktime.m4
   m4/mode_t.m4
   m4/multiarch.m4
+  m4/nanosleep.m4
   m4/nocrash.m4
   m4/nproc.m4
   m4/nstrftime.m4
diff --git a/m4/nanosleep.m4 b/m4/nanosleep.m4
new file mode 100644
index 0000000000..1964b1ea47
--- /dev/null
+++ b/m4/nanosleep.m4
@@ -0,0 +1,139 @@
+# serial 41
+
+dnl From Jim Meyering.
+dnl Check for the nanosleep function.
+dnl If not found, use the supplied replacement.
+dnl
+
+# Copyright (C) 1999-2001, 2003-2022 Free Software Foundation, Inc.
+
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_NANOSLEEP],
+[
+ AC_REQUIRE([gl_TIME_H_DEFAULTS])
+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+
+ dnl Persuade glibc and Solaris <time.h> to declare nanosleep.
+ AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+
+ AC_CHECK_DECLS_ONCE([alarm])
+
+ nanosleep_save_libs=$LIBS
+
+ # Solaris 2.5.1 needs -lposix4 to get the nanosleep function.
+ # Solaris 7 prefers the library name -lrt to the obsolescent name -lposix4.
+ LIB_NANOSLEEP=
+ AC_SUBST([LIB_NANOSLEEP])
+ AC_SEARCH_LIBS([nanosleep], [rt posix4],
+                [test "$ac_cv_search_nanosleep" = "none required" ||
+                 LIB_NANOSLEEP=$ac_cv_search_nanosleep])
+ if test "x$ac_cv_search_nanosleep" != xno; then
+   dnl The system has a nanosleep function.
+
+   AC_REQUIRE([gl_MULTIARCH])
+   if test $APPLE_UNIVERSAL_BUILD = 1; then
+     # A universal build on Apple Mac OS X platforms.
+     # The test result would be 'no (mishandles large arguments)' in 64-bit
+     # mode but 'yes' in 32-bit mode. But we need a configuration result that
+     # is valid in both modes.
+     gl_cv_func_nanosleep='no (mishandles large arguments)'
+   fi
+
+   AC_CACHE_CHECK([for working nanosleep],
+    [gl_cv_func_nanosleep],
+    [
+     AC_RUN_IFELSE(
+       [AC_LANG_SOURCE([[
+          #include <errno.h>
+          #include <limits.h>
+          #include <signal.h>
+          #include <time.h>
+          #include <unistd.h>
+          #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
+          #define TYPE_MAXIMUM(t) \
+            ((t) (! TYPE_SIGNED (t) \
+                  ? (t) -1 \
+                  : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
+
+          #if HAVE_DECL_ALARM
+          static void
+          check_for_SIGALRM (int sig)
+          {
+            if (sig != SIGALRM)
+              _exit (1);
+          }
+          #endif
+
+          int
+          main ()
+          {
+            static struct timespec ts_sleep;
+            static struct timespec ts_remaining;
+            /* Test for major problems first.  */
+            if (! nanosleep)
+              return 2;
+            ts_sleep.tv_sec = 0;
+            ts_sleep.tv_nsec = 1;
+            #if HAVE_DECL_ALARM
+            {
+              static struct sigaction act;
+              act.sa_handler = check_for_SIGALRM;
+              sigemptyset (&act.sa_mask);
+              sigaction (SIGALRM, &act, NULL);
+              alarm (1);
+              if (nanosleep (&ts_sleep, NULL) != 0)
+                return 3;
+              /* Test for a minor problem: the handling of large arguments.  */
+              ts_sleep.tv_sec = TYPE_MAXIMUM (time_t);
+              ts_sleep.tv_nsec = 999999999;
+              alarm (1);
+              if (nanosleep (&ts_sleep, &ts_remaining) != -1)
+                return 4;
+              if (errno != EINTR)
+                return 5;
+              if (ts_remaining.tv_sec <= TYPE_MAXIMUM (time_t) - 10)
+                return 6;
+            }
+            #else /* A simpler test for native Windows.  */
+            if (nanosleep (&ts_sleep, &ts_remaining) < 0)
+              return 3;
+            #endif
+            return 0;
+          }]])],
+       [gl_cv_func_nanosleep=yes],
+       [case $? in dnl (
+        4|5|6) gl_cv_func_nanosleep='no (mishandles large arguments)';; dnl (
+        *)   gl_cv_func_nanosleep=no;;
+        esac],
+       [case "$host_os" in dnl ((
+          linux*) # Guess it halfway works when the kernel is Linux.
+            gl_cv_func_nanosleep='guessing no (mishandles large arguments)' ;;
+          mingw*) # Guess no on native Windows.
+            gl_cv_func_nanosleep='guessing no' ;;
+          *)      # If we don't know, obey --enable-cross-guesses.
+            gl_cv_func_nanosleep="$gl_cross_guess_normal" ;;
+        esac
+       ])
+    ])
+   case "$gl_cv_func_nanosleep" in
+     *yes)
+       REPLACE_NANOSLEEP=0
+       ;;
+     *)
+       REPLACE_NANOSLEEP=1
+       case "$gl_cv_func_nanosleep" in
+         *"mishandles large arguments"*)
+           AC_DEFINE([HAVE_BUG_BIG_NANOSLEEP], [1],
+             [Define to 1 if nanosleep mishandles large arguments.])
+           ;;
+       esac
+       ;;
+   esac
+ else
+   HAVE_NANOSLEEP=0
+ fi
+ LIBS=$nanosleep_save_libs
+])
-- 
2.35.1

Reply via email to