]> git.eshelyaron.com Git - emacs.git/commitdiff
Consult libpng-config more consistently.
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 2 May 2014 19:34:03 +0000 (12:34 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 2 May 2014 19:34:03 +0000 (12:34 -0700)
* configure.ac (edit_cflags): Move this up and to the top level,
so that PNG_CFLAGS can use it too.
(PNG_CFLAGS): New var.
(png_longjmp): Use PNG_CFLAGS when checking.
(LIBPNG): Be consistent about -lpng16 etc; e.g., don't use -lpng16
in some places and -lpng in others.  Test libpng-config's exit
status.  If it succeeds, use its output rather than appending -lz -lm.
* src/Makefile.in (PNG_CFLAGS): New var.
(ALL_CFLAGS): Use it.
* src/image.c [HAVE_PNG]: Don't worry about <libpng/png.h>, as
CFLAGS now handles this.

Fixes: debbugs:17339
ChangeLog
configure.ac
src/ChangeLog
src/Makefile.in
src/image.c

index c79e1b019765ea140afc8132d344f5b82c8ac9e7..5b583849bd7014ec9f50488c3ef9d6b95622dc0e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2014-05-02  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Consult libpng-config more consistently (Bug#17339).
+       * configure.ac (edit_cflags): Move this up and to the top level,
+       so that PNG_CFLAGS can use it too.
+       (PNG_CFLAGS): New var.
+       (png_longjmp): Use PNG_CFLAGS when checking.
+       (LIBPNG): Be consistent about -lpng16 etc; e.g., don't use -lpng16
+       in some places and -lpng in others.  Test libpng-config's exit
+       status.  If it succeeds, use its output rather than appending -lz -lm.
+
 2014-05-01  Glenn Morris  <rgm@gnu.org>
 
        * configure.ac (LIBPNG): Consult libpng-config for the precise
index 5aed265849e1027b55219683f8b89add1c92b678..ee4826f1574604e6e527506edaf3a1114f77b814 100644 (file)
@@ -897,6 +897,12 @@ else
   AC_SUBST([GNULIB_WARN_CFLAGS])
 fi
 
+edit_cflags="
+  s,///*,/,g
+  s/^/ /
+  s/ -I/ $isystem/g
+  s/^ //
+"
 
 
 dnl Some other nice autoconf tests.
@@ -1340,12 +1346,6 @@ AC_DEFUN([PKG_CHECK_MODULES], [
         if "$PKG_CONFIG" --exists "$2" 2>&AS_MESSAGE_LOG_FD &&
           $1_CFLAGS=`"$PKG_CONFIG" --cflags "$2" 2>&AS_MESSAGE_LOG_FD` &&
           $1_LIBS=`"$PKG_CONFIG" --libs "$2" 2>&AS_MESSAGE_LOG_FD`; then
-           edit_cflags="
-             s,///*,/,g
-             s/^/ /
-             s/ -I/ $isystem/g
-             s/^ //
-           "
            $1_CFLAGS=`AS_ECHO(["$$1_CFLAGS"]) | sed -e "$edit_cflags"`
            $1_LIBS=`AS_ECHO(["$$1_LIBS"]) | sed -e 's,///*,/,g'`
             AC_MSG_RESULT([yes CFLAGS='$$1_CFLAGS' LIBS='$$1_LIBS'])
@@ -3070,62 +3070,55 @@ AC_SUBST(LIBJPEG)
 ### mingw32 doesn't use -lpng, since it loads the library dynamically.
 HAVE_PNG=no
 LIBPNG=
+PNG_CFLAGS=
 if test "${opsys}" = "mingw32"; then
   if test "${with_png}" != "no"; then
-    AC_CHECK_HEADER(png.h, HAVE_PNG=yes, HAVE_PNG=no)
-  fi
-  if test "${HAVE_PNG}" = "yes"; then
-    AC_DEFINE(HAVE_PNG, 1, [Define to 1 if you have the png library (-lpng).])
-
-    AC_CHECK_DECL(png_longjmp,
-      [],
-      [AC_DEFINE(PNG_DEPSTRUCT, [],
-        [Define to empty to suppress deprecation warnings when building
-         with --enable-gcc-warnings and with libpng versions before 1.5,
-         which lack png_longjmp.])],
-      [[#ifdef HAVE_LIBPNG_PNG_H
-       # include <libpng/png.h>
-       #else
-       # include <png.h>
-       #endif
-      ]])
+    AC_CHECK_HEADER([png.h], [HAVE_PNG=yes])
   fi
 elif test "${HAVE_X11}" = "yes" || test "${HAVE_W32}" = "yes"; then
   if test "${with_png}" != "no"; then
-    # Debian unstable as of July 2003 has multiple libpngs, and puts png.h
-    # in /usr/include/libpng.
-    AC_CHECK_HEADERS(png.h libpng/png.h, break)
-    if test "$ac_cv_header_png_h" = yes || test "$ac_cv_header_libpng_png_h" = yes ; then
-      AC_CHECK_LIB(png, png_get_channels, HAVE_PNG=yes, , -lz -lm)
-    fi
-  fi
 
-  if test "${HAVE_PNG}" = "yes"; then
-    AC_DEFINE(HAVE_PNG, 1, [Define to 1 if you have the png library.])
-
-    dnl Some systems, eg NetBSD 6, only provide eg "libpng16", not "libpng".
-    lpng=`libpng-config --libs 2> /dev/null`
-    case $lpng in
-      -l*) : ;;
-      *) lpng="-lpng" ;;
-    esac
-    LIBPNG="$lpng -lz -lm"
-
-    AC_CHECK_DECL(png_longjmp,
-      [],
-      [AC_DEFINE(PNG_DEPSTRUCT, [],
-        [Define to empty to suppress deprecation warnings when building
-         with --enable-gcc-warnings and with libpng versions before 1.5,
-         which lack png_longjmp.])],
-      [[#ifdef HAVE_LIBPNG_PNG_H
-       # include <libpng/png.h>
-       #else
-       # include <png.h>
-       #endif
-      ]])
+    dnl NetBSD 6 provides libpng16, not libpng.
+    if png_cflags=`(libpng-config --cflags) 2>&AS_MESSAGE_LOG_FD` &&
+       png_libs=`(libpng-config --libs) 2>&AS_MESSAGE_LOG_FD`
+    then
+      HAVE_PNG=yes
+      PNG_CFLAGS=`AS_ECHO(["$png_cflags"]) | sed -e "$edit_cflags"`
+      LIBPNG=$png_libs
+    else
+      # libpng-config does not work; configure it by hand.
+      # Debian unstable as of July 2003 has multiple libpngs, and puts png.h
+      # in /usr/include/libpng.
+      AC_CHECK_HEADERS([png.h libpng/png.h],
+       [AC_CHECK_LIB([png], [png_get_channels],
+          [HAVE_PNG=yes
+           LIBPNG='-lpng -lz -lm'
+           if test "$ac_cv_header_libpng_png_h" = yes; then
+             PNG_CFLAGS=-I/usr/include/libpng
+           fi],
+          [],
+          [-lz -lm])
+        break])
+    fi
   fi
 fi
+if test $HAVE_PNG = yes; then
+  AC_DEFINE([HAVE_PNG], [1], [Define to 1 if you have the png library.])
+
+  SAVE_CFLAGS=$CFLAGS
+  CFLAGS="$CFLAGS $PNG_CFLAGS"
+  AC_CHECK_DECL([png_longjmp],
+    [],
+    [AC_DEFINE([PNG_DEPSTRUCT], [],
+       [Define to empty to suppress deprecation warnings when building
+       with --enable-gcc-warnings and with libpng versions before 1.5,
+       which lack png_longjmp.])],
+    [[#include <png.h>
+    ]])
+  CFLAGS=$SAVE_CFLAGS
+fi
 AC_SUBST(LIBPNG)
+AC_SUBST(PNG_CFLAGS)
 
 HAVE_ZLIB=no
 LIBZ=
index 12a0cd63dc0006c75130e6e1dbb5faed333ccd1a..29fb2dd1edfee933adfa4a59b0996b64a083dbf6 100644 (file)
@@ -1,3 +1,11 @@
+2014-05-02  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Consult libpng-config more consistently (Bug#17339).
+       * Makefile.in (PNG_CFLAGS): New var.
+       (ALL_CFLAGS): Use it.
+       * image.c [HAVE_PNG]: Don't worry about <libpng/png.h>, as
+       CFLAGS now handles this.
+
 2014-05-01  Glenn Morris  <rgm@gnu.org>
 
        * floatfns.c (Fisnan):
index 388923596c9fb853345f343f048be11d682f8679..c35e38bb290ca324c4d7de6ce67f7b1400d3f430 100644 (file)
@@ -77,6 +77,7 @@ C_SWITCH_MACHINE=@C_SWITCH_MACHINE@
 C_SWITCH_SYSTEM=@C_SWITCH_SYSTEM@
 
 GNUSTEP_CFLAGS=@GNUSTEP_CFLAGS@
+PNG_CFLAGS=@PNG_CFLAGS@
 
 ## Define C_SWITCH_X_SITE to contain any special flags your compiler
 ## may need to deal with X Windows.  For instance, if you've defined
@@ -325,6 +326,7 @@ ALL_CFLAGS=-Demacs $(MYCPPFLAGS) -I. -I$(srcdir) \
   -I$(lib) -I$(srcdir)/../lib \
   $(C_SWITCH_MACHINE) $(C_SWITCH_SYSTEM) $(C_SWITCH_X_SITE) \
   $(GNUSTEP_CFLAGS) $(CFLAGS_SOUND) $(RSVG_CFLAGS) $(IMAGEMAGICK_CFLAGS) \
+  $(PNG_CFLAGS) \
   $(LIBXML2_CFLAGS) $(DBUS_CFLAGS) $(XRANDR_CFLAGS) $(XINERAMA_CFLAGS) \
   $(SETTINGS_CFLAGS) $(FREETYPE_CFLAGS) $(FONTCONFIG_CFLAGS) \
   $(LIBOTF_CFLAGS) $(M17N_FLT_CFLAGS) $(DEPFLAGS) \
index 4133aaa7621b630d054a1e580afe1c66f89dfef0..dcbe5942b32945f0d7ec288443d9e401b62aeef2 100644 (file)
@@ -22,12 +22,8 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <unistd.h>
 
 #ifdef HAVE_PNG
-#if defined HAVE_LIBPNG_PNG_H
-# include <libpng/png.h>
-#else
 # include <png.h>
 #endif
-#endif
 
 #include <setjmp.h>
 #include <c-ctype.h>