]> git.draconx.ca Git - liblbx.git/commitdiff
build: Import the libpng check from marksim.
authorNick Bowler <draconx@users.sourceforge.net>
Sun, 1 Nov 2009 18:37:26 +0000 (13:37 -0500)
committerNick Bowler <draconx@users.sourceforge.net>
Sun, 1 Nov 2009 21:41:05 +0000 (16:41 -0500)
This replaces the PKG_CHECK macros from transcode.

.gitignore
Makefile.am
acinclude.m4 [deleted file]
configure.ac
m4/.gitignore [new file with mode: 0644]
m4/libpng.m4 [new file with mode: 0644]
src/Makefile.am

index a58fa89d994ca5c15440b669a090fabbc7439988..92b03e35b18460103320fb8681e19ab6f0beb8d5 100644 (file)
@@ -21,7 +21,4 @@ depcomp
 install-sh
 stamp-h1
 
-pkg_err_file
-pkg_rpt_file
-
 liblbx-*.tar.gz
index 330a7645e54d91bfa5255d86468acce36a4a0b4e..98eeac895b1041b35dbf94fe3ee664b7c7ccd11e 100644 (file)
@@ -1,4 +1,3 @@
 ACLOCAL_AMFLAGS = -I m4
 
 SUBDIRS = src doc/man
-DISTCLEANFILES = pkg_err_file pkg_rpt_file
diff --git a/acinclude.m4 b/acinclude.m4
deleted file mode 100644 (file)
index 89db997..0000000
+++ /dev/null
@@ -1,229 +0,0 @@
-dnl Borrowed from Transcode (http://www.transcoding.org/cgi-bin/transcode)
-
-dnl PKG_INIT(rptfile, errfile)
-dnl
-AC_DEFUN([PKG_INIT],
-[
-pkg_err="no"
-pkg_err_file="pkg_err_file"
-pkg_rpt_file="pkg_rpt_file"
-
-if test x"$1" != x"" ; then
-  pkg_rpt_file="$1"
-fi
-echo -n > $pkg_rpt_file
-
-if test x"$2" != x"" ; then
-  pkg_err_file="$2"
-fi
-echo -n > $pkg_err_file
-])
-
-
-dnl PKG_ERROR(name, object, req-enable, pkg, url, [error message])
-AC_DEFUN([PKG_ERROR],
-[
-pkg_err="yes"
-this_pkg_err="yes"
-
-prob=""
-if test x"$3" = x"required" ; then
-  prob="requirement failed"
-else
-  prob="option '--enable-$1' failed"
-fi
-
-cat >> $pkg_err_file <<EOF
-ERROR: $prob: $6
-$2 can be found in the following packages:
-  $4  $5
-
-EOF
-])
-
-
-dnl PKG_CHECK(pkg-name, def-enabled, var-name, pkgconfig-name, conf-script,
-dnl     header, lib, symbol)
-dnl Test for pkg-name, and define var-name_CFLAGS and var-name_LIBS
-dnl   and HAVE_var-name if found
-dnl
-dnl 1 name          name of package; required (pkg-config name if applicable)
-dnl 2 req-enable    enable  by default, 'required', 'yes' or 'no'; required
-dnl 3 var-name      name stub for variables, preferably uppercase; required
-dnl 4 conf-script   name of "-config" script or 'no'
-dnl 5 header        header file to check or 'none'
-dnl 6 lib           library to check or 'none'
-dnl 7 symbol        symbol from the library to check or ''
-dnl 8 pkg           package (pkg-config name if applicable)
-dnl 9 url           homepage for the package
-
-AC_DEFUN([PKG_CHECK],
-[
-if test x"$2" != x"required" ; then
-  AC_MSG_CHECKING([whether $1 support is requested])
-  AC_ARG_ENABLE($1,
-    AC_HELP_STRING([--enable-$1],
-      [build with $1 support ($2)]),
-    [case "${enableval}" in
-      yes) ;;
-      no)  ;;
-      *) AC_MSG_ERROR(bad value ${enableval} for --enable-$1) ;;
-    esac],
-    enable_$1="$2")
-  AC_MSG_RESULT($enable_$1)
-else
-  enable_$1="yes"
-fi
-
-AC_ARG_WITH($1-prefix,
-  AC_HELP_STRING([--with-$1-prefix=PFX],
-    [prefix where $1 is installed (/usr)]),
-  w_$1_p="$withval", w_$1_p="")
-
-AC_ARG_WITH($1-includes,
-  AC_HELP_STRING([--with-$1-includes=DIR],
-    [directory where $1 headers ($5) are installed (/usr/include)]),
-  w_$1_i="$withval", w_$1_i="")
-
-AC_ARG_WITH($1-libs,
-  AC_HELP_STRING([--with-$1-libs=DIR],
-    [directory where $1 libararies (lib$6.so) are installed (/usr/lib)]),
-  w_$1_l="$withval", w_$1_l="")
-
-have_$1="no"
-this_pkg_err="no"
-
-if test x"$enable_$1" = x"yes" ; then
-
-  dnl pkg-config
-
-  pkg_config_$1="no"
-  AC_MSG_CHECKING([for pkgconfig support for $1])
-  if test x"$PKG_CONFIG" != x"no" ; then
-    if $PKG_CONFIG $8 --exists ; then
-      pkg_config_$1="yes"
-    fi
-  fi
-  AC_MSG_RESULT($pkg_config_$1)
-
-  dnl *-config
-
-  if test x"$4" != x"no" ; then
-    if test x"$w_$1_p" != x"" ; then
-      if test -x $w_$1_p/bin/$4 ; then
-        $1_config="$w_$1_p/bin/$4"
-      fi
-    fi
-    AC_PATH_PROG($1_config, $4, no)
-  else
-    $1_config="no"
-  fi
-
-  # get and test the _CFLAGS
-
-  AC_MSG_CHECKING([how to determine $3_CFLAGS])
-  if test x"$w_$1_i" != x"" ; then
-    $1_ii="-I$w_$1_i"
-    AC_MSG_RESULT(user)
-  else
-    if test x"$pkg_config_$1" != x"no" ; then
-      $1_ii="`$PKG_CONFIG $8 --cflags`"
-      AC_MSG_RESULT(pkg-config)
-    else
-      if test x"$$1_config" != x"no" ; then
-        $1_ii="`$$1_config --cflags`"
-        AC_MSG_RESULT($$1_config)
-      else
-        if test x"$w_$1_p" != x"" ; then
-          $1_ii="-I$w_$1_p/include"
-          AC_MSG_RESULT(prefix)
-        else
-          $1_ii="-I/usr/include"
-          AC_MSG_RESULT(default)
-        fi
-      fi
-    fi
-  fi
-  ipaths="" ; xi=""
-  for i in $$1_ii ; do
-    case $i in
-      -I*) ipaths="$ipaths $i" ;;
-        *) xi="$xi $i" ;;
-    esac
-  done
-  $1_ii="$ipaths"
-  $1_ii="`echo $$1_ii | sed -e 's/  */ /g'`"
-  $3_EXTRA_CFLAGS="$$3_EXTRA_CFLAGS $xi"
-  $3_EXTRA_CFLAGS="`echo $$3_EXTRA_CFLAGS | sed -e 's/  */ /g'`"
-
-  if test x"$5" != x"none" ; then
-    save_CPPFLAGS="$CPPFLAGS"
-    CPPFLAGS="$CPPFLAGS $$1_ii"
-    AC_CHECK_HEADER([$5],
-      [$3_CFLAGS="$$1_ii"],
-      [PKG_ERROR($1, $5, $2, $8, $9, [cannot compile $5])])
-    CPPFLAGS="$save_CPPFLAGS"
-  fi
-
-  # get and test the _LIBS
-
-  AC_MSG_CHECKING([how to determine $3_LIBS])
-  if test x"$w_$1_l" != x"" ; then
-    $1_ll="-L$w_$1_l"
-    AC_MSG_RESULT(user)
-  else
-    if test x"$pkg_config_$1" != x"no" ; then
-      $1_ll="`$PKG_CONFIG $8 --libs`"
-      AC_MSG_RESULT(pkg-config)
-    else
-      if test x"$$1_config" != x"no" ; then
-        $1_ll="`$$1_config --libs`"
-        AC_MSG_RESULT($$1_config)
-      else
-        if test x"$w_$1_p" != x"" ; then
-          $1_ll="-L$w_$1_p${deflib}"
-          AC_MSG_RESULT(prefix)
-        else
-          $1_ll="-L/usr${deflib}"
-          AC_MSG_RESULT(default)
-        fi
-      fi
-    fi
-  fi
-  lpaths="" ; xlibs="" ; xlf=""
-  for l in $$1_ll ; do
-    case $l in
-      -L*) lpaths="$lpaths $l" ;;
-      -l*) test x"$l" != x"-l$6" && xlibs="$xlibs $l" ;;
-        *) xlf="$xlf $l" ;;
-    esac
-  done
-  $1_ll="$lpaths"
-  $1_ll="`echo $$1_ll | sed -e 's/  */ /g'`"
-  xl=""
-  for i in $xlibs $xlf ; do
-    echo " $$3_EXTRA_LIBS " | grep -vq " $i " && xl="$xl $i"
-  done
-  $3_EXTRA_LIBS="$$3_EXTRA_LIBS $xl"
-  $3_EXTRA_LIBS="`echo $$3_EXTRA_LIBS | sed -e 's/  */ /g'`"
-
-  if test x"$6" != x"none" ; then
-    save_LDFLAGS="$LDFLAGS"
-    LDFLAGS="$LDFLAGS $$1_ll"
-    AC_CHECK_LIB([$6], [$7],
-      [$3_LIBS="$$1_ll -l$6 $$3_EXTRA_LIBS"],
-      [PKG_ERROR($1, lib$6, $2, $8, $9, [cannot link against lib$6])],
-      [$$3_EXTRA_LIBS])
-    LDFLAGS="$save_LDFLAGS"
-  fi
-
-  if test x"$this_pkg_err" = x"no" ; then
-    have_$1="yes"
-  fi
-
-else
-  $3_CFLAGS=""
-  $3_LIBS=""  
-fi
-])
-
index 9d6b209ac7fd054f5cfced57b8f92ac1ebd8f304..bbc14fbcd2f1b3957c0bccd41543f539add91160 100644 (file)
@@ -10,20 +10,9 @@ AC_PROG_CC_C99
 AC_HEADER_ASSERT
 AC_C_BIGENDIAN
 
-# pkg-config
-PKG_INIT
-if test x"$PKG_CONFIG" = x""; then
-       AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
-fi
-
 LT_INIT
 
-# libpng
-PKG_CHECK(libpng, yes, [PNG], [libpng-config], [png.h], png,
-          png_create_write_struct, libpng, [http://www.libpng.org/])
-AC_SUBST(PNG_CFLAGS)
-AC_SUBST(PNG_LIBS)
-
+CHECK_LIBPNG([1.2], [have_libpng=yes], [have_libpng=no])
 AM_CONDITIONAL([BUILD_LBXIMG], [test x"$have_libpng" = x"yes"])
 
 AC_CONFIG_FILES([
diff --git a/m4/.gitignore b/m4/.gitignore
new file mode 100644 (file)
index 0000000..f6749fb
--- /dev/null
@@ -0,0 +1,5 @@
+lt~obsolete.m4
+ltoptions.m4
+ltsugar.m4
+ltversion.m4
+libtool.m4
diff --git a/m4/libpng.m4 b/m4/libpng.m4
new file mode 100644 (file)
index 0000000..5adeb0f
--- /dev/null
@@ -0,0 +1,109 @@
+dnl Copyright (C) 2009 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.
+
+dnl _LIBPNG_TRY_VERSION(min-version)
+AC_DEFUN([_LIBPNG_TRY_VERSION], [dnl
+sedhead='s/@<:@0-9@:>@@<:@0-9@:>@*/<<<&>>>/'
+sedtail='s/.*<<<\(.*\)>>>.*/\1/;t;s/.*/0/'
+png_min_major=`printf   '%s' '$1' | sed -e "$sedhead"1 -e "$sedtail"`
+png_min_minor=`printf   '%s' '$1' | sed -e "$sedhead"2 -e "$sedtail"`
+png_min_release=`printf '%s' '$1' | sed -e "$sedhead"3 -e "$sedtail"`
+png_min_build=`printf   '%s' '$1' | sed -e "$sedhead"4 -e "$sedtail"`
+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
+#include <png.h>
+#if PNG_LIBPNG_VER_MAJOR < $png_min_major
+#  error Invalid libpng major version
+#elif PNG_LIBPNG_VER_MAJOR == $png_min_major
+#  if PNG_LIBPNG_VER_MINOR < $png_min_minor
+#    error Invalid libpng minor version
+#  elif PNG_LIBPNG_VER_MINOR == $png_min_minor
+#    if PNG_LIBPNG_VER_RELEASE < $png_min_release
+#      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
+#  endif
+#endif
+], [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])
+else
+       ifelse([$3], [], [AC_MSG_FAILURE([dnl
+libpng version >= ifelse([$1], [], [1.0], [$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,
+consider adjusting LIBPNG_CFLAGS and/or LIBPNG_LIBS as necessary.
+
+If pkg-config is installed, it may help to adjust PKG_CONFIG_PATH
+if libpng is installed in a non-standard prefix.
+])], [$3])
+fi
+])
index 3602e247211d7f1b2860e3cc30d61a6170d919bc..13e47a1c8cf42ef8e0b16ad4cc98b71fd70f51f2 100644 (file)
@@ -12,7 +12,6 @@ lbxtool_LDADD     = liblbx.la
 if BUILD_LBXIMG
 bin_PROGRAMS     += lbximg
 lbximg_SOURCES    = tools.h lbximg.c
-lbximg_LDADD      = liblbx.la
-lbximg_CFLAGS     = $(PNG_CFLAGS)
-lbximg_LDFLAGS    = $(PNG_LIBS)
+lbximg_LDADD      = liblbx.la $(LIBPNG_LIBS)
+lbximg_CFLAGS     = $(LIBPNG_CFLAGS)
 endif