[PATCH v2.5 weston 03/11] configure.ac: Correctly check for functions and libraries

Quentin Glidic sardemff7+wayland at sardemff7.net
Tue Dec 10 03:28:53 PST 2013


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

AC_SEARCH_LIBS is preferred over AC_CHECK_FUNC and AC_CHECK_LIB
See
http://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf.html#Libraries
AC_SEARCH_LIBS is doing precisely the double checking we used to have
for dlopen

Introduce WS_SEARCH_LIBS to make it easier for contributors

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

WS_SEARCH_LIBS one-liner version

 configure.ac | 20 ++++----------------
 m4/weston.m4 | 14 ++++++++++++++
 2 files changed, 18 insertions(+), 16 deletions(-)
 create mode 100644 m4/weston.m4

diff --git a/configure.ac b/configure.ac
index 40ae145..849cad7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,9 +41,7 @@ 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)
+WS_SEARCH_LIBS(DLOPEN, [dlopen], [dl])
 
 AC_CHECK_DECL(SFD_CLOEXEC,[],
 	      [AC_MSG_ERROR("SFD_CLOEXEC is needed to compile weston")],
@@ -258,13 +256,7 @@ fi
 AM_CONDITIONAL(ENABLE_VAAPI_RECORDER, test "x$have_libva" = xyes)
 
 
-AC_CHECK_LIB([jpeg], [jpeg_CreateDecompress], have_jpeglib=yes)
-if test x$have_jpeglib = xyes; then
-  JPEG_LIBS="-ljpeg"
-else
-  AC_ERROR([libjpeg not found])
-fi
-AC_SUBST(JPEG_LIBS)
+WS_SEARCH_LIBS(JPEG, [jpeg_CreateDecompress], [jpeg])
 
 PKG_CHECK_MODULES(CAIRO, [cairo])
 
@@ -334,12 +326,8 @@ AS_IF([test "x$have_systemd_login_209" = "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])
-  if test x$have_pam == xno; then
-    AC_ERROR([weston-launch requires pam])
-  fi
-  PAM_LIBS=-lpam
-  AC_SUBST(PAM_LIBS)
+	WS_SEARCH_LIBS(PAM, [pam_open_session], [pam],
+		       [pam support required for weston-launch])
 fi
 
 if test x$enable_egl = xyes; then
diff --git a/m4/weston.m4 b/m4/weston.m4
new file mode 100644
index 0000000..ca38823
--- /dev/null
+++ b/m4/weston.m4
@@ -0,0 +1,14 @@
+# WS_SEARCH_LIBS(VARIABLE-PREFIX, FUNCTION, SEARCH-LIBS,
+#                [ERROR-MSG-IF-NOT-FOUND])
+# --------------------------------------------------------
+# Search for a library defining FUNC, if it's not already available
+AC_DEFUN([WS_SEARCH_LIBS], [dnl
+AC_ARG_VAR([$1][_LIBS], [linker flags for $1])dnl
+AC_SEARCH_LIBS([$2], [$3])
+case "$ac_cv_search_$2" in
+	no) AC_MSG_ERROR([m4_default([$4], [$2 required but not found])]) ;;
+	"none required") ;;
+	*) $1[]_LIBS="$ac_cv_search_$2" ;;
+esac
+AC_SUBST([$1][_LIBS])
+])
-- 
1.8.5.1



More information about the wayland-devel mailing list