From f8c2cef5e60d31f48c44fc883bc72d2f6090834b Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 4 May 2014 14:28:08 -0700 Subject: [PATCH] Consult libpng-config more consistently. This is mainly for simplicity, but it should also avoid some future problems like the ones we recently had with NetBSD. * configure.ac (LIBPNG): Configure after LIBZ. Use libpng-config for cflags, too. Append -lz if we're not already doing that with LIBZ. Do not bother appending -lm, since we always append that. Coalesce some duplicate code. * src/Makefile.in (PNG_CFLAGS): New var. (ALL_CFLAGS): Use it. * src/image.c [HAVE_PNG]: Don't worry about , as CFLAGS now handles this. Fixes: debbugs:17339 --- ChangeLog | 8 ++++ configure.ac | 113 ++++++++++++++++++++++-------------------------- src/ChangeLog | 16 +++---- src/Makefile.in | 2 + src/image.c | 4 -- 5 files changed, 67 insertions(+), 76 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3d6cc362b67..d9837bc3c12 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2014-05-04 Paul Eggert + Consult libpng-config more consistently (Bug#17339). + This is mainly for simplicity, but it should also avoid + some future problems like the ones we recently had with NetBSD. + * configure.ac (LIBPNG): Configure after LIBZ. Use libpng-config + for cflags, too. Append -lz if we're not already doing that with + LIBZ. Do not bother appending -lm, since we always append that. + Coalesce some duplicate code. + * autogen.sh: Use ‘"’ to quote a message that often contains ‘'’. Require ImageMagick >= 6.3.5, due to PixelSetMagickColor (Bug#17339). diff --git a/configure.ac b/configure.ac index 47bb458a767..1381f3669dd 100644 --- a/configure.ac +++ b/configure.ac @@ -3014,67 +3014,6 @@ elif test "${HAVE_X11}" = "yes" || test "${HAVE_W32}" = "yes"; then fi AC_SUBST(LIBJPEG) -### Use -lpng if available, unless `--with-png=no'. -### mingw32 doesn't use -lpng, since it loads the library dynamically. -HAVE_PNG=no -LIBPNG= -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 - #else - # include - #endif - ]]) - 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 - #else - # include - #endif - ]]) - fi -fi -AC_SUBST(LIBPNG) - HAVE_ZLIB=no LIBZ= if test "${with_zlib}" != "no"; then @@ -3094,6 +3033,58 @@ if test "${HAVE_ZLIB}" = "yes"; then fi AC_SUBST(LIBZ) +### Use -lpng if available, unless `--with-png=no'. +HAVE_PNG=no +LIBPNG= +PNG_CFLAGS= +if test "${with_png}" != no; then + # mingw32 loads the library dynamically. + if test "$opsys" = mingw32; then + AC_CHECK_HEADER([png.h], [HAVE_PNG=yes]) + elif 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 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' + if test "$ac_cv_header_png_h" != yes; then + PNG_CFLAGS=-I/usr/include/libpng + fi + break], + [], [-lz -lm])]) + fi + # $LIBPNG requires explicit -lz in some cases. + # We don't know what those cases are, exactly, so play it safe and + # append -lz to any nonempty $LIBPNG, unless we're already using LIBZ. + if test -n "$LIBPNG" && test -z "$LIBZ"; then + LIBPNG="$LIBPNG -lz" + 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 + ]]) + CFLAGS=$SAVE_CFLAGS +fi +AC_SUBST(LIBPNG) +AC_SUBST(PNG_CFLAGS) ### Use -ltiff if available, unless `--with-tiff=no'. ### mingw32 doesn't use -ltiff, since it loads the library dynamically. diff --git a/src/ChangeLog b/src/ChangeLog index e06163c32ce..01569db30e6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,8 +1,10 @@ 2014-05-04 Paul Eggert - Revert recent libpng changes (Bug#17339). - * Makefile.in (PNG_CFLAGS): Remove; all uses removed. - * image.c [HAVE_LIBPNG_PNG_H]: Include , not . + 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 , as + CFLAGS now handles this. 2014-05-03 Paul Eggert @@ -15,14 +17,6 @@ * buffer.c (overlay_strings): Fix the wording of the commentary. -2014-05-02 Paul Eggert - - 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 , as - CFLAGS now handles this. - 2014-05-01 Glenn Morris * floatfns.c (Fisnan): diff --git a/src/Makefile.in b/src/Makefile.in index 388923596c9..c35e38bb290 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -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) \ diff --git a/src/image.c b/src/image.c index d558540c6e7..c26c0db2b4f 100644 --- a/src/image.c +++ b/src/image.c @@ -22,12 +22,8 @@ along with GNU Emacs. If not, see . */ #include #ifdef HAVE_PNG -#if defined HAVE_LIBPNG_PNG_H -# include -#else # include #endif -#endif #include #include -- 2.39.5