1 # semaphore.m4 serial 1
2 dnl Copyright (C) 2019-2020 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.
7 # Sets LIB_SEMAPHORE to the library needed, in addition to $(LIBMULTITHREAD),
8 # for getting the <semaphore.h> functions.
10 AC_DEFUN([gl_SEMAPHORE],
12 AC_REQUIRE([gl_THREADLIB])
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],
23 LIBS="$LIBS $LIBMULTITHREAD"
26 [[#include <semaphore.h>]],
27 [[sem_post ((sem_t *)0);]])],
28 [gl_cv_semaphore_lib=none],
32 [[#include <semaphore.h>]],
33 [[sem_post ((sem_t *)0);]])],
34 [gl_cv_semaphore_lib='-lrt'],
35 [gl_cv_semaphore_lib=none])
39 if test "x$gl_cv_semaphore_lib" = xnone; then
42 LIB_SEMAPHORE="$gl_cv_semaphore_lib"
44 AC_SUBST([LIB_SEMAPHORE])