Simple Directmedia Layer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

214 lines
7.6 KiB

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