File: wm_imgfmt_check.m4

package info (click to toggle)
wmaker 0.95.7-8
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 14,876 kB
  • ctags: 10,510
  • sloc: ansic: 97,511; sh: 13,970; perl: 3,582; makefile: 1,476; lisp: 219; python: 34
file content (332 lines) | stat: -rw-r--r-- 14,811 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# wm_imgfmt_check.m4 - Macros to check for image file format support libraries
#
# Copyright (c) 2013 Christophe CURIS
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


# WM_IMGFMT_CHECK_GIF
# -------------------
#
# Check for GIF file support through 'libgif' or 'giflib v5'
# The check depends on variable 'enable_gif' being either:
#   yes  - detect, fail if not found
#   no   - do not detect, disable support
#   auto - detect, disable if not found
#
# When found, append appropriate stuff in GFXLIBS, and append info to
# the variable 'supported_gfx'
# When not found, append info to variable 'unsupported'
AC_DEFUN_ONCE([WM_IMGFMT_CHECK_GIF],
[AC_REQUIRE([_WM_LIB_CHECK_FUNCTS])
AS_IF([test "x$enable_gif" = "xno"],
    [unsupported="$unsupported GIF"],
    [AC_CACHE_CHECK([for GIF support library], [wm_cv_imgfmt_gif],
        [wm_cv_imgfmt_gif=no
         wm_save_LIBS="$LIBS"
         dnl
         dnl We check first if one of the known libraries is available
         for wm_arg in "-lgif" ; do
           AS_IF([wm_fn_lib_try_link "DGifOpenFileName" "$XLFLAGS $XLIBS $wm_arg"],
             [wm_cv_imgfmt_gif="$wm_arg" ; break])
         done
         LIBS="$wm_save_LIBS"
         AS_IF([test "x$enable_gif$wm_cv_imgfmt_gif" = "xyesno"],
           [AC_MSG_ERROR([explicit GIF support requested but no library found])])
         AS_IF([test "x$wm_cv_imgfmt_gif" != "xno"],
           [dnl
            dnl A library was found, now check for the appropriate header
            wm_save_CFLAGS="$CFLAGS"
            AS_IF([wm_fn_lib_try_compile "gif_lib.h" "" "return 0" ""],
              [],
              [AC_MSG_ERROR([found $wm_cv_imgfmt_gif but could not find appropriate header - are you missing libgif-dev package?])])
            AS_IF([wm_fn_lib_try_compile "gif_lib.h" 'const char *filename = "dummy";' "DGifOpenFileName(filename)" ""],
              [wm_cv_imgfmt_gif="$wm_cv_imgfmt_gif version:4"],
              [AC_COMPILE_IFELSE(
                [AC_LANG_PROGRAM(
                  [@%:@include <gif_lib.h>

const char *filename = "dummy";],
                  [  int error_code;
  DGifOpenFileName(filename, &error_code);] )],
                [wm_cv_imgfmt_gif="$wm_cv_imgfmt_gif version:5"],
                [AC_MSG_ERROR([found $wm_cv_imgfmt_gif and header, but cannot compile - unsupported version?])])dnl
              ]
            )
            CFLAGS="$wm_save_CFLAGS"])
         ])
    AS_IF([test "x$wm_cv_imgfmt_gif" = "xno"],
        [unsupported="$unsupported GIF"
         enable_gif="no"],
        [supported_gfx="$supported_gfx GIF"
         WM_APPEND_ONCE([`echo "$wm_cv_imgfmt_gif" | sed -e 's, *version:.*,,' `], [GFXLIBS])
         AC_DEFINE_UNQUOTED([USE_GIF],
           [`echo "$wm_cv_imgfmt_gif" | sed -e 's,.*version:,,' `],
           [defined when valid GIF library with header was found])])
    ])
AM_CONDITIONAL([USE_GIF], [test "x$enable_gif" != "xno"])dnl
]) dnl AC_DEFUN


# WM_IMGFMT_CHECK_JPEG
# --------------------
#
# Check for JPEG file support through 'libjpeg'
# The check depends on variable 'enable_jpeg' being either:
#   yes  - detect, fail if not found
#   no   - do not detect, disable support
#   auto - detect, disable if not found
#
# When found, append appropriate stuff in GFXLIBS, and append info to
# the variable 'supported_gfx'
# When not found, append info to variable 'unsupported'
AC_DEFUN_ONCE([WM_IMGFMT_CHECK_JPEG],
[WM_LIB_CHECK([JPEG], [-ljpeg], [jpeg_destroy_compress], [$XLFLAGS $XLIBS],
    [AC_COMPILE_IFELSE(
                [AC_LANG_PROGRAM(
                    [@%:@include <stdlib.h>
@%:@include <stdio.h>
@%:@include <jpeglib.h>],
                    [  struct jpeg_decompress_struct cinfo;

  jpeg_destroy_decompress(&cinfo);])],
                [],
                [AS_ECHO([failed])
                 AS_ECHO(["$as_me: error: found $CACHEVAR but cannot compile header"])
                 AS_ECHO(["$as_me: error:   - does header 'jpeglib.h' exists? (is package 'jpeg-dev' missing?)"])
                 AS_ECHO(["$as_me: error:   - version of header is not supported? (report to dev team)"])
                 AC_MSG_ERROR([JPEG library is not usable, cannot continue])])
           ],
    [supported_gfx], [GFXLIBS])dnl
]) dnl AC_DEFUN


# WM_IMGFMT_CHECK_PNG
# -------------------
#
# Check for PNG file support through 'libpng'
# The check depends on variable 'enable_png' being either:
#   yes  - detect, fail if not found
#   no   - do not detect, disable support
#   auto - detect, disable if not found
#
# When found, append appropriate stuff in GFXLIBS, and append info to
# the variable 'supported_gfx'
# When not found, append info to variable 'unsupported'
AC_DEFUN_ONCE([WM_IMGFMT_CHECK_PNG],
[WM_LIB_CHECK([PNG], ["-lpng" "-lpng -lz" "-lpng -lz -lm"], [png_get_valid], [$XLFLAGS $XLIBS],
    [wm_save_CFLAGS="$CFLAGS"
     AS_IF([wm_fn_lib_try_compile "png.h" "" "return 0" ""],
         [],
         [AC_MSG_ERROR([found $CACHEVAR but could not find appropriate header - are you missing libpng-dev package?])])
     AS_IF([wm_fn_lib_try_compile "png.h" "" "png_get_valid(NULL, NULL, PNG_INFO_tRNS)" ""],
         [],
         [AC_MSG_ERROR([found $CACHEVAR and header, but cannot compile - unsupported version?])])
     CFLAGS="$wm_save_CFLAGS"],
    [supported_gfx], [GFXLIBS])dnl
]) dnl AC_DEFUN


# WM_IMGFMT_CHECK_TIFF
# --------------------
#
# Check for TIFF file support through 'libtiff'
# The check depends on variable 'enable_tiff' being either:
#   yes  - detect, fail if not found
#   no   - do not detect, disable support
#   auto - detect, disable if not found
#
# When found, append appropriate stuff in GFXLIBS, and append info to
# the variable 'supported_gfx'
# When not found, append info to variable 'unsupported'
AC_DEFUN_ONCE([WM_IMGFMT_CHECK_TIFF],
[WM_LIB_CHECK([TIFF],
    ["-ltiff"  \
     dnl TIFF can have a dependancy over zlib
     "-ltiff -lz" "-ltiff -lz -lm"  \
     dnl It may also have a dependancy to jpeg_lib
     "-ltiff -ljpeg" "-ltiff -ljpeg -lz" "-ltiff -ljpeg -lz -lm"  \
     dnl There is also a possible dependancy on JBIGKit
     "-ltiff -ljpeg -ljbig -lz"  \
     dnl Probably for historical reasons?
     "-ltiff34" "-ltiff34 -ljpeg" "-ltiff34 -ljpeg -lm"],
    [TIFFGetVersion], [$XLFLAGS $XLIBS],
    [wm_save_CFLAGS="$CFLAGS"
     AS_IF([wm_fn_lib_try_compile "tiffio.h" "" "return 0" ""],
         [],
         [AC_MSG_ERROR([found $CACHEVAR but could not find appropriate header - are you missing libtiff-dev package?])])
     AS_IF([wm_fn_lib_try_compile "tiffio.h" 'const char *filename = "dummy";' 'TIFFOpen(filename, "r")' ""],
         [],
         [AC_MSG_ERROR([found $CACHEVAR and header, but cannot compile - unsupported version?])])
     CFLAGS="$wm_save_CFLAGS"],
    [supported_gfx], [GFXLIBS])dnl
]) dnl AC_DEFUN


# WM_IMGFMT_CHECK_WEBP
# --------------------
#
# Check for WEBP file support through 'libwebp'
# The check depends on variable 'enable_webp' being either:
#   yes  - detect, fail if not found
#   no   - do not detect, disable support
#   auto - detect, disable if not found
#
# When found, append appropriate stuff in GFXLIBS, and append info to
# the variable 'supported_gfx'
# When not found, append info to variable 'unsupported'
AC_DEFUN_ONCE([WM_IMGFMT_CHECK_WEBP],
[AS_IF([test "x$enable_webp" = "xno"],
    [unsupported="$unsupported WebP"],
    [AC_CACHE_CHECK([for WebP support library], [wm_cv_imgfmt_webp],
        [wm_cv_imgfmt_webp=no
         dnl
         dnl The library is using a special trick on the functions to provide
         dnl compatibility between versions, so we cannot try linking against
         dnl a symbol without first using the header to handle it
         wm_save_LIBS="$LIBS"
         LIBS="$LIBS -lwebp"
         AC_TRY_LINK(
             [@%:@include <webp/decode.h>],
             [WebPGetFeatures(NULL, 1024, NULL);],
             [wm_cv_imgfmt_webp="-lwebp"])
         LIBS="$wm_save_LIBS"
         AS_IF([test "x$enable_webp$wm_cv_imgfmt_webp" = "xyesno"],
              [AC_MSG_ERROR([explicit WebP support requested but no library found])])dnl
        ])
     AS_IF([test "x$wm_cv_imgfmt_webp" = "xno"],
         [unsupported="$unsupported WebP"
          enable_webp="no"],
         [supported_gfx="$supported_gfx WebP"
          WM_APPEND_ONCE([$wm_cv_imgfmt_webp], [GFXLIBS])dnl
          AC_DEFINE([USE_WEBP], [1],
              [defined when valid Webp library with header was found])])dnl
    ])
AM_CONDITIONAL([USE_WEBP], [test "x$enable_webp" != "xno"])dnl
])


# 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_LIB_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_lib_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_lib_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_lib_try_compile "X11/xpm.h" 'char *filename = "dummy";' 'XpmReadFileToXpmImage(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"
         WM_APPEND_ONCE([$wm_cv_imgfmt_xpm], [GFXLIBS])
         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_MAGICK
# ----------------------
#
# Check for MagickWand library to support more image file formats
# The check depends on variable 'enable_magick' being either:
#   yes  - detect, fail if not found
#   no   - do not detect, disable support
#   auto - detect, disable if not found
#
# When found, store the appropriate compilation flags in MAGICKFLAGS
# and MAGICKLIBS, and append info to the variable 'supported_gfx'
# When not found, append info to variable 'unsupported'
AC_DEFUN_ONCE([WM_IMGFMT_CHECK_MAGICK],
[AC_REQUIRE([_WM_LIB_CHECK_FUNCTS])
AS_IF([test "x$enable_magick" = "xno"],
    [unsupported="$unsupported Magick"],
    [AC_CACHE_CHECK([for Magick support library], [wm_cv_libchk_magick],
        [wm_cv_libchk_magick=no
         dnl First try to get the configuration from either pkg-config (the official way)
         dnl or with the fallback MagickWand-config
         AS_IF([test "x$PKGCONFIG" = "x"],
             [AC_PATH_PROGS_FEATURE_CHECK([magickwand], [MagickWand-config],
                 [wm_cv_libchk_magick_cflags=`$ac_path_magickwand --cflags`
                  wm_cv_libchk_magick_libs=`$ac_path_magickwand --ldflags`
                  wm_cv_libchk_magick=magickwand])],
             [AS_IF([$PKGCONFIG --exists MagickWand],
                 [wm_cv_libchk_magick_cflags=`$PKGCONFIG --cflags MagickWand`
                  wm_cv_libchk_magick_libs=`$PKGCONFIG --libs MagickWand`
                  wm_cv_libchk_magick=pkgconfig])])
         AS_IF([test "x$wm_cv_libchk_magick" = "xno"],
             [AS_IF([test "x$enable_magick" != "xauto"],
                 [AC_MSG_RESULT([not found])
                  AC_MSG_ERROR([explicit Magick support requested but configuration not found with pkg-config and MagickWand-config - are you missing libmagickwand-dev package?])])],
             [dnl The configuration was found, check that it actually works
              wm_save_LIBS="$LIBS"
              dnl
              dnl We check that the library is available
              AS_IF([wm_fn_lib_try_link "NewMagickWand" "$wm_cv_libchk_magick_libs"],
                  [wm_cv_libchk_magick=maybe])
              LIBS="$wm_save_LIBS"
              AS_IF([test "x$wm_cv_libchk_magick" != "xmaybe"],
                  [AC_MSG_ERROR([MagickWand was found but the library does not link])])
              dnl
              dnl The library was found, check if header is available and compiles
              wm_save_CFLAGS="$CFLAGS"
              AS_IF([wm_fn_lib_try_compile "wand/magick_wand.h" "MagickWand *wand;" "wand = NewMagickWand()" "$wm_cv_libchk_magick_cflags"],
                  [wm_cv_libchk_magick="$wm_cv_libchk_magick_cflags % $wm_cv_libchk_magick_libs"],
                  [AC_MSG_ERROR([found MagickWand library but could not compile its header])])
              CFLAGS="$wm_save_CFLAGS"])dnl
         ])
     AS_IF([test "x$wm_cv_libchk_magick" = "xno"],
         [unsupported="$unsupported Magick"
          enable_magick="no"],
         [supported_gfx="$supported_gfx Magick"
          MAGICKFLAGS=`echo "$wm_cv_libchk_magick" | sed -e 's, *%.*$,,' `
           MAGICKLIBS=`echo "$wm_cv_libchk_magick" | sed -e 's,^.*% *,,' `
          AC_DEFINE([USE_MAGICK], [1],
              [defined when MagickWand library with header was found])])
     ])
AM_CONDITIONAL([USE_MAGICK], [test "x$enable_magick" != "xno"])dnl
AC_SUBST(MAGICKFLAGS)dnl
AC_SUBST(MAGICKLIBS)dnl
]) dnl AC_DEFUN