]> git.draconx.ca Git - liblbx.git/commitdiff
build: Split out core logic from libpng detection.
authorNick Bowler <nbowler@draconx.ca>
Thu, 11 Feb 2010 00:06:52 +0000 (19:06 -0500)
committerNick Bowler <nbowler@draconx.ca>
Thu, 11 Feb 2010 04:46:55 +0000 (23:46 -0500)
This allows it to be used for other libraries.  This new method also
better handles the various mechanisms for setting cflags/libs.

configure.ac
m4/dxutils.m4 [new file with mode: 0644]
m4/libpng.m4

index c03b931b9c32fc7f311ab47b2b1430136c05b1be..f772576636ddb174cad8a84cd3087a43a24882a5 100644 (file)
@@ -17,12 +17,23 @@ AC_PROG_CC_C99
 gl_EARLY
 
 AC_HEADER_ASSERT
-
 LT_INIT
-
 gl_INIT
-
-CHECK_LIBPNG([1.2], [have_libpng=yes], [have_libpng=no])
+PKG_PROG_PKG_CONFIG
+
+AC_ARG_ENABLE([lbximg],
+       [AS_HELP_STRING([--enable-lbximg],
+               [build the lbximg tool (requires libpng) [default=auto]])],
+       [enable_lbximg=$enableval],
+       [enable_lbximg=auto])
+
+have_libpng=no
+if test x"$enable_lbximg" = x"auto"; then
+DX_CHECK_LIBPNG([1.2], [have_libpng=yes], [have_libpng=no])
+fi
+if test x"$enable_lbximg" = x"yes"; then
+DX_CHECK_LIBPNG([1.2], [have_libpng=yes])
+fi
 AM_CONDITIONAL([BUILD_LBXIMG], [test x"$have_libpng" = x"yes"])
 
 # A horrible combination of bugs makes this necessary for GTK+ detection.
diff --git a/m4/dxutils.m4 b/m4/dxutils.m4
new file mode 100644 (file)
index 0000000..4349ca6
--- /dev/null
@@ -0,0 +1,71 @@
+dnl Copyright (C) 2010 Nick Bowler
+dnl Copying and distribution of this file, with or without modification,
+dnl are permitted in any medium without royalty provided the copyright
+dnl notice and this notice are preserved.  This file is offered as-is,
+dnl without any warranty.
+
+m4_pattern_forbid([^_?DX_])
+
+dnl DX_PKG_CONFIG(env-base, [pkg-id], [pkg-help])
+AC_DEFUN([DX_PKG_CONFIG], [dnl
+AC_ARG_VAR(m4_toupper([$1])[_CFLAGS], [C compiler flags for ]ifelse(
+       [$3], [], [$1], [$3]))dnl
+AC_ARG_VAR(m4_toupper([$1])[_LIBS],   [linker flags for ]ifelse(
+       [$3], [], [$1], [$3]))dnl
+
+ifelse([$2], [], [], [dnl
+AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
+if test x"$PKG_CONFIG" != x; then
+       AC_MSG_CHECKING([pkg-config database for $2])
+       _PKG_CONFIG(m4_tolower([$1])[_cflags], [cflags], [$2])
+       _PKG_CONFIG(m4_tolower([$1])[_libs],   [libs],   [$2])
+       if test x$pkg_failed = xyes; then
+               errors=`$PKG_CONFIG --errors-to-stdout --print-errors $2`
+               echo "$errors" >&AS_MESSAGE_LOG_FD
+               AC_MSG_RESULT([no])
+       else
+               AC_MSG_RESULT([yes])
+       fi
+fi])])
+
+dnl _DX_CHECK_LIB([env-base], [test-program], [cflags], [libs], [test])
+AC_DEFUN([_DX_CHECK_LIB], [dnl
+if test x"$dx_cv_[]m4_tolower([$1])_found" = x"no"; then
+if ifelse([$5], [], [:], [$5]); then
+       CFLAGS="$3 $dx_old_cflags"
+       LIBS="$4 $dx_old_libs"
+
+       AC_LINK_IFELSE([$2], [dnl
+               dx_cv_[]m4_tolower([$1])_found="yes"
+               dx_cv_[]m4_tolower([$1])_cflags="$3"
+               dx_cv_[]m4_tolower([$1])_libs="$4"
+               ], [:])
+fi
+fi
+])
+
+dnl DX_CHECK_LIB([env-base], [message], [test-program],
+dnl              [[[cflags1],[libs1],[test1]],[[cflags2],[libs2],[test2]],...])
+AC_DEFUN([DX_CHECK_LIB], [dnl
+AC_LANG_PUSH([C])
+dx_old_cflags=$CFLAGS
+dx_old_libs=$LIBS
+
+AC_CACHE_CHECK([$2], [dx_cv_]m4_tolower([$1])[_found], [dnl
+AC_CACHE_VAL([dx_cv_]m4_tolower([$1])[_libs],   [dnl
+AC_CACHE_VAL([dx_cv_]m4_tolower([$1])[_cflags], [dnl
+       dx_cv_[]m4_tolower([$1])_found=no
+       m4_foreach([dx_tuple], [$4], [_DX_CHECK_LIB([$1], [$3], dx_tuple)])
+])])])
+
+if test x"$dx_cv_[]m4_tolower([$1])_found" = x"yes"; then
+       m4_toupper([$1])_CFLAGS=$dx_cv_[]m4_tolower([$1])_cflags
+       m4_toupper([$1])_LIBS=$dx_cv_[]m4_tolower([$1])_libs
+       AC_SUBST(m4_toupper([$1])[_CFLAGS])
+       AC_SUBST(m4_toupper([$1])[_LIBS])
+fi
+
+CFLAGS=$dx_old_cflags
+LIBS=$dx_old_libs
+AC_LANG_POP([C])
+])
index da3bac90a0bb4bc2f175b43c75c0307636f2a14f..52db43ef22eea544eec69cb0321a520c2095c9db 100644 (file)
@@ -4,104 +4,49 @@ dnl are permitted in any medium without royalty provided the copyright
 dnl notice and this notice are preserved.  This file is offered as-is,
 dnl without any warranty.
 
-dnl _LIBPNG_TRY_VERSION(min-version)
-AC_DEFUN([_LIBPNG_TRY_VERSION], [dnl
-shead='s/@<:@0-9@:>@@<:@0-9@:>@*/<<<&>>>/'
-sbody='s/.*<<<\(.*\)>>>.*/\1/;t'
-stail='s/.*/0/'
-png_min_major=`printf   '%s' '$1' | sed -e "$shead"1 -e "$sbody" -e "$stail"`
-png_min_minor=`printf   '%s' '$1' | sed -e "$shead"2 -e "$sbody" -e "$stail"`
-png_min_release=`printf '%s' '$1' | sed -e "$shead"3 -e "$sbody" -e "$stail"`
-png_min_build=`printf   '%s' '$1' | sed -e "$shead"4 -e "$sbody" -e "$stail"`
-png_min_status=`printf  '%s' '$1' | sed '
-       t
-       s/.*alpha.*/PNG_LIBPNG_BUILD_ALPHA/
-       t
-       s/.*beta.*/PNG_LIBPNG_BUILD_BETA/
-       t
-       s/.*rc.*/PNG_LIBPNG_BUILD_RC/
-       t
-       s/.*/PNG_LIBPNG_BUILD_STABLE/
-'`
-
-AC_CACHE_CHECK([for libpng version at least $1],
-       [libpng_cv_sufficient_ver],
-       [AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
+dnl _DX_LIBPNG_TEST_PROGRAM(major, minor, release)
+AC_DEFUN([_DX_LIBPNG_TEST_PROGRAM], [AC_LANG_PROGRAM([dnl
 #include <png.h>
-#if PNG_LIBPNG_VER_MAJOR < $png_min_major
+ifelse([$1], [], [], [dnl
+#if PNG_LIBPNG_VER_MAJOR < $1
 #  error Invalid libpng major version
-#elif PNG_LIBPNG_VER_MAJOR == $png_min_major
-#  if PNG_LIBPNG_VER_MINOR < $png_min_minor
+ifelse([$2], [], [], [dnl
+#elif PNG_LIBPNG_VER_MAJOR == $1
+#  if PNG_LIBPNG_VER_MINOR < $2
 #    error Invalid libpng minor version
-#  elif PNG_LIBPNG_VER_MINOR == $png_min_minor
-#    if PNG_LIBPNG_VER_RELEASE < $png_min_release
+ifelse([$3], [], [], [dnl
+#  elif PNG_LIBPNG_VER_MINOR == $2
+#    if PNG_LIBPNG_VER_RELEASE < $3
 #      error Invalid libpng release
-#    elif PNG_LIBPNG_VER_RELEASE == $png_min_release
-#      if PNG_LIBPNG_BUILD_BASE_TYPE < $png_min_status
-#        error Invalid libpng release status
-#      elif PNG_LIBPNG_BUILD_BASE_TYPE == $png_min_status
-#        if PNG_LIBPNG_VER_BUILD < $png_min_build
-#          error Invalid libpng build
-#        endif
-#      endif
 #    endif
+])dnl
 #  endif
+])dnl
 #endif
+])dnl
 ], [dnl
 png_structp png  = png_create_read_struct("", 0, 0, 0);
 png_infop   info = png_create_info_struct(png);
-])], [libpng_cv_sufficient_ver=yes], [libpng_cv_sufficient_ver=no])])
-])
-
-dnl CHECK_LIBPNG([min-version], [action-if-ok], [action-if-fail])
-AC_DEFUN([CHECK_LIBPNG],
-[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
-AC_ARG_VAR([LIBPNG_CFLAGS], [C compiler flags for libpng])dnl
-AC_ARG_VAR([LIBPNG_LIBS],   [linker flags for libpng])dnl
-
-if test x"$PKG_CONFIG" != x; then
-       AC_MSG_CHECKING([pkg-config database for libpng])
-       _PKG_CONFIG([libpng_cflags], [cflags], [libpng])
-       _PKG_CONFIG([libpng_libs],   [libs],   [libpng])
-       if test x$pkg_failed = xyes; then
-               errors=`$PKG_CONFIG --errors-to-stdout --print-errors libpng`
-               echo "$errors" >&AS_MESSAGE_LOG_FD
-               AC_MSG_RESULT([no])
-       else
-               if test x"$LIBPNG_CFLAGS" = x; then
-                       LIBPNG_CFLAGS=$pkg_cv_libpng_cflags
-               fi
-               if test x"$LIBPNG_LIBS" = x; then
-                       LIBPNG_LIBS=$pkg_cv_libpng_libs
-               fi
-
-               AC_MSG_RESULT([yes])
-       fi
-fi
-
-if test x"$LIBPNG_LIBS" = x; then
-       LIBPNG_LIBS=-lpng
-fi
-
-AC_LANG_PUSH([C])
-old_cflags=$CFLAGS
-old_libs=$LIBS
-CFLAGS="$LIBPNG_CFLAGS $CFLAGS"
-LIBS="$LIBPNG_LIBS $LIBS"
-
-_LIBPNG_TRY_VERSION(ifelse([$1], [], [1.0], [$1]))
-
-CFLAGS=$old_cflags
-LIBS=$old_libs
-AC_LANG_POP([C])
-
-if test x"$libpng_cv_sufficient_ver" = x"yes"; then
-       AC_SUBST([LIBPNG_CFLAGS])
-       AC_SUBST([LIBPNG_LIBS])
-       ifelse([$2], [], [true], [$2])
+])])
+
+dnl DX_CHECK_LIBPNG([min-version], [action-if-ok], [action-if-fail])
+AC_DEFUN([DX_CHECK_LIBPNG],
+[DX_PKG_CONFIG([libpng], [libpng], [libpng])
+
+DX_CHECK_LIB([libpng],
+       [for libpng[]ifelse([$1], [], [], [ version at least $1])],
+       [m4_apply([_DX_LIBPNG_TEST_PROGRAM], m4_split([$1], [\.]))], [dnl
+               [[$LIBPNG_CFLAGS], [$LIBPNG_LIBS]],
+               [[$pkg_cv_libpng_cflags], [$pkg_cv_libpng_libs],
+                       [test ! x"$pkg_failed" = x"yes"]],
+               [[], [-lpng]],
+               ])
+
+if test x"$dx_cv_libpng_found" = x"yes"; then
+       ifelse([$2], [], [:], [$2])
 else
        ifelse([$3], [], [AC_MSG_FAILURE([dnl
-libpng version >= ifelse([$1], [], [1.0], [$1]) is required.  The latest
+libpng[]ifelse([$1], [], [], [ version at least $1]) is required.  The latest
 version can be obtained from http://libpng.org/pub/png/libpng.html.
 
 If libpng is installed but was not found by this configure script,