1
0

acinclude.m4 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. dnl AM_PATH_SDL2([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
  8. dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
  9. dnl
  10. AC_DEFUN([AM_PATH_SDL2],
  11. [dnl
  12. dnl Get the cflags and libraries from the sdl2-config script
  13. dnl
  14. AC_ARG_WITH(sdl-prefix,[ --with-sdl-prefix=PFX Prefix where SDL is installed (optional)],
  15. sdl_prefix="$withval", sdl_prefix="")
  16. AC_ARG_WITH(sdl-exec-prefix,[ --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)],
  17. sdl_exec_prefix="$withval", sdl_exec_prefix="")
  18. AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run a test SDL program],
  19. , enable_sdltest=yes)
  20. min_sdl_version=ifelse([$1], ,2.0.0,$1)
  21. if test "x$sdl_prefix$sdl_exec_prefix" = x ; then
  22. PKG_CHECK_MODULES([SDL], [sdl2 >= $min_sdl_version],
  23. [sdl_pc=yes],
  24. [sdl_pc=no])
  25. else
  26. sdl_pc=no
  27. if test x$sdl_exec_prefix != x ; then
  28. sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix"
  29. if test x${SDL2_CONFIG+set} != xset ; then
  30. SDL2_CONFIG=$sdl_exec_prefix/bin/sdl2-config
  31. fi
  32. fi
  33. if test x$sdl_prefix != x ; then
  34. sdl_config_args="$sdl_config_args --prefix=$sdl_prefix"
  35. if test x${SDL2_CONFIG+set} != xset ; then
  36. SDL2_CONFIG=$sdl_prefix/bin/sdl2-config
  37. fi
  38. fi
  39. fi
  40. if test "x$sdl_pc" = xyes ; then
  41. no_sdl=""
  42. SDL2_CONFIG="$PKG_CONFIG sdl2"
  43. else
  44. as_save_PATH="$PATH"
  45. if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then
  46. PATH="$prefix/bin:$prefix/usr/bin:$PATH"
  47. fi
  48. AC_PATH_PROG(SDL2_CONFIG, sdl2-config, no, [$PATH])
  49. PATH="$as_save_PATH"
  50. AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
  51. no_sdl=""
  52. if test "$SDL2_CONFIG" = "no" ; then
  53. no_sdl=yes
  54. else
  55. SDL_CFLAGS=`$SDL2_CONFIG $sdl_config_args --cflags`
  56. SDL_LIBS=`$SDL2_CONFIG $sdl_config_args --libs`
  57. sdl_major_version=`$SDL2_CONFIG $sdl_config_args --version | \
  58. sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
  59. sdl_minor_version=`$SDL2_CONFIG $sdl_config_args --version | \
  60. sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
  61. sdl_micro_version=`$SDL2_CONFIG $sdl_config_args --version | \
  62. sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
  63. if test "x$enable_sdltest" = "xyes" ; then
  64. ac_save_CFLAGS="$CFLAGS"
  65. ac_save_CXXFLAGS="$CXXFLAGS"
  66. ac_save_LIBS="$LIBS"
  67. CFLAGS="$CFLAGS $SDL_CFLAGS"
  68. CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
  69. LIBS="$LIBS $SDL_LIBS"
  70. dnl
  71. dnl Now check if the installed SDL is sufficiently new. (Also sanity
  72. dnl checks the results of sdl2-config to some extent
  73. dnl
  74. rm -f conf.sdltest
  75. AC_RUN_IFELSE([AC_LANG_SOURCE([[
  76. #include <stdio.h>
  77. #include <stdlib.h>
  78. #include "SDL.h"
  79. int main (int argc, char *argv[])
  80. {
  81. int major, minor, micro;
  82. FILE *fp = fopen("conf.sdltest", "w");
  83. if (fp) fclose(fp);
  84. if (sscanf("$min_sdl_version", "%d.%d.%d", &major, &minor, &micro) != 3) {
  85. printf("%s, bad version string\n", "$min_sdl_version");
  86. exit(1);
  87. }
  88. if (($sdl_major_version > major) ||
  89. (($sdl_major_version == major) && ($sdl_minor_version > minor)) ||
  90. (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro)))
  91. {
  92. return 0;
  93. }
  94. else
  95. {
  96. printf("\n*** 'sdl2-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
  97. printf("*** of SDL required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro);
  98. printf("*** best to upgrade to the required version.\n");
  99. printf("*** If sdl2-config was wrong, set the environment variable SDL2_CONFIG\n");
  100. printf("*** to point to the correct copy of sdl2-config, and remove the file\n");
  101. printf("*** config.cache before re-running configure\n");
  102. return 1;
  103. }
  104. }
  105. ]])], [], [no_sdl=yes], [echo $ac_n "cross compiling; assumed OK... $ac_c"])
  106. CFLAGS="$ac_save_CFLAGS"
  107. CXXFLAGS="$ac_save_CXXFLAGS"
  108. LIBS="$ac_save_LIBS"
  109. fi
  110. fi
  111. if test "x$no_sdl" = x ; then
  112. AC_MSG_RESULT(yes)
  113. else
  114. AC_MSG_RESULT(no)
  115. fi
  116. fi
  117. if test "x$no_sdl" = x ; then
  118. ifelse([$2], , :, [$2])
  119. else
  120. if test "$SDL2_CONFIG" = "no" ; then
  121. echo "*** The sdl2-config script installed by SDL could not be found"
  122. echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
  123. echo "*** your path, or set the SDL2_CONFIG environment variable to the"
  124. echo "*** full path to sdl2-config."
  125. else
  126. if test -f conf.sdltest ; then
  127. :
  128. else
  129. echo "*** Could not run SDL test program, checking why..."
  130. CFLAGS="$CFLAGS $SDL_CFLAGS"
  131. CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
  132. LIBS="$LIBS $SDL_LIBS"
  133. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  134. #include <stdio.h>
  135. #include "SDL.h"
  136. int main(int argc, char *argv[])
  137. { return 0; }
  138. #undef main
  139. #define main K_and_R_C_main
  140. ]], [[ return 0; ]])],
  141. [ echo "*** The test program compiled, but did not run. This usually means"
  142. echo "*** that the run-time linker is not finding SDL or finding the wrong"
  143. echo "*** version of SDL. If it is not finding SDL, you'll need to set your"
  144. echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
  145. echo "*** to the installed location Also, make sure you have run ldconfig if that"
  146. echo "*** is required on your system"
  147. echo "***"
  148. echo "*** If you have an old version installed, it is best to remove it, although"
  149. echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
  150. [ echo "*** The test program failed to compile or link. See the file config.log for the"
  151. echo "*** exact error that occured. This usually means SDL was incorrectly installed"
  152. echo "*** or that you have moved SDL since it was installed. In the latter case, you"
  153. echo "*** may want to edit the sdl2-config script: $SDL2_CONFIG" ])
  154. CFLAGS="$ac_save_CFLAGS"
  155. CXXFLAGS="$ac_save_CXXFLAGS"
  156. LIBS="$ac_save_LIBS"
  157. fi
  158. fi
  159. SDL_CFLAGS=""
  160. SDL_LIBS=""
  161. ifelse([$3], , :, [$3])
  162. fi
  163. AC_SUBST(SDL_CFLAGS)
  164. AC_SUBST(SDL_LIBS)
  165. rm -f conf.sdltest
  166. ])
  167. # pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
  168. # serial 1 (pkg-config-0.24)
  169. #
  170. # Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
  171. #
  172. # This program is free software; you can redistribute it and/or modify
  173. # it under the terms of the GNU General Public License as published by
  174. # the Free Software Foundation; either version 2 of the License, or
  175. # (at your option) any later version.
  176. #
  177. # This program is distributed in the hope that it will be useful, but
  178. # WITHOUT ANY WARRANTY; without even the implied warranty of
  179. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  180. # General Public License for more details.
  181. #
  182. # You should have received a copy of the GNU General Public License
  183. # along with this program; if not, write to the Free Software
  184. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  185. #
  186. # As a special exception to the GNU General Public License, if you
  187. # distribute this file as part of a program that contains a
  188. # configuration script generated by Autoconf, you may include it under
  189. # the same distribution terms that you use for the rest of that program.
  190. # PKG_PROG_PKG_CONFIG([MIN-VERSION])
  191. # ----------------------------------
  192. AC_DEFUN([PKG_PROG_PKG_CONFIG],
  193. [m4_pattern_forbid([^_?PKG_[A-Z_]+$])
  194. m4_pattern_allow([^PKG_CONFIG(_PATH|_LIBDIR)?$])
  195. AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
  196. AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
  197. AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
  198. if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
  199. AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
  200. fi
  201. if test -n "$PKG_CONFIG"; then
  202. _pkg_min_version=m4_default([$1], [0.9.0])
  203. AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
  204. if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
  205. AC_MSG_RESULT([yes])
  206. else
  207. AC_MSG_RESULT([no])
  208. PKG_CONFIG=""
  209. fi
  210. fi[]dnl
  211. ])# PKG_PROG_PKG_CONFIG
  212. # PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  213. #
  214. # Check to see whether a particular set of modules exists. Similar
  215. # to PKG_CHECK_MODULES(), but does not set variables or print errors.
  216. #
  217. # Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
  218. # only at the first occurence in configure.ac, so if the first place
  219. # it's called might be skipped (such as if it is within an "if", you
  220. # have to call PKG_CHECK_EXISTS manually
  221. # --------------------------------------------------------------
  222. AC_DEFUN([PKG_CHECK_EXISTS],
  223. [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
  224. if test -n "$PKG_CONFIG" && \
  225. AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
  226. m4_default([$2], [:])
  227. m4_ifvaln([$3], [else
  228. $3])dnl
  229. fi])
  230. # _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
  231. # ---------------------------------------------
  232. m4_define([_PKG_CONFIG],
  233. [if test -n "$$1"; then
  234. pkg_cv_[]$1="$$1"
  235. elif test -n "$PKG_CONFIG"; then
  236. PKG_CHECK_EXISTS([$3],
  237. [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`],
  238. [pkg_failed=yes])
  239. else
  240. pkg_failed=untried
  241. fi[]dnl
  242. ])# _PKG_CONFIG
  243. # _PKG_SHORT_ERRORS_SUPPORTED
  244. # -----------------------------
  245. AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
  246. [AC_REQUIRE([PKG_PROG_PKG_CONFIG])
  247. if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
  248. _pkg_short_errors_supported=yes
  249. else
  250. _pkg_short_errors_supported=no
  251. fi[]dnl
  252. ])# _PKG_SHORT_ERRORS_SUPPORTED
  253. # PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
  254. # [ACTION-IF-NOT-FOUND])
  255. #
  256. #
  257. # Note that if there is a possibility the first call to
  258. # PKG_CHECK_MODULES might not happen, you should be sure to include an
  259. # explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
  260. #
  261. #
  262. # --------------------------------------------------------------
  263. AC_DEFUN([PKG_CHECK_MODULES],
  264. [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
  265. AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
  266. AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
  267. pkg_failed=no
  268. AC_MSG_CHECKING([for $2])
  269. _PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
  270. _PKG_CONFIG([$1][_LIBS], [libs], [$2])
  271. m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
  272. and $1[]_LIBS to avoid the need to call pkg-config.
  273. See the pkg-config man page for more details.])
  274. if test $pkg_failed = yes; then
  275. AC_MSG_RESULT([no])
  276. _PKG_SHORT_ERRORS_SUPPORTED
  277. if test $_pkg_short_errors_supported = yes; then
  278. $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "$2" 2>&1`
  279. else
  280. $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors "$2" 2>&1`
  281. fi
  282. # Put the nasty error message in config.log where it belongs
  283. echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
  284. m4_default([$4], [AC_MSG_ERROR(
  285. [Package requirements ($2) were not met:
  286. $$1_PKG_ERRORS
  287. Consider adjusting the PKG_CONFIG_PATH environment variable if you
  288. installed software in a non-standard prefix.
  289. _PKG_TEXT])[]dnl
  290. ])
  291. elif test $pkg_failed = untried; then
  292. AC_MSG_RESULT([no])
  293. m4_default([$4], [AC_MSG_FAILURE(
  294. [The pkg-config script could not be found or is too old. Make sure it
  295. is in your PATH or set the PKG_CONFIG environment variable to the full
  296. path to pkg-config.
  297. _PKG_TEXT
  298. To get pkg-config, see <http://pkg-config.freedesktop.org/>.])[]dnl
  299. ])
  300. else
  301. $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
  302. $1[]_LIBS=$pkg_cv_[]$1[]_LIBS
  303. AC_MSG_RESULT([yes])
  304. $3
  305. fi[]dnl
  306. ])# PKG_CHECK_MODULES