[v8,6/6] configure: detect libdl and librt

Submitted by Leonid Bobrov on Feb. 27, 2019, 7:13 p.m.

Details

Message ID 20190227191313.66300-6-mazocomp@disroot.org
State Superseded
Headers show
Series "Series without cover letter" ( rev: 1 ) in Wayland

Not browsing as part of any series.

Commit Message

Leonid Bobrov Feb. 27, 2019, 7:13 p.m.
Signed-off-by: Leonid Bobrov <mazocomp@disroot.org>
---
 Makefile.am  |  6 +++---
 configure.ac |  6 ++++++
 m4/weston.m4 | 37 +++++++++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+), 3 deletions(-)
 create mode 100644 m4/weston.m4

Patch hide | download patch | download mbox

diff --git a/Makefile.am b/Makefile.am
index f47d055..489f581 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -71,7 +71,7 @@  nodist_include_HEADERS =			\
 	protocol/wayland-client-protocol.h
 
 libwayland_server_la_CFLAGS = $(FFI_CFLAGS) $(AM_CFLAGS) -pthread
-libwayland_server_la_LIBADD = $(FFI_LIBS) libwayland-private.la libwayland-util.la -lrt -lm
+libwayland_server_la_LIBADD = $(FFI_LIBS) libwayland-private.la libwayland-util.la $(RT_LIBS) -lm
 libwayland_server_la_LDFLAGS = -version-info 1:0:1
 libwayland_server_la_SOURCES =			\
 	src/wayland-server.c			\
@@ -83,7 +83,7 @@  nodist_libwayland_server_la_SOURCES =		\
 	protocol/wayland-protocol.c
 
 libwayland_client_la_CFLAGS = $(FFI_CFLAGS) $(AM_CFLAGS) -pthread
-libwayland_client_la_LIBADD = $(FFI_LIBS) libwayland-private.la libwayland-util.la -lrt -lm
+libwayland_client_la_LIBADD = $(FFI_LIBS) libwayland-private.la libwayland-util.la $(RT_LIBS) -lm
 libwayland_client_la_LDFLAGS = -version-info 3:0:3
 libwayland_client_la_SOURCES =			\
 	src/wayland-client.c
@@ -227,7 +227,7 @@  libtest_runner_la_LIBADD =			\
 	libwayland-client.la			\
 	libwayland-server.la			\
 	libtest-helpers.la			\
-	-lrt -ldl $(FFI_LIBS)
+	$(RT_LIBS) $(DL_LIBS) $(FFI_LIBS)
 
 array_test_SOURCES = tests/array-test.c
 array_test_LDADD = libtest-runner.la
diff --git a/configure.ac b/configure.ac
index a60a927..064b8a8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -79,6 +79,12 @@  AC_CHECK_HEADERS([signal.h])
 # Credential support on *BSD
 AC_CHECK_HEADERS([sys/ucred.h])
 
+# *BSD don't have libdl, but they have its functions in libc
+WESTON_SEARCH_LIBS([DL], [dl], [dlsym])
+
+# OpenBSD doesn't have librt, but it has its functions in libc
+WESTON_SEARCH_LIBS([RT], [rt], [clock_gettime])
+
 AC_ARG_ENABLE([libraries],
 	      [AC_HELP_STRING([--disable-libraries],
 			      [Disable compilation of wayland libraries])],
diff --git a/m4/weston.m4 b/m4/weston.m4
new file mode 100644
index 0000000..636f9fb
--- /dev/null
+++ b/m4/weston.m4
@@ -0,0 +1,37 @@ 
+dnl
+dnl Copyright © 2016 Quentin “Sardem FF7” Glidic
+dnl
+dnl Permission is hereby granted, free of charge, to any person obtaining a
+dnl copy of this software and associated documentation files (the "Software"),
+dnl to deal in the Software without restriction, including without limitation
+dnl the rights to use, copy, modify, merge, publish, distribute, sublicense,
+dnl and/or sell copies of the Software, and to permit persons to whom the
+dnl Software is furnished to do so, subject to the following conditions:
+dnl
+dnl The above copyright notice and this permission notice (including the next
+dnl paragraph) shall be included in all copies or substantial portions of the
+dnl Software.
+dnl
+dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+dnl IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+dnl FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+dnl THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+dnl LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+dnl FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+dnl DEALINGS IN THE SOFTWARE.
+dnl
+
+dnl WESTON_SEARCH_LIBS(PREFIX, search-libs, function, [action-if-found], [action-if-not-found], [other-libraries])
+dnl WESTON_SEARCH_LIBS is a wrapper around AC_SEARCH_LIBS with a little difference:
+dnl action-if-found is called even if no library is required
+AC_DEFUN([WESTON_SEARCH_LIBS], [
+	weston_save_LIBS=${LIBS}
+	AC_SEARCH_LIBS([$3], [$2], [$4], [$5], [$6])
+	AS_CASE([${ac_cv_search_][$3][}],
+		['none required'], [$4],
+		[no], [],
+		[$1][_LIBS=${ac_cv_search_][$3][}]
+	)
+	AC_SUBST([$1][_LIBS])
+	LIBS=${weston_save_LIBS}
+])