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.
 
 
 

203 lines
6.7 KiB

  1. dnl
  2. dnl Lol Engine
  3. dnl
  4. dnl Copyright © 2010—2017 Sam Hocevar <sam@hocevar.net>
  5. dnl
  6. dnl Lol Engine is free software. It comes without any warranty, to
  7. dnl the extent permitted by applicable law. You can redistribute it
  8. dnl and/or modify it under the terms of the Do What the Fuck You Want
  9. dnl to Public License, Version 2, as published by the WTFPL Task Force.
  10. dnl See http://www.wtfpl.net/ for more details.
  11. dnl
  12. # LOL_AC_CHECK_SDL()
  13. # ------------------
  14. AC_DEFUN([LOL_AC_CHECK_SDL],
  15. [
  16. ac_cv_my_have_sdl="no"
  17. ac_cv_my_have_old_sdl="no"
  18. ac_cv_my_have_sdl_image="no"
  19. ac_cv_my_have_sdl_mixer="no"
  20. if test "${enable_sdl}" != "no"; then
  21. LOL_AC_CHECK_SDL_INNER()
  22. fi
  23. AM_CONDITIONAL(LOL_USE_SDL, test "${ac_cv_my_have_sdl}" != "no")
  24. AM_CONDITIONAL(LOL_USE_SDL_MIXER, test "${ac_cv_my_have_sdl_mixer}" != "no")
  25. AM_CONDITIONAL(LOL_USE_SDL_IMAGE, test "${ac_cv_my_have_sdl_image}" != "no")
  26. AM_CONDITIONAL(LOL_USE_OLD_SDL, test "${ac_cv_my_have_old_sdl}" != "no")
  27. ])
  28. # LOL_AC_CHECK_SDL_INNER()
  29. # ------------------------
  30. AC_DEFUN([LOL_AC_CHECK_SDL_INNER],
  31. [
  32. dnl Find which version of SDL to use (always required on Linux or Win32)
  33. dnl
  34. dnl Defined C/C++ macros:
  35. dnl LOL_USE_SDL -- whether SDL v2 was found
  36. dnl LOL_USE_OLD_SDL -- whether SDL v1 was found
  37. dnl LOL_USE_SDL_IMAGE -- whether SDL_image (v1 or v2) was found
  38. dnl LOL_USE_SDL_MIXER -- whether SDL_mixer (v1 or v2) was found
  39. dnl HAVE_SDL_H -- whether to include <SDL.h>
  40. dnl HAVE_SDL_SDL_H -- whether to include <SDL/SDL.h>
  41. dnl HAVE_SDL2_SDL_H -- whether to include <SDL2/SDL.h>
  42. dnl Generated automake conditionals:
  43. dnl LOL_USE_SDL -- whether SDL v2 was found
  44. dnl LOL_USE_OLD_SDL -- whether SDL v1 was found
  45. dnl LOL_USE_SDL_IMAGE -- whether SDL_image was found
  46. dnl LOL_USE_SDL_MIXER -- whether SDL_mixer was found
  47. dnl Generated shell variables:
  48. dnl SDL_CFLAGS -- flags for SDL compilation
  49. dnl SDL_LIBS -- flags for SDL linking
  50. dnl First, try the proper pkg-config check for SDL2
  51. if test "x${ac_cv_my_have_sdl}" = xno; then
  52. PKG_CHECK_MODULES(SDL2, sdl2,
  53. [ac_cv_my_have_sdl="yes"
  54. PKG_CHECK_MODULES(SDL2MIXER, SDL2_mixer,
  55. [ac_cv_my_have_sdl_mixer="yes"
  56. AC_DEFINE(HAVE_SDL_MIXER_H, 1, Define to 1 to use SDL_mixer.h)],
  57. [:])
  58. PKG_CHECK_MODULES(SDL2IMAGE, SDL2_image,
  59. [ac_cv_my_have_sdl_image="yes"
  60. AC_DEFINE(HAVE_SDL_IMAGE_H, 1, Define to 1 to use SDL_image.h)],
  61. [:])
  62. SDL_CFLAGS="${SDL2_CFLAGS} ${SDL2MIXER_CFLAGS} ${SDL2IMAGE_CFLAGS}"
  63. SDL_LIBS="${SDL2_LIBS} ${SDL2MIXER_LIBS} ${SDL2IMAGE_LIBS}"
  64. AC_DEFINE(HAVE_SDL_H, 1, Define to 1 to use SDL.h)],
  65. [:])
  66. fi
  67. dnl Maybe all this has failed, try direct inclusion instead
  68. if test "x${ac_cv_my_have_sdl}" = xno; then
  69. save_CPPFLAGS="${CPPFLAGS}"
  70. save_LIBS="${LIBS}"
  71. CPPFLAGS="${CPPFLAGS} ${SDL_CFLAGS}"
  72. LIBS="${LIBS} ${SDL_LIBS}"
  73. AC_CHECK_HEADERS(SDL.h SDL/SDL.h SDL2/SDL.h,
  74. [ac_cv_my_have_sdl="yes"])
  75. if test "x${ac_cv_my_have_sdl}" != xno; then
  76. AC_CHECK_HEADERS(SDL_mixer.h SDL/SDL_mixer.h SDL2/SDL_mixer.h,
  77. [ac_cv_my_have_sdl_mixer="yes"])
  78. AC_CHECK_HEADERS(SDL_image.h SDL/SDL_image.h SDL2/SDL_image.h,
  79. [ac_cv_my_have_sdl_image="yes"])
  80. AC_CHECK_LIB(SDL2, main,
  81. [SDL_LIBS="${SDL_LIBS} -lSDL2"],
  82. [ac_cv_my_have_sdl="no"])
  83. AC_CHECK_LIB(SDL2main, main,
  84. [SDL_LIBS="${SDL_LIBS} -lSDL2main -lSDL2"])
  85. AC_CHECK_LIB(SDL2_mixer, main,
  86. [SDLMIXER_LIBS="${SDLMIXER_LIBS} -lSDL2_mixer"],
  87. [ac_cv_my_have_sdl_mixer="no"])
  88. AC_CHECK_LIB(SDL2_image, main,
  89. [SDLIMAGE_LIBS="${SDLIMAGE_LIBS} -lSDL2_image"],
  90. [ac_cv_my_have_sdl_image="no"])
  91. SDL_CFLAGS="${SDL_CFLAGS} ${SDLMIXER_CFLAGS} ${SDLIMAGE_CFLAGS}"
  92. SDL_LIBS="${SDL_LIBS} ${SDLMIXER_LIBS} ${SDLIMAGE_LIBS}"
  93. fi
  94. CPPFLAGS="${save_CPPFLAGS}"
  95. LIBS="${save_LIBS}"
  96. fi
  97. dnl Then, try the proper pkg-config check for SDL 1.x
  98. if test "x${ac_cv_my_have_sdl}" = xno \
  99. -a "x${ac_cv_my_have_old_sdl}" = xno; then
  100. PKG_CHECK_MODULES(SDL, sdl,
  101. [ac_cv_my_have_old_sdl="yes"
  102. PKG_CHECK_MODULES(SDLMIXER, SDL_mixer,
  103. [ac_cv_my_have_sdl_mixer="yes"
  104. AC_DEFINE(HAVE_SDL_MIXER_H, 1, Define to 1 to use SDL_mixer.h)],
  105. [:])
  106. PKG_CHECK_MODULES(SDLIMAGE, SDL_image,
  107. [ac_cv_my_have_sdl_image="yes"
  108. AC_DEFINE(HAVE_SDL_IMAGE_H, 1, Define to 1 to use SDL_image.h)],
  109. [:])
  110. SDL_CFLAGS="${SDL_CFLAGS} ${SDLMIXER_CFLAGS} ${SDLIMAGE_CFLAGS}"
  111. SDL_LIBS="${SDL_LIBS} ${SDLMIXER_LIBS} ${SDLIMAGE_LIBS}"
  112. AC_DEFINE(HAVE_SDL_H, 1, Define to 1 to use SDL.h)],
  113. [:])
  114. fi
  115. dnl Then the old sdl-config method
  116. if test "x${ac_cv_my_have_sdl}" = xno \
  117. -a "x${ac_cv_my_have_old_sdl}" = xno \
  118. -a "x${cross_compiling}" != xyes; then
  119. AC_PATH_PROG(SDL_CONFIG, sdl-config, no)
  120. if test "${SDL_CONFIG}" != "no" && "${SDL_CONFIG}" --version >/dev/null; then
  121. ac_cv_my_have_old_sdl="yes"
  122. SDL_CFLAGS="${SDL_CFLAGS} `${SDL_CONFIG} --cflags`"
  123. SDL_LIBS="${SDL_LIBS} `${SDL_CONFIG} --libs`"
  124. AC_DEFINE(HAVE_SDL_H, 1, Define to 1 to use SDL.h)
  125. fi
  126. fi
  127. dnl Finally, try direct inclusion
  128. if test "x${ac_cv_my_have_sdl}" = xno \
  129. -a "x${ac_cv_my_have_old_sdl}" = xno; then
  130. save_CPPFLAGS="${CPPFLAGS}"
  131. save_LIBS="${LIBS}"
  132. CPPFLAGS="${CPPFLAGS} ${SDL_CFLAGS}"
  133. LIBS="${LIBS} ${SDL_LIBS}"
  134. AC_CHECK_HEADERS(SDL.h SDL/SDL.h, [ac_cv_my_have_old_sdl="yes"])
  135. if test "x${ac_cv_my_have_old_sdl}" != xno; then
  136. AC_CHECK_HEADERS(SDL_mixer.h SDL/SDL_mixer.h,
  137. [ac_cv_my_have_sdl_mixer="yes"])
  138. AC_CHECK_HEADERS(SDL_image.h SDL/SDL_image.h,
  139. [ac_cv_my_have_sdl_image="yes"])
  140. AC_CHECK_LIB(SDL, main,
  141. [SDL_LIBS="${SDL_LIBS} -lSDL"],
  142. [ac_cv_my_have_old_sdl="no"])
  143. AC_CHECK_LIB(SDLmain, main,
  144. [SDL_LIBS="${SDL_LIBS} -lSDLmain -lSDL"])
  145. AC_CHECK_LIB(SDL_mixer, main,
  146. [SDLMIXER_LIBS="${SDLMIXER_LIBS} -lSDL_mixer"],
  147. [ac_cv_my_have_sdl_mixer="no"])
  148. AC_CHECK_LIB(SDL_image, main,
  149. [SDLIMAGE_LIBS="${SDLIMAGE_LIBS} -lSDL_image"],
  150. [ac_cv_my_have_sdl_image="no"])
  151. fi
  152. SDL_CFLAGS="${SDL_CFLAGS} ${SDLMIXER_CFLAGS} ${SDLIMAGE_CFLAGS}"
  153. SDL_LIBS="${SDL_LIBS} ${SDLMIXER_LIBS} ${SDLIMAGE_LIBS}"
  154. CPPFLAGS="${save_CPPFLAGS}"
  155. LIBS="${save_LIBS}"
  156. fi
  157. dnl Convert all this into conditionals
  158. if test "x${ac_cv_my_have_sdl}" = xno; then
  159. AC_MSG_WARN([SDL v2 not found])
  160. else
  161. AC_DEFINE(LOL_USE_SDL, 1, Define to 1 to use SDL)
  162. fi
  163. if test "x${ac_cv_my_have_sdl_mixer}" = xno; then
  164. AC_MSG_WARN([SDL_mixer not found])
  165. else
  166. AC_DEFINE(LOL_USE_SDL_MIXER, 1, Define to 1 to use SDL_mixer)
  167. fi
  168. if test "x${ac_cv_my_have_sdl_image}" = xno; then
  169. AC_MSG_WARN([SDL_image not found])
  170. else
  171. AC_DEFINE(LOL_USE_SDL_IMAGE, 1, Define to 1 to use SDL_image)
  172. fi
  173. if test "x${ac_cv_my_have_old_sdl}" != xno; then
  174. AC_DEFINE(LOL_USE_OLD_SDL, 1, Define to 1 to use SDL)
  175. fi
  176. ]) # LOL_AC_CHECK_SDL_INNER