Merge http://git.sxemacs.org/sxemacs
[sxemacs] / m4 / sxe-mm.m4
1 dnl sxe-mm.m4 -- Multimedia goodness
2
3 dnl MM tests
4 dnl ========
5
6 AC_DEFUN([SXE_MM_CHECK_XPM], [
7         ## arg #1: action on success
8         ## arg #2: action on failure
9         pushdef([MM_SUCC], [$1])
10         pushdef([MM_FAIL], [$2])
11
12         AC_MSG_CHECKING([for xpm support])
13         AC_MSG_RESULT([])
14
15         MM_SUCC
16         if test "$window_system" = "none"; then
17                 MM_FAIL
18         fi
19
20         SXE_DUMP_LIBS
21         SXE_LANG_WERROR([off])
22         CPPFLAGS="$CPPFLAGS $X_CFLAGS"
23         LDFLAGS="$LDFLAGS $X_PRE_LIBS $X_LIBS $libs_x"
24         LIBS="$LIBS -lXpm -lX11"
25
26         SXE_CHECK_HEADERS([X11/xpm.h], [:], [MM_FAIL])
27
28         AC_MSG_CHECKING([for Xpm (more recent than 3.4f)])
29         AC_RUN_IFELSE([AC_LANG_SOURCE([[
30 #define XPM_NUMBERS
31 #include <X11/xpm.h>
32 int main(int c, char **v)
33 {
34         return c == 1 ? 0 :
35                 XpmIncludeVersion != XpmLibraryVersion() ? 1 :
36                 XpmIncludeVersion < 30406 ? 2 : 0 ;
37 }]])], [./conftest dummy_arg; xpm_status=$?;
38                 if test "$xpm_status" = "0"; then
39                         AC_MSG_RESULT([yes])
40                 else
41                         AC_MSG_RESULT([no])
42                         MM_FAIL
43                         if test "$xpm_status" = "1"; then
44                                 AC_MSG_WARN([dnl
45 Xpm library version and header file version don't match!
46 I have disabled xpm on your behalf.])
47                         elif test "$xpm_status" = "2"; then
48                                 AC_MSG_WARN([dnl
49 Xpm library version is too old!
50 I have disabled xpm on your behalf.])
51                         else
52                                 AC_MSG_WARN([dnl
53 Internal xpm detection logic error!])
54                         fi
55                 fi], [dnl
56                 AC_MSG_RESULT([no])
57                 MM_FAIL], [dnl
58                 AC_MSG_RESULT([no])
59                 MM_FAIL])
60         xe_check_libs=
61         SXE_RESTORE_LIBS
62 ])dnl SXE_MM_CHECK_XPM
63
64 AC_DEFUN([SXE_MM_CHECK_XFACE], [
65         ## arg #1: action on success
66         ## arg #2: action on failure
67         pushdef([MM_SUCC], [$1])
68         pushdef([MM_FAIL], [$2])
69
70         AC_MSG_CHECKING([for xface support])
71         AC_MSG_RESULT([])
72
73         SXE_DUMP_LIBS
74         SXE_LANG_WERROR([off])
75         dnl SXE_PREPEND([-I$x_includes], [c_switch_site])
76         dnl SXE_PREPEND([-L$x_libraries], [ld_switch_site])
77         CPPFLAGS="$CPPFLAGS $X_CFLAGS"
78         LDFLAGS="$LDFLAGS $X_LIBS"
79
80         MM_SUCC
81         if test "$window_system" = "none"; then
82                 MM_FAIL
83         fi
84
85         SXE_CHECK_HEADERS([compface.h], [:], [MM_FAIL])
86         AC_CHECK_LIB([compface], [UnGenFace], [:], [MM_FAIL])
87
88         SXE_RESTORE_LIBS
89 ])dnl SXE_MM_CHECK_XFACE
90
91 AC_DEFUN([SXE_MM_CHECK_GIF], [
92         ## arg #1: action on success
93         ## arg #2: action on failure
94         pushdef([MM_SUCC], [$1])
95         pushdef([MM_FAIL], [$2])
96
97         AC_MSG_CHECKING([for gif support])
98         AC_MSG_RESULT([])
99
100         SXE_DUMP_LIBS
101
102         MM_SUCC
103         if test "$window_system" = "none"; then
104                 MM_FAIL
105         fi
106
107         SXE_RESTORE_LIBS
108 ])dnl SXE_MM_CHECK_GIF
109
110 AC_DEFUN([SXE_MM_CHECK_JPEG], [
111         ## arg #1: action on success
112         ## arg #2: action on failure
113         pushdef([MM_SUCC], [$1])
114         pushdef([MM_FAIL], [$2])
115
116         AC_MSG_CHECKING([for jpeg support])
117         AC_MSG_RESULT([])
118
119         SXE_DUMP_LIBS
120         SXE_LANG_WERROR([off])
121         dnl SXE_PREPEND([-I$x_includes], [c_switch_site])
122         dnl SXE_PREPEND([-L$x_libraries], [ld_switch_site])
123         CPPFLAGS="$CPPFLAGS $X_CFLAGS"
124         LDFLAGS="$LDFLAGS $X_LIBS"
125
126         MM_SUCC
127         if test "$window_system" = "none"; then
128                 MM_FAIL
129         fi
130
131         SXE_CHECK_HEADERS([jpeglib.h], [:], [MM_FAIL])
132         AC_CHECK_LIB([jpeg], [jpeg_destroy_decompress], [:], [MM_FAIL], [$INFLATE_LIB])
133
134         SXE_RESTORE_LIBS
135 ])dnl SXE_MM_CHECK_JPEG
136
137
138 AC_DEFUN([_SXE_MM_CHECK_PNG_HEADERS], [dnl
139         ## defines sxe_cv_feat_png_headers
140         ## also defines and substs PNG_CPPFLAGS
141
142         SXE_DUMP_LIBS
143         SXE_LANG_WERROR([off])
144         PNG_CPPFLAGS="$CPPFLAGS $X_CFLAGS"
145         CPPFLAGS="$PNG_CPPFLAGS"
146         SXE_CHECK_HEADERS([png.h])
147         SXE_RESTORE_LIBS
148
149         if test "${ac_cv_header_png_h}" = "yes"; then
150                 sxe_cv_feat_png_headers="yes"
151         else
152                 sxe_cv_feat_png_headers="no"
153         fi
154
155         AC_SUBST([PNG_CPPFLAGS])
156 ])dnl _SXE_MM_CHECK_PNG_HEADERS
157
158 AC_DEFUN([_SXE_MM_CHECK_PNG_LIBS], [dnl
159         ## defines sxe_cv_feat_png_libs
160         ## also defines and substs PNG_LIBS and PNG_LDFLAGS
161
162         SXE_DUMP_LIBS
163         SXE_LANG_WERROR([off])
164         PNG_LDFLAGS="$LDFLAGS $X_LIBS"
165         LDFLAGS="$PNG_LDFLAGS"
166         AC_CHECK_LIB([png], [png_read_image], [], [], [$INFLATE_LIB])
167         SXE_RESTORE_LIBS
168
169         if test "${ac_cv_lib_png_png_read_image}" = "yes"; then
170                 sxe_cv_feat_png_libs="yes"
171                 PNG_LIBS="$INFLATE_LIB -lpng"
172         else
173                 sxe_cv_feat_png_libs="no"
174                 PNG_LIBS=
175         fi
176
177         AC_SUBST([PNG_LIBS])
178         AC_SUBST([PNG_LDFLAGS])
179 ])dnl _SXE_MM_CHECK_PNG_LIBS
180
181 AC_DEFUN([_SXE_MM_CHECK_PNG_VERSION], [dnl
182         ## defines sxe_cv_tmp_png_status to yes if version info seems okay
183         AC_REQUIRE([_SXE_MM_CHECK_PNG_HEADERS])
184         AC_REQUIRE([_SXE_MM_CHECK_PNG_LIBS])
185
186         SXE_MSG_CHECKING([for workable png version information])
187
188         SXE_DUMP_LIBS
189         LDFLAGS="$LDFLAGS $PNG_LDFLAGS"
190         LIBS="$LIBS $PNG_LIBS"
191         AC_RUN_IFELSE([AC_LANG_SOURCE([[
192 #if defined HAVE_PNG_H
193 # include <png.h>
194 #endif /* HAVE_PNG_H */
195
196 int main(int c, char **v)
197 {
198         if (c == 1) {
199                 return 0;
200         }
201         if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING) != 0) {
202                 return 1;
203         }
204         return (PNG_LIBPNG_VER < 10002) ? 2 : 0 ;
205 }]])], [./conftest dummy_arg; png_status=$?;
206                 if test "$png_status" = "0"; then
207                         sxe_cv_tmp_png_status="yes"
208
209                 elif test "$png_status" = "1"; then
210                         sxe_cv_tmp_png_status="yes"
211                         AC_MSG_WARN([dnl
212 PNG library version and header file don't match!
213 This is odd but I think I give it a whirl.
214 If things work out badly I suggest to turn off your computer forever.])
215
216                 elif test "$png_status" = "2"; then
217                         sxe_cv_tmp_png_status="no"
218                         AC_MSG_WARN([dnl
219 PNG library version too old (pre 1.0.2)!
220 I have disabled PNG support on your behalf.])
221
222                 else
223                         sxe_cv_tmp_png_status="no"
224                         AC_MSG_ERROR([dnl
225 Whatever happened just now, I'm completely fucked.])
226                 fi], [sxe_cv_tmp_png_status="no"], [sxe_cv_tmp_png_status="no"])
227         SXE_MSG_RESULT([${sxe_cv_tmp_png_status}])
228         SXE_RESTORE_LIBS
229 ])dnl _SXE_MM_CHECK_PNG_VERSION
230
231 AC_DEFUN([SXE_MM_CHECK_PNG], [
232         ## SXE_MM_CHECK_PNG(<action-if-found>, <action-if-not-found>)
233         ## defines HAVE_PNG in case png is usable
234         pushdef([MM_SUCC], [$1])
235         pushdef([MM_FAIL], [$2])
236
237         SXE_MSG_CHECKING([for PNG support])
238         SXE_MSG_RESULT([])
239
240         _SXE_MM_CHECK_PNG_HEADERS
241         _SXE_MM_CHECK_PNG_LIBS
242         _SXE_MM_CHECK_PNG_VERSION
243
244         ## final judgement
245         ## we want to see a header and png_read_image really
246         if test "${sxe_cv_feat_png_headers}" = "yes" -a \
247                 "${sxe_cv_feat_png_libs}" = "yes" -a \
248                 "${sxe_cv_tmp_png_status}" = "yes"; then
249                 sxe_cv_feat_png="yes"
250                 AC_DEFINE([HAVE_PNG], [1], [Define to 1 if png is usable.])
251                 MM_SUCC
252         else
253                 sxe_cv_feat_png="no"
254                 MM_FAIL
255         fi
256 ])dnl SXE_MM_CHECK_PNG
257
258 AC_DEFUN([SXE_MM_CHECK_TIFF], [
259         ## arg #1: action on success
260         ## arg #2: action on failure
261         pushdef([MM_SUCC], [$1])
262         pushdef([MM_FAIL], [$2])
263
264         AC_MSG_CHECKING([for TIFF support])
265         AC_MSG_RESULT([])
266
267         SXE_DUMP_LIBS
268         SXE_LANG_WERROR([off])
269         dnl SXE_PREPEND([-I$x_includes], [c_switch_site])
270         dnl SXE_PREPEND([-L$x_libraries], [ld_switch_site])
271         CPPFLAGS="$CPPFLAGS $X_CFLAGS"
272         LDFLAGS="$LDFLAGS $X_LIBS"
273
274         MM_SUCC
275         if test "$window_system" = "none"; then
276                 MM_FAIL
277         fi
278
279         SXE_CHECK_HEADERS([tiffio.h], [:], [MM_FAIL])
280         AC_CHECK_LIB([tiff], [TIFFClientOpen], [:], [MM_FAIL], [$INFLATE_LIB])
281
282         SXE_RESTORE_LIBS
283 ])dnl SXE_MM_CHECK_TIFF
284
285 AC_DEFUN([SXE_MM_SEARCH_INFLATE], [
286         dnl Too many stupid linkers can't detect cascaded lib dependencies
287         dnl  until runtime. So we always search for libz compression support.
288         AC_SEARCH_LIBS([inflate], [c z gz], [
289                 if test "$ac_cv_lib_c_inflate" = "yes"; then
290                         INFLATE_LIB="c"
291                 elif test "$ac_cv_lib_z_inflate" = "yes"; then
292                         INFLATE_LIB="z"
293                 elif test "$ac_cv_lib_gz_inflate" = "yes"; then
294                         INFLATE_LIB="gz"
295                 fi], [INFLATE_LIB=])
296         if test -n "$INFLATE_LIB"; then
297                 SXE_PREPEND([$INFLATE_LIB], [MM_LIBS])
298         fi
299 ])dnl SXE_MM_SEARCH_INFLATE
300
301 AC_DEFUN([SXE_MM_CHECK_SNDFILE], [
302         ## assumes $PKG_CONFIG is defined
303         ## arg #1: action on success
304         ## arg #2: action on failure
305
306         _SXE_MM_CHECK_pkgconfig_based([sndfile], [sndfile], [1.0.12], [dnl
307                 sf_open sf_close sf_readf_short sf_readf_int dnl
308                 sf_readf_float sf_seek sf_open_virtual],
309                 [sndfile.h], [$1], [$2])
310 ])dnl SXE_MM_CHECK_SNDFILE
311
312 AC_DEFUN([SXE_MM_CHECK_FFMPEG], [
313         ## assumes $PKG_CONFIG is defined
314         ## arg #1: action on success
315         ## arg #2: action on failure
316         pushdef([ACTION_IF_FOUND], [$1])
317         pushdef([ACTION_IF_NOT_FOUND], [$2])
318
319         sxe_cv_feat_ffmpeg=
320         ## we can't use that one since we have to check multiple headers
321 dnl     _SXE_MM_CHECK_pkgconfig_based([ffmpeg], [libavformat], [49.0.0], [dnl
322 dnl             av_open_input_file av_close_input_file av_find_stream_info dnl
323 dnl             url_fopen av_probe_input_format avcodec_find_decoder dnl
324 dnl             avcodec_open av_read_frame av_seek_frame av_register_all dnl
325 dnl             avcodec_decode_audio avcodec_decode_audio2], [avformat.h],
326 dnl             [sxe_cv_feat_ffmpeg=yes], [sxe_cv_feat_ffmpeg=no])
327
328 dnl     Dropped in favour of sxe-pkgconfig.m4 macros
329 dnl     _SXE_CHECK_pkgconfig_based([ffmpeg], [libavformat], [49.0.0])
330
331         SXE_PC_CHECK_VERSION_ATLEAST([libavformat], [51.0.0])
332
333         SXE_CHECK_FFMPEG_HEADERS
334         SXE_CHECK_FFMPEG_LIBS
335
336         ## make sure we have at least one of the headers
337         if test "$ac_cv_header_avformat_h" = "yes" -o \
338                 "$ac_cv_header_ffmpeg_avformat_h" = "yes" -o \
339                 "$ac_cv_header_libavformat_avformat_h" = "yes"; then
340                 sxe_cv_feat_ffmpeg_headers="yes"
341         fi
342         ## make sure either decode_audio or decode_audio2 is there
343         if test "$ac_cv_lib_avformat_avcodec_decode_audio2" = "yes" -o \
344                 "$ac_cv_lib_avformat_avcodec_decode_audio" = "yes"; then
345                 sxe_cv_feat_ffmpeg_decoders="yes"
346         fi
347         ## make sure we can either use av_register_protocol()
348         ## or register_protocol()
349         if test "$ac_cv_lib_avformat_av_register_protocol" = "yes" -o \
350                 "$ac_cv_lib_avformat_register_protocol" = "yes"; then
351                 sxe_cv_feat_ffmpeg_proto_reg="yes"
352         fi
353         ## make sure this bloody av context allocator is there
354         if test "$ac_cv_lib_avformat_avformat_alloc_context" = "yes" -o \
355                 "$ac_cv_lib_avformat_av_alloc_format_context" = "yes"; then
356                 sxe_cv_feat_ffmpeg_avformat_alloc="yes"
357         fi
358         if test "$sxe_cv_feat_ffmpeg_headers" = "yes" -a \
359                 "$sxe_cv_feat_ffmpeg_decoders" = "yes" -a \
360                 "$sxe_cv_feat_ffmpeg_proto_reg" = "yes" -a \
361                 "$sxe_cv_feat_ffmpeg_avformat_alloc" = "yes" -a \
362                 "$ac_cv_lib_avformat_av_close_input_file" = "yes" -a \
363                 "$ac_cv_lib_avformat_av_find_stream_info" = "yes" -a \
364                 "$ac_cv_lib_avformat_av_open_input_file" = "yes" -a \
365                 "$ac_cv_lib_avformat_av_probe_input_format" = "yes" -a \
366                 "$ac_cv_lib_avformat_av_read_frame" = "yes" -a \
367                 "$ac_cv_lib_avformat_av_register_all" = "yes" -a \
368                 "$ac_cv_lib_avformat_av_seek_frame" = "yes" -a \
369                 "$ac_cv_lib_avformat_avcodec_find_decoder" = "yes" -a \
370                 "$ac_cv_lib_avformat_avcodec_open" = "yes" -a \
371                 "$ac_cv_lib_avformat_url_fopen" = "yes"; then
372                 sxe_cv_feat_ffmpeg="yes"
373         else
374                 sxe_cv_feat_ffmpeg="no"
375         fi
376
377         ## newer ffmpegs want a bioctx** in url_fopen, check that
378         AC_MSG_CHECKING([what url_fopen() needs])
379         sxe_cv_tmp_ffmpeg_url_fopen="uncertain"
380
381         SXE_DUMP_LIBS
382         CPPFLAGS="$CPPFLAGS ${FFMPEG_CPPFLAGS}"
383         SXE_LANG_WERROR([off])
384         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
385 #if defined HAVE_ERRNO_H
386 # include <errno.h>
387 #endif
388 #if defined HAVE_LIBAVFORMAT_AVFORMAT_H
389 # include <libavformat/avformat.h>
390 #elif defined HAVE_FFMPEG_AVFORMAT_H
391 # include <ffmpeg/avformat.h>
392 #elif defined HAVE_AVFORMAT_H
393 # include <avformat.h>
394 #endif
395
396 extern int foobar(void);
397 int foobar(void)
398 {
399         ByteIOContext *bioctx = 0;
400
401         url_fopen(&bioctx, "/foobar", URL_RDONLY);
402         return 0;
403 }
404                 ]])], [sxe_cv_tmp_ffmpeg_url_fopen="ByteIOContext**"], [:])
405         SXE_RESTORE_LIBS
406
407         SXE_DUMP_LIBS
408         CPPFLAGS="$CPPFLAGS ${FFMPEG_CPPFLAGS}"
409         SXE_LANG_WERROR([on])
410         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
411 #if defined HAVE_ERRNO_H
412 # include <errno.h>
413 #endif
414 #if defined HAVE_LIBAVFORMAT_AVFORMAT_H
415 # include <libavformat/avformat.h>
416 #elif defined HAVE_FFMPEG_AVFORMAT_H
417 # include <ffmpeg/avformat.h>
418 #elif defined HAVE_AVFORMAT_H
419 # include <avformat.h>
420 #endif
421
422 extern int foobar(void);
423 int foobar(void)
424 {
425         ByteIOContext *bioctx = 0;
426
427         url_fopen(bioctx, "/foobar", URL_RDONLY);
428         return 0;
429 }
430                 ]])], [sxe_cv_tmp_ffmpeg_url_fopen="ByteIOContext*"], [:])
431         SXE_RESTORE_LIBS
432
433         ## post the result
434         AC_MSG_RESULT([$sxe_cv_tmp_ffmpeg_url_fopen])
435
436         if test "$sxe_cv_tmp_ffmpeg_url_fopen" = "ByteIOContext**"; then
437                 AC_DEFINE([FFMPEG_URL_FOPEN_BIOCTX_STAR_STAR], [1],
438                         [Whether url_fopen want a ByteIOContext**])
439         elif test "$sxe_cv_tmp_ffmpeg_url_fopen" = "ByteIOContext*"; then
440                 AC_DEFINE([FFMPEG_URL_FOPEN_BIOCTX_STAR], [1],
441                         [Whether url_fopen want a ByteIOContext*])
442         else
443                 sxe_cv_feat_ffmpeg="no"
444         fi
445
446         if test "$sxe_cv_feat_ffmpeg" = "yes"; then
447                 :
448                 ACTION_IF_FOUND
449         else
450                 :
451                 ACTION_IF_NOT_FOUND
452         fi
453
454         popdef([ACTION_IF_FOUND])
455         popdef([ACTION_IF_NOT_FOUND])
456 ])dnl SXE_MM_CHECK_FFMPEG
457
458 AC_DEFUN([SXE_CHECK_FFMPEG_HEADERS], [dnl
459         FFMPEG_CPPFLAGS="$(${PKG_CONFIG} --cflags libavformat)"
460
461         ## backup current configuration
462         SXE_DUMP_LIBS
463         CPPFLAGS="${CPPFLAGS} ${FFMPEG_CPPFLAGS}"
464         AC_CHECK_HEADERS([avformat.h ffmpeg/avformat.h libavformat/avformat.h])
465         ## restore configuration
466         SXE_RESTORE_LIBS
467 ])dnl SXE_CHECK_FFMPEG_HEADERS
468
469 AC_DEFUN([SXE_CHECK_FFMPEG_LIBS], [dnl
470         FFMPEG_LDFLAGS="$(${PKG_CONFIG} --libs-only-other libavformat) \
471                 $(${PKG_CONFIG} --libs-only-L libavformat)"
472         FFMPEG_LIBS="$(${PKG_CONFIG} --libs-only-l libavformat)"
473
474         ## backup current configuration
475         SXE_DUMP_LIBS
476         LDFLAGS="${LDFLAGS} ${FFMPEG_LDFLAGS}"
477
478         AC_CHECK_LIB([avformat], [av_open_input_file], [:], [:], [${FFMPEG_LIBS}])
479         AC_CHECK_LIB([avformat], [av_close_input_file], [:], [:], [${FFMPEG_LIBS}])
480         AC_CHECK_LIB([avformat], [av_find_stream_info], [:], [:], [${FFMPEG_LIBS}])
481         AC_CHECK_LIB([avformat], [url_fopen], [:], [:], [${FFMPEG_LIBS}])
482         AC_CHECK_LIB([avformat], [av_probe_input_format], [:], [:], [${FFMPEG_LIBS}])
483         AC_CHECK_LIB([avformat], [avcodec_find_decoder], [:], [:], [${FFMPEG_LIBS}])
484         AC_CHECK_LIB([avformat], [avcodec_open], [:], [:], [${FFMPEG_LIBS}])
485         AC_CHECK_LIB([avformat], [av_read_frame], [:], [:], [${FFMPEG_LIBS}])
486         AC_CHECK_LIB([avformat], [av_seek_frame], [:], [:], [${FFMPEG_LIBS}])
487         AC_CHECK_LIB([avformat], [av_register_all], [:], [:], [${FFMPEG_LIBS}])
488         AC_CHECK_LIB([avformat], [avcodec_decode_audio], [:], [:], [${FFMPEG_LIBS}])
489         AC_CHECK_LIB([avformat], [avcodec_decode_audio2], [:], [:], [${FFMPEG_LIBS}])
490
491         AC_CHECK_LIB([avformat], [av_alloc_format_context], [:], [:], [${FFMPEG_LIBS}])
492         AC_CHECK_LIB([avformat], [avformat_alloc_context], [:], [:], [${FFMPEG_LIBS}])
493         AC_CHECK_LIB([avformat], [register_protocol], [:], [:], [${FFMPEG_LIBS}])
494         AC_CHECK_LIB([avformat], [av_register_protocol], [:], [:], [${FFMPEG_LIBS}])
495
496         if test "$ac_cv_lib_avformat_av_alloc_format_context" = "yes"; then
497                 AC_DEFINE([HAVE_AV_ALLOC_FORMAT_CONTEXT], [1], [Description here!])
498         fi
499         if test "$ac_cv_lib_avformat_avformat_alloc_context" = "yes"; then
500                 AC_DEFINE([HAVE_AVFORMAT_ALLOC_CONTEXT], [1], [Description here!])
501         fi
502
503         if test "$ac_cv_lib_avformat___avcodec_decode_audio2" = "yes" -o \
504                 "$ac_cv_lib_avformat_avcodec_decode_audio2" = "yes"; then
505                 AC_DEFINE([HAVE_AVCODEC_DECODE_AUDIO2], [1], [Description here!])
506         fi
507         if test "$ac_cv_lib_avformat___avcodec_decode_audio" = "yes" -o \
508                 "$ac_cv_lib_avformat_avcodec_decode_audio" = "yes"; then
509                 AC_DEFINE([HAVE_AVCODEC_DECODE_AUDIO], [1], [Description here!])
510         fi
511
512         if test "$ac_cv_lib_avformat_av_register_protocol" = "yes"; then
513                 AC_DEFINE([HAVE_AV_REGISTER_PROTOCOL], [1], [Description here!])
514         fi
515         if test "$ac_cv_lib_avformat_register_protocol" = "yes"; then
516                 AC_DEFINE([HAVE_REGISTER_PROTOCOL], [1], [Description here!])
517         fi
518
519         ## restore configuration
520         SXE_RESTORE_LIBS
521 ])dnl SXE_CHECK_FFMPEG_LIBS
522
523
524 dnl
525 dnl SoX
526 dnl ===
527 AC_DEFUN([SXE_MM_CHECK_SOX], [dnl
528         ## call like this SXE_MM_CHECK_SOX([<if-found>], [<if-not-found>])
529         ## arg #1: action on success
530         ## arg #2: action on failure
531         pushdef([ACTION_IF_FOUND], [$1])
532         pushdef([ACTION_IF_NOT_FOUND], [$2])
533
534         AC_CACHE_CHECK([for SoX support], [sxe_cv_feat_sox], [_SXE_CHECK_SOX])
535
536         if test "$sox_too_old" = "yes"; then
537                 AS_MESSAGE([*** Detected SoX, but it is too old.])
538                 AS_MESSAGE([*** Consider upgrading, see http://sox.sourceforge.net])
539                 ACTION_IF_NOT_FOUND
540                 :
541         elif test "$sxe_cv_feat_sox" = "yes"; then
542                 ACTION_IF_FOUND
543                 :
544         else
545                 ACTION_IF_NOT_FOUND
546                 :
547         fi
548
549         popdef([ACTION_IF_FOUND])
550         popdef([ACTION_IF_NOT_FOUND])
551 ])dnl SXE_MM_CHECK_SOX
552
553 AC_DEFUN([_SXE_CHECK_SOX], [dnl
554         AC_REQUIRE([SXE_CHECK_SOX_LOCATOR])
555
556         if test "$have_libst_config" = "no" -o -z "$LIBST_CONFIG"; then
557                 AS_MESSAGE([*** libst-config not found.])
558                 AS_MESSAGE([*** Cannot check for SoX.])
559                 have_libst_config=no
560                 LIBST_CONFIG=
561         else
562                 AC_REQUIRE([SXE_CHECK_SOX_LOCATIONS])
563                 AC_REQUIRE([SXE_CHECK_SOX_HEADERS])
564                 AC_REQUIRE([SXE_CHECK_SOX_LIBS])
565                 AC_REQUIRE([SXE_CHECK_SOX_STRUCTS])
566                 :
567         fi
568
569         if test "$ac_cv_lib_sox_sox_open_read" = "yes" -a \
570                 "$ac_cv_lib_sox_sox_close" = "yes" -a \
571                 "$ac_cv_lib_sox_sox_seek" = "yes" -a \
572                 "$ac_cv_header_sox_h" = "yes" -a \
573                 "$ac_cv_type_sox_format_t" = "yes" -a \
574                 "$ac_cv_type_struct_sox_format" = "yes" -a \
575                 "$sxe_cv_mm_sox_open_read_fooked" != "yes"; then
576                 sox_libs="-lsox $sox_libs"
577                 sxe_cv_feat_sox="yes"
578         elif test "$ac_cv_lib_st_st_close" = "yes" -a \
579                 "$ac_cv_lib_st_st_read" = "yes" -a \
580                 "$ac_cv_lib_st_st_seek" = "yes" -a \
581                 "$ac_cv_header_st_h" = "yes" -a \
582                 "$ac_cv_type_ft_t" = "yes" -a \
583                 "$ac_cv_type_struct_st_soundstream" = "yes" -a \
584                 "$sxe_cv_mm_sox_open_read_fooked" != "yes"; then
585                 sox_libs="-lst $sox_libs"
586                 sxe_cv_feat_sox="yes"
587         else
588                 sxe_cv_feat_sox="no"
589         fi
590 ])dnl _SXE_CHECK_SOX
591
592 AC_DEFUN([SXE_CHECK_SOX_LOCATOR], [dnl
593         SXE_SEARCH_CONFIG_PROG([libst-config])
594 ])dnl SXE_CHECK_SOX_LOCATOR
595
596 AC_DEFUN([SXE_CHECK_SOX_LOCATIONS], [dnl
597         AC_REQUIRE([SXE_CHECK_SOX_LOCATOR])
598         if test "$have_libst_config" = "no" -o -z "$LIBST_CONFIG"; then
599                 sox_cppflags=
600                 sox_ldflags=
601                 sox_libs=
602         else
603                 sox_cppflags="$($LIBST_CONFIG --cflags)"
604                 sox_ldflags="-L$($LIBST_CONFIG --libdir)"
605                 sox_libs="$($LIBST_CONFIG --libs)"
606         fi
607 ])dnl SXE_CHECK_SOX_PLACES
608
609 AC_DEFUN([SXE_PUMP_SOX_LOCATIONS], [dnl
610         SXE_DUMP_LIBS
611         CPPFLAGS="$CPPFLAGS $sox_cppflags"
612         LDFLAGS="$LDFLAGS $sox_ldflags"
613         LIBS="$LIBS $sox_libs"
614 ])dnl SXE_PUMP_SOX_LOCATIONS
615
616 AC_DEFUN([SXE_DUMP_SOX_LOCATIONS], [dnl
617         SXE_RESTORE_LIBS
618 ])dnl SXE_DUMP_SOX_LOCATIONS
619
620 AC_DEFUN([SXE_CHECK_SOX_HEADERS], [dnl
621         AC_REQUIRE([SXE_CHECK_SOX_LOCATIONS])
622         SXE_PUMP_SOX_LOCATIONS
623         AC_CHECK_HEADERS([st.h])
624         AC_CHECK_HEADERS([sox.h])
625         SXE_DUMP_SOX_LOCATIONS
626 ])dnl SXE_CHECK_SOX_HEADERS
627
628 AC_DEFUN([SXE_CHECK_SOX_LIBS], [dnl
629         AC_REQUIRE([SXE_CHECK_SOX_LOCATIONS])
630
631         echo "void cleanup(void) {}" > cleanup.c
632         $CC -c -o cleanup.o cleanup.c
633
634         SXE_PUMP_SOX_LOCATIONS
635         ## we need 12.17.9 with st_open_read
636         AC_CHECK_LIB([st], [st_open_read], [:], [:],
637                 [cleanup.o $sox_ldflags $sox_libs])
638         AC_CHECK_LIB([st], [st_close], [:], [:], [cleanup.o $sox_ldflags $sox_libs])
639         AC_CHECK_LIB([st], [st_read], [:], [:], [cleanup.o $sox_ldflags $sox_libs])
640         AC_CHECK_LIB([st], [st_seek], [:], [:], [cleanup.o $sox_ldflags $sox_libs])
641
642         ## checks for the spankin' new sox
643         AC_CHECK_LIB([sox], [sox_open_read], [:], [:],
644                 [cleanup.o $sox_ldflags $sox_libs])
645         AC_CHECK_LIB([sox], [sox_close], [:], [:], [cleanup.o $sox_ldflags $sox_libs])
646         AC_CHECK_LIB([sox], [sox_read], [:], [:], [cleanup.o $sox_ldflags $sox_libs])
647         AC_CHECK_LIB([sox], [sox_seek], [:], [:], [cleanup.o $sox_ldflags $sox_libs])
648
649         SXE_DUMP_SOX_LOCATIONS
650
651         SXE_DUMP_LIBS
652         CPPFLAGS="$CPPFLAGS ${SOX_CPPFLAGS}"
653         SXE_LANG_WERROR([on])
654         SXE_MSG_CHECKING([whether sox_open_read() takes 4 arguments])
655         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
656 #if defined HAVE_ERRNO_H
657 # include <errno.h>
658 #endif
659 #if defined HAVE_SOX_H
660 # include <sox.h>
661 #endif
662                 ]], [
663                 sox_open_read("tmp", NULL, NULL, NULL);
664                 ])],
665                 [sxe_cv_mm_sox_open_read_4args="yes"],
666                 [sxe_cv_mm_sox_open_read_4args="no"])
667         SXE_MSG_RESULT([$sxe_cv_mm_sox_open_read_4args])
668
669         SXE_MSG_CHECKING([whether sox_open_read() takes 3 arguments])
670         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
671 #if defined HAVE_ERRNO_H
672 # include <errno.h>
673 #endif
674 #if defined HAVE_SOX_H
675 # include <sox.h>
676 #endif
677                 ]], [
678                 sox_open_read("tmp", NULL, NULL);
679                 ])],
680                 [sxe_cv_mm_sox_open_read_3args="yes"],
681                 [sxe_cv_mm_sox_open_read_3args="no"])
682         SXE_MSG_RESULT([$sxe_cv_mm_sox_open_read_3args])
683         SXE_RESTORE_LIBS
684
685         if test "$sxe_cv_mm_sox_open_read_3args" = "yes"; then
686                 AC_DEFINE([HAVE_SOX_OPEN_READ_3ARGS], [1],
687                         [Whether sox_open_read() takes 3 arguments.])
688                 AC_DEFINE([HAVE_SOX_OPEN_READ_NARGS], [3],
689                         [How many arguments sox_open_read() takes.])
690         elif test "$sxe_cv_mm_sox_open_read_4args" = "yes"; then
691                 AC_DEFINE([HAVE_SOX_OPEN_READ_4ARGS], [1],
692                         [Whether sox_open_read() takes 4 arguments.])
693                 AC_DEFINE([HAVE_SOX_OPEN_READ_NARGS], [4],
694                         [How many arguments sox_open_read() takes.])
695         else
696                 AC_MSG_NOTICE([
697 Very weird SoX you've got there.
698 I better disable SoX on your behalf.
699                         ])
700                 sxe_cv_mm_sox_open_read_fooked="yes"
701         fi
702
703         ## clean up our cleanup snack
704         rm -f cleanup.c cleanup.o
705 ])dnl SXE_CHECK_SOX_LIBS
706
707 AC_DEFUN([SXE_CHECK_SOX_STRUCTS], [dnl
708         ## the old structs
709         AC_CHECK_TYPES([ft_t], [:], [:], [
710 #if defined HAVE_ST_H
711 # include <st.h>
712 #endif
713                 ])
714         AC_CHECK_TYPES([st_signalinfo_t], [:], [:], [
715 #if defined HAVE_ST_H
716 # include <st.h>
717 #endif
718                 ])
719         AC_CHECK_TYPES([st_ssize_t], [:], [:], [
720 #ifdef HAVE_ST_H
721 # include <st.h>
722 #endif
723                 ])
724         AC_CHECK_TYPES([st_sample_t], [:], [:], [
725 #ifdef HAVE_ST_H
726 # include <st.h>
727 #endif
728                 ])
729         AC_CHECK_TYPES([struct st_soundstream], [:], [:], [
730 #if defined HAVE_ST_H
731 # include <st.h>
732 #endif
733                 ])
734         AC_CHECK_MEMBERS([struct st_soundstream.info], [:], [:], [
735 #if defined HAVE_ST_H
736 # include <st.h>
737 #endif
738                 ])
739         AC_CHECK_MEMBERS([struct st_soundstream.signal], [:], [:], [
740 #if defined HAVE_ST_H
741 # include <st.h>
742 #endif
743                 ])
744
745         ## evaluating the results
746         if test "$ac_cv_member_struct_st_soundstream_info" = "yes"; then
747                 AC_DEFINE([MEMBER_STRUCT_ST_SOUNDSTREAM_INFO], [1],
748                         [Whether we have the `info' slot])
749         fi
750         if test "$ac_cv_member_struct_st_soundstream_signal" = "yes"; then
751                 AC_DEFINE([MEMBER_STRUCT_ST_SOUNDSTREAM_SIGNAL], [1],
752                         [Whether we have the `signal' slot])
753         fi
754
755         ## the new structs
756         AC_CHECK_TYPES([sox_format_t], [:], [:], [
757 #ifdef HAVE_SOX_H
758 # include <sox.h>
759 #endif
760                 ])
761         AC_CHECK_TYPES([sox_ssize_t], [:], [:], [
762 #ifdef HAVE_SOX_H
763 # include <sox.h>
764 #endif
765                 ])
766         AC_CHECK_TYPES([sox_sample_t], [:], [:], [
767 #ifdef HAVE_SOX_H
768 # include <sox.h>
769 #endif
770                 ])
771         AC_CHECK_TYPES([sox_signalinfo_t], [:], [:], [
772 #if defined HAVE_SOX_H
773 # include <sox.h>
774 #endif
775                 ])
776         AC_CHECK_TYPES([struct sox_format], [:], [:], [
777 #ifdef HAVE_SOX_H
778 # include <sox.h>
779 #endif
780                 ])
781         AC_CHECK_MEMBERS([struct sox_format.signal], [:], [:], [
782 #ifdef HAVE_SOX_H
783 # include <sox.h>
784 #endif
785                 ])
786
787         AC_CHECK_MEMBERS([sox_signalinfo_t.precision], [:], [:], [
788 #ifdef HAVE_SOX_H
789 # include <sox.h>
790 #endif
791                 ])
792 ])dnl SXE_CHECK_SOX_STRUCTS
793
794 \f
795 AC_DEFUN([SXE_MM_CHECK_MAD], [
796         ## arg #1: action on success
797         ## arg #2: action on failure
798         pushdef([MM_SUCC], [$1])
799         pushdef([MM_FAIL], [$2])
800
801         AC_MSG_CHECKING([for mad support])
802         AC_MSG_RESULT([])
803
804         MM_SUCC
805         SXE_CHECK_HEADERS([mad.h], [:], [MM_FAIL])
806         AC_CHECK_LIB([mad], [mad_synth_init], [:], [MM_FAIL])
807         AC_CHECK_LIB([mad], [mad_stream_init], [:], [MM_FAIL])
808         AC_CHECK_LIB([mad], [mad_frame_init], [:], [MM_FAIL])
809         AC_CHECK_LIB([mad], [mad_synth_frame], [:], [MM_FAIL])
810         AC_CHECK_LIB([mad], [mad_stream_buffer], [:], [MM_FAIL])
811         AC_CHECK_LIB([mad], [mad_frame_decode], [:], [MM_FAIL])
812
813         popdef([MM_SUCC])
814         popdef([MM_FAIL])
815 ])dnl SXE_MM_CHECK_MAD
816
817 AC_DEFUN([SXE_MM_CHECK_MAGIC], [
818         ## assumes $PKG_CONFIG is defined
819         ## arg #1: action on success
820         ## arg #2: action on failure
821         pushdef([MM_SUCC], [$1])
822         pushdef([MM_FAIL], [$2])
823
824         AC_MSG_CHECKING([for libmagic/file support])
825         AC_MSG_RESULT([])
826
827         SXE_DUMP_LIBS
828         MM_SUCC
829         AC_CHECK_LIB([magic], [magic_open], [:], [MM_FAIL])
830         SXE_CHECK_HEADERS([magic.h], [:], [MM_FAIL])
831         SXE_CHECK_HEADERS([file.h])
832         SXE_RESTORE_LIBS
833
834         popdef([MM_SUCC])
835         popdef([MM_FAIL])
836 ])dnl SXE_MM_CHECK_MAGIC
837
838
839 AC_DEFUN([SXE_MM_CHECK_OSS], [
840         ## arg #1: action on success
841         ## arg #2: action on failure
842         pushdef([MM_SUCC], [$1])
843         pushdef([MM_FAIL], [$2])
844
845         AC_MSG_CHECKING([for OSS support])
846         AC_MSG_RESULT([])
847
848         SXE_DUMP_LIBS
849         MM_FAIL
850         SXE_CHECK_HEADERS([machine/soundcard.h sys/soundcard.h linux/soundcard.h soundcard.h])
851         if test "$ac_cv_header_linux_soundcard_h"="yes" -o      \
852                 "$ac_cv_header_machine_soundcard_h"="yes" -o    \
853                 "$ac_cv_header_soundcard_h"="yes" -o            \
854                 "$ac_cv_header_sys_soundcard_h"="yes"
855         then
856                 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
857 #if defined HAVE_MACHINE_SOUNDCARD_H && HAVE_MACHINE_SOUNDCARD_H
858 #include <machine/soundcard.h>
859 #elif defined HAVE_SYS_SOUNDCARD_H && HAVE_SYS_SOUNDCARD_H
860 #include <sys/soundcard.h>
861 #elif defined HAVE_LINUX_SOUNDCARD_H && HAVE_LINUX_SOUNDCARD_H
862 #include <linux/soundcard.h>
863 #else
864 #include <soundcard.h>
865 #endif
866 ]], 
867                 [[ ioctl(0, SNDCTL_DSP_RESET, 0); ]])],
868                         [oss_ioctl_linked=yes],
869                         [oss_ioctl_linked=no])
870                 if test "${oss_ioctl_linked}" = "no" 
871                 then
872                         if test "${opsys}" = "netbsd"
873                         then
874                                 AC_CHECK_LIB([ossaudio],[_oss_ioctl],
875                                         [
876                                                 # netbsd needs this Linux OSS emulator library, just a ioctl
877                                                 # wrapper really
878                                                 MM_SUCC
879                                                 SXE_PREPEND([-lossaudio], [MM_LIBS])
880                                         ])
881                         fi
882                 else
883                         MM_SUCC
884                 fi
885         fi
886         SXE_RESTORE_LIBS
887
888         popdef([MM_SUCC])
889         popdef([MM_FAIL])
890 ])dnl SXE_MM_CHECK_OSS
891
892 AC_DEFUN([SXE_MM_CHECK_PULSE], [
893         ## assumes $PKG_CONFIG is defined
894         ## arg #1: action on success
895         ## arg #2: action on failure
896
897         PULSE_REQUIRED_VERSION=0.9.3
898         _SXE_MM_CHECK_pkgconfig_based(dnl
899                 [pulse], [libpulse], [$PULSE_REQUIRED_VERSION], [dnl
900                 pa_mainloop_new pa_threaded_mainloop_new pa_mainloop_iterate dnl
901                 pa_threaded_mainloop_lock pa_threaded_mainloop_unlock dnl
902                 pa_mainloop_get_api pa_threaded_mainloop_get_api dnl
903                 pa_mainloop_free pa_threaded_mainloop_free dnl
904                 pa_threaded_mainloop_stop dnl
905                 pa_context_new pa_context_get_state pa_context_is_pending dnl
906                 pa_context_disconnect dnl
907                 pa_operation_unref dnl
908                 pa_stream_new pa_stream_get_state pa_stream_write dnl
909                 pa_stream_set_state_callback pa_stream_set_write_callback dnl
910                 pa_stream_unref pa_stream_connect_playback pa_stream_disconnect dnl
911                 pa_stream_cork],
912                 [pulse/pulseaudio.h], [$1], [$2])
913 ])dnl SXE_MM_CHECK_PULSE
914
915 AC_DEFUN([SXE_MM_CHECK_JACK], [
916         ## assumes $PKG_CONFIG is defined
917         ## arg #1: action on success
918         ## arg #2: action on failure
919
920         _SXE_MM_CHECK_pkgconfig_based([jack], [jack], [0.98.0], [dnl
921                 jack_client_open jack_get_ports jack_port_register dnl
922                 jack_set_process_callback jack_set_error_function dnl
923                 jack_on_shutdown jack_activate jack_connect jack_disconnect dnl
924                 jack_client_close jack_port_get_buffer], [jack/jack.h], [$1], [$2])
925 ])dnl SXE_MM_CHECK_JACK
926
927 AC_DEFUN([SXE_MM_CHECK_AO], [
928         ## assumes $PKG_CONFIG is defined
929         ## arg #1: action on success
930         ## arg #2: action on failure
931
932         _SXE_MM_CHECK_pkgconfig_based([ao], [ao], [0.6], [dnl
933                 ao_initialize ao_driver_id ao_default_driver_id dnl
934                 ao_open_live ao_close ao_shutdown ao_play], [ao/ao.h], [$1], [$2])
935 ])dnl SXE_MM_CHECK_AO
936
937 AC_DEFUN([SXE_MM_CHECK_ARTS], [
938         ## arg #1: action on success
939         ## arg #2: action on failure
940         pushdef([MM_SUCC], [$1])
941         pushdef([MM_FAIL], [$2])
942
943         SXE_SEARCH_CONFIG_PROG([artsc-config])
944
945         AC_MSG_CHECKING([for aRts support])
946         AC_MSG_RESULT([])
947
948         if test "$have_artsc_config" = "no" -o -z "$ARTSC_CONFIG"; then
949                 AS_MESSAGE([*** artsc-config not found.])
950                 AS_MESSAGE([*** Cannot check for aRts.])
951                 have_artsc_config=no
952                 ARTSC_CONFIG=
953                 MM_FAIL
954         fi
955
956         if test "$have_artsc_config" = "yes"; then
957                 ARTS_VERSION=`$ARTSC_CONFIG --arts-version`
958                 ARTS_MAJOR_VERSION=`echo $ARTS_VERSION | awk -F. '{print $1}'`
959                 ARTS_MINOR_VERSION=`echo $ARTS_VERSION | awk -F. '{print $2}'`
960
961                 dnl since we are not using most of the arts features, it suffices
962                 dnl to have a version 1.x (x >= 0)
963                 dnl if test "$ARTS_MAJOR_VERSION" -eq 1 -a \
964                 dnl   "$ARTS_MINOR_VERSION" -ge 0; then
965
966                 SXE_DUMP_LIBS
967                 ARTS_CPPFLAGS="`$ARTSC_CONFIG --cflags`"
968                 ARTS_LDFLAGS="-L`$ARTSC_CONFIG --libs`"
969                 CPPFLAGS="$CPPFLAGS $ARTS_CPPFLAGS"
970                 LDFLAGS="$CPPFLAGS $ARTS_LDFLAGS"
971
972                 MM_SUCC
973                 SXE_CHECK_HEADERS([artsc.h], [:], [MM_FAIL])
974                 AC_CHECK_LIB([artsc], [arts_init], [:], [MM_FAIL], [$arts_libs])
975                 AC_CHECK_LIB([artsc], [arts_free], [:], [MM_FAIL], [$arts_libs])
976                 AC_CHECK_LIB([artsc], [arts_write], [:], [MM_FAIL], [$arts_libs])
977                 AC_CHECK_LIB([artsc], [arts_play_stream], [:], [MM_FAIL], [$arts_libs])
978                 AC_CHECK_LIB([artsc], [arts_stream_set], [:], [MM_FAIL], [$arts_libs])
979                 AC_CHECK_LIB([artsc], [arts_close_stream], [:], [MM_FAIL], [$arts_libs])
980
981                 ## restore anything
982                 SXE_RESTORE_LIBS
983         fi
984
985         popdef([MM_SUCC])
986         popdef([MM_FAIL])
987 ])dnl SXE_MM_CHECK_ARTS
988
989 AC_DEFUN([SXE_MM_CHECK_ESD], [
990         ## arg #1: action on success
991         ## arg #2: action on failure
992         SXE_SEARCH_CONFIG_PROG([esd-config])
993
994         pushdef([MM_SUCC], [$1])
995         pushdef([MM_FAIL], [$2])
996
997         AC_MSG_CHECKING([for ESD support])
998         AC_MSG_RESULT([])
999
1000         if test "$have_esd_config" = "no" -o -z "$ESD_CONFIG"; then
1001                 AS_MESSAGE([*** esd-config not found.])
1002                 AS_MESSAGE([*** Cannot check for ESD.])
1003                 have_esd_config=no
1004                 ESD_CONFIG=
1005                 MM_FAIL
1006         fi
1007
1008         if test "$have_esd_config" = "yes"; then
1009                 SXE_DUMP_LIBS
1010                 ESD_CPPFLAGS="`$ESD_CONFIG --cflags`"
1011                 ESD_LDFLAGS="-L`$ESD_CONFIG --libs`"
1012                 dnl SXE_APPEND([$esd_c_switch], [c_switch_site])
1013                 dnl SXE_PREPEND([$esd_libs], [LIBS])
1014                 CPPFLAGS="$CPPFLAGS $ESD_CPPFLAGS"
1015                 LDFLAGS="$LDFLAGS $ESD_LDFLAGS"
1016
1017                 MM_SUCC
1018                 SXE_CHECK_HEADERS([esd.h], [:], [MM_FAIL])
1019                 AC_CHECK_LIB([esd], [esd_play_stream], [:], [MM_FAIL], [$esd_libs])
1020
1021                 ## restore anything
1022                 SXE_RESTORE_LIBS
1023         fi
1024
1025         popdef([MM_SUCC])
1026         popdef([MM_FAIL])
1027 ])dnl SXE_MM_CHECK_ESD
1028
1029 AC_DEFUN([SXE_MM_CHECK_ALSA], [
1030         ## call like this SXE_MM_CHECK_ALSA([<if-found>], [<if-not-found>])
1031         ## defines HAVE_ALSA, HAVE_ALSA_SOUND
1032         ## and sxe_cv_feat_alsa
1033         pushdef([ACTION_IF_FOUND], [$1])
1034         pushdef([ACTION_IF_NOT_FOUND], [$2])
1035
1036         AC_CACHE_CHECK([for ALSA support],
1037                 [sxe_cv_feat_alsa], [_SXE_MM_CHECK_ALSA])
1038
1039         if test "$sxe_cv_feat_alsa" = "yes"; then
1040                 AC_DEFINE([HAVE_ALSA], [1],
1041                         [Whether ALSA can be used as sound device])
1042                 AC_DEFINE([HAVE_ALSA_SOUND], [1],
1043                         [Whether ALSA can be used as sound device])
1044                 ACTION_IF_FOUND
1045                 :
1046         else
1047                 ACTION_IF_NOT_FOUND
1048                 :
1049         fi
1050         popdef([ACTION_IF_FOUND])
1051         popdef([ACTION_IF_NOT_FOUND])
1052 ])dnl SXE_MM_CHECK_ALSA
1053
1054 AC_DEFUN([_SXE_MM_CHECK_ALSA], [dnl
1055
1056         AC_REQUIRE([SXE_CHECK_ALSA_HEADERS])
1057         AC_REQUIRE([SXE_CHECK_ALSA_VERSION])
1058         AC_REQUIRE([SXE_CHECK_ALSA_LIBS])
1059
1060         if test "$ac_cv_header_alsa_input_h" = "yes" -a \
1061                 "$ac_cv_header_alsa_output_h" = "yes" -a \
1062                 "$ac_cv_header_alsa_global_h" = "yes" -a \
1063                 "$ac_cv_header_alsa_conf_h" = "yes" -a \
1064                 "$ac_cv_header_alsa_pcm_h" = "yes" -a \
1065                 "$ac_cv_header_alsa_error_h" = "yes" -a \
1066                 \
1067                 "$sxe_mm_alsa_version_supported_p" = "yes" -a \
1068                 \
1069                 "$ac_cv_lib_asound_snd_pcm_close" = "yes" -a \
1070                 "$ac_cv_lib_asound_snd_pcm_hw_free" = "yes" -a \
1071                 "$ac_cv_lib_asound_snd_pcm_hw_params_any" = "yes" -a \
1072                 "$ac_cv_lib_asound_snd_pcm_hw_params_free" = "yes" -a \
1073                 "$ac_cv_lib_asound_snd_pcm_hw_params_set_access" = "yes" -a \
1074                 "$ac_cv_lib_asound_snd_pcm_hw_params_set_channels" = "yes" -a \
1075                 "$ac_cv_lib_asound_snd_pcm_hw_params_set_format" = "yes" -a \
1076                 "$ac_cv_lib_asound_snd_pcm_hw_params_set_rate_near" = "yes" -a \
1077                 "$ac_cv_lib_asound_snd_pcm_hw_params_test_channels" = "yes" -a \
1078                 "$ac_cv_lib_asound_snd_pcm_hw_params_test_format" = "yes" -a \
1079                 "$ac_cv_lib_asound_snd_pcm_open" = "yes" -a \
1080                 "$ac_cv_lib_asound_snd_pcm_prepare" = "yes" -a \
1081                 "$ac_cv_lib_asound_snd_pcm_writei" = "yes"; then
1082                 sxe_cv_feat_alsa="yes"
1083         else
1084                 sxe_cv_feat_alsa="no"
1085         fi
1086 ])dnl _SXE_MM_CHECK_ALSA
1087
1088 AC_DEFUN([SXE_CHECK_ALSA_HEADERS], [dnl
1089         ## dump the current configuration
1090         SXE_DUMP_LIBS
1091         SXE_LANG_WERROR([off])
1092         SXE_CHECK_HEADERS([alsa/input.h alsa/output.h alsa/global.h])
1093         SXE_CHECK_HEADERS([alsa/conf.h], [:], [:], [[
1094 #include <stdlib.h>
1095 #include <stdio.h>
1096 #if defined HAVE_ALSA_INPUT_H
1097 # include <alsa/input.h>
1098 #endif
1099 #if defined HAVE_ALSA_OUTPUT_H
1100 # include <alsa/output.h>
1101 #endif
1102 #if defined HAVE_ALSA_GLOBAL_H
1103 # include <alsa/global.h>
1104 #endif
1105 ]])
1106         SXE_CHECK_HEADERS([alsa/pcm.h alsa/error.h alsa/version.h], [:], [:], [[
1107 #include <stdlib.h>
1108 #include <stdio.h>
1109 #if defined HAVE_ALSA_INPUT_H
1110 # include <alsa/input.h>
1111 #endif
1112 #if defined HAVE_ALSA_OUTPUT_H
1113 # include <alsa/output.h>
1114 #endif
1115 #if defined HAVE_ALSA_GLOBAL_H
1116 # include <alsa/global.h>
1117 #endif
1118 #if defined HAVE_ALSA_CONF_H
1119 # include <alsa/conf.h>
1120 #endif
1121 ]])
1122         ## restor everything
1123         SXE_RESTORE_LIBS
1124 ])dnl SXE_CHECK_ALSA_HEADERS
1125
1126 AC_DEFUN([SXE_CHECK_ALSA_VERSION], [dnl
1127         AC_REQUIRE([SXE_CHECK_ALSA_HEADERS])
1128
1129         ## dump the configuration
1130         SXE_DUMP_LIBS
1131         SXE_LANG_WERROR([off])
1132         AC_MSG_CHECKING([for alsa version])
1133
1134         AC_RUN_IFELSE([AC_LANG_SOURCE([[
1135 #include <stdlib.h>
1136 #include <stdio.h>
1137 #if defined HAVE_ALSA_INPUT_H
1138 # include <alsa/input.h>
1139 #endif
1140 #if defined HAVE_ALSA_OUTPUT_H
1141 # include <alsa/output.h>
1142 #endif
1143 #if defined HAVE_ALSA_GLOBAL_H
1144 # include <alsa/global.h>
1145 #endif
1146 #if defined HAVE_ALSA_CONF_H
1147 # include <alsa/conf.h>
1148 #endif
1149 #if defined HAVE_ALSA_PCM_H
1150 # include <alsa/pcm.h>
1151 #endif
1152 #if defined HAVE_ALSA_ERROR_H
1153 # include <alsa/error.h>
1154 #endif
1155 #if defined HAVE_ALSA_CONF_H
1156 # include <alsa/version.h>
1157 #endif
1158
1159 int main(int c, char *v[]) 
1160 {
1161         fprintf(stdout, SND_LIB_VERSION_STR);
1162         return 0;
1163 }]])], dnl [./conftest; alsa_subminor=$?],[alsa_subminor=$?],[alsa_subminor=0]
1164         [sxe_mm_alsa_version=$(./conftest)],
1165         [:], [sxe_mm_alsa_version="undeterminable"])
1166
1167         case "${sxe_mm_alsa_version}" in
1168         0.*.* | 1.0.3* | 1.0.9* )
1169                 AC_MSG_RESULT([${sxe_mm_alsa_version} (known to break)])
1170                 AC_MSG_WARN([Your ALSA version is _KNOWN_ to fail! Do not say we have not warned you!])
1171                 sxe_mm_alsa_version_supported_p="no"
1172                 ;;
1173         1.0.2 | 1.0.4* | 1.0.5* | 1.0.6* | 1.0.7* | 1.0.8* ) 
1174                 AC_MSG_RESULT([${sxe_mm_alsa_version} (suspicious to break)])
1175                 AC_MSG_WARN([Your ALSA version has not been tested. Do not be surprised if it fails!])
1176                 sxe_mm_alsa_version_supported_p="no"
1177                 ;;
1178         1.0.10* | 1.0.11* | 1.0.12* | 1.0.13* | 1.0.14* | 1.0.15* | 1.0.16* )
1179                 AC_MSG_RESULT([${sxe_mm_alsa_version} (sane)])
1180                 sxe_mm_alsa_version_supported_p="yes"
1181                 ;;
1182         1.* )
1183                 AC_MSG_RESULT([${sxe_mm_alsa_version} (unknown)])
1184                 AC_MSG_NOTICE([Your ALSA version is unknown, however we are confident that it works.])
1185                 AC_MSG_NOTICE([However, if we screwed up something, please report back!])
1186                 sxe_mm_alsa_version_supported_p="yes"
1187                 ;;
1188         * )
1189                 AC_MSG_RESULT([${sxe_mm_alsa_version} (unknown)])
1190                 AC_MSG_WARN([Your ALSA version is unknown hence not supported!])
1191                 sxe_mm_alsa_version_supported_p="no"
1192                 ;;
1193         esac
1194
1195         ## restore everything
1196         SXE_RESTORE_LIBS
1197 ])dnl SXE_CHECK_ALSA_VERSION
1198
1199 AC_DEFUN([SXE_CHECK_ALSA_LIBS], [dnl
1200         ## dump the current configuration
1201         SXE_DUMP_LIBS
1202
1203         AC_CHECK_LIB([asound], [snd_pcm_open], [:], [:])
1204         AC_CHECK_LIB([asound], [snd_pcm_close], [:], [:])
1205         AC_CHECK_LIB([asound], [snd_pcm_hw_free], [:], [:])
1206         AC_CHECK_LIB([asound], [snd_pcm_hw_params_any], [:], [:])
1207         AC_CHECK_LIB([asound], [snd_pcm_hw_params_set_access], [:], [:])
1208         AC_CHECK_LIB([asound], [snd_pcm_hw_params_free], [:], [:])
1209         AC_CHECK_LIB([asound], [snd_pcm_hw_params_test_channels], [:], [:])
1210         AC_CHECK_LIB([asound], [snd_pcm_hw_params_test_format], [:], [:])
1211         AC_CHECK_LIB([asound], [snd_pcm_hw_params_set_channels], [:], [:])
1212         AC_CHECK_LIB([asound], [snd_pcm_hw_params_set_format], [:], [:])
1213         AC_CHECK_LIB([asound], [snd_pcm_hw_params_set_rate_near], [:], [:])
1214         AC_CHECK_LIB([asound], [snd_pcm_prepare], [:], [:])
1215         AC_CHECK_LIB([asound], [snd_pcm_writei], [:], [:])
1216
1217         ## restore everything
1218         SXE_RESTORE_LIBS
1219 ])dnl SXE_CHECK_ALSA_LIBS
1220
1221
1222
1223 AC_DEFUN([SXE_MM_CHECK_NAS], [
1224         ## arg #1: action on success
1225         ## arg #2: action on failure
1226         pushdef([MM_SUCC], [$1])
1227         pushdef([MM_FAIL], [$2])
1228
1229         AC_MSG_CHECKING([for NAS support])
1230         AC_MSG_RESULT([])
1231
1232         SXE_DUMP_LIBS
1233
1234         MM_SUCC
1235         ## NAS is often stored inside the X hierarchy, so ...
1236         CPPFLAGS="$CPPFLAGS $X_CFLAGS"
1237         LDFLAGS="$LDFLAGS $X_LIBS"
1238         SXE_CHECK_HEADERS([audio/audiolib.h], [:], [MM_FAIL])
1239         AC_CHECK_LIB([audio], [AuOpenServer], [:], [MM_FAIL])
1240         AC_CHECK_LIB([audio], [AuCloseServer], [:], [MM_FAIL])
1241         AC_CHECK_LIB([audio], [AuCreateFlow], [:], [MM_FAIL])
1242         AC_CHECK_LIB([audio], [AuStartFlow], [:], [MM_FAIL])
1243         AC_CHECK_LIB([audio], [AuStopFlow], [:], [MM_FAIL])
1244         AC_CHECK_LIB([audio], [AuScanForTypedEvent], [:], [MM_FAIL])
1245         AC_CHECK_LIB([audio], [AuDispatchEvent], [:], [MM_FAIL])
1246         AC_CHECK_LIB([audio], [AuSetErrorHandler], [:], [MM_FAIL])
1247         AC_CHECK_LIB([audio], [AuSetIOErrorHandler], [:], [MM_FAIL])
1248         AC_CHECK_LIB([audio], [AuWriteElement], [:], [MM_FAIL])
1249         AC_CHECK_LIB([audio], [AuSetElements], [:], [MM_FAIL])
1250         AC_CHECK_LIB([audio], [AuRegisterEventHandler], [:], [MM_FAIL])
1251         AC_CHECK_LIB([audio], [AuSetElementParameters], [:], [MM_FAIL])
1252
1253         dnl If the nas library does not contain the error jump point,
1254         dnl then we force safer behavior.
1255         AC_EGREP_HEADER([AuXtErrorJump], [audio/Xtutil.h], [], [old_nas=yes])
1256         if test "$old_nas" = "yes"; then
1257                 AC_DEFINE([NAS_NO_ERROR_JUMP], [1], [Description here!])
1258         fi
1259
1260         ## restore anything
1261         SXE_RESTORE_LIBS
1262
1263         popdef([MM_SUCC])
1264         popdef([MM_FAIL])
1265 ])dnl SXE_MM_CHECK_NAS
1266
1267 dnl sxe-mm.m4 ends here