1 # Configure paths for SDL
3 # stolen from Manish Singh
4 # stolen back from Frank Belew
5 # stolen from Manish Singh
6 # Shamelessly stolen from Owen Taylor
9 # * also look for SDL2.framework under Mac OS X
13 dnl AM_PATH_SDL2([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
14 dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
16 AC_DEFUN([AM_PATH_SDL2],
18 dnl Get the cflags and libraries from the sdl2-config script
20 AC_ARG_WITH(sdl-prefix,[ --with-sdl-prefix=PFX Prefix where SDL is installed (optional)],
21 sdl_prefix="$withval", sdl_prefix="")
22 AC_ARG_WITH(sdl-exec-prefix,[ --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)],
23 sdl_exec_prefix="$withval", sdl_exec_prefix="")
24 AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run a test SDL program],
26 AC_ARG_ENABLE(sdlframework, [ --disable-sdlframework Do not search for SDL2.framework],
27 , search_sdl_framework=yes)
29 AC_ARG_VAR(SDL2_FRAMEWORK, [Path to SDL2.framework])
31 min_sdl_version=ifelse([$1], ,2.0.0,$1)
33 if test "x$sdl_prefix$sdl_exec_prefix" = x ; then
34 PKG_CHECK_MODULES([SDL], [sdl2 >= $min_sdl_version],
39 if test x$sdl_exec_prefix != x ; then
40 sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix"
41 if test x${SDL2_CONFIG+set} != xset ; then
42 SDL2_CONFIG=$sdl_exec_prefix/bin/sdl2-config
45 if test x$sdl_prefix != x ; then
46 sdl_config_args="$sdl_config_args --prefix=$sdl_prefix"
47 if test x${SDL2_CONFIG+set} != xset ; then
48 SDL2_CONFIG=$sdl_prefix/bin/sdl2-config
53 if test "x$sdl_pc" = xyes ; then
55 SDL2_CONFIG="pkg-config sdl2"
58 if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then
59 PATH="$prefix/bin:$prefix/usr/bin:$PATH"
61 AC_PATH_PROG(SDL2_CONFIG, sdl2-config, no, [$PATH])
65 if test "$SDL2_CONFIG" = "no" -a "x$search_sdl_framework" = "xyes"; then
66 AC_MSG_CHECKING(for SDL2.framework)
67 if test "x$SDL2_FRAMEWORK" != x; then
68 sdl_framework=$SDL2_FRAMEWORK
70 for d in / ~/ /System/; do
71 if test -d "$dLibrary/Frameworks/SDL2.framework"; then
72 sdl_framework="$dLibrary/Frameworks/SDL2.framework"
77 if test -d $sdl_framework; then
78 AC_MSG_RESULT($sdl_framework)
79 sdl_framework_dir=`dirname $sdl_framework`
80 SDL_CFLAGS="-F$sdl_framework_dir -Wl,-framework,SDL2 -I$sdl_framework/include"
81 SDL_LIBS="-F$sdl_framework_dir -Wl,-framework,SDL2"
87 if test "$SDL2_CONFIG" != "no"; then
88 if test "x$sdl_pc" = "xno"; then
89 AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
90 SDL_CFLAGS=`$SDL2_CONFIG $sdl_config_args --cflags`
91 SDL_LIBS=`$SDL2_CONFIG $sdl_config_args --libs`
94 sdl_major_version=`$SDL2_CONFIG $sdl_config_args --version | \
95 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
96 sdl_minor_version=`$SDL2_CONFIG $sdl_config_args --version | \
97 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
98 sdl_micro_version=`$SDL2_CONFIG $sdl_config_args --version | \
99 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
100 if test "x$enable_sdltest" = "xyes" ; then
101 ac_save_CFLAGS="$CFLAGS"
102 ac_save_CXXFLAGS="$CXXFLAGS"
104 CFLAGS="$CFLAGS $SDL_CFLAGS"
105 CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
106 LIBS="$LIBS $SDL_LIBS"
108 dnl Now check if the installed SDL is sufficiently new. (Also sanity
109 dnl checks the results of sdl2-config to some extent
119 my_strdup (char *str)
125 new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
126 strcpy (new_str, str);
134 int main (int argc, char *argv[])
136 int major, minor, micro;
139 /* This hangs on some systems (?)
140 system ("touch conf.sdltest");
142 { FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); }
144 /* HP/UX 9 (%@#!) writes to sscanf strings */
145 tmp_version = my_strdup("$min_sdl_version");
146 if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) {
147 printf("%s, bad version string\n", "$min_sdl_version");
151 if (($sdl_major_version > major) ||
152 (($sdl_major_version == major) && ($sdl_minor_version > minor)) ||
153 (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro)))
159 printf("\n*** 'sdl2-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
160 printf("*** of SDL required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro);
161 printf("*** best to upgrade to the required version.\n");
162 printf("*** If sdl2-config was wrong, set the environment variable SDL2_CONFIG\n");
163 printf("*** to point to the correct copy of sdl2-config, and remove the file\n");
164 printf("*** config.cache before re-running configure\n");
169 ],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
170 CFLAGS="$ac_save_CFLAGS"
171 CXXFLAGS="$ac_save_CXXFLAGS"
175 if test "x$sdl_pc" = "xno"; then
176 if test "x$no_sdl" = "xyes"; then
184 if test "x$no_sdl" = x ; then
185 ifelse([$2], , :, [$2])
187 if test "$SDL2_CONFIG" = "no" ; then
188 echo "*** The sdl2-config script installed by SDL could not be found"
189 echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
190 echo "*** your path, or set the SDL2_CONFIG environment variable to the"
191 echo "*** full path to sdl2-config."
193 if test -f conf.sdltest ; then
196 echo "*** Could not run SDL test program, checking why..."
197 CFLAGS="$CFLAGS $SDL_CFLAGS"
198 CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
199 LIBS="$LIBS $SDL_LIBS"
204 int main(int argc, char *argv[])
207 #define main K_and_R_C_main
209 [ echo "*** The test program compiled, but did not run. This usually means"
210 echo "*** that the run-time linker is not finding SDL or finding the wrong"
211 echo "*** version of SDL. If it is not finding SDL, you'll need to set your"
212 echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
213 echo "*** to the installed location Also, make sure you have run ldconfig if that"
214 echo "*** is required on your system"
216 echo "*** If you have an old version installed, it is best to remove it, although"
217 echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
218 [ echo "*** The test program failed to compile or link. See the file config.log for the"
219 echo "*** exact error that occured. This usually means SDL was incorrectly installed"
220 echo "*** or that you have moved SDL since it was installed. In the latter case, you"
221 echo "*** may want to edit the sdl2-config script: $SDL2_CONFIG" ])
222 CFLAGS="$ac_save_CFLAGS"
223 CXXFLAGS="$ac_save_CXXFLAGS"
229 ifelse([$3], , :, [$3])