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          | 29 ++++++++++-------------------
 m4/wm_imgfmt_check.m4 | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 wrlib/Makefile.am     |  5 ++++-
 wrlib/xpm.c           |  6 +-----
 4 files changed, 64 insertions(+), 25 deletions(-)

diff --git a/configure.ac b/configure.ac
index 605bc8f..bdc1bbe 100644
--- a/configure.ac
+++ b/configure.ac
@@ -124,6 +124,7 @@ AS_IF([test "x$debug" = "xyes"],
 dnl Tracking on what is detected for final status
 dnl =============================================
 unsupported=""
+supported_gfx=""
 
 
 dnl Platform-specific Makefile setup
@@ -625,24 +626,14 @@ dnl ==============================================
 
 dnl XPM Support
 dnl ===========
-xpm=yes
-AC_ARG_ENABLE(xpm, AS_HELP_STRING([--disable-xpm], [disable use of XPM pixmaps 
through libXpm]),
-       xpm=$enableval, xpm=yes)
-
-if test "$xpm" = yes; then
-    WM_CHECK_LIB(Xpm, XpmCreatePixmapFromData, [$XLFLAGS $XLIBS])
-
-    if test "x$ac_cv_lib_Xpm_XpmCreatePixmapFromData" = xyes; then
-        WM_CHECK_HEADER(X11/xpm.h)
-       if test "x$ac_cv_header_X11_xpm_h" = xyes; then
-               GFXLIBS="$GFXLIBS -lXpm"
-               supported_gfx="XPM"
-               AC_DEFINE(USE_XPM, 1, [define if XPM libraries are available 
(set by configure)])
-       else
-               supported_gfx="builtin-XPM"
-       fi
-    fi
-fi
+AC_ARG_ENABLE([xpm],
+    [AS_HELP_STRING([--disable-xpm], [disable use of XPM pixmaps through 
libXpm])],
+    [AS_CASE(["$enableval"],
+        [yes|no], [],
+        [AC_MSG_ERROR([bad value $enableval for --enable-xpm])] )],
+    [enable_xpm=auto])
+WM_IMGFMT_CHECK_XPM
+
 
 # for wmlib
 AC_SUBST(XCFLAGS)
@@ -835,7 +826,7 @@ echo "Installation path prefix            : $prefix"
 echo "Installation path for binaries      : $_bindir"
 echo "Installation path for libraries     : $libdir"
 echo "Installation path for WPrefs.app    : $wprefs_base_dir" | sed -e 
's|\${prefix}|'"$prefix|"
-echo "Supported graphic format libraries  : $supported_gfx"
+echo "Supported graphic format libraries  :$supported_gfx"
 echo "Unsupported features                :$unsupported"
 echo "Antialiased text support in WINGs   : $xft"
 echo "Xinerama extension support          : $xinerama"
diff --git a/m4/wm_imgfmt_check.m4 b/m4/wm_imgfmt_check.m4
index 2ab9a17..cd276b0 100644
--- a/m4/wm_imgfmt_check.m4
+++ b/m4/wm_imgfmt_check.m4
@@ -248,6 +248,55 @@ AM_CONDITIONAL([USE_TIFF], [test "x$enable_tiff" != 
"xno"])dnl
 ]) dnl AC_DEFUN
 
 
+# WM_IMGFMT_CHECK_XPM
+# -------------------
+#
+# Check for XPM file support through 'libXpm'
+# The check depends on variable 'enable_xpm' being either:
+#   yes  - detect, fail if not found
+#   no   - do not detect, use internal support
+#   auto - detect, use internal if not found
+#
+# When found, append appropriate stuff in GFXLIBS, and append info to
+# the variable 'supported_gfx'
+AC_DEFUN_ONCE([WM_IMGFMT_CHECK_XPM],
+[AC_REQUIRE([_WM_IMGFMT_CHECK_FUNCTS])
+AS_IF([test "x$enable_xpm" = "xno"],
+    [supported_gfx="$supported_gfx builtin-XPM"],
+    [AC_CACHE_CHECK([for XPM support library], [wm_cv_imgfmt_xpm],
+        [wm_cv_imgfmt_xpm=no
+         dnl
+         dnl We check first if one of the known libraries is available
+         wm_save_LIBS="$LIBS"
+         AS_IF([wm_fn_imgfmt_try_link "XpmCreatePixmapFromData" "$XLFLAGS 
$XLIBS -lXpm"],
+           [wm_cv_imgfmt_xpm="-lXpm" ; break])
+         LIBS="$wm_save_LIBS"
+         AS_IF([test "x$enable_xpm$wm_cv_imgfmt_xpm" = "xyesno"],
+           [AC_MSG_ERROR([explicit libXpm support requested but no library 
found])])
+         AS_IF([test "x$wm_cv_imgfmt_xpm" != "xno"],
+           [dnl
+            dnl A library was found, now check for the appropriate header
+            wm_save_CFLAGS="$CFLAGS"
+            AS_IF([wm_fn_imgfmt_try_compile "X11/xpm.h" "return 0" "$XCFLAGS"],
+              [],
+              [AC_MSG_ERROR([found $wm_cv_imgfmt_xpm but could not find 
appropriate header - are you missing libXpm-dev package?])])
+            AS_IF([wm_fn_imgfmt_try_compile "X11/xpm.h" 
'XpmReadFileToXpmImage((char *)filename, NULL, NULL)' "$XCFLAGS"],
+              [],
+              [AC_MSG_ERROR([found $wm_cv_imgfmt_xpm and header, but cannot 
compile - unsupported version?])])
+            CFLAGS="$wm_save_CFLAGS"])
+         ])
+    AS_IF([test "x$wm_cv_imgfmt_xpm" = "xno"],
+        [supported_gfx="$supported_gfx builtin-XPM"
+         enable_xpm="no"],
+        [supported_gfx="$supported_gfx XPM"
+         GFXLIBS="$GFXLIBS $wm_cv_imgfmt_xpm"
+         AC_DEFINE([USE_XPM], [1],
+           [defined when valid XPM library with header was found])])
+    ])
+AM_CONDITIONAL([USE_XPM], [test "x$enable_xpm" != "xno"])dnl
+]) dnl AC_DEFUN
+
+
 # _WM_IMGFMT_CHECK_FUNCTS
 # -----------------------
 # (internal shell functions)
diff --git a/wrlib/Makefile.am b/wrlib/Makefile.am
index 5f4946a..ded558e 100644
--- a/wrlib/Makefile.am
+++ b/wrlib/Makefile.am
@@ -35,7 +35,6 @@ libwraster_la_SOURCES =       \
        rotate.c        \
        convolve.c      \
        nxpm.c          \
-       xpm.c           \
        xutil.c         \
        ppm.c
 
@@ -55,6 +54,10 @@ if USE_TIFF
 libwraster_la_SOURCES += tiff.c
 endif
 
+if USE_XPM
+libwraster_la_SOURCES += xpm.c
+endif
+
 LTCOMPILE2=`echo $(LTCOMPILE) | sed -e s/-fomit-frame-pointer//`
 COMPILE2=`echo $(COMPILE) | sed -e s/-fomit-frame-pointer//`
 
diff --git a/wrlib/xpm.c b/wrlib/xpm.c
index 12aadc6..441d957 100644
--- a/wrlib/xpm.c
+++ b/wrlib/xpm.c
@@ -1,4 +1,4 @@
-/* xpm.c - load XPM image from file
+/* xpm.c - load XPM image from file using libXpm
  *
  * Raster graphics library
  *
@@ -22,8 +22,6 @@
 
 #include <config.h>
 
-#ifdef USE_XPM
-
 #include <X11/Xlib.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -271,5 +269,3 @@ RImage *RLoadXPM(RContext * context, const char *file)
        XpmFreeXpmImage(&xpm);
        return image;
 }
-
-#endif                         /* USE_XPM */
-- 
1.8.4.rc3


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

Reply via email to