1 # wm_imgfmt_check.m4 - Macros to check for image file format support libraries
3 # Copyright (c) 2013 Christophe CURIS
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 # Check for GIF file support through 'libgif', 'libungif' or 'giflib v5'
23 # The check depends on variable 'enable_gif' being either:
24 # yes - detect, fail if not found
25 # no - do not detect, disable support
26 # auto - detect, disable if not found
28 # When found, append appropriate stuff in GFXLIBS, and append info to
29 # the variable 'supported_gfx'
30 # When not found, append info to variable 'unsupported'
31 AC_DEFUN_ONCE([WM_IMGFMT_CHECK_GIF],
32 [AC_REQUIRE([_WM_LIB_CHECK_FUNCTS])
33 AS_IF([test "x$enable_gif" = "xno"],
34 [unsupported="$unsupported GIF"],
35 [AC_CACHE_CHECK([for GIF support library], [wm_cv_imgfmt_gif],
39 dnl We check first if one of the known libraries is available
40 for wm_arg in "-lgif" "-lungif" ; do
41 AS_IF([wm_fn_lib_try_link "DGifOpenFileName" "$XLFLAGS $XLIBS $wm_arg"],
42 [wm_cv_imgfmt_gif="$wm_arg" ; break])
45 AS_IF([test "x$enable_gif$wm_cv_imgfmt_gif" = "xyesno"],
46 [AC_MSG_ERROR([explicit GIF support requested but no library found])])
47 AS_IF([test "x$wm_cv_imgfmt_gif" != "xno"],
49 dnl A library was found, now check for the appropriate header
50 wm_save_CFLAGS="$CFLAGS"
51 AS_IF([wm_fn_lib_try_compile "gif_lib.h" "" "return 0" ""],
53 [AC_MSG_ERROR([found $wm_cv_imgfmt_gif but could not find appropriate header - are you missing libgif-dev package?])])
54 AS_IF([wm_fn_lib_try_compile "gif_lib.h" 'const char *filename = "dummy";' "DGifOpenFileName(filename)" ""],
55 [wm_cv_imgfmt_gif="$wm_cv_imgfmt_gif version:4"],
58 [@%:@include <gif_lib.h>
60 const char *filename = "dummy";],
62 DGifOpenFileName(filename, &error_code);] )],
63 [wm_cv_imgfmt_gif="$wm_cv_imgfmt_gif version:5"],
64 [AC_MSG_ERROR([found $wm_cv_imgfmt_gif and header, but cannot compile - unsupported version?])])dnl
67 CFLAGS="$wm_save_CFLAGS"])
69 AS_IF([test "x$wm_cv_imgfmt_gif" = "xno"],
70 [unsupported="$unsupported GIF"
72 [supported_gfx="$supported_gfx GIF"
73 WM_APPEND_ONCE([`echo "$wm_cv_imgfmt_gif" | sed -e 's, *version:.*,,' `], [GFXLIBS])
74 AC_DEFINE_UNQUOTED([USE_GIF],
75 [`echo "$wm_cv_imgfmt_gif" | sed -e 's,.*version:,,' `],
76 [defined when valid GIF library with header was found])])
78 AM_CONDITIONAL([USE_GIF], [test "x$enable_gif" != "xno"])dnl
82 # WM_IMGFMT_CHECK_JPEG
83 # --------------------
85 # Check for JPEG file support through 'libjpeg'
86 # The check depends on variable 'enable_jpeg' being either:
87 # yes - detect, fail if not found
88 # no - do not detect, disable support
89 # auto - detect, disable if not found
91 # When found, append appropriate stuff in GFXLIBS, and append info to
92 # the variable 'supported_gfx'
93 # When not found, append info to variable 'unsupported'
94 AC_DEFUN_ONCE([WM_IMGFMT_CHECK_JPEG],
95 [WM_LIB_CHECK([JPEG], [-ljpeg], [jpeg_destroy_compress], [$XLFLAGS $XLIBS],
98 [@%:@include <stdlib.h>
100 @%:@include <jpeglib.h>],
101 [ struct jpeg_decompress_struct cinfo;
103 jpeg_destroy_decompress(&cinfo);])],
106 AS_ECHO(["$as_me: error: found $CACHEVAR but cannot compile header"])
107 AS_ECHO(["$as_me: error: - does header 'jpeglib.h' exists? (is package 'jpeg-dev' missing?)"])
108 AS_ECHO(["$as_me: error: - version of header is not supported? (report to dev team)"])
109 AC_MSG_ERROR([JPEG library is not usable, cannot continue])])
111 [supported_gfx], [GFXLIBS])dnl
115 # WM_IMGFMT_CHECK_PNG
116 # -------------------
118 # Check for PNG file support through 'libpng'
119 # The check depends on variable 'enable_png' being either:
120 # yes - detect, fail if not found
121 # no - do not detect, disable support
122 # auto - detect, disable if not found
124 # When found, append appropriate stuff in GFXLIBS, and append info to
125 # the variable 'supported_gfx'
126 # When not found, append info to variable 'unsupported'
127 AC_DEFUN_ONCE([WM_IMGFMT_CHECK_PNG],
128 [WM_LIB_CHECK([PNG], ["-lpng" "-lpng -lz" "-lpng -lz -lm"], [png_get_valid], [$XLFLAGS $XLIBS],
129 [wm_save_CFLAGS="$CFLAGS"
130 AS_IF([wm_fn_lib_try_compile "png.h" "" "return 0" ""],
132 [AC_MSG_ERROR([found $CACHEVAR but could not find appropriate header - are you missing libpng-dev package?])])
133 AS_IF([wm_fn_lib_try_compile "png.h" "" "png_get_valid(NULL, NULL, PNG_INFO_tRNS)" ""],
135 [AC_MSG_ERROR([found $CACHEVAR and header, but cannot compile - unsupported version?])])
136 CFLAGS="$wm_save_CFLAGS"],
137 [supported_gfx], [GFXLIBS])dnl
141 # WM_IMGFMT_CHECK_TIFF
142 # --------------------
144 # Check for TIFF file support through 'libtiff'
145 # The check depends on variable 'enable_tiff' being either:
146 # yes - detect, fail if not found
147 # no - do not detect, disable support
148 # auto - detect, disable if not found
150 # When found, append appropriate stuff in GFXLIBS, and append info to
151 # the variable 'supported_gfx'
152 # When not found, append info to variable 'unsupported'
153 AC_DEFUN_ONCE([WM_IMGFMT_CHECK_TIFF],
154 [WM_LIB_CHECK([TIFF],
156 dnl TIFF can have a dependancy over zlib
157 "-ltiff -lz" "-ltiff -lz -lm" \
158 dnl It may also have a dependancy to jpeg_lib
159 "-ltiff -ljpeg" "-ltiff -ljpeg -lz" "-ltiff -ljpeg -lz -lm" \
160 dnl There is also a possible dependancy on JBIGKit
161 "-ltiff -ljpeg -ljbig -lz" \
162 dnl Probably for historical reasons?
163 "-ltiff34" "-ltiff34 -ljpeg" "-ltiff34 -ljpeg -lm"],
164 [TIFFGetVersion], [$XLFLAGS $XLIBS],
165 [wm_save_CFLAGS="$CFLAGS"
166 AS_IF([wm_fn_lib_try_compile "tiffio.h" "" "return 0" ""],
168 [AC_MSG_ERROR([found $CACHEVAR but could not find appropriate header - are you missing libtiff-dev package?])])
169 AS_IF([wm_fn_lib_try_compile "tiffio.h" 'const char *filename = "dummy";' 'TIFFOpen(filename, "r")' ""],
171 [AC_MSG_ERROR([found $CACHEVAR and header, but cannot compile - unsupported version?])])
172 CFLAGS="$wm_save_CFLAGS"],
173 [supported_gfx], [GFXLIBS])dnl
177 # WM_IMGFMT_CHECK_WEBP
178 # -------------------
180 # Check for WEBP file support through 'libwebp'
181 # The check depends on variable 'enable_webp' being either:
182 # yes - detect, fail if not found
183 # no - do not detect, disable support
184 # auto - detect, disable if not found
186 # When found, append appropriate stuff in GFXLIBS, and append info to
187 # the variable 'supported_gfx'
188 # When not found, append info to variable 'unsupported'
189 AC_DEFUN_ONCE([WM_IMGFMT_CHECK_WEBP],
190 [WM_LIB_CHECK([WEBP], ["-lwebp"], [VP8DecodeLayer], [$XLFLAGS $XLIBS],
191 [wm_save_CFLAGS="$CFLAGS"
192 AS_IF([wm_fn_lib_try_compile "webp/decode.h" "" "return 0" ""],
194 [AC_MSG_ERROR([found $CACHEVAR but could not find appropriate header - are you missing libwebp-dev package?])])
195 CFLAGS="$wm_save_CFLAGS"],
196 [supported_gfx], [GFXLIBS])dnl
200 # WM_IMGFMT_CHECK_XPM
201 # -------------------
203 # Check for XPM file support through 'libXpm'
204 # The check depends on variable 'enable_xpm' being either:
205 # yes - detect, fail if not found
206 # no - do not detect, use internal support
207 # auto - detect, use internal if not found
209 # When found, append appropriate stuff in GFXLIBS, and append info to
210 # the variable 'supported_gfx'
211 AC_DEFUN_ONCE([WM_IMGFMT_CHECK_XPM],
212 [AC_REQUIRE([_WM_LIB_CHECK_FUNCTS])
213 AS_IF([test "x$enable_xpm" = "xno"],
214 [supported_gfx="$supported_gfx builtin-XPM"],
215 [AC_CACHE_CHECK([for XPM support library], [wm_cv_imgfmt_xpm],
218 dnl We check first if one of the known libraries is available
220 AS_IF([wm_fn_lib_try_link "XpmCreatePixmapFromData" "$XLFLAGS $XLIBS -lXpm"],
221 [wm_cv_imgfmt_xpm="-lXpm" ; break])
223 AS_IF([test "x$enable_xpm$wm_cv_imgfmt_xpm" = "xyesno"],
224 [AC_MSG_ERROR([explicit libXpm support requested but no library found])])
225 AS_IF([test "x$wm_cv_imgfmt_xpm" != "xno"],
227 dnl A library was found, now check for the appropriate header
228 wm_save_CFLAGS="$CFLAGS"
229 AS_IF([wm_fn_lib_try_compile "X11/xpm.h" "" "return 0" "$XCFLAGS"],
231 [AC_MSG_ERROR([found $wm_cv_imgfmt_xpm but could not find appropriate header - are you missing libXpm-dev package?])])
232 AS_IF([wm_fn_lib_try_compile "X11/xpm.h" 'char *filename = "dummy";' 'XpmReadFileToXpmImage(filename, NULL, NULL)' "$XCFLAGS"],
234 [AC_MSG_ERROR([found $wm_cv_imgfmt_xpm and header, but cannot compile - unsupported version?])])
235 CFLAGS="$wm_save_CFLAGS"])
237 AS_IF([test "x$wm_cv_imgfmt_xpm" = "xno"],
238 [supported_gfx="$supported_gfx builtin-XPM"
240 [supported_gfx="$supported_gfx XPM"
241 WM_APPEND_ONCE([$wm_cv_imgfmt_xpm], [GFXLIBS])
242 AC_DEFINE([USE_XPM], [1],
243 [defined when valid XPM library with header was found])])
245 AM_CONDITIONAL([USE_XPM], [test "x$enable_xpm" != "xno"])dnl
249 # WM_IMGFMT_CHECK_MAGICK
250 # ----------------------
252 # Check for MagickWand library to support more image file formats
253 # The check depends on variable 'enable_magick' being either:
254 # yes - detect, fail if not found
255 # no - do not detect, disable support
256 # auto - detect, disable if not found
258 # When found, store the appropriate compilation flags in MAGICKFLAGS
259 # and MAGICKLIBS, and append info to the variable 'supported_gfx'
260 # When not found, append info to variable 'unsupported'
261 AC_DEFUN_ONCE([WM_IMGFMT_CHECK_MAGICK],
262 [AC_REQUIRE([_WM_LIB_CHECK_FUNCTS])
263 AS_IF([test "x$enable_magick" = "xno"],
264 [unsupported="$unsupported Magick"],
265 [AC_CACHE_CHECK([for Magick support library], [wm_cv_libchk_magick],
266 [wm_cv_libchk_magick=no
267 dnl First try to get the configuration from either pkg-config (the official way)
268 dnl or with the fallback MagickWand-config
269 AS_IF([test "x$PKGCONFIG" = "x"],
270 [AC_PATH_PROGS_FEATURE_CHECK([magickwand], [MagickWand-config],
271 [wm_cv_libchk_magick_cflags=`$ac_path_magickwand --cflags`
272 wm_cv_libchk_magick_libs=`$ac_path_magickwand --ldflags`
273 wm_cv_libchk_magick=magickwand])],
274 [AS_IF([$PKGCONFIG --exists MagickWand],
275 [wm_cv_libchk_magick_cflags=`$PKGCONFIG --cflags MagickWand`
276 wm_cv_libchk_magick_libs=`$PKGCONFIG --libs MagickWand`
277 wm_cv_libchk_magick=pkgconfig])])
278 AS_IF([test "x$wm_cv_libchk_magick" = "xno"],
279 [AS_IF([test "x$enable_magick" != "xauto"],
280 [AC_MSG_RESULT([not found])
281 AC_MSG_ERROR([explicit Magick support requested but configuration not found with pkg-config and MagickWand-config - are you missing libmagickwand-dev package?])])],
282 [dnl The configuration was found, check that it actually works
285 dnl We check that the library is available
286 AS_IF([wm_fn_lib_try_link "NewMagickWand" "$wm_cv_libchk_magick_libs"],
287 [wm_cv_libchk_magick=maybe])
289 AS_IF([test "x$wm_cv_libchk_magick" != "xmaybe"],
290 [AC_MSG_ERROR([MagickWand was found but the library does not link])])
292 dnl The library was found, check if header is available and compiles
293 wm_save_CFLAGS="$CFLAGS"
294 AS_IF([wm_fn_lib_try_compile "wand/magick_wand.h" "MagickWand *wand;" "wand = NewMagickWand()" "$wm_cv_libchk_magick_cflags"],
295 [wm_cv_libchk_magick="$wm_cv_libchk_magick_cflags % $wm_cv_libchk_magick_libs"],
296 [AC_MSG_ERROR([found MagickWand library but could not compile its header])])
297 CFLAGS="$wm_save_CFLAGS"])dnl
299 AS_IF([test "x$wm_cv_libchk_magick" = "xno"],
300 [unsupported="$unsupported Magick"
302 [supported_gfx="$supported_gfx Magick"
303 MAGICKFLAGS=`echo "$wm_cv_libchk_magick" | sed -e 's, *%.*$,,' `
304 MAGICKLIBS=`echo "$wm_cv_libchk_magick" | sed -e 's,^.*% *,,' `
305 AC_DEFINE([USE_MAGICK], [1],
306 [defined when MagickWand library with header was found])])
308 AM_CONDITIONAL([USE_MAGICK], [test "x$enable_magick" != "xno"])dnl
309 AC_SUBST(MAGICKFLAGS)dnl
310 AC_SUBST(MAGICKLIBS)dnl