]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/builddeps/win32/sdl/share/aclocal/sdl2.m4
Revert "Update Windows 32 bit SDL build dependency to 2.0.10"
[xonotic/xonotic.git] / misc / builddeps / win32 / sdl / share / aclocal / sdl2.m4
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 #
8 # Changelog:
9 # * also look for SDL2.framework under Mac OS X
10
11 # serial 1
12
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
15 dnl
16 AC_DEFUN([AM_PATH_SDL2],
17 [dnl 
18 dnl Get the cflags and libraries from the sdl2-config script
19 dnl
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],
25                     , enable_sdltest=yes)
26 AC_ARG_ENABLE(sdlframework, [  --disable-sdlframework Do not search for SDL2.framework],
27         , search_sdl_framework=yes)
28
29 AC_ARG_VAR(SDL2_FRAMEWORK, [Path to SDL2.framework])
30
31   min_sdl_version=ifelse([$1], ,2.0.0,$1)
32
33   if test "x$sdl_prefix$sdl_exec_prefix" = x ; then
34     PKG_CHECK_MODULES([SDL], [sdl2 >= $min_sdl_version],
35            [sdl_pc=yes],
36            [sdl_pc=no])
37   else
38     sdl_pc=no
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
43       fi
44     fi
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
49       fi
50     fi
51   fi
52
53   if test "x$sdl_pc" = xyes ; then
54     no_sdl=""
55     SDL2_CONFIG="pkg-config sdl2"
56   else
57     as_save_PATH="$PATH"
58     if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then
59       PATH="$prefix/bin:$prefix/usr/bin:$PATH"
60     fi
61     AC_PATH_PROG(SDL2_CONFIG, sdl2-config, no, [$PATH])
62     PATH="$as_save_PATH"
63     no_sdl=""
64
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
69       else
70         for d in / ~/ /System/; do
71           if test -d "$dLibrary/Frameworks/SDL2.framework"; then
72             sdl_framework="$dLibrary/Frameworks/SDL2.framework"
73           fi
74         done
75       fi
76
77       if test x"$sdl_framework" != x && 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"
82       else
83         no_sdl=yes
84       fi
85     fi
86
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`
92       fi
93
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"
103         ac_save_LIBS="$LIBS"
104         CFLAGS="$CFLAGS $SDL_CFLAGS"
105         CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
106         LIBS="$LIBS $SDL_LIBS"
107 dnl
108 dnl Now check if the installed SDL is sufficiently new. (Also sanity
109 dnl checks the results of sdl2-config to some extent
110 dnl
111       rm -f conf.sdltest
112       AC_TRY_RUN([
113 #include <stdio.h>
114 #include <stdlib.h>
115 #include <string.h>
116 #include "SDL.h"
117
118 char*
119 my_strdup (char *str)
120 {
121   char *new_str;
122   
123   if (str)
124     {
125       new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
126       strcpy (new_str, str);
127     }
128   else
129     new_str = NULL;
130   
131   return new_str;
132 }
133
134 int main (int argc, char *argv[])
135 {
136   int major, minor, micro;
137   char *tmp_version;
138
139   /* This hangs on some systems (?)
140   system ("touch conf.sdltest");
141   */
142   { FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); }
143
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, &micro) != 3) {
147      printf("%s, bad version string\n", "$min_sdl_version");
148      exit(1);
149    }
150
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)))
154     {
155       return 0;
156     }
157   else
158     {
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");
165       return 1;
166     }
167 }
168
169 ],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
170         CFLAGS="$ac_save_CFLAGS"
171         CXXFLAGS="$ac_save_CXXFLAGS"
172         LIBS="$ac_save_LIBS"
173
174       fi
175       if test "x$sdl_pc" = "xno"; then
176         if test "x$no_sdl" = "xyes"; then
177           AC_MSG_RESULT(no)
178         else
179           AC_MSG_RESULT(yes)
180         fi
181       fi
182     fi
183   fi
184   if test "x$no_sdl" = x ; then
185      ifelse([$2], , :, [$2])
186   else
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."
192      else
193        if test -f conf.sdltest ; then
194         :
195        else
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"
200           AC_TRY_LINK([
201 #include <stdio.h>
202 #include "SDL.h"
203
204 int main(int argc, char *argv[])
205 { return 0; }
206 #undef  main
207 #define main K_and_R_C_main
208 ],      [ return 0; ],
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"
215           echo "***"
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"
224           LIBS="$ac_save_LIBS"
225        fi
226      fi
227      SDL_CFLAGS=""
228      SDL_LIBS=""
229      ifelse([$3], , :, [$3])
230   fi
231   AC_SUBST(SDL_CFLAGS)
232   AC_SUBST(SDL_LIBS)
233   rm -f conf.sdltest
234 ])