1# Configure paths for SDL
2# Sam Lantinga 9/21/99
3# stolen from Manish Singh
4# stolen back from Frank Belew
5# stolen from Manish Singh
6# Shamelessly stolen from Owen Taylor
7
8dnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
9dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
10dnl
11AC_DEFUN([AM_PATH_SDL],
12[dnl
13dnl Get the cflags and libraries from the sdl-config script
14dnl
15AC_ARG_WITH(sdl-prefix,[  --with-sdl-prefix=PFX   Prefix where SDL is installed (optional)],
16            sdl_prefix="$withval", sdl_prefix="")
17AC_ARG_WITH(sdl-exec-prefix,[  --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)],
18            sdl_exec_prefix="$withval", sdl_exec_prefix="")
19AC_ARG_ENABLE(sdltest, [  --disable-sdltest       Do not try to compile and run a test SDL program],
20		    , enable_sdltest=yes)
21
22  if test x$sdl_exec_prefix != x ; then
23     sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix"
24     if test x${SDL_CONFIG+set} != xset ; then
25        SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config
26     fi
27  fi
28  if test x$sdl_prefix != x ; then
29     sdl_args="$sdl_args --prefix=$sdl_prefix"
30     if test x${SDL_CONFIG+set} != xset ; then
31        SDL_CONFIG=$sdl_prefix/bin/sdl-config
32     fi
33  fi
34
35  AC_REQUIRE([AC_CANONICAL_TARGET])
36  PATH="$prefix/bin:$prefix/usr/bin:$PATH"
37  AC_PATH_PROG(SDL_CONFIG, sdl-config, no, [$PATH])
38  min_sdl_version=ifelse([$1], ,0.11.0,$1)
39  AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
40  no_sdl=""
41  if test "$SDL_CONFIG" = "no" ; then
42    no_sdl=yes
43  else
44    SDL_CFLAGS=`$SDL_CONFIG $sdlconf_args --cflags`
45    SDL_LIBS=`$SDL_CONFIG $sdlconf_args --libs`
46
47    sdl_major_version=`$SDL_CONFIG $sdl_args --version | \
48           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
49    sdl_minor_version=`$SDL_CONFIG $sdl_args --version | \
50           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
51    sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \
52           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
53    if test "x$enable_sdltest" = "xyes" ; then
54      ac_save_CFLAGS="$CFLAGS"
55      ac_save_CXXFLAGS="$CXXFLAGS"
56      ac_save_LIBS="$LIBS"
57      CFLAGS="$CFLAGS $SDL_CFLAGS"
58      CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
59      LIBS="$LIBS $SDL_LIBS"
60dnl
61dnl Now check if the installed SDL is sufficiently new. (Also sanity
62dnl checks the results of sdl-config to some extent
63dnl
64      rm -f conf.sdltest
65      AC_TRY_RUN([
66#include <stdio.h>
67#include <stdlib.h>
68#include <string.h>
69#include "SDL.h"
70
71char*
72my_strdup (char *str)
73{
74  char *new_str;
75
76  if (str)
77    {
78      new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
79      strcpy (new_str, str);
80    }
81  else
82    new_str = NULL;
83
84  return new_str;
85}
86
87int main (int argc, char *argv[])
88{
89  int major, minor, micro;
90  char *tmp_version;
91
92  /* This hangs on some systems (?)
93  system ("touch conf.sdltest");
94  */
95  { FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); }
96
97  /* HP/UX 9 (%@#!) writes to sscanf strings */
98  tmp_version = my_strdup("$min_sdl_version");
99  if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
100     printf("%s, bad version string\n", "$min_sdl_version");
101     exit(1);
102   }
103
104   if (($sdl_major_version > major) ||
105      (($sdl_major_version == major) && ($sdl_minor_version > minor)) ||
106      (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro)))
107    {
108      return 0;
109    }
110  else
111    {
112      printf("\n*** 'sdl-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
113      printf("*** of SDL required is %d.%d.%d. If sdl-config is correct, then it is\n", major, minor, micro);
114      printf("*** best to upgrade to the required version.\n");
115      printf("*** If sdl-config was wrong, set the environment variable SDL_CONFIG\n");
116      printf("*** to point to the correct copy of sdl-config, and remove the file\n");
117      printf("*** config.cache before re-running configure\n");
118      return 1;
119    }
120}
121
122],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
123       CFLAGS="$ac_save_CFLAGS"
124       CXXFLAGS="$ac_save_CXXFLAGS"
125       LIBS="$ac_save_LIBS"
126     fi
127  fi
128  if test "x$no_sdl" = x ; then
129     AC_MSG_RESULT(yes)
130     ifelse([$2], , :, [$2])
131  else
132     AC_MSG_RESULT(no)
133     if test "$SDL_CONFIG" = "no" ; then
134       echo "*** The sdl-config script installed by SDL could not be found"
135       echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
136       echo "*** your path, or set the SDL_CONFIG environment variable to the"
137       echo "*** full path to sdl-config."
138     else
139       if test -f conf.sdltest ; then
140        :
141       else
142          echo "*** Could not run SDL test program, checking why..."
143          CFLAGS="$CFLAGS $SDL_CFLAGS"
144          CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
145          LIBS="$LIBS $SDL_LIBS"
146          AC_TRY_LINK([
147#include <stdio.h>
148#include "SDL.h"
149
150int main(int argc, char *argv[])
151{ return 0; }
152#undef  main
153#define main K_and_R_C_main
154],      [ return 0; ],
155        [ echo "*** The test program compiled, but did not run. This usually means"
156          echo "*** that the run-time linker is not finding SDL or finding the wrong"
157          echo "*** version of SDL. If it is not finding SDL, you'll need to set your"
158          echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
159          echo "*** to the installed location  Also, make sure you have run ldconfig if that"
160          echo "*** is required on your system"
161	  echo "***"
162          echo "*** If you have an old version installed, it is best to remove it, although"
163          echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
164        [ echo "*** The test program failed to compile or link. See the file config.log for the"
165          echo "*** exact error that occured. This usually means SDL was incorrectly installed"
166          echo "*** or that you have moved SDL since it was installed. In the latter case, you"
167          echo "*** may want to edit the sdl-config script: $SDL_CONFIG" ])
168          CFLAGS="$ac_save_CFLAGS"
169          CXXFLAGS="$ac_save_CXXFLAGS"
170          LIBS="$ac_save_LIBS"
171       fi
172     fi
173     SDL_CFLAGS=""
174     SDL_LIBS=""
175     ifelse([$3], , :, [$3])
176  fi
177  AC_SUBST(SDL_CFLAGS)
178  AC_SUBST(SDL_LIBS)
179  rm -f conf.sdltest
180])
181
182
183# Configure paths for libogg
184# Jack Moffitt <jack@icecast.org> 10-21-2000
185# Shamelessly stolen from Owen Taylor and Manish Singh
186
187dnl XIPH_PATH_OGG([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
188dnl Test for libogg, and define OGG_CFLAGS and OGG_LIBS
189dnl
190AC_DEFUN([XIPH_PATH_OGG],
191[dnl
192dnl Get the cflags and libraries
193dnl
194AC_ARG_WITH(ogg,[  --with-ogg=PFX   Prefix where libogg is installed (optional)], ogg_prefix="$withval", ogg_prefix="")
195AC_ARG_WITH(ogg-libraries,[  --with-ogg-libraries=DIR   Directory where libogg library is installed (optional)], ogg_libraries="$withval", ogg_libraries="")
196AC_ARG_WITH(ogg-includes,[  --with-ogg-includes=DIR   Directory where libogg header files are installed (optional)], ogg_includes="$withval", ogg_includes="")
197AC_ARG_ENABLE(oggtest, [  --disable-oggtest       Do not try to compile and run a test Ogg program],, enable_oggtest=yes)
198
199  if test "x$ogg_libraries" != "x" ; then
200    OGG_LIBS="-L$ogg_libraries"
201  elif test "x$ogg_prefix" != "x" ; then
202    OGG_LIBS="-L$ogg_prefix/lib"
203  elif test "x$prefix" != "xNONE" ; then
204    OGG_LIBS="-L$libdir"
205  fi
206
207  OGG_LIBS="$OGG_LIBS -logg"
208
209  if test "x$ogg_includes" != "x" ; then
210    OGG_CFLAGS="-I$ogg_includes"
211  elif test "x$ogg_prefix" != "x" ; then
212    OGG_CFLAGS="-I$ogg_prefix/include"
213  elif test "x$prefix" != "xNONE"; then
214    OGG_CFLAGS=""
215  fi
216
217  AC_MSG_CHECKING(for Ogg)
218  no_ogg=""
219
220
221  if test "x$enable_oggtest" = "xyes" ; then
222    ac_save_CFLAGS="$CFLAGS"
223    ac_save_LIBS="$LIBS"
224    CFLAGS="$CFLAGS $OGG_CFLAGS"
225    LIBS="$LIBS $OGG_LIBS"
226dnl
227dnl Now check if the installed Ogg is sufficiently new.
228dnl
229      rm -f conf.oggtest
230      AC_TRY_RUN([
231#include <stdio.h>
232#include <stdlib.h>
233#include <string.h>
234#include <ogg/ogg.h>
235
236int main ()
237{
238  system("touch conf.oggtest");
239  return 0;
240}
241
242],, no_ogg=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
243       CFLAGS="$ac_save_CFLAGS"
244       LIBS="$ac_save_LIBS"
245  fi
246
247  if test "x$no_ogg" = "x" ; then
248     AC_MSG_RESULT(yes)
249     ifelse([$1], , :, [$1])
250  else
251     AC_MSG_RESULT(no)
252     if test -f conf.oggtest ; then
253       :
254     else
255       echo "*** Could not run Ogg test program, checking why..."
256       CFLAGS="$CFLAGS $OGG_CFLAGS"
257       LIBS="$LIBS $OGG_LIBS"
258       AC_TRY_LINK([
259#include <stdio.h>
260#include <ogg/ogg.h>
261],     [ return 0; ],
262       [ echo "*** The test program compiled, but did not run. This usually means"
263       echo "*** that the run-time linker is not finding Ogg or finding the wrong"
264       echo "*** version of Ogg. If it is not finding Ogg, you'll need to set your"
265       echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
266       echo "*** to the installed location  Also, make sure you have run ldconfig if that"
267       echo "*** is required on your system"
268       echo "***"
269       echo "*** If you have an old version installed, it is best to remove it, although"
270       echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
271       [ echo "*** The test program failed to compile or link. See the file config.log for the"
272       echo "*** exact error that occured. This usually means Ogg was incorrectly installed"
273       echo "*** or that you have moved Ogg since it was installed." ])
274       CFLAGS="$ac_save_CFLAGS"
275       LIBS="$ac_save_LIBS"
276     fi
277     OGG_CFLAGS=""
278     OGG_LIBS=""
279     ifelse([$2], , :, [$2])
280  fi
281  AC_SUBST(OGG_CFLAGS)
282  AC_SUBST(OGG_LIBS)
283  rm -f conf.oggtest
284])
285
286# Configure paths for libvorbis
287# Jack Moffitt <jack@icecast.org> 10-21-2000
288# Shamelessly stolen from Owen Taylor and Manish Singh
289# thomasvs added check for vorbis_bitrate_addblock which is new in rc3
290
291dnl XIPH_PATH_VORBIS([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
292dnl Test for libvorbis, and define VORBIS_CFLAGS and VORBIS_LIBS
293dnl
294AC_DEFUN([XIPH_PATH_VORBIS],
295[dnl
296dnl Get the cflags and libraries
297dnl
298AC_ARG_WITH(vorbis,[  --with-vorbis=PFX   Prefix where libvorbis is installed (optional)], vorbis_prefix="$withval", vorbis_prefix="")
299AC_ARG_WITH(vorbis-libraries,[  --with-vorbis-libraries=DIR   Directory where libvorbis library is installed (optional)], vorbis_libraries="$withval", vorbis_libraries="")
300AC_ARG_WITH(vorbis-includes,[  --with-vorbis-includes=DIR   Directory where libvorbis header files are installed (optional)], vorbis_includes="$withval", vorbis_includes="")
301AC_ARG_ENABLE(vorbistest, [  --disable-vorbistest       Do not try to compile and run a test Vorbis program],, enable_vorbistest=yes)
302
303  if test "x$vorbis_libraries" != "x" ; then
304    VORBIS_LIBS="-L$vorbis_libraries"
305  elif test "x$vorbis_prefix" != "x" ; then
306    VORBIS_LIBS="-L$vorbis_prefix/lib"
307  elif test "x$prefix" != "xNONE"; then
308    VORBIS_LIBS="-L$libdir"
309  fi
310
311  VORBIS_LIBS="$VORBIS_LIBS -lvorbis -lm"
312  VORBISFILE_LIBS="-lvorbisfile"
313  VORBISENC_LIBS="-lvorbisenc"
314
315  if test "x$vorbis_includes" != "x" ; then
316    VORBIS_CFLAGS="-I$vorbis_includes"
317  elif test "x$vorbis_prefix" != "x" ; then
318    VORBIS_CFLAGS="-I$vorbis_prefix/include"
319  elif test "x$prefix" != "xNONE"; then
320    VORBIS_CFLAGS=""
321  fi
322
323
324  AC_MSG_CHECKING(for Vorbis)
325  no_vorbis=""
326
327
328  if test "x$enable_vorbistest" = "xyes" ; then
329    ac_save_CFLAGS="$CFLAGS"
330    ac_save_LIBS="$LIBS"
331    CFLAGS="$CFLAGS $VORBIS_CFLAGS $OGG_CFLAGS"
332    LIBS="$LIBS $VORBIS_LIBS $VORBISENC_LIBS $OGG_LIBS"
333dnl
334dnl Now check if the installed Vorbis is sufficiently new.
335dnl
336      rm -f conf.vorbistest
337      AC_TRY_RUN([
338#include <stdio.h>
339#include <stdlib.h>
340#include <string.h>
341#include <vorbis/codec.h>
342#include <vorbis/vorbisenc.h>
343
344int main ()
345{
346    vorbis_block 	vb;
347    vorbis_dsp_state	vd;
348    vorbis_info		vi;
349
350    vorbis_info_init (&vi);
351    vorbis_encode_init (&vi, 2, 44100, -1, 128000, -1);
352    vorbis_analysis_init (&vd, &vi);
353    vorbis_block_init (&vd, &vb);
354    /* this function was added in 1.0rc3, so this is what we're testing for */
355    vorbis_bitrate_addblock (&vb);
356
357    system("touch conf.vorbistest");
358    return 0;
359}
360
361],, no_vorbis=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
362       CFLAGS="$ac_save_CFLAGS"
363       LIBS="$ac_save_LIBS"
364  fi
365
366  if test "x$no_vorbis" = "x" ; then
367     AC_MSG_RESULT(yes)
368     ifelse([$1], , :, [$1])
369  else
370     AC_MSG_RESULT(no)
371     if test -f conf.vorbistest ; then
372       :
373     else
374       echo "*** Could not run Vorbis test program, checking why..."
375       CFLAGS="$CFLAGS $VORBIS_CFLAGS"
376       LIBS="$LIBS $VORBIS_LIBS $OGG_LIBS"
377       AC_TRY_LINK([
378#include <stdio.h>
379#include <vorbis/codec.h>
380],     [ return 0; ],
381       [ echo "*** The test program compiled, but did not run. This usually means"
382       echo "*** that the run-time linker is not finding Vorbis or finding the wrong"
383       echo "*** version of Vorbis. If it is not finding Vorbis, you'll need to set your"
384       echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
385       echo "*** to the installed location  Also, make sure you have run ldconfig if that"
386       echo "*** is required on your system"
387       echo "***"
388       echo "*** If you have an old version installed, it is best to remove it, although"
389       echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
390       [ echo "*** The test program failed to compile or link. See the file config.log for the"
391       echo "*** exact error that occured. This usually means Vorbis was incorrectly installed"
392       echo "*** or that you have moved Vorbis since it was installed." ])
393       CFLAGS="$ac_save_CFLAGS"
394       LIBS="$ac_save_LIBS"
395     fi
396     VORBIS_CFLAGS=""
397     VORBIS_LIBS=""
398     VORBISFILE_LIBS=""
399     VORBISENC_LIBS=""
400     ifelse([$2], , :, [$2])
401  fi
402  AC_SUBST(VORBIS_CFLAGS)
403  AC_SUBST(VORBIS_LIBS)
404  AC_SUBST(VORBISFILE_LIBS)
405  AC_SUBST(VORBISENC_LIBS)
406  rm -f conf.vorbistest
407])
408
409dnl XIPH_PATH_THEORA([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
410dnl Test for libtheora, and define THEORA_CFLAGS and THEORA_LIBS
411dnl
412AC_DEFUN([XIPH_PATH_THEORA],
413[dnl
414dnl Get the cflags and libraries
415dnl
416AC_ARG_WITH(theora,[  --with-theora=PFX   Prefix where libtheora is installed (optional)], theora_prefix="$withval", theora_prefix="")
417AC_ARG_WITH(theora-libraries,[  --with-theora-libraries=DIR   Directory where libtheora library is installed (optional)], theora_libraries="$withval", theora_libraries="")
418AC_ARG_WITH(theora-includes,[  --with-theora-includes=DIR   Directory where libtheora header files are installed (optional)], theora_includes="$withval", theora_includes="")
419AC_ARG_ENABLE(theoratest, [  --disable-theoratest       Do not try to compile and run a test Theora program],, enable_theoratest=yes)
420
421  if test "x$theora_libraries" != "x" ; then
422    THEORA_LIBS="-L$theora_libraries"
423  elif test "x$theora_prefix" != "x" ; then
424    THEORA_LIBS="-L$theora_prefix/lib"
425  elif test "x$prefix" != "xNONE"; then
426    THEORA_LIBS="-L$libdir"
427  fi
428
429  THEORA_LIBS="$THEORA_LIBS -ltheora"
430
431  if test "x$theora_includes" != "x" ; then
432    THEORA_CFLAGS="-I$theora_includes"
433  elif test "x$theora_prefix" != "x" ; then
434    THEORA_CFLAGS="-I$theora_prefix/include"
435  elif test "x$prefix" != "xNONE"; then
436    THEORA_CFLAGS=""
437  fi
438
439
440  AC_MSG_CHECKING(for Theora)
441  no_theora=""
442
443
444  if test "x$enable_theoratest" = "xyes" ; then
445    ac_save_CFLAGS="$CFLAGS"
446    ac_save_LIBS="$LIBS"
447    CFLAGS="$CFLAGS $THEORA_CFLAGS $OGG_CFLAGS"
448    LIBS="$LIBS $THEORA_LIBS $OGG_LIBS"
449dnl
450dnl Now check if the installed Theora is sufficiently new.
451dnl
452      rm -f conf.theoratest
453      AC_TRY_RUN([
454#include <stdio.h>
455#include <stdlib.h>
456#include <string.h>
457#include <theora/theora.h>
458#include <vorbis/codec.h>
459
460int main ()
461{
462    theora_info		ti;
463    theora_state	ts;
464
465    theora_info_init(&ti);
466
467    system("touch conf.theoratest");
468    return 0;
469}
470
471],, no_theora=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
472       CFLAGS="$ac_save_CFLAGS"
473       LIBS="$ac_save_LIBS"
474  fi
475
476  if test "x$no_theora" = "x" ; then
477     AC_MSG_RESULT(yes)
478     ifelse([$1], , :, [$1])
479  else
480     AC_MSG_RESULT(no)
481     if test -f conf.theoratest ; then
482       :
483     else
484       echo "*** Could not run Theora test program, checking why..."
485       CFLAGS="$CFLAGS $THEORA_CFLAGS"
486       LIBS="$LIBS $THEORA_LIBS $OGG_LIBS"
487       AC_TRY_LINK([
488#include <stdio.h>
489#include <vorbis/codec.h>
490],     [ return 0; ],
491       [ echo "*** The test program compiled, but did not run. This usually means"
492       echo "*** that the run-time linker is not finding Theora or finding the wrong"
493       echo "*** version of Theora. If it is not finding Theora, you'll need to set your"
494       echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
495       echo "*** to the installed location  Also, make sure you have run ldconfig if that"
496       echo "*** is required on your system"
497       echo "***"
498       echo "*** If you have an old version installed, it is best to remove it, although"
499       echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
500       [ echo "*** The test program failed to compile or link. See the file config.log for the"
501       echo "*** exact error that occured. This usually means Theora was incorrectly installed"
502       echo "*** or that you have moved Theora since it was installed." ])
503       CFLAGS="$ac_save_CFLAGS"
504       LIBS="$ac_save_LIBS"
505     fi
506     THEORA_CFLAGS=""
507     THEORA_LIBS=""
508     ifelse([$2], , :, [$2])
509  fi
510  AC_SUBST(THEORA_CFLAGS)
511  AC_SUBST(THEORA_LIBS)
512  rm -f conf.theoratest
513])
514
515
516dnl AM_PATH_OPENAL([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
517dnl Test for OpenAL, and define OPENAL_CFLAGS and OPENAL_LIBS
518dnl
519AC_DEFUN([AM_PATH_OPENAL],
520[dnl
521dnl Get the cflags and libraries
522dnl
523AC_ARG_WITH(openal,[  --with-openal=PFX   Prefix where OpenAL is installed (optional)], openal_prefix="$withval", openal_prefix="")
524AC_ARG_WITH(openal-libraries,[  --with-openal-libraries=DIR   Directory where OpenAL library is installed (optional)], openal_libraries="$withval", openal_libraries="")
525AC_ARG_WITH(openal-includes,[  --with-openal-includes=DIR   Directory where OpenAL header files are installed (optional)], openal_includes="$withval", openal_includes="")
526AC_ARG_ENABLE(openaltest, [  --disable-openaltest       Do not try to compile and run a test OpenAL program],, enable_openaltest=yes)
527
528  if test "x$openal_libraries" != "x" ; then
529    OPENAL_LIBS="-L$openal_libraries"
530  elif test "x$openal_prefix" != "x" ; then
531    OPENAL_LIBS="-L$openal_prefix/lib"
532  elif test "x$prefix" != "xNONE"; then
533    OPENAL_LIBS="-L$libdir"
534  fi
535
536  OPENAL_LIBS="$OPENAL_LIBS -lopenal"
537
538  if test "x$openal_includes" != "x" ; then
539    OPENAL_CFLAGS="-I$openal_includes"
540  elif test "x$openal_prefix" != "x" ; then
541    OPENAL_CFLAGS="-I$openal_prefix/include"
542  elif test "x$prefix" != "xNONE"; then
543    OPENAL_CFLAGS=""
544  fi
545
546
547  AC_MSG_CHECKING(for OpenAL)
548  no_openal=""
549
550
551  if test "x$enable_openaltest" = "xyes" ; then
552    ac_save_CFLAGS="$CFLAGS"
553    ac_save_LIBS="$LIBS"
554    CFLAGS="$CFLAGS $OPENAL_CFLAGS"
555    LIBS="$LIBS $OPENAL_LIBS"
556dnl
557dnl Now check if the installed OpenAL is sufficiently new.
558dnl
559      rm -f conf.openaltest
560      AC_TRY_RUN([
561#include <stdio.h>
562#include <stdlib.h>
563#include <string.h>
564#include <AL/al.h>
565#include <AL/alc.h>
566
567int main ()
568{
569#ifdef AL_VERSION_1_1
570	alcIsExtensionPresent(NULL, (const ALCchar*)"ALC_ENUMERATION_EXT");
571
572	system("touch conf.openaltest");
573	return 0;
574#else
575	printf("\n*** OpenAL version 1.1 or greater is required.\n");
576	return 1;
577#endif
578}
579
580],, no_openal=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
581     CFLAGS="$ac_save_CFLAGS"
582     LIBS="$ac_save_LIBS"
583  fi
584
585  if test "x$no_openal" = "x" ; then
586     AC_MSG_RESULT(yes)
587     ifelse([$1], , :, [$1])
588  else
589     AC_MSG_RESULT(no)
590     if test -f conf.openaltest ; then
591       :
592     else
593       echo "*** Could not run OpenAL test program, checking why..."
594       CFLAGS="$CFLAGS $OPENAL_CFLAGS"
595       LIBS="$LIBS $OPENAL_LIBS"
596       AC_TRY_LINK([
597#include <stdio.h>
598#include <AL/al.h>
599],     [ return 0; ],
600       [ echo "*** The test program compiled, but did not run. This usually means"
601       echo "*** that the run-time linker is not finding OpenAL or finding the wrong"
602       echo "*** version of OpenAL. If it is not finding OpenAL, you'll need to set your"
603       echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
604       echo "*** to the installed location  Also, make sure you have run ldconfig if that"
605       echo "*** is required on your system"
606       echo "***"
607       echo "*** If you have an old version installed, it is best to remove it, although"
608       echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
609       [ echo "*** The test program failed to compile or link. See the file config.log for the"
610       echo "*** exact error that occured. This usually means OpenAL was incorrectly installed"
611       echo "*** or that you have moved OpenAL since it was installed." ])
612       CFLAGS="$ac_save_CFLAGS"
613       LIBS="$ac_save_LIBS"
614     fi
615     OPENAL_CFLAGS=""
616     OPENAL_LIBS=""
617     ifelse([$2], , :, [$2])
618  fi
619  AC_SUBST(OPENAL_CFLAGS)
620  AC_SUBST(OPENAL_LIBS)
621  rm -f conf.openaltest
622])
623
624dnl AM_PATH_OPENGL([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
625dnl Test for OpenGL, and define OPENGL_CFLAGS and OPENGL_LIBS
626dnl
627AC_DEFUN([AM_PATH_OPENGL],
628[dnl
629dnl Get the cflags and libraries
630dnl
631AC_ARG_WITH(opengl,[  --with-opengl=PFX   Prefix where OpenGL is installed (optional)], opengl_prefix="$withval", opengl_prefix="")
632AC_ARG_WITH(opengl-libraries,[  --with-opengl-libraries=DIR   Directory where OpenGL library is installed (optional)], opengl_libraries="$withval", opengl_libraries="")
633AC_ARG_WITH(opengl-includes,[  --with-opengl-includes=DIR   Directory where OpenGL header files are installed (optional)], opengl_includes="$withval", opengl_includes="")
634AC_ARG_ENABLE(opengltest, [  --disable-opengltest       Do not try to compile and run a test OpenGL program],, enable_opengltest=yes)
635
636  if test "x$opengl_libraries" != "x" ; then
637    OPENGL_LIBS="-L$opengl_libraries"
638  elif test "x$opengl_prefix" != "x" ; then
639    OPENGL_LIBS="-L$opengl_prefix/lib"
640  elif test "x$prefix" != "xNONE"; then
641    OPENGL_LIBS="-L$libdir"
642  fi
643
644  OPENGL_LIBS="$OPENGL_LIBS -lGL -lGLU"
645
646  if test "x$opengl_includes" != "x" ; then
647    OPENGL_CFLAGS="-I$opengl_includes"
648  elif test "x$opengl_prefix" != "x" ; then
649    OPENGL_CFLAGS="-I$opengl_prefix/include"
650  elif test "x$prefix" != "xNONE"; then
651    OPENGL_CFLAGS=""
652  fi
653
654
655  no_opengl=""
656
657
658  if test "x$enable_opengltest" = "xyes" ; then
659    ac_save_CFLAGS="$CFLAGS"
660    ac_save_LIBS="$LIBS"
661    CFLAGS="$CFLAGS $OPENGL_CFLAGS"
662    LIBS="$LIBS $OPENGL_LIBS"
663
664    AC_CHECK_LIB(GL, glPushMatrix,
665      [AC_CHECK_HEADER(GL/gl.h,
666        [AC_CHECK_LIB(GLU, gluPerspective,
667          [AC_CHECK_HEADER(GL/glu.h, ,
668            dnl NOTE: this is a failure
669            no_opengl=yes
670          )]
671        )]
672      )]
673    )
674
675    CFLAGS="$ac_save_CFLAGS"
676    LIBS="$ac_save_LIBS"
677  fi
678
679  if test "x$no_opengl" = "x" ; then
680     ifelse([$1], , :, [$1])
681  else
682     OPENGL_CFLAGS=""
683     OPENGL_LIBS=""
684     ifelse([$2], , :, [$2])
685  fi
686  AC_SUBST(OPENGL_CFLAGS)
687  AC_SUBST(OPENGL_LIBS)
688])
689