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])
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],
25 LIBS="$LIBS $LIBMULTITHREAD"
28 [[#include <semaphore.h>]],
29 [[sem_post ((sem_t *)0);]])],
30 [gl_cv_semaphore_lib=none],
34 [[#include <semaphore.h>]],
35 [[sem_post ((sem_t *)0);]])],
36 [gl_cv_semaphore_lib='-lrt'],
37 [gl_cv_semaphore_lib=none])
41 if test "x$gl_cv_semaphore_lib" = xnone; then
44 LIB_SEMAPHORE="$gl_cv_semaphore_lib"
46 AC_SUBST([LIB_SEMAPHORE])