doc: Improve usability of generated PDF.
[gnulib.git] / m4 / semaphore.m4
blobfc0750debb17f02366bd49307f819533af5ed24f
1 # semaphore.m4
2 # serial 2
3 dnl Copyright (C) 2019-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
9 # Sets LIB_SEMAPHORE to the library needed, in addition to $(LIBMULTITHREAD),
10 # for getting the <semaphore.h> functions.
12 AC_DEFUN([gl_SEMAPHORE],
14   AC_REQUIRE([gl_THREADLIB])
15   dnl sem_post is
16   dnl   - in libc on macOS, FreeBSD, AIX, IRIX, Solaris 11, Haiku, Cygwin,
17   dnl   - in libpthread on glibc systems, OpenBSD,
18   dnl   - in libpthread or librt on NetBSD,
19   dnl   - in librt on HP-UX 11, OSF/1, Solaris 10.
20   dnl On the platforms where -lpthread is needed, it is contained in
21   dnl $LIBMULTITHREAD. Therefore, the only library we need to test for is -lrt.
22   AC_CACHE_CHECK([for library needed for semaphore functions],
23     [gl_cv_semaphore_lib],
24     [saved_LIBS="$LIBS"
25      LIBS="$LIBS $LIBMULTITHREAD"
26      AC_LINK_IFELSE(
27        [AC_LANG_PROGRAM(
28           [[#include <semaphore.h>]],
29           [[sem_post ((sem_t *)0);]])],
30        [gl_cv_semaphore_lib=none],
31        [LIBS="$LIBS -lrt"
32         AC_LINK_IFELSE(
33           [AC_LANG_PROGRAM(
34              [[#include <semaphore.h>]],
35              [[sem_post ((sem_t *)0);]])],
36           [gl_cv_semaphore_lib='-lrt'],
37           [gl_cv_semaphore_lib=none])
38        ])
39      LIBS="$saved_LIBS"
40     ])
41   if test "x$gl_cv_semaphore_lib" = xnone; then
42     LIB_SEMAPHORE=
43   else
44     LIB_SEMAPHORE="$gl_cv_semaphore_lib"
45   fi
46   AC_SUBST([LIB_SEMAPHORE])