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          | 53 ++++++++++++++++++-----------------------------
 m4/wm_imgfmt_check.m4 | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++
 wrlib/Makefile.am     |  5 ++++-
 wrlib/jpeg.c          |  4 ----
 4 files changed, 81 insertions(+), 38 deletions(-)

diff --git a/configure.ac b/configure.ac
index 4ebce21..63d1729 100644
--- a/configure.ac
+++ b/configure.ac
@@ -691,26 +691,13 @@ fi
 
 dnl JPEG Support
 dnl ============
-jpeg=yes
-ljpeg=""
-AC_ARG_ENABLE(jpeg, AS_HELP_STRING([--disable-jpeg], [disable JPEG support 
through libjpeg]),
-       jpeg=$enableval, jpeg=yes, jpeg=no)
-
-if test "$jpeg" = yes; then
-    WM_CHECK_LIB(jpeg, jpeg_destroy_compress)
-
-    if test "x$ac_cv_lib_jpeg_jpeg_destroy_compress" = xyes; then
-
-       ljpeg="-ljpeg"
-
-       WM_CHECK_HEADER(jpeglib.h)
-       if test "x$ac_cv_header_jpeglib_h" = xyes; then
-           GFXLIBS="$GFXLIBS -ljpeg"
-           supported_gfx="$supported_gfx JPEG"
-            AC_DEFINE(USE_JPEG, 1, [define if JPEG libraries are available 
(set by configure)])
-       fi
-    fi
-fi
+AC_ARG_ENABLE([jpeg],
+    [AS_HELP_STRING([--disable-jpeg], [disable JPEG support through libjpeg])],
+    [AS_CASE(["$enableval"],
+        [yes|no], [],
+        [AC_MSG_ERROR([bad value $enableval for --enable-jpeg])] )],
+    [enable_jpeg=auto])
+WM_IMGFMT_CHECK_JPEG
 
 
 dnl GIF Support
@@ -921,19 +908,19 @@ echo
 
 dnl WM_PRINT_REDCRAP_BUG_STATUS
 
-if test "x$ac_cv_header_jpeglib_h" != xyes; then
-echo "WARNING   WARNING   WARNING   WARNING   WARNING   WARNING   WARNING"
-echo
-echo "JPEG support will not be included because the JPEG library is"
-echo "not installed correctly or was not found. Background images"
-echo "from themes will not display as they usually are JPEG files."
-echo
-echo "To fix, download and install the jpeg library and/or make sure you"
-echo "installed all jpeg related packages, SPECIALLY the development packages"
-echo "like jpeg-devel (if you use some prepackaged version of libjpeg)."
-echo
-echo "WARNING   WARNING   WARNING   WARNING   WARNING   WARNING   WARNING"
-fi
+AS_IF([test "x$enable_jpeg" = xno], [dnl
+    AS_ECHO(["WARNING   WARNING   WARNING   WARNING   WARNING   WARNING   
WARNING"])
+    AS_ECHO([])
+    AS_ECHO(["JPEG support will not be included because the JPEG library is"])
+    AS_ECHO(["not installed correctly or was not found. Background images"])
+    AS_ECHO(["from themes will not display as they usually are JPEG files."])
+    AS_ECHO([])
+    AS_ECHO(["To fix, download and install the jpeg library and/or make sure 
you"])
+    AS_ECHO(["installed all jpeg related packages, SPECIALLY the development 
packages"])
+    AS_ECHO(["like jpeg-dev (if you use some prepackaged version of 
libjpeg)."])
+    AS_ECHO([])
+    AS_ECHO(["WARNING   WARNING   WARNING   WARNING   WARNING   WARNING   
WARNING"])dnl
+])
 
 
 dnl This is for Emacs.  I'm lazy, I know... (nicolai)
diff --git a/m4/wm_imgfmt_check.m4 b/m4/wm_imgfmt_check.m4
index e5f403d..3231f7b 100644
--- a/m4/wm_imgfmt_check.m4
+++ b/m4/wm_imgfmt_check.m4
@@ -79,6 +79,63 @@ const char *filename = "dummy";],
 ]) dnl AC_DEFUN
 
 
+# WM_IMGFMT_CHECK_JPEG
+# --------------------
+#
+# Check for JPEG file support through 'libjpeg'
+# The check depends on variable 'enable_jpeg' 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_JPEG],
+[AC_REQUIRE([_WM_IMGFMT_CHECK_FUNCTS])
+AS_IF([test "x$enable_jpeg" = "xno"],
+    [unsupported="$unsupported JPEG"],
+    [AC_CACHE_CHECK([for JPEG support library], [wm_cv_imgfmt_jpeg],
+        [wm_cv_imgfmt_jpeg=no
+         wm_save_LIBS="$LIBS"
+         dnl
+         dnl We check first if one of the known libraries is available
+         AS_IF([wm_fn_imgfmt_try_link "jpeg_destroy_compress" "$XLFLAGS $XLIBS 
-ljpeg"],
+             [wm_cv_imgfmt_jpeg="-ljpeg"])
+         LIBS="$wm_save_LIBS"
+         AS_IF([test "x$enable_jpeg$wm_cv_imgfmt_jpeg" = "xyesno"],
+             [AC_MSG_ERROR([explicit JPEG support requested but no library 
found])])
+         AS_IF([test "x$wm_cv_imgfmt_jpeg" != "xno"],
+           [dnl
+            dnl A library was found, now check for the appropriate header
+            AC_COMPILE_IFELSE(
+                [AC_LANG_PROGRAM(
+                    [@%:@include <stdlib.h>
+@%:@include <stdio.h>
+@%:@include <jpeglib.h>],
+                    [  struct jpeg_decompress_struct cinfo;
+
+  jpeg_destroy_decompress(&cinfo);])],
+                [],
+                [AS_ECHO([failed])
+                 AS_ECHO(["$as_me: error: found $wm_cv_imgfmt_jpeg but cannot 
compile header"])
+                 AS_ECHO(["$as_me: error:   - does header 'jpeglib.h' exists? 
(is package 'jpeg-dev' missing?)"])
+                 AS_ECHO(["$as_me: error:   - version of header is not 
supported? (report to dev team)"])
+                 AC_MSG_ERROR([JPEG library is not usable, cannot continue])])
+           ])
+         ])
+    AS_IF([test "x$wm_cv_imgfmt_jpeg" = "xno"],
+        [unsupported="$unsupported JPEG"
+         enable_jpeg="no"],
+        [supported_gfx="$supported_gfx JPEG"
+         GFXLIBS="$GFXLIBS $wm_cv_imgfmt_jpeg"
+         AC_DEFINE([USE_JPEG], [1],
+           [defined when valid JPEG library with header was found])])
+    ])
+AM_CONDITIONAL([USE_JPEG], [test "x$enable_jpeg" != "xno"])dnl
+]) dnl AC_DEFUN
+
+
 # _WM_IMGFMT_CHECK_FUNCTS
 # -----------------------
 # (internal shell functions)
diff --git a/wrlib/Makefile.am b/wrlib/Makefile.am
index dc379a1..e5991d5 100644
--- a/wrlib/Makefile.am
+++ b/wrlib/Makefile.am
@@ -39,13 +39,16 @@ libwraster_la_SOURCES =     \
        xutil.c         \
        ppm.c           \
        png.c           \
-       jpeg.c          \
        tiff.c
 
 if USE_GIF
 libwraster_la_SOURCES += gif.c
 endif
 
+if USE_JPEG
+libwraster_la_SOURCES += jpeg.c
+endif
+
 LTCOMPILE2=`echo $(LTCOMPILE) | sed -e s/-fomit-frame-pointer//`
 COMPILE2=`echo $(COMPILE) | sed -e s/-fomit-frame-pointer//`
 
diff --git a/wrlib/jpeg.c b/wrlib/jpeg.c
index 2648c40..815181b 100644
--- a/wrlib/jpeg.c
+++ b/wrlib/jpeg.c
@@ -25,8 +25,6 @@
 /* Avoid a compiler warning */
 #undef HAVE_STDLIB_H
 
-#ifdef USE_JPEG
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -190,5 +188,3 @@ RImage *RLoadJPEG(const char *file_name)
 
        return image;
 }
-
-#endif                         /* USE_JPEG */
-- 
1.8.4.rc3


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

Reply via email to