1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-22 14:08:06 +01:00

wrlib: Moved configure's detection of PNG support to a dedicated macro

The original check was not compliant with autoconf's syntax, did not
have a very good behaviour for user and was not easy to make evolve.

The new macro:
 - uses as much as possible autoconf macros for portability and code
consistency;
 - provides a consistent behaviour on yes/no/auto (if user explicitly
enables support, do not silently disable if not found; if library is found
but not the header, complain to let user install it or explicitly disable
support);
 - makes uses of shell functions to keep generated configure smaller by
sharing reusable stuff;
 - uses an automake conditional to avoid compiling the file is support is
not enabled

It includes a typo fixed by Amadeusz S-B³awiñski.-A

Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
Christophe CURIS
2013-11-04 20:52:30 +01:00
committed by Carlos R. Mafra
parent 777bf28ab3
commit 1c21d946ec
4 changed files with 63 additions and 35 deletions

View File

@@ -657,36 +657,13 @@ dnl ===============================================
dnl PNG Support
dnl ===========
png=yes
AC_ARG_ENABLE(png, AS_HELP_STRING([--disable-png], [disable PNG support through libpng]),
png=$enableval, png=yes, png=no)
if test "$png" = yes ; then
my_libname=""
WM_CHECK_LIB(png, png_get_valid, [-lm])
if test "x$ac_cv_lib_png_png_get_valid" = xyes; then
my_libname="-lpng"
fi
dnl
dnl Retry with zlib
dnl
if test "x$my_libname" = x; then
unset ac_cv_lib_png_png_get_valid
WM_CHECK_LIB(png, png_get_valid, [-lz -lm])
if test "x$ac_cv_lib_png_png_get_valid" = xyes; then
my_libname="-lpng -lz"
fi
fi
if test "x$ac_cv_lib_png_png_get_valid" = xyes; then
WM_CHECK_HEADER(png.h)
if test "x$ac_cv_header_png_h" = xyes; then
GFXLIBS="$GFXLIBS $my_libname"
supported_gfx="$supported_gfx PNG"
AC_DEFINE(USE_PNG, 1, [define if PNG libraries are available (set by configure)])
fi
fi
fi
AC_ARG_ENABLE([png],
[AS_HELP_STRING([--disable-png], [disable PNG support through libpng])],
[AS_CASE(["$enableval"],
[yes|no], [],
[AC_MSG_ERROR([bad value $enableval for --enable-png])] )],
[enable_png=auto])
WM_IMGFMT_CHECK_PNG
dnl JPEG Support

View File

@@ -136,6 +136,58 @@ AM_CONDITIONAL([USE_JPEG], [test "x$enable_jpeg" != "xno"])dnl
]) dnl AC_DEFUN
# WM_IMGFMT_CHECK_PNG
# -------------------
#
# Check for PNG file support through 'libpng'
# The check depends on variable 'enable_png' being either:
# yes - detect, fail if not found
# no - do not detect, disable support
# auto - detect, disable if not found
#
# When found, append appropriate stuff in GFXLIBS, and append info to
# the variable 'supported_gfx'
# When not found, append info to variable 'unsupported'
AC_DEFUN_ONCE([WM_IMGFMT_CHECK_PNG],
[AC_REQUIRE([_WM_IMGFMT_CHECK_FUNCTS])
AS_IF([test "x$enable_png" = "xno"],
[unsupported="$unsupported PNG"],
[AC_CACHE_CHECK([for PNG support library], [wm_cv_imgfmt_png],
[wm_cv_imgfmt_png=no
dnl
dnl We check first if one of the known libraries is available
wm_save_LIBS="$LIBS"
for wm_arg in "-lpng" "-lpng -lz" "-lpng -lz -lm" ; do
AS_IF([wm_fn_imgfmt_try_link "png_get_valid" "$XLFLAGS $XLIBS $wm_arg"],
[wm_cv_imgfmt_png="$wm_arg" ; break])
done
LIBS="$wm_save_LIBS"
AS_IF([test "x$enable_png$wm_cv_imgfmt_png" = "xyesno"],
[AC_MSG_ERROR([explicit PNG support requested but no library found])])
AS_IF([test "x$wm_cv_imgfmt_png" != "xno"],
[dnl
dnl A library was found, now check for the appropriate header
wm_save_CFLAGS="$CFLAGS"
AS_IF([wm_fn_imgfmt_try_compile "png.h" "return 0" ""],
[],
[AC_MSG_ERROR([found $wm_cv_imgfmt_png but could not find appropriate header - are you missing libpng-dev package?])])
AS_IF([wm_fn_imgfmt_try_compile "png.h" "png_get_valid(NULL, NULL, PNG_INFO_tRNS)" ""],
[],
[AC_MSG_ERROR([found $wm_cv_imgfmt_png and header, but cannot compile - unsupported version?])])
CFLAGS="$wm_save_CFLAGS"])
])
AS_IF([test "x$wm_cv_imgfmt_png" = "xno"],
[unsupported="$unsupported PNG"
enable_png="no"],
[supported_gfx="$supported_gfx PNG"
GFXLIBS="$GFXLIBS $wm_cv_imgfmt_png"
AC_DEFINE([USE_PNG], [1],
[defined when valid PNG library with header was found])])
])
AM_CONDITIONAL([USE_PNG], [test "x$enable_png" != "xno"])dnl
]) dnl AC_DEFUN
# _WM_IMGFMT_CHECK_FUNCTS
# -----------------------
# (internal shell functions)

View File

@@ -38,7 +38,6 @@ libwraster_la_SOURCES = \
xpm.c \
xutil.c \
ppm.c \
png.c \
tiff.c
if USE_GIF
@@ -49,6 +48,10 @@ if USE_JPEG
libwraster_la_SOURCES += jpeg.c
endif
if USE_PNG
libwraster_la_SOURCES += png.c
endif
LTCOMPILE2=`echo $(LTCOMPILE) | sed -e s/-fomit-frame-pointer//`
COMPILE2=`echo $(COMPILE) | sed -e s/-fomit-frame-pointer//`

View File

@@ -22,8 +22,6 @@
#include <config.h>
#ifdef USE_PNG
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -215,5 +213,3 @@ RImage *RLoadPNG(RContext *context, const char *file)
free(png_rows);
return image;
}
#endif /* USE_PNG */