[PATCH weston] build: Add (and use) an AC_SEARCH_LIBS wrapper

Quentin Glidic sardemff7+wayland at sardemff7.net
Fri Apr 22 10:14:16 UTC 2016


From: Quentin Glidic <sardemff7+git at sardemff7.net>

Signed-off-by: Quentin Glidic <sardemff7+git at sardemff7.net>
---

Not too much Autotools- or m4-foo needed here.

Please note the behaviour difference from AC_CHECK_LIB/AC_SEARCH_LIBS:
we call action-if-found if the function is available directly, just
in case some crazy libc has jpeg support. :-)

CCed Gustavo Zacarias so he can test it still works as expected for him.

 configure.ac | 18 +++++-------------
 m4/weston.m4 | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 13 deletions(-)
 create mode 100644 m4/weston.m4

diff --git a/configure.ac b/configure.ac
index 670200c..4199616 100644
--- a/configure.ac
+++ b/configure.ac
@@ -42,14 +42,10 @@ AC_ARG_VAR([WESTON_SHELL_CLIENT],
 
 PKG_PROG_PKG_CONFIG()
 
-AC_CHECK_FUNC([dlopen], [],
-              AC_CHECK_LIB([dl], [dlopen], DLOPEN_LIBS="-ldl"))
-AC_SUBST(DLOPEN_LIBS)
+WESTON_SEARCH_LIBS([DLOPEN], [dl], [dlopen])
 
 # In old glibc versions (< 2.17) clock_gettime() is in librt
-AC_SEARCH_LIBS([clock_gettime], [rt],
-             [CLOCK_GETTIME_LIBS="-lrt"])
-AC_SUBST([CLOCK_GETTIME_LIBS])
+WESTON_SEARCH_LIBS([CLOCK_GETTIME], [rt], [clock_gettime])
 
 AC_CHECK_DECL(SFD_CLOEXEC,[],
 	      [AC_MSG_ERROR("SFD_CLOEXEC is needed to compile weston")],
@@ -303,12 +299,10 @@ AC_ARG_WITH([jpeg],
             AS_HELP_STRING([--without-jpeg],
                            [Use jpeglib for JPEG decoding support [default=auto]]))
 AS_IF([test "x$with_jpeg" != "xno"],
-      [AC_CHECK_LIB([jpeg], [jpeg_CreateDecompress], [have_jpeglib=yes], [have_jpeglib=no])],
+      [WESTON_SEARCH_LIBS([JPEG], [jpeg], [jpeg_CreateDecompress], [have_jpeglib=yes], [have_jpeglib=no])],
       [have_jpeglib=no])
 AS_IF([test "x$have_jpeglib" = "xyes"],
-      [JPEG_LIBS="-ljpeg"
-       AC_SUBST([JPEG_LIBS])
-       AC_DEFINE([HAVE_JPEG], [1], [Have jpeglib])],
+      [AC_DEFINE([HAVE_JPEG], [1], [Have jpeglib])],
       [AS_IF([test "x$with_jpeg" = "xyes"],
              [AC_MSG_ERROR([JPEG support explicitly requested, but jpeglib couldn't be found])])])
 
@@ -418,12 +412,10 @@ AS_IF([test "x$enable_resize_optimization" = "xyes"],
 AC_ARG_ENABLE(weston-launch, [  --enable-weston-launch],, enable_weston_launch=yes)
 AM_CONDITIONAL(BUILD_WESTON_LAUNCH, test x$enable_weston_launch == xyes)
 if test x$enable_weston_launch == xyes; then
-  AC_CHECK_LIB([pam], [pam_open_session], [have_pam=yes], [have_pam=no])
+  WESTON_SEARCH_LIBS([PAM], [pam], [pam_open_session], [have_pam=yes], [have_pam=no])
   if test x$have_pam == xno; then
     AC_ERROR([weston-launch requires pam])
   fi
-  PAM_LIBS=-lpam
-  AC_SUBST(PAM_LIBS)
 fi
 
 AM_CONDITIONAL(HAVE_PANGO, test "x$have_pango" = "xyes")
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}
+])
-- 
2.8.1



More information about the wayland-devel mailing list