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