sdl2.m4 6.8 KB

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