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],
19 AS_HELP_STRING([--with-sdl2-prefix=PFX], [Prefix where SDL2 is installed (optional)]),
20 [sdl2_prefix="$withval"], [sdl2_prefix=""])
22 AC_ARG_WITH([sdl2-exec-prefix],
23 AS_HELP_STRING([--with-sdl2-exec-prefix=PFX], [Exec prefix where SDL2 is installed (optional)]),
24 [sdl2_exec_prefix="$withval"], [sdl2_exec_prefix=""])
26 AC_ARG_ENABLE([sdl2test],
27 AS_HELP_STRING([--disable-sdl2test], [Do not try to compile and run a test SDL2 program]),
28 [], [enable_sdl2test=yes])
30 min_sdl2_version=ifelse([$1], ,2.0.0,$1)
32 if test "x$sdl2_prefix$sdl2_exec_prefix" = x ; then
33 PKG_CHECK_MODULES([SDL2], [sdl2 >= $min_sdl2_version],
38 if test x$sdl2_exec_prefix != x ; then
39 sdl2_config_args="$sdl2_config_args --exec-prefix=$sdl2_exec_prefix"
40 if test x${SDL2_CONFIG+set} != xset ; then
41 SDL2_CONFIG=$sdl2_exec_prefix/bin/sdl2-config
44 if test x$sdl2_prefix != x ; then
45 sdl2_config_args="$sdl2_config_args --prefix=$sdl2_prefix"
46 if test x${SDL2_CONFIG+set} != xset ; then
47 SDL2_CONFIG=$sdl2_prefix/bin/sdl2-config
52 if test "x$sdl2_pc" = xyes ; then
54 SDL2_CONFIG="pkg-config sdl2"
57 if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then
58 PATH="$prefix/bin:$prefix/usr/bin:$PATH"
60 AC_PATH_PROG(SDL2_CONFIG, sdl2-config, no, [$PATH])
62 AC_MSG_CHECKING(for SDL2 - version >= $min_sdl2_version)
65 if test "$SDL2_CONFIG" = "no" ; then
68 SDL2_CFLAGS=`$SDL2_CONFIG $sdl2_config_args --cflags`
69 SDL2_LIBS=`$SDL2_CONFIG $sdl2_config_args --libs`
71 sdl2_major_version=`$SDL2_CONFIG $sdl2_config_args --version | \
72 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
73 sdl2_minor_version=`$SDL2_CONFIG $sdl2_config_args --version | \
74 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
75 sdl2_micro_version=`$SDL2_CONFIG $sdl2_config_args --version | \
76 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
77 if test "x$enable_sdl2test" = "xyes" ; then
78 ac_save_CFLAGS="$CFLAGS"
79 ac_save_CXXFLAGS="$CXXFLAGS"
81 CFLAGS="$CFLAGS $SDL2_CFLAGS"
82 CXXFLAGS="$CXXFLAGS $SDL2_CFLAGS"
83 LIBS="$LIBS $SDL2_LIBS"
85 dnl Now check if the installed SDL2 is sufficiently new. (Also sanity
86 dnl checks the results of sdl2-config to some extent
89 AC_RUN_IFELSE([AC_LANG_SOURCE([[
102 new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
103 strcpy (new_str, str);
111 int main (int argc, char *argv[])
113 int major, minor, micro;
116 /* This hangs on some systems (?)
117 system ("touch conf.sdl2test");
119 { FILE *fp = fopen("conf.sdl2test", "a"); if ( fp ) fclose(fp); }
121 /* HP/UX 9 writes to sscanf strings */
122 tmp_version = my_strdup("$min_sdl2_version");
123 if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) {
124 printf("%s, bad version string\n", "$min_sdl2_version");
128 if (($sdl2_major_version > major) ||
129 (($sdl2_major_version == major) && ($sdl2_minor_version > minor)) ||
130 (($sdl2_major_version == major) && ($sdl2_minor_version == minor) && ($sdl2_micro_version >= micro)))
136 printf("\n*** 'sdl2-config --version' returned %d.%d.%d, but the minimum version\n", $sdl2_major_version, $sdl2_minor_version, $sdl2_micro_version);
137 printf("*** of SDL2 required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro);
138 printf("*** best to upgrade to the required version.\n");
139 printf("*** If sdl2-config was wrong, set the environment variable SDL2_CONFIG\n");
140 printf("*** to point to the correct copy of sdl2-config, and remove the file\n");
141 printf("*** config.cache before re-running configure\n");
146 ]])], [], [no_sdl2=yes], [echo $ac_n "cross compiling; assumed OK... $ac_c"])
147 CFLAGS="$ac_save_CFLAGS"
148 CXXFLAGS="$ac_save_CXXFLAGS"
152 if test "x$no_sdl" = x ; then
158 if test "x$no_sdl2" = x ; then
159 ifelse([$2], , :, [$2])
161 if test "$SDL2_CONFIG" = "no" ; then
162 echo "*** The sdl2-config script installed by SDL2 could not be found"
163 echo "*** If SDL2 was installed in PREFIX, make sure PREFIX/bin is in"
164 echo "*** your path, or set the SDL2_CONFIG environment variable to the"
165 echo "*** full path to sdl2-config."
167 if test -f conf.sdl2test ; then
170 echo "*** Could not run SDL2 test program, checking why..."
171 CFLAGS="$CFLAGS $SDL2_CFLAGS"
172 CXXFLAGS="$CXXFLAGS $SDL2_CFLAGS"
173 LIBS="$LIBS $SDL2_LIBS"
174 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
178 int main(int argc, char *argv[])
181 #define main K_and_R_C_main
182 ]], [[ return 0; ]])],
183 [ echo "*** The test program compiled, but did not run. This usually means"
184 echo "*** that the run-time linker is not finding SDL2 or finding the wrong"
185 echo "*** version of SDL2. If it is not finding SDL2, you'll need to set your"
186 echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
187 echo "*** to the installed location Also, make sure you have run ldconfig if that"
188 echo "*** is required on your system"
190 echo "*** If you have an old version installed, it is best to remove it, although"
191 echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
192 [ echo "*** The test program failed to compile or link. See the file config.log for the"
193 echo "*** exact error that occurred. This usually means SDL2 was incorrectly installed"
194 echo "*** or that you have moved SDL2 since it was installed. In the latter case, you"
195 echo "*** may want to edit the sdl2-config script: $SDL2_CONFIG" ])
196 CFLAGS="$ac_save_CFLAGS"
197 CXXFLAGS="$ac_save_CXXFLAGS"
203 ifelse([$3], , :, [$3])
205 AC_SUBST(SDL2_CFLAGS)