sdl2.m4 7.7 KB

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