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_IMGFMT_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_imgfmt_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_imgfmt_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_imgfmt_try_compile "gif_lib.h" "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 GFXLIBS="$GFXLIBS `echo "$wm_cv_imgfmt_gif" | sed -e 's, *version:.*,,' `"
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 [AC_REQUIRE([_WM_IMGFMT_CHECK_FUNCTS])
96 AS_IF([test "x$enable_jpeg" = "xno"],
97 [unsupported="$unsupported JPEG"],
98 [AC_CACHE_CHECK([for JPEG support library], [wm_cv_imgfmt_jpeg],
102 dnl We check first if one of the known libraries is available
103 AS_IF([wm_fn_imgfmt_try_link "jpeg_destroy_compress" "$XLFLAGS $XLIBS -ljpeg"],
104 [wm_cv_imgfmt_jpeg="-ljpeg"])
106 AS_IF([test "x$enable_jpeg$wm_cv_imgfmt_jpeg" = "xyesno"],
107 [AC_MSG_ERROR([explicit JPEG support requested but no library found])])
108 AS_IF([test "x$wm_cv_imgfmt_jpeg" != "xno"],
110 dnl A library was found, now check for the appropriate header
113 [@%:@include <stdlib.h>
114 @%:@include <stdio.h>
115 @%:@include <jpeglib.h>],
116 [ struct jpeg_decompress_struct cinfo;
118 jpeg_destroy_decompress(&cinfo);])],
121 AS_ECHO(["$as_me: error: found $wm_cv_imgfmt_jpeg but cannot compile header"])
122 AS_ECHO(["$as_me: error: - does header 'jpeglib.h' exists? (is package 'jpeg-dev' missing?)"])
123 AS_ECHO(["$as_me: error: - version of header is not supported? (report to dev team)"])
124 AC_MSG_ERROR([JPEG library is not usable, cannot continue])])
127 AS_IF([test "x$wm_cv_imgfmt_jpeg" = "xno"],
128 [unsupported="$unsupported JPEG"
130 [supported_gfx="$supported_gfx JPEG"
131 GFXLIBS="$GFXLIBS $wm_cv_imgfmt_jpeg"
132 AC_DEFINE([USE_JPEG], [1],
133 [defined when valid JPEG library with header was found])])
135 AM_CONDITIONAL([USE_JPEG], [test "x$enable_jpeg" != "xno"])dnl
139 # WM_IMGFMT_CHECK_PNG
140 # -------------------
142 # Check for PNG file support through 'libpng'
143 # The check depends on variable 'enable_png' being either:
144 # yes - detect, fail if not found
145 # no - do not detect, disable support
146 # auto - detect, disable if not found
148 # When found, append appropriate stuff in GFXLIBS, and append info to
149 # the variable 'supported_gfx'
150 # When not found, append info to variable 'unsupported'
151 AC_DEFUN_ONCE([WM_IMGFMT_CHECK_PNG],
152 [AC_REQUIRE([_WM_IMGFMT_CHECK_FUNCTS])
153 AS_IF([test "x$enable_png" = "xno"],
154 [unsupported="$unsupported PNG"],
155 [AC_CACHE_CHECK([for PNG support library], [wm_cv_imgfmt_png],
158 dnl We check first if one of the known libraries is available
160 for wm_arg in "-lpng" "-lpng -lz" "-lpng -lz -lm" ; do
161 AS_IF([wm_fn_imgfmt_try_link "png_get_valid" "$XLFLAGS $XLIBS $wm_arg"],
162 [wm_cv_imgfmt_png="$wm_arg" ; break])
165 AS_IF([test "x$enable_png$wm_cv_imgfmt_png" = "xyesno"],
166 [AC_MSG_ERROR([explicit PNG support requested but no library found])])
167 AS_IF([test "x$wm_cv_imgfmt_png" != "xno"],
169 dnl A library was found, now check for the appropriate header
170 wm_save_CFLAGS="$CFLAGS"
171 AS_IF([wm_fn_imgfmt_try_compile "png.h" "return 0" ""],
173 [AC_MSG_ERROR([found $wm_cv_imgfmt_png but could not find appropriate header - are you missing libpng-dev package?])])
174 AS_IF([wm_fn_imgfmt_try_compile "png.h" "png_get_valid(NULL, NULL, PNG_INFO_tRNS)" ""],
176 [AC_MSG_ERROR([found $wm_cv_imgfmt_png and header, but cannot compile - unsupported version?])])
177 CFLAGS="$wm_save_CFLAGS"])
179 AS_IF([test "x$wm_cv_imgfmt_png" = "xno"],
180 [unsupported="$unsupported PNG"
182 [supported_gfx="$supported_gfx PNG"
183 GFXLIBS="$GFXLIBS $wm_cv_imgfmt_png"
184 AC_DEFINE([USE_PNG], [1],
185 [defined when valid PNG library with header was found])])
187 AM_CONDITIONAL([USE_PNG], [test "x$enable_png" != "xno"])dnl
191 # WM_IMGFMT_CHECK_TIFF
192 # --------------------
194 # Check for TIFF file support through 'libtiff'
195 # The check depends on variable 'enable_tiff' being either:
196 # yes - detect, fail if not found
197 # no - do not detect, disable support
198 # auto - detect, disable if not found
200 # When found, append appropriate stuff in GFXLIBS, and append info to
201 # the variable 'supported_gfx'
202 # When not found, append info to variable 'unsupported'
203 AC_DEFUN_ONCE([WM_IMGFMT_CHECK_TIFF],
204 [AC_REQUIRE([_WM_IMGFMT_CHECK_FUNCTS])
205 AS_IF([test "x$enable_tiff" = "xno"],
206 [unsupported="$unsupported TIFF"],
207 [AC_CACHE_CHECK([for TIFF support library], [wm_cv_imgfmt_tiff],
208 [wm_cv_imgfmt_tiff=no
210 dnl We check first if one of the known libraries is available
212 for wm_arg in "-ltiff" \
213 dnl TIFF can have a dependancy over zlib
214 "-ltiff -lz" "-ltiff -lz -lm" \
215 dnl It may also have a dependancy to jpeg_lib
216 "-ltiff -ljpeg" "-ltiff -ljpeg -lz" "-ltiff -ljpeg -lz -lm" \
217 dnl There is also a possible dependancy on JBIGKit
218 "-ltiff -ljpeg -ljbig -lz" \
219 dnl Probably for historical reasons?
220 "-ltiff34" "-ltiff34 -ljpeg" "-ltiff34 -ljpeg -lm" ; do
221 AS_IF([wm_fn_imgfmt_try_link "TIFFGetVersion" "$XLFLAGS $XLIBS $wm_arg"],
222 [wm_cv_imgfmt_tiff="$wm_arg" ; break])
225 AS_IF([test "x$enable_tiff$wm_cv_imgfmt_tiff" = "xyesno"],
226 [AC_MSG_ERROR([explicit TIFF support requested but no library found])])
227 AS_IF([test "x$wm_cv_imgfmt_tiff" != "xno"],
229 dnl A library was found, now check for the appropriate header
230 wm_save_CFLAGS="$CFLAGS"
231 AS_IF([wm_fn_imgfmt_try_compile "tiffio.h" "return 0" ""],
233 [AC_MSG_ERROR([found $wm_cv_imgfmt_tiff but could not find appropriate header - are you missing libtiff-dev package?])])
234 AS_IF([wm_fn_imgfmt_try_compile "tiffio.h" 'TIFFOpen(filename, "r")' ""],
236 [AC_MSG_ERROR([found $wm_cv_imgfmt_tiff and header, but cannot compile - unsupported version?])])
237 CFLAGS="$wm_save_CFLAGS"])
239 AS_IF([test "x$wm_cv_imgfmt_tiff" = "xno"],
240 [unsupported="$unsupported TIFF"
242 [supported_gfx="$supported_gfx TIFF"
243 GFXLIBS="$GFXLIBS $wm_cv_imgfmt_tiff"
244 AC_DEFINE([USE_TIFF], [1],
245 [defined when valid TIFF library with header was found])])
247 AM_CONDITIONAL([USE_TIFF], [test "x$enable_tiff" != "xno"])dnl
251 # WM_IMGFMT_CHECK_XPM
252 # -------------------
254 # Check for XPM file support through 'libXpm'
255 # The check depends on variable 'enable_xpm' being either:
256 # yes - detect, fail if not found
257 # no - do not detect, use internal support
258 # auto - detect, use internal if not found
260 # When found, append appropriate stuff in GFXLIBS, and append info to
261 # the variable 'supported_gfx'
262 AC_DEFUN_ONCE([WM_IMGFMT_CHECK_XPM],
263 [AC_REQUIRE([_WM_IMGFMT_CHECK_FUNCTS])
264 AS_IF([test "x$enable_xpm" = "xno"],
265 [supported_gfx="$supported_gfx builtin-XPM"],
266 [AC_CACHE_CHECK([for XPM support library], [wm_cv_imgfmt_xpm],
269 dnl We check first if one of the known libraries is available
271 AS_IF([wm_fn_imgfmt_try_link "XpmCreatePixmapFromData" "$XLFLAGS $XLIBS -lXpm"],
272 [wm_cv_imgfmt_xpm="-lXpm" ; break])
274 AS_IF([test "x$enable_xpm$wm_cv_imgfmt_xpm" = "xyesno"],
275 [AC_MSG_ERROR([explicit libXpm support requested but no library found])])
276 AS_IF([test "x$wm_cv_imgfmt_xpm" != "xno"],
278 dnl A library was found, now check for the appropriate header
279 wm_save_CFLAGS="$CFLAGS"
280 AS_IF([wm_fn_imgfmt_try_compile "X11/xpm.h" "return 0" "$XCFLAGS"],
282 [AC_MSG_ERROR([found $wm_cv_imgfmt_xpm but could not find appropriate header - are you missing libXpm-dev package?])])
283 AS_IF([wm_fn_imgfmt_try_compile "X11/xpm.h" 'XpmReadFileToXpmImage((char *)filename, NULL, NULL)' "$XCFLAGS"],
285 [AC_MSG_ERROR([found $wm_cv_imgfmt_xpm and header, but cannot compile - unsupported version?])])
286 CFLAGS="$wm_save_CFLAGS"])
288 AS_IF([test "x$wm_cv_imgfmt_xpm" = "xno"],
289 [supported_gfx="$supported_gfx builtin-XPM"
291 [supported_gfx="$supported_gfx XPM"
292 GFXLIBS="$GFXLIBS $wm_cv_imgfmt_xpm"
293 AC_DEFINE([USE_XPM], [1],
294 [defined when valid XPM library with header was found])])
296 AM_CONDITIONAL([USE_XPM], [test "x$enable_xpm" != "xno"])dnl
300 # _WM_IMGFMT_CHECK_FUNCTS
301 # -----------------------
302 # (internal shell functions)
304 # Create 2 shell functions:
305 # wm_fn_imgfmt_try_link: try to link against library
306 # wm_fn_imgfmt_try_compile: try to compile against header
308 AC_DEFUN_ONCE([_WM_IMGFMT_CHECK_FUNCTS],
309 [@%:@ wm_fn_imgfmt_try_link FUNCTION LFLAGS
310 @%:@ -------------------------------------
311 @%:@ Try linking aginst library in $LFLAGS using function named $FUNCTION
312 @%:@ Assumes that LIBS have been saved in 'wm_save_LIBS' by caller
313 wm_fn_imgfmt_try_link ()
315 LIBS="$wm_save_LIBS $[]2"
316 AC_TRY_LINK_FUNC([$[]1],
319 AS_SET_STATUS([$wm_retval])
322 @%:@ wm_fn_imgfmt_try_compile HEADER FUNC_CALL CFLAGS
323 @%:@ -----------------------------------------
324 @%:@ Try to compile using header $HEADER and trying to call a function
325 @%:@ using the $FUNC_CALL expression and using extra $CFLAGS in the
326 @%:@ compiler's command line
327 @%:@ Assumes that CFLAGS have been saved in 'wm_save_CFLAGS' by caller
328 wm_fn_imgfmt_try_compile ()
330 CFLAGS="$wm_save_CFLAGS $[]3"
332 [AC_LANG_PROGRAM([@%:@include <$[]1>
334 const char *filename = "dummy";], [ $[]2;])],
337 AS_SET_STATUS([$wm_retval])