wrlib: Moved configure's detection of XPM support to a dedicated macro
[wmaker-crm.git] / m4 / wm_imgfmt_check.m4
blobcd276b07cd1306e5700f796c11285212e97f865d
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.
19 # WM_IMGFMT_CHECK_GIF
20 # -------------------
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],
36         [wm_cv_imgfmt_gif=no
37          wm_save_LIBS="$LIBS"
38          dnl
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])
43          done
44          LIBS="$wm_save_LIBS"
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"],
48            [dnl
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" ""],
52               [],
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"],
56               [AC_COMPILE_IFELSE(
57                 [AC_LANG_PROGRAM(
58                   [@%:@include <gif_lib.h>
60 const char *filename = "dummy";],
61                   [  int error_code;
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
65               ]
66             )
67             CFLAGS="$wm_save_CFLAGS"])
68          ])
69     AS_IF([test "x$wm_cv_imgfmt_gif" = "xno"],
70         [unsupported="$unsupported GIF"
71          enable_gif="no"],
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])])
77     ])
78     AM_CONDITIONAL([USE_GIF], [test "x$enable_gif" != "xno"])dnl
79 ]) dnl AC_DEFUN
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],
99         [wm_cv_imgfmt_jpeg=no
100          wm_save_LIBS="$LIBS"
101          dnl
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"])
105          LIBS="$wm_save_LIBS"
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"],
109            [dnl
110             dnl A library was found, now check for the appropriate header
111             AC_COMPILE_IFELSE(
112                 [AC_LANG_PROGRAM(
113                     [@%:@include <stdlib.h>
114 @%:@include <stdio.h>
115 @%:@include <jpeglib.h>],
116                     [  struct jpeg_decompress_struct cinfo;
118   jpeg_destroy_decompress(&cinfo);])],
119                 [],
120                 [AS_ECHO([failed])
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])])
125            ])
126          ])
127     AS_IF([test "x$wm_cv_imgfmt_jpeg" = "xno"],
128         [unsupported="$unsupported JPEG"
129          enable_jpeg="no"],
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])])
134     ])
135 AM_CONDITIONAL([USE_JPEG], [test "x$enable_jpeg" != "xno"])dnl
136 ]) dnl AC_DEFUN
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],
156         [wm_cv_imgfmt_png=no
157          dnl
158          dnl We check first if one of the known libraries is available
159          wm_save_LIBS="$LIBS"
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])
163          done
164          LIBS="$wm_save_LIBS"
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"],
168            [dnl
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" ""],
172               [],
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)" ""],
175               [],
176               [AC_MSG_ERROR([found $wm_cv_imgfmt_png and header, but cannot compile - unsupported version?])])
177             CFLAGS="$wm_save_CFLAGS"])
178          ])
179     AS_IF([test "x$wm_cv_imgfmt_png" = "xno"],
180         [unsupported="$unsupported PNG"
181          enable_png="no"],
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])])
186     ])
187 AM_CONDITIONAL([USE_PNG], [test "x$enable_png" != "xno"])dnl
188 ]) dnl AC_DEFUN
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
209          dnl
210          dnl We check first if one of the known libraries is available
211          wm_save_LIBS="$LIBS"
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])
223          done
224          LIBS="$wm_save_LIBS"
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"],
228            [dnl
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" ""],
232               [],
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")' ""],
235               [],
236               [AC_MSG_ERROR([found $wm_cv_imgfmt_tiff and header, but cannot compile - unsupported version?])])
237             CFLAGS="$wm_save_CFLAGS"])
238          ])
239     AS_IF([test "x$wm_cv_imgfmt_tiff" = "xno"],
240         [unsupported="$unsupported TIFF"
241          enable_tiff="no"],
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])])
246     ])
247 AM_CONDITIONAL([USE_TIFF], [test "x$enable_tiff" != "xno"])dnl
248 ]) dnl AC_DEFUN
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],
267         [wm_cv_imgfmt_xpm=no
268          dnl
269          dnl We check first if one of the known libraries is available
270          wm_save_LIBS="$LIBS"
271          AS_IF([wm_fn_imgfmt_try_link "XpmCreatePixmapFromData" "$XLFLAGS $XLIBS -lXpm"],
272            [wm_cv_imgfmt_xpm="-lXpm" ; break])
273          LIBS="$wm_save_LIBS"
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"],
277            [dnl
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"],
281               [],
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"],
284               [],
285               [AC_MSG_ERROR([found $wm_cv_imgfmt_xpm and header, but cannot compile - unsupported version?])])
286             CFLAGS="$wm_save_CFLAGS"])
287          ])
288     AS_IF([test "x$wm_cv_imgfmt_xpm" = "xno"],
289         [supported_gfx="$supported_gfx builtin-XPM"
290          enable_xpm="no"],
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])])
295     ])
296 AM_CONDITIONAL([USE_XPM], [test "x$enable_xpm" != "xno"])dnl
297 ]) dnl AC_DEFUN
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],
317     [wm_retval=0],
318     [wm_retval=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"
331   AC_COMPILE_IFELSE(
332     [AC_LANG_PROGRAM([@%:@include <$[]1>
334 const char *filename = "dummy";], [  $[]2;])],
335     [wm_retval=0],
336     [wm_retval=1])
337   AS_SET_STATUS([$wm_retval])