From: Christophe CURIS <[email protected]>

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

Signed-off-by: Christophe CURIS <[email protected]>
---
 configure.ac          | 57 ++++++++++--------------------------------------
 m4/wm_imgfmt_check.m4 | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++
 wrlib/Makefile.am     |  7 ++++--
 wrlib/tiff.c          |  4 ----
 4 files changed, 76 insertions(+), 52 deletions(-)

diff --git a/configure.ac b/configure.ac
index 7c65c30..605bc8f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -690,55 +690,20 @@ WM_IMGFMT_CHECK_GIF
 
 dnl TIFF Support
 dnl ============
-AC_ARG_ENABLE(tiff, 
-AS_HELP_STRING([--disable-tiff], [disable use of TIFF images through libtiff]),
-       tif=$enableval, tif=yes, tif=no)
-
-#
-# TIFF can optionally have JPEG and/or zlib support. Must find out
-# when they are supported so that correct library flags are passed during
-# detection and linkage
-#
-#
-# By default use xpm icons if tiff is not found.
-ICONEXT="xpm"
-#
-
-if test "$tif" = yes; then
-    my_libname=""
-    WM_CHECK_LIB(tiff, TIFFGetVersion, [-lm])
-    if test "x$ac_cv_lib_tiff_TIFFGetVersion" = xyes; then
-       my_libname="-ltiff"
-    fi
-dnl
-dnl Retry with zlib
-dnl
-    unset ac_cv_lib_tiff_TIFFGetVersion
-    if test "x$my_libname" = x; then
-       WM_CHECK_LIB(tiff, TIFFGetVersion, [$ljpeg -lz -lm])
-       if test "x$ac_cv_lib_tiff_TIFFGetVersion" = xyes; then
-           my_libname="-ltiff -lz"
-       fi
-    fi
+AC_ARG_ENABLE([tiff],
+    [AS_HELP_STRING([--disable-tiff], [disable use of TIFF images through 
libtiff])],
+    [AS_CASE(["$enableval"],
+        [yes|no], [],
+        [AC_MSG_ERROR([bad value $enableval for --enable-tiff])] )],
+    [enable_tiff=auto])
+WM_IMGFMT_CHECK_TIFF
 
-    if test "x$my_libname" = x; then
-       WM_CHECK_LIB(tiff34, TIFFGetVersion, [$ljpeg -lm])
-       if test "x$ac_cv_lib_tiff34_TIFFGetVersion" = xyes; then
-           my_libname="-ltiff34"
-       fi
-    fi
 
+# Choice of the default format for icons
+AS_IF([test "x$enable_tiff" != "xno"],
+    [ICONEXT="tiff"],
+    [ICONEXT="xpm"])
 
-    if test "x$my_libname" != x; then
-       WM_CHECK_HEADER(tiffio.h)
-       if test "x$ac_cv_header_tiffio_h" = xyes; then
-           GFXLIBS="$my_libname $GFXLIBS"
-           ICONEXT="tiff"
-            supported_gfx="$supported_gfx TIFF"
-            AC_DEFINE(USE_TIFF, 1, [define if TIFF libraries are available 
(set by configure)])            
-       fi
-    fi
-fi
 
 LIBRARY_SEARCH_PATH="$lib_search_path"
 HEADER_SEARCH_PATH="$inc_search_path"
diff --git a/m4/wm_imgfmt_check.m4 b/m4/wm_imgfmt_check.m4
index 2d53e43..2ab9a17 100644
--- a/m4/wm_imgfmt_check.m4
+++ b/m4/wm_imgfmt_check.m4
@@ -188,6 +188,66 @@ AM_CONDITIONAL([USE_PNG], [test "x$enable_png" != 
"xno"])dnl
 ]) dnl AC_DEFUN
 
 
+# WM_IMGFMT_CHECK_TIFF
+# --------------------
+#
+# Check for TIFF file support through 'libtiff'
+# The check depends on variable 'enable_tiff' 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_TIFF],
+[AC_REQUIRE([_WM_IMGFMT_CHECK_FUNCTS])
+AS_IF([test "x$enable_tiff" = "xno"],
+    [unsupported="$unsupported TIFF"],
+    [AC_CACHE_CHECK([for TIFF support library], [wm_cv_imgfmt_tiff],
+        [wm_cv_imgfmt_tiff=no
+         dnl
+         dnl We check first if one of the known libraries is available
+         wm_save_LIBS="$LIBS"
+         for wm_arg in "-ltiff"  \
+             dnl TIFF can have a dependancy over zlib
+             "-ltiff -lz" "-ltiff -lz -lm"  \
+             dnl It may also have a dependancy to jpeg_lib
+             "-ltiff -ljpeg" "-ltiff -ljpeg -lz" "-ltiff -ljpeg -lz -lm"  \
+             dnl There is also a possible dependancy on JBIGKit
+             "-ltiff -ljpeg -ljbig -lz"  \
+             dnl Probably for historical reasons?
+             "-ltiff34" "-ltiff34 -ljpeg" "-ltiff34 -ljpeg -lm" ; do
+           AS_IF([wm_fn_imgfmt_try_link "TIFFGetVersion" "$XLFLAGS $XLIBS 
$wm_arg"],
+             [wm_cv_imgfmt_tiff="$wm_arg" ; break])
+         done
+         LIBS="$wm_save_LIBS"
+         AS_IF([test "x$enable_tiff$wm_cv_imgfmt_tiff" = "xyesno"],
+           [AC_MSG_ERROR([explicit TIFF support requested but no library 
found])])
+         AS_IF([test "x$wm_cv_imgfmt_tiff" != "xno"],
+           [dnl
+            dnl A library was found, now check for the appropriate header
+            wm_save_CFLAGS="$CFLAGS"
+            AS_IF([wm_fn_imgfmt_try_compile "tiffio.h" "return 0" ""],
+              [],
+              [AC_MSG_ERROR([found $wm_cv_imgfmt_tiff but could not find 
appropriate header - are you missing libtiff-dev package?])])
+            AS_IF([wm_fn_imgfmt_try_compile "tiffio.h" 'TIFFOpen(filename, 
"r")' ""],
+              [],
+              [AC_MSG_ERROR([found $wm_cv_imgfmt_tiff and header, but cannot 
compile - unsupported version?])])
+            CFLAGS="$wm_save_CFLAGS"])
+         ])
+    AS_IF([test "x$wm_cv_imgfmt_tiff" = "xno"],
+        [unsupported="$unsupported TIFF"
+         enable_tiff="no"],
+        [supported_gfx="$supported_gfx TIFF"
+         GFXLIBS="$GFXLIBS $wm_cv_imgfmt_tiff"
+         AC_DEFINE([USE_TIFF], [1],
+           [defined when valid TIFF library with header was found])])
+    ])
+AM_CONDITIONAL([USE_TIFF], [test "x$enable_tiff" != "xno"])dnl
+]) dnl AC_DEFUN
+
+
 # _WM_IMGFMT_CHECK_FUNCTS
 # -----------------------
 # (internal shell functions)
diff --git a/wrlib/Makefile.am b/wrlib/Makefile.am
index a4ede86..5f4946a 100644
--- a/wrlib/Makefile.am
+++ b/wrlib/Makefile.am
@@ -37,8 +37,7 @@ libwraster_la_SOURCES =       \
        nxpm.c          \
        xpm.c           \
        xutil.c         \
-       ppm.c           \
-       tiff.c
+       ppm.c
 
 if USE_GIF
 libwraster_la_SOURCES += gif.c
@@ -52,6 +51,10 @@ if USE_PNG
 libwraster_la_SOURCES += png.c
 endif
 
+if USE_TIFF
+libwraster_la_SOURCES += tiff.c
+endif
+
 LTCOMPILE2=`echo $(LTCOMPILE) | sed -e s/-fomit-frame-pointer//`
 COMPILE2=`echo $(COMPILE) | sed -e s/-fomit-frame-pointer//`
 
diff --git a/wrlib/tiff.c b/wrlib/tiff.c
index a54596d..9bf033b 100644
--- a/wrlib/tiff.c
+++ b/wrlib/tiff.c
@@ -22,8 +22,6 @@
 
 #include <config.h>
 
-#ifdef USE_TIFF
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -141,5 +139,3 @@ RImage *RLoadTIFF(const char *file, int index)
 
        return image;
 }
-
-#endif                         /* USE_TIFF */
-- 
1.8.4.rc3


-- 
To unsubscribe, send mail to [email protected].

Reply via email to