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.
 
 
 

183 lines
6.0 KiB

  1. # LOL_CHECK_SDL()
  2. # ---------------
  3. AC_DEFUN([LOL_CHECK_SDL],
  4. [
  5. dnl Find which version of SDL to use (always required on Linux or Win32)
  6. dnl
  7. dnl Defined C/C++ macros:
  8. dnl USE_SDL -- whether SDL v2 was found
  9. dnl USE_OLD_SDL -- whether SDL v1 was found
  10. dnl USE_SDL_IMAGE -- whether SDL_image (v1 or v2) was found
  11. dnl USE_SDL_MIXER -- whether SDL_mixer (v1 or v2) was found
  12. dnl HAVE_SDL_H -- whether to include <SDL.h>
  13. dnl HAVE_SDL_SDL_H -- whether to include <SDL/SDL.h>
  14. dnl HAVE_SDL2_SDL_H -- whether to include <SDL2/SDL.h>
  15. dnl Generated automake conditionals:
  16. dnl USE_SDL -- whether SDL v2 was found
  17. dnl USE_OLD_SDL -- whether SDL v1 was found
  18. dnl USE_SDL_IMAGE -- whether SDL_image was found
  19. dnl USE_SDL_MIXER -- whether SDL_mixer was found
  20. dnl Generated shell variables:
  21. dnl SDL_CFLAGS -- flags for SDL compilation
  22. dnl SDL_LIBS -- flags for SDL linking
  23. ac_cv_my_have_sdl="no"
  24. ac_cv_my_have_old_sdl="no"
  25. ac_cv_my_have_sdl_image="no"
  26. ac_cv_my_have_sdl_mixer="no"
  27. dnl First, try the proper pkg-config check for SDL2
  28. if test "x${ac_cv_my_have_sdl}" = xno; then
  29. PKG_CHECK_MODULES(SDL2, sdl2,
  30. [ac_cv_my_have_sdl="yes"
  31. PKG_CHECK_MODULES(SDL2MIXER, SDL2_mixer,
  32. [ac_cv_my_have_sdl_mixer="yes"
  33. AC_DEFINE(HAVE_SDL_MIXER_H, 1, Define to 1 to use SDL_mixer.h)],
  34. [:])
  35. PKG_CHECK_MODULES(SDL2IMAGE, SDL2_image,
  36. [ac_cv_my_have_sdl_image="yes"
  37. AC_DEFINE(HAVE_SDL_IMAGE_H, 1, Define to 1 to use SDL_image.h)],
  38. [:])
  39. SDL_CFLAGS="${SDL2_CFLAGS} ${SDL2MIXER_CFLAGS} ${SDL2IMAGE_CFLAGS}"
  40. SDL_LIBS="${SDL2_LIBS} ${SDL2MIXER_LIBS} ${SDL2IMAGE_LIBS}"
  41. AC_DEFINE(HAVE_SDL_H, 1, Define to 1 to use SDL.h)],
  42. [:])
  43. fi
  44. dnl Maybe all this has failed, try direct inclusion instead
  45. if test "x${ac_cv_my_have_sdl}" = xno; then
  46. save_CPPFLAGS="${CPPFLAGS}"
  47. save_LIBS="${LIBS}"
  48. CPPFLAGS="${CPPFLAGS} ${SDL_CFLAGS}"
  49. LIBS="${LIBS} ${SDL_LIBS}"
  50. AC_CHECK_HEADERS(SDL.h SDL/SDL.h SDL2/SDL.h, [ac_cv_my_have_sdl="yes"])
  51. if test "x${ac_cv_my_have_sdl}" != xno; then
  52. AC_CHECK_HEADERS(SDL_mixer.h SDL/SDL_mixer.h SDL2/SDL_mixer.h,
  53. [ac_cv_my_have_sdl_mixer="yes"])
  54. AC_CHECK_HEADERS(SDL_image.h SDL/SDL_image.h SDL2/SDL_image.h,
  55. [ac_cv_my_have_sdl_image="yes"])
  56. AC_CHECK_LIB(SDL2, main,
  57. [SDL_LIBS="${SDL_LIBS} -lSDL2"],
  58. [ac_cv_my_have_sdl="no"])
  59. AC_CHECK_LIB(SDL2main, main,
  60. [SDL_LIBS="${SDL_LIBS} -lSDL2main -lSDL2"])
  61. AC_CHECK_LIB(SDL2_mixer, main,
  62. [SDLMIXER_LIBS="${SDLMIXER_LIBS} -lSDL2_mixer"],
  63. [ac_cv_my_have_sdl_mixer="no"])
  64. AC_CHECK_LIB(SDL2_image, main,
  65. [SDLIMAGE_LIBS="${SDLIMAGE_LIBS} -lSDL2_image"],
  66. [ac_cv_my_have_sdl_image="no"])
  67. fi
  68. SDL_CFLAGS="${SDL_CFLAGS} ${SDLMIXER_CFLAGS} ${SDLIMAGE_CFLAGS}"
  69. SDL_LIBS="${SDL_LIBS} ${SDLMIXER_LIBS} ${SDLIMAGE_LIBS}"
  70. CPPFLAGS="${save_CPPFLAGS}"
  71. LIBS="${save_LIBS}"
  72. fi
  73. dnl Then, try the proper pkg-config check for SDL 1.x
  74. if test "x${ac_cv_my_have_sdl}" = xno \
  75. -a "x${ac_cv_my_have_old_sdl}" = xno; then
  76. PKG_CHECK_MODULES(SDL, sdl,
  77. [ac_cv_my_have_old_sdl="yes"
  78. PKG_CHECK_MODULES(SDLMIXER, SDL_mixer,
  79. [ac_cv_my_have_sdl_mixer="yes"
  80. AC_DEFINE(HAVE_SDL_MIXER_H, 1, Define to 1 to use SDL_mixer.h)],
  81. [:])
  82. PKG_CHECK_MODULES(SDLIMAGE, SDL_image,
  83. [ac_cv_my_have_sdl_image="yes"
  84. AC_DEFINE(HAVE_SDL_IMAGE_H, 1, Define to 1 to use SDL_image.h)],
  85. [:])
  86. SDL_CFLAGS="${SDL_CFLAGS} ${SDLMIXER_CFLAGS} ${SDLIMAGE_CFLAGS}"
  87. SDL_LIBS="${SDL_LIBS} ${SDLMIXER_LIBS} ${SDLIMAGE_LIBS}"
  88. AC_DEFINE(HAVE_SDL_H, 1, Define to 1 to use SDL.h)],
  89. [:])
  90. fi
  91. dnl Then the old sdl-config method
  92. if test "x${ac_cv_my_have_sdl}" = xno \
  93. -a "x${ac_cv_my_have_old_sdl}" = xno \
  94. -a "x${cross_compiling}" != xyes; then
  95. AC_PATH_PROG(SDL_CONFIG, sdl-config, no)
  96. if test "${SDL_CONFIG}" != "no" && "${SDL_CONFIG}" --version >/dev/null; then
  97. ac_cv_my_have_old_sdl="yes"
  98. SDL_CFLAGS="${SDL_CFLAGS} `${SDL_CONFIG} --cflags`"
  99. SDL_LIBS="${SDL_LIBS} `${SDL_CONFIG} --libs`"
  100. AC_DEFINE(HAVE_SDL_H, 1, Define to 1 to use SDL.h)
  101. fi
  102. fi
  103. dnl Finally, try direct inclusion
  104. if test "x${ac_cv_my_have_sdl}" = xno \
  105. -a "x${ac_cv_my_have_old_sdl}" = xno; then
  106. save_CPPFLAGS="${CPPFLAGS}"
  107. save_LIBS="${LIBS}"
  108. CPPFLAGS="${CPPFLAGS} ${SDL_CFLAGS}"
  109. LIBS="${LIBS} ${SDL_LIBS}"
  110. AC_CHECK_HEADERS(SDL.h SDL/SDL.h, [ac_cv_my_have_old_sdl="yes"])
  111. if test "x${ac_cv_my_have_old_sdl}" != xno; then
  112. AC_CHECK_HEADERS(SDL_mixer.h SDL/SDL_mixer.h,
  113. [ac_cv_my_have_sdl_mixer="yes"])
  114. AC_CHECK_HEADERS(SDL_image.h SDL/SDL_image.h,
  115. [ac_cv_my_have_sdl_image="yes"])
  116. AC_CHECK_LIB(SDL, main,
  117. [SDL_LIBS="${SDL_LIBS} -lSDL"],
  118. [ac_cv_my_have_old_sdl="no"])
  119. AC_CHECK_LIB(SDLmain, main,
  120. [SDL_LIBS="${SDL_LIBS} -lSDLmain -lSDL"])
  121. AC_CHECK_LIB(SDL_mixer, main,
  122. [SDLMIXER_LIBS="${SDLMIXER_LIBS} -lSDL_mixer"],
  123. [ac_cv_my_have_sdl_mixer="no"])
  124. AC_CHECK_LIB(SDL_image, main,
  125. [SDLIMAGE_LIBS="${SDLIMAGE_LIBS} -lSDL_image"],
  126. [ac_cv_my_have_sdl_image="no"])
  127. fi
  128. SDL_CFLAGS="${SDL_CFLAGS} ${SDLMIXER_CFLAGS} ${SDLIMAGE_CFLAGS}"
  129. SDL_LIBS="${SDL_LIBS} ${SDLMIXER_LIBS} ${SDLIMAGE_LIBS}"
  130. CPPFLAGS="${save_CPPFLAGS}"
  131. LIBS="${save_LIBS}"
  132. fi
  133. dnl Convert all this into conditionals
  134. if test "x${ac_cv_my_have_sdl}" = xno; then
  135. AC_MSG_WARN([SDL v2 not found])
  136. else
  137. AC_DEFINE(USE_SDL, 1, Define to 1 to use SDL)
  138. fi
  139. AM_CONDITIONAL(USE_SDL, test "x${ac_cv_my_have_sdl}" = xyes)
  140. if test "x${ac_cv_my_have_sdl_mixer}" = xno; then
  141. AC_MSG_WARN([SDL_mixer not found])
  142. else
  143. AC_DEFINE(USE_SDL_MIXER, 1, Define to 1 to use SDL_mixer)
  144. fi
  145. AM_CONDITIONAL(USE_SDL_MIXER, test "x${ac_cv_my_have_sdl_mixer}" = xyes)
  146. if test "x${ac_cv_my_have_sdl_image}" = xno; then
  147. AC_MSG_WARN([SDL_image not found])
  148. else
  149. AC_DEFINE(USE_SDL_IMAGE, 1, Define to 1 to use SDL_image)
  150. fi
  151. AM_CONDITIONAL(USE_SDL_IMAGE, test "x${ac_cv_my_have_sdl_image}" = xyes)
  152. if test "x${ac_cv_my_have_old_sdl}" != xno; then
  153. AC_DEFINE(USE_OLD_SDL, 1, Define to 1 to use SDL)
  154. fi
  155. AM_CONDITIONAL(USE_OLD_SDL, test "x${ac_cv_my_have_old_sdl}" = xyes)
  156. ])# LOL_CHECK_SDL