1 # Configure paths for SDL2
3 # stolen from Manish Singh
4 # stolen back from Frank Belew
5 # stolen from Manish Singh
6 # Shamelessly stolen from Owen Taylor
7 # Taken to Freeciv from SDL release 2.0.0 - modified to work together with sdl1.2
11 dnl AM_PATH_SDL2([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
12 dnl Test for SDL, and define SDL2_CFLAGS and SDL2_LIBS
14 AC_DEFUN([AM_PATH_SDL2],
16 dnl Get the cflags and libraries from the sdl2-config script
18 AC_ARG_WITH(sdl2-prefix,[ --with-sdl2-prefix=PFX Prefix where SDL2 is installed (optional)],
19 sdl2_prefix="$withval", sdl2_prefix="")
20 AC_ARG_WITH(sdl2-exec-prefix,[ --with-sdl2-exec-prefix=PFX Exec prefix where SDL2 is installed (optional)],
21 sdl2_exec_prefix="$withval", sdl2_exec_prefix="")
22 AC_ARG_ENABLE(sdl2test, [ --disable-sdl2test Do not try to compile and run a test SDL2 program],
23 , enable_sdl2test=yes)
25 min_sdl2_version=ifelse([$1], ,2.0.0,$1)
27 if test "x$sdl2_prefix$sdl2_exec_prefix" = x ; then
28 PKG_CHECK_MODULES([SDL2], [sdl2 >= $min_sdl2_version],
33 if test x$sdl2_exec_prefix != x ; then
34 sdl2_config_args="$sdl2_config_args --exec-prefix=$sdl2_exec_prefix"
35 if test x${SDL2_CONFIG+set} != xset ; then
36 SDL2_CONFIG=$sdl2_exec_prefix/bin/sdl2-config
39 if test x$sdl2_prefix != x ; then
40 sdl2_config_args="$sdl2_config_args --prefix=$sdl2_prefix"
41 if test x${SDL2_CONFIG+set} != xset ; then
42 SDL2_CONFIG=$sdl2_prefix/bin/sdl2-config
47 if test "x$sdl2_pc" = xyes ; then
49 SDL2_CONFIG="pkg-config sdl2"
52 if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then
53 PATH="$prefix/bin:$prefix/usr/bin:$PATH"
55 AC_PATH_PROG(SDL2_CONFIG, sdl2-config, no, [$PATH])
57 AC_MSG_CHECKING(for SDL2 - version >= $min_sdl2_version)
60 if test "$SDL2_CONFIG" = "no" ; then
63 SDL2_CFLAGS=`$SDL2_CONFIG $sdl2_config_args --cflags`
64 SDL2_LIBS=`$SDL2_CONFIG $sdl2_config_args --libs`
66 sdl2_major_version=`$SDL2_CONFIG $sdl2_config_args --version | \
67 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
68 sdl2_minor_version=`$SDL2_CONFIG $sdl2_config_args --version | \
69 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
70 sdl2_micro_version=`$SDL2_CONFIG $sdl2_config_args --version | \
71 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
72 if test "x$enable_sdl2test" = "xyes" ; then
73 ac_save_CFLAGS="$CFLAGS"
74 ac_save_CXXFLAGS="$CXXFLAGS"
76 CFLAGS="$CFLAGS $SDL2_CFLAGS"
77 CXXFLAGS="$CXXFLAGS $SDL2_CFLAGS"
78 LIBS="$LIBS $SDL2_LIBS"
80 dnl Now check if the installed SDL2 is sufficiently new. (Also sanity
81 dnl checks the results of sdl2-config to some extent
97 new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
98 strcpy (new_str, str);
106 int main (int argc, char *argv[])
108 int major, minor, micro;
111 /* This hangs on some systems (?)
112 system ("touch conf.sdl2test");
114 { FILE *fp = fopen("conf.sdl2test", "a"); if ( fp ) fclose(fp); }
116 /* HP/UX 9 (%@#!) writes to sscanf strings */
117 tmp_version = my_strdup("$min_sdl2_version");
118 if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) {
119 printf("%s, bad version string\n", "$min_sdl2_version");
123 if (($sdl2_major_version > major) ||
124 (($sdl2_major_version == major) && ($sdl2_minor_version > minor)) ||
125 (($sdl2_major_version == major) && ($sdl2_minor_version == minor) && ($sdl2_micro_version >= micro)))
131 printf("\n*** 'sdl2-config --version' returned %d.%d.%d, but the minimum version\n", $sdl2_major_version, $sdl2_minor_version, $sdl2_micro_version);
132 printf("*** of SDL2 required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro);
133 printf("*** best to upgrade to the required version.\n");
134 printf("*** If sdl2-config was wrong, set the environment variable SDL2_CONFIG\n");
135 printf("*** to point to the correct copy of sdl2-config, and remove the file\n");
136 printf("*** config.cache before re-running configure\n");
141 ],, no_sdl2=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
142 CFLAGS="$ac_save_CFLAGS"
143 CXXFLAGS="$ac_save_CXXFLAGS"
147 if test "x$no_sdl" = x ; then
153 if test "x$no_sdl2" = x ; then
154 ifelse([$2], , :, [$2])
156 if test "$SDL2_CONFIG" = "no" ; then
157 echo "*** The sdl2-config script installed by SDL2 could not be found"
158 echo "*** If SDL2 was installed in PREFIX, make sure PREFIX/bin is in"
159 echo "*** your path, or set the SDL2_CONFIG environment variable to the"
160 echo "*** full path to sdl2-config."
162 if test -f conf.sdl2test ; then
165 echo "*** Could not run SDL2 test program, checking why..."
166 CFLAGS="$CFLAGS $SDL2_CFLAGS"
167 CXXFLAGS="$CXXFLAGS $SDL2_CFLAGS"
168 LIBS="$LIBS $SDL2_LIBS"
173 int main(int argc, char *argv[])
176 #define main K_and_R_C_main
178 [ echo "*** The test program compiled, but did not run. This usually means"
179 echo "*** that the run-time linker is not finding SDL2 or finding the wrong"
180 echo "*** version of SDL2. If it is not finding SDL2, you'll need to set your"
181 echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
182 echo "*** to the installed location Also, make sure you have run ldconfig if that"
183 echo "*** is required on your system"
185 echo "*** If you have an old version installed, it is best to remove it, although"
186 echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
187 [ echo "*** The test program failed to compile or link. See the file config.log for the"
188 echo "*** exact error that occured. This usually means SDL2 was incorrectly installed"
189 echo "*** or that you have moved SDL2 since it was installed. In the latter case, you"
190 echo "*** may want to edit the sdl2-config script: $SDL2_CONFIG" ])
191 CFLAGS="$ac_save_CFLAGS"
192 CXXFLAGS="$ac_save_CXXFLAGS"
198 ifelse([$3], , :, [$3])
200 AC_SUBST(SDL2_CFLAGS)