sdl.m4 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. dnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
  8. dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
  9. dnl
  10. AC_DEFUN([AM_PATH_SDL],
  11. [dnl
  12. dnl Get the cflags and libraries from the sdl-config script
  13. dnl
  14. AC_ARG_WITH(sdl-prefix,[ --with-sdl-prefix=PFX Prefix where SDL is installed (optional)],
  15. sdl_prefix="$withval", sdl_prefix="")
  16. AC_ARG_WITH(sdl-exec-prefix,[ --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)],
  17. sdl_exec_prefix="$withval", sdl_exec_prefix="")
  18. AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run a test SDL program],
  19. , enable_sdltest=yes)
  20. if test x$sdl_exec_prefix != x ; then
  21. sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix"
  22. if test x${SDL_CONFIG+set} != xset ; then
  23. SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config
  24. fi
  25. fi
  26. if test x$sdl_prefix != x ; then
  27. sdl_config_args="$sdl_config_args --prefix=$sdl_prefix"
  28. if test x${SDL_CONFIG+set} != xset ; then
  29. SDL_CONFIG=$sdl_prefix/bin/sdl-config
  30. fi
  31. fi
  32. if test "x$prefix" != xNONE; then
  33. PATH="$prefix/bin:$prefix/usr/bin:$PATH"
  34. fi
  35. AC_PATH_PROG(SDL_CONFIG, sdl-config, no, [$PATH])
  36. min_sdl_version=ifelse([$1], ,0.11.0,$1)
  37. AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
  38. no_sdl=""
  39. if test "$SDL_CONFIG" = "no" ; then
  40. no_sdl=yes
  41. else
  42. SDL_CFLAGS=`$SDL_CONFIG $sdl_config_args --cflags`
  43. SDL_LIBS=`$SDL_CONFIG $sdl_config_args --libs`
  44. sdl_major_version=`$SDL_CONFIG $sdl_config_args --version | \
  45. sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
  46. sdl_minor_version=`$SDL_CONFIG $sdl_config_args --version | \
  47. sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
  48. sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \
  49. sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
  50. if test "x$enable_sdltest" = "xyes" ; then
  51. ac_save_CFLAGS="$CFLAGS"
  52. ac_save_CXXFLAGS="$CXXFLAGS"
  53. ac_save_LIBS="$LIBS"
  54. CFLAGS="$CFLAGS $SDL_CFLAGS"
  55. CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
  56. LIBS="$LIBS $SDL_LIBS"
  57. dnl
  58. dnl Now check if the installed SDL is sufficiently new. (Also sanity
  59. dnl checks the results of sdl-config to some extent
  60. dnl
  61. rm -f conf.sdltest
  62. AC_TRY_RUN([
  63. #include <stdio.h>
  64. #include <stdlib.h>
  65. #include <string.h>
  66. #include "SDL.h"
  67. char*
  68. my_strdup (char *str)
  69. {
  70. char *new_str;
  71. if (str)
  72. {
  73. new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
  74. strcpy (new_str, str);
  75. }
  76. else
  77. new_str = NULL;
  78. return new_str;
  79. }
  80. int main (int argc, char *argv[])
  81. {
  82. int major, minor, micro;
  83. char *tmp_version;
  84. /* This hangs on some systems (?)
  85. system ("touch conf.sdltest");
  86. */
  87. { FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); }
  88. /* HP/UX 9 (%@#!) writes to sscanf strings */
  89. tmp_version = my_strdup("$min_sdl_version");
  90. if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
  91. printf("%s, bad version string\n", "$min_sdl_version");
  92. exit(1);
  93. }
  94. if (($sdl_major_version > major) ||
  95. (($sdl_major_version == major) && ($sdl_minor_version > minor)) ||
  96. (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro)))
  97. {
  98. return 0;
  99. }
  100. else
  101. {
  102. printf("\n*** 'sdl-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
  103. printf("*** of SDL required is %d.%d.%d. If sdl-config is correct, then it is\n", major, minor, micro);
  104. printf("*** best to upgrade to the required version.\n");
  105. printf("*** If sdl-config was wrong, set the environment variable SDL_CONFIG\n");
  106. printf("*** to point to the correct copy of sdl-config, and remove the file\n");
  107. printf("*** config.cache before re-running configure\n");
  108. return 1;
  109. }
  110. }
  111. ],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
  112. CFLAGS="$ac_save_CFLAGS"
  113. CXXFLAGS="$ac_save_CXXFLAGS"
  114. LIBS="$ac_save_LIBS"
  115. fi
  116. fi
  117. if test "x$no_sdl" = x ; then
  118. AC_MSG_RESULT(yes)
  119. ifelse([$2], , :, [$2])
  120. else
  121. AC_MSG_RESULT(no)
  122. if test "$SDL_CONFIG" = "no" ; then
  123. echo "*** The sdl-config script installed by SDL could not be found"
  124. echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
  125. echo "*** your path, or set the SDL_CONFIG environment variable to the"
  126. echo "*** full path to sdl-config."
  127. else
  128. if test -f conf.sdltest ; then
  129. :
  130. else
  131. echo "*** Could not run SDL test program, checking why..."
  132. CFLAGS="$CFLAGS $SDL_CFLAGS"
  133. CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
  134. LIBS="$LIBS $SDL_LIBS"
  135. AC_TRY_LINK([
  136. #include <stdio.h>
  137. #include "SDL.h"
  138. int main(int argc, char *argv[])
  139. { return 0; }
  140. #undef main
  141. #define main K_and_R_C_main
  142. ], [ return 0; ],
  143. [ echo "*** The test program compiled, but did not run. This usually means"
  144. echo "*** that the run-time linker is not finding SDL or finding the wrong"
  145. echo "*** version of SDL. If it is not finding SDL, you'll need to set your"
  146. echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
  147. echo "*** to the installed location Also, make sure you have run ldconfig if that"
  148. echo "*** is required on your system"
  149. echo "***"
  150. echo "*** If you have an old version installed, it is best to remove it, although"
  151. echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
  152. [ echo "*** The test program failed to compile or link. See the file config.log for the"
  153. echo "*** exact error that occured. This usually means SDL was incorrectly installed"
  154. echo "*** or that you have moved SDL since it was installed. In the latter case, you"
  155. echo "*** may want to edit the sdl-config script: $SDL_CONFIG" ])
  156. CFLAGS="$ac_save_CFLAGS"
  157. CXXFLAGS="$ac_save_CXXFLAGS"
  158. LIBS="$ac_save_LIBS"
  159. fi
  160. fi
  161. SDL_CFLAGS=""
  162. SDL_LIBS=""
  163. ifelse([$3], , :, [$3])
  164. fi
  165. AC_SUBST(SDL_CFLAGS)
  166. AC_SUBST(SDL_LIBS)
  167. rm -f conf.sdltest
  168. ])