wmaker: remove useless null pointer check (Coverity #109612)
[wmaker-crm.git] / m4 / wm_imgfmt_check.m4
blob5dd9ec7fd7b0704248eef084adc69dbe2e87a3d1
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.
20 # WM_IMGFMT_CHECK_GIF
21 # -------------------
23 # Check for GIF file support through 'libgif', 'libungif' or 'giflib v5'
24 # The check depends on variable 'enable_gif' being either:
25 #   yes  - detect, fail if not found
26 #   no   - do not detect, disable support
27 #   auto - detect, disable if not found
29 # When found, append appropriate stuff in GFXLIBS, and append info to
30 # the variable 'supported_gfx'
31 # When not found, append info to variable 'unsupported'
32 AC_DEFUN_ONCE([WM_IMGFMT_CHECK_GIF],
33 [AC_REQUIRE([_WM_LIB_CHECK_FUNCTS])
34 AS_IF([test "x$enable_gif" = "xno"],
35     [unsupported="$unsupported GIF"],
36     [AC_CACHE_CHECK([for GIF support library], [wm_cv_imgfmt_gif],
37         [wm_cv_imgfmt_gif=no
38          wm_save_LIBS="$LIBS"
39          dnl
40          dnl We check first if one of the known libraries is available
41          for wm_arg in "-lgif" "-lungif" ; do
42            AS_IF([wm_fn_lib_try_link "DGifOpenFileName" "$XLFLAGS $XLIBS $wm_arg"],
43              [wm_cv_imgfmt_gif="$wm_arg" ; break])
44          done
45          LIBS="$wm_save_LIBS"
46          AS_IF([test "x$enable_gif$wm_cv_imgfmt_gif" = "xyesno"],
47            [AC_MSG_ERROR([explicit GIF support requested but no library found])])
48          AS_IF([test "x$wm_cv_imgfmt_gif" != "xno"],
49            [dnl
50             dnl A library was found, now check for the appropriate header
51             wm_save_CFLAGS="$CFLAGS"
52             AS_IF([wm_fn_lib_try_compile "gif_lib.h" "" "return 0" ""],
53               [],
54               [AC_MSG_ERROR([found $wm_cv_imgfmt_gif but could not find appropriate header - are you missing libgif-dev package?])])
55             AS_IF([wm_fn_lib_try_compile "gif_lib.h" 'const char *filename = "dummy";' "DGifOpenFileName(filename)" ""],
56               [wm_cv_imgfmt_gif="$wm_cv_imgfmt_gif version:4"],
57               [AC_COMPILE_IFELSE(
58                 [AC_LANG_PROGRAM(
59                   [@%:@include <gif_lib.h>
61 const char *filename = "dummy";],
62                   [  int error_code;
63   DGifOpenFileName(filename, &error_code);] )],
64                 [wm_cv_imgfmt_gif="$wm_cv_imgfmt_gif version:5"],
65                 [AC_MSG_ERROR([found $wm_cv_imgfmt_gif and header, but cannot compile - unsupported version?])])dnl
66               ]
67             )
68             CFLAGS="$wm_save_CFLAGS"])
69          ])
70     AS_IF([test "x$wm_cv_imgfmt_gif" = "xno"],
71         [unsupported="$unsupported GIF"
72          enable_gif="no"],
73         [supported_gfx="$supported_gfx GIF"
74          WM_APPEND_ONCE([`echo "$wm_cv_imgfmt_gif" | sed -e 's, *version:.*,,' `], [GFXLIBS])
75          AC_DEFINE_UNQUOTED([USE_GIF],
76            [`echo "$wm_cv_imgfmt_gif" | sed -e 's,.*version:,,' `],
77            [defined when valid GIF library with header was found])])
78     ])
79 AM_CONDITIONAL([USE_GIF], [test "x$enable_gif" != "xno"])dnl
80 ]) dnl AC_DEFUN
83 # WM_IMGFMT_CHECK_JPEG
84 # --------------------
86 # Check for JPEG file support through 'libjpeg'
87 # The check depends on variable 'enable_jpeg' being either:
88 #   yes  - detect, fail if not found
89 #   no   - do not detect, disable support
90 #   auto - detect, disable if not found
92 # When found, append appropriate stuff in GFXLIBS, and append info to
93 # the variable 'supported_gfx'
94 # When not found, append info to variable 'unsupported'
95 AC_DEFUN_ONCE([WM_IMGFMT_CHECK_JPEG],
96 [WM_LIB_CHECK([JPEG], [-ljpeg], [jpeg_destroy_compress], [$XLFLAGS $XLIBS],
97     [AC_COMPILE_IFELSE(
98                 [AC_LANG_PROGRAM(
99                     [@%:@include <stdlib.h>
100 @%:@include <stdio.h>
101 @%:@include <jpeglib.h>],
102                     [  struct jpeg_decompress_struct cinfo;
104   jpeg_destroy_decompress(&cinfo);])],
105                 [],
106                 [AS_ECHO([failed])
107                  AS_ECHO(["$as_me: error: found $CACHEVAR but cannot compile header"])
108                  AS_ECHO(["$as_me: error:   - does header 'jpeglib.h' exists? (is package 'jpeg-dev' missing?)"])
109                  AS_ECHO(["$as_me: error:   - version of header is not supported? (report to dev team)"])
110                  AC_MSG_ERROR([JPEG library is not usable, cannot continue])])
111            ],
112     [supported_gfx], [GFXLIBS])dnl
113 ]) dnl AC_DEFUN
116 # WM_IMGFMT_CHECK_PNG
117 # -------------------
119 # Check for PNG file support through 'libpng'
120 # The check depends on variable 'enable_png' being either:
121 #   yes  - detect, fail if not found
122 #   no   - do not detect, disable support
123 #   auto - detect, disable if not found
125 # When found, append appropriate stuff in GFXLIBS, and append info to
126 # the variable 'supported_gfx'
127 # When not found, append info to variable 'unsupported'
128 AC_DEFUN_ONCE([WM_IMGFMT_CHECK_PNG],
129 [WM_LIB_CHECK([PNG], ["-lpng" "-lpng -lz" "-lpng -lz -lm"], [png_get_valid], [$XLFLAGS $XLIBS],
130     [wm_save_CFLAGS="$CFLAGS"
131      AS_IF([wm_fn_lib_try_compile "png.h" "" "return 0" ""],
132          [],
133          [AC_MSG_ERROR([found $CACHEVAR but could not find appropriate header - are you missing libpng-dev package?])])
134      AS_IF([wm_fn_lib_try_compile "png.h" "" "png_get_valid(NULL, NULL, PNG_INFO_tRNS)" ""],
135          [],
136          [AC_MSG_ERROR([found $CACHEVAR and header, but cannot compile - unsupported version?])])
137      CFLAGS="$wm_save_CFLAGS"],
138     [supported_gfx], [GFXLIBS])dnl
139 ]) dnl AC_DEFUN
142 # WM_IMGFMT_CHECK_TIFF
143 # --------------------
145 # Check for TIFF file support through 'libtiff'
146 # The check depends on variable 'enable_tiff' being either:
147 #   yes  - detect, fail if not found
148 #   no   - do not detect, disable support
149 #   auto - detect, disable if not found
151 # When found, append appropriate stuff in GFXLIBS, and append info to
152 # the variable 'supported_gfx'
153 # When not found, append info to variable 'unsupported'
154 AC_DEFUN_ONCE([WM_IMGFMT_CHECK_TIFF],
155 [WM_LIB_CHECK([TIFF],
156     ["-ltiff"  \
157      dnl TIFF can have a dependancy over zlib
158      "-ltiff -lz" "-ltiff -lz -lm"  \
159      dnl It may also have a dependancy to jpeg_lib
160      "-ltiff -ljpeg" "-ltiff -ljpeg -lz" "-ltiff -ljpeg -lz -lm"  \
161      dnl There is also a possible dependancy on JBIGKit
162      "-ltiff -ljpeg -ljbig -lz"  \
163      dnl Probably for historical reasons?
164      "-ltiff34" "-ltiff34 -ljpeg" "-ltiff34 -ljpeg -lm"],
165     [TIFFGetVersion], [$XLFLAGS $XLIBS],
166     [wm_save_CFLAGS="$CFLAGS"
167      AS_IF([wm_fn_lib_try_compile "tiffio.h" "" "return 0" ""],
168          [],
169          [AC_MSG_ERROR([found $CACHEVAR but could not find appropriate header - are you missing libtiff-dev package?])])
170      AS_IF([wm_fn_lib_try_compile "tiffio.h" 'const char *filename = "dummy";' 'TIFFOpen(filename, "r")' ""],
171          [],
172          [AC_MSG_ERROR([found $CACHEVAR and header, but cannot compile - unsupported version?])])
173      CFLAGS="$wm_save_CFLAGS"],
174     [supported_gfx], [GFXLIBS])dnl
175 ]) dnl AC_DEFUN
178 # WM_IMGFMT_CHECK_WEBP
179 # --------------------
181 # Check for WEBP file support through 'libwebp'
182 # The check depends on variable 'enable_webp' being either:
183 #   yes  - detect, fail if not found
184 #   no   - do not detect, disable support
185 #   auto - detect, disable if not found
187 # When found, append appropriate stuff in GFXLIBS, and append info to
188 # the variable 'supported_gfx'
189 # When not found, append info to variable 'unsupported'
190 AC_DEFUN_ONCE([WM_IMGFMT_CHECK_WEBP],
191 [AS_IF([test "x$enable_webp" = "xno"],
192     [unsupported="$unsupported WebP"],
193     [AC_CACHE_CHECK([for WebP support library], [wm_cv_imgfmt_webp],
194         [wm_cv_imgfmt_webp=no
195          dnl
196          dnl The library is using a special trick on the functions to provide
197          dnl compatibility between versions, so we cannot try linking against
198          dnl a symbol without first using the header to handle it
199          wm_save_LIBS="$LIBS"
200          LIBS="$LIBS -lwebp"
201          AC_TRY_LINK(
202              [@%:@include <webp/decode.h>],
203              [WebPGetFeatures(NULL, 1024, NULL);],
204              [wm_cv_imgfmt_webp="-lwebp"])
205          LIBS="$wm_save_LIBS"
206          AS_IF([test "x$enable_webp$wm_cv_imgfmt_webp" = "xyesno"],
207               [AC_MSG_ERROR([explicit WebP support requested but no library found])])dnl
208         ])
209      AS_IF([test "x$wm_cv_imgfmt_webp" = "xno"],
210          [unsupported="$unsupported WebP"
211           enable_webp="no"],
212          [supported_gfx="$supported_gfx WebP"
213           WM_APPEND_ONCE([$wm_cv_imgfmt_webp], [GFXLIBS])dnl
214           AC_DEFINE([USE_WEBP], [1],
215               [defined when valid Webp library with header was found])])dnl
216     ])
217 AM_CONDITIONAL([USE_WEBP], [test "x$enable_webp" != "xno"])dnl
221 # WM_IMGFMT_CHECK_XPM
222 # -------------------
224 # Check for XPM file support through 'libXpm'
225 # The check depends on variable 'enable_xpm' being either:
226 #   yes  - detect, fail if not found
227 #   no   - do not detect, use internal support
228 #   auto - detect, use internal if not found
230 # When found, append appropriate stuff in GFXLIBS, and append info to
231 # the variable 'supported_gfx'
232 AC_DEFUN_ONCE([WM_IMGFMT_CHECK_XPM],
233 [AC_REQUIRE([_WM_LIB_CHECK_FUNCTS])
234 AS_IF([test "x$enable_xpm" = "xno"],
235     [supported_gfx="$supported_gfx builtin-XPM"],
236     [AC_CACHE_CHECK([for XPM support library], [wm_cv_imgfmt_xpm],
237         [wm_cv_imgfmt_xpm=no
238          dnl
239          dnl We check first if one of the known libraries is available
240          wm_save_LIBS="$LIBS"
241          AS_IF([wm_fn_lib_try_link "XpmCreatePixmapFromData" "$XLFLAGS $XLIBS -lXpm"],
242            [wm_cv_imgfmt_xpm="-lXpm" ; break])
243          LIBS="$wm_save_LIBS"
244          AS_IF([test "x$enable_xpm$wm_cv_imgfmt_xpm" = "xyesno"],
245            [AC_MSG_ERROR([explicit libXpm support requested but no library found])])
246          AS_IF([test "x$wm_cv_imgfmt_xpm" != "xno"],
247            [dnl
248             dnl A library was found, now check for the appropriate header
249             wm_save_CFLAGS="$CFLAGS"
250             AS_IF([wm_fn_lib_try_compile "X11/xpm.h" "" "return 0" "$XCFLAGS"],
251               [],
252               [AC_MSG_ERROR([found $wm_cv_imgfmt_xpm but could not find appropriate header - are you missing libXpm-dev package?])])
253             AS_IF([wm_fn_lib_try_compile "X11/xpm.h" 'char *filename = "dummy";' 'XpmReadFileToXpmImage(filename, NULL, NULL)' "$XCFLAGS"],
254               [],
255               [AC_MSG_ERROR([found $wm_cv_imgfmt_xpm and header, but cannot compile - unsupported version?])])
256             CFLAGS="$wm_save_CFLAGS"])
257          ])
258     AS_IF([test "x$wm_cv_imgfmt_xpm" = "xno"],
259         [supported_gfx="$supported_gfx builtin-XPM"
260          enable_xpm="no"],
261         [supported_gfx="$supported_gfx XPM"
262          WM_APPEND_ONCE([$wm_cv_imgfmt_xpm], [GFXLIBS])
263          AC_DEFINE([USE_XPM], [1],
264            [defined when valid XPM library with header was found])])
265     ])
266 AM_CONDITIONAL([USE_XPM], [test "x$enable_xpm" != "xno"])dnl
267 ]) dnl AC_DEFUN
270 # WM_IMGFMT_CHECK_MAGICK
271 # ----------------------
273 # Check for MagickWand library to support more image file formats
274 # The check depends on variable 'enable_magick' being either:
275 #   yes  - detect, fail if not found
276 #   no   - do not detect, disable support
277 #   auto - detect, disable if not found
279 # When found, store the appropriate compilation flags in MAGICKFLAGS
280 # and MAGICKLIBS, and append info to the variable 'supported_gfx'
281 # When not found, append info to variable 'unsupported'
282 AC_DEFUN_ONCE([WM_IMGFMT_CHECK_MAGICK],
283 [AC_REQUIRE([_WM_LIB_CHECK_FUNCTS])
284 AS_IF([test "x$enable_magick" = "xno"],
285     [unsupported="$unsupported Magick"],
286     [AC_CACHE_CHECK([for Magick support library], [wm_cv_libchk_magick],
287         [wm_cv_libchk_magick=no
288          dnl First try to get the configuration from either pkg-config (the official way)
289          dnl or with the fallback MagickWand-config
290          AS_IF([test "x$PKGCONFIG" = "x"],
291              [AC_PATH_PROGS_FEATURE_CHECK([magickwand], [MagickWand-config],
292                  [wm_cv_libchk_magick_cflags=`$ac_path_magickwand --cflags`
293                   wm_cv_libchk_magick_libs=`$ac_path_magickwand --ldflags`
294                   wm_cv_libchk_magick=magickwand])],
295              [AS_IF([$PKGCONFIG --exists MagickWand],
296                  [wm_cv_libchk_magick_cflags=`$PKGCONFIG --cflags MagickWand`
297                   wm_cv_libchk_magick_libs=`$PKGCONFIG --libs MagickWand`
298                   wm_cv_libchk_magick=pkgconfig])])
299          AS_IF([test "x$wm_cv_libchk_magick" = "xno"],
300              [AS_IF([test "x$enable_magick" != "xauto"],
301                  [AC_MSG_RESULT([not found])
302                   AC_MSG_ERROR([explicit Magick support requested but configuration not found with pkg-config and MagickWand-config - are you missing libmagickwand-dev package?])])],
303              [dnl The configuration was found, check that it actually works
304               wm_save_LIBS="$LIBS"
305               dnl
306               dnl We check that the library is available
307               AS_IF([wm_fn_lib_try_link "NewMagickWand" "$wm_cv_libchk_magick_libs"],
308                   [wm_cv_libchk_magick=maybe])
309               LIBS="$wm_save_LIBS"
310               AS_IF([test "x$wm_cv_libchk_magick" != "xmaybe"],
311                   [AC_MSG_ERROR([MagickWand was found but the library does not link])])
312               dnl
313               dnl The library was found, check if header is available and compiles
314               wm_save_CFLAGS="$CFLAGS"
315               AS_IF([wm_fn_lib_try_compile "wand/magick_wand.h" "MagickWand *wand;" "wand = NewMagickWand()" "$wm_cv_libchk_magick_cflags"],
316                   [wm_cv_libchk_magick="$wm_cv_libchk_magick_cflags % $wm_cv_libchk_magick_libs"],
317                   [AC_MSG_ERROR([found MagickWand library but could not compile its header])])
318               CFLAGS="$wm_save_CFLAGS"])dnl
319          ])
320      AS_IF([test "x$wm_cv_libchk_magick" = "xno"],
321          [unsupported="$unsupported Magick"
322           enable_magick="no"],
323          [supported_gfx="$supported_gfx Magick"
324           MAGICKFLAGS=`echo "$wm_cv_libchk_magick" | sed -e 's, *%.*$,,' `
325            MAGICKLIBS=`echo "$wm_cv_libchk_magick" | sed -e 's,^.*% *,,' `
326           AC_DEFINE([USE_MAGICK], [1],
327               [defined when MagickWand library with header was found])])
328      ])
329 AM_CONDITIONAL([USE_MAGICK], [test "x$enable_magick" != "xno"])dnl
330 AC_SUBST(MAGICKFLAGS)dnl
331 AC_SUBST(MAGICKLIBS)dnl
332 ]) dnl AC_DEFUN