sdl2.m4 8.1 KB

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