slouken@0
|
1 |
# Configure paths for SDL
|
slouken@0
|
2 |
# Sam Lantinga 9/21/99
|
slouken@0
|
3 |
# stolen from Manish Singh
|
slouken@0
|
4 |
# stolen back from Frank Belew
|
slouken@0
|
5 |
# stolen from Manish Singh
|
slouken@0
|
6 |
# Shamelessly stolen from Owen Taylor
|
slouken@10382
|
7 |
#
|
slouken@10382
|
8 |
# Changelog:
|
slouken@10382
|
9 |
# * also look for SDL2.framework under Mac OS X
|
slouken@0
|
10 |
|
slouken@4441
|
11 |
# serial 1
|
slouken@4441
|
12 |
|
slouken@6890
|
13 |
dnl AM_PATH_SDL2([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
|
slouken@0
|
14 |
dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
|
slouken@0
|
15 |
dnl
|
slouken@6272
|
16 |
AC_DEFUN([AM_PATH_SDL2],
|
slouken@0
|
17 |
[dnl
|
slouken@6250
|
18 |
dnl Get the cflags and libraries from the sdl2-config script
|
slouken@0
|
19 |
dnl
|
slouken@0
|
20 |
AC_ARG_WITH(sdl-prefix,[ --with-sdl-prefix=PFX Prefix where SDL is installed (optional)],
|
slouken@0
|
21 |
sdl_prefix="$withval", sdl_prefix="")
|
slouken@0
|
22 |
AC_ARG_WITH(sdl-exec-prefix,[ --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)],
|
slouken@0
|
23 |
sdl_exec_prefix="$withval", sdl_exec_prefix="")
|
slouken@0
|
24 |
AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run a test SDL program],
|
slouken@0
|
25 |
, enable_sdltest=yes)
|
slouken@10382
|
26 |
AC_ARG_ENABLE(sdlframework, [ --disable-sdlframework Do not search for SDL2.framework],
|
slouken@10382
|
27 |
, search_sdl_framework=yes)
|
slouken@10382
|
28 |
|
slouken@10382
|
29 |
AC_ARG_VAR(SDL2_FRAMEWORK, [Path to SDL2.framework])
|
slouken@0
|
30 |
|
slouken@7251
|
31 |
min_sdl_version=ifelse([$1], ,2.0.0,$1)
|
slouken@3340
|
32 |
|
slouken@3340
|
33 |
if test "x$sdl_prefix$sdl_exec_prefix" = x ; then
|
slouken@6250
|
34 |
PKG_CHECK_MODULES([SDL], [sdl2 >= $min_sdl_version],
|
slouken@3340
|
35 |
[sdl_pc=yes],
|
slouken@6250
|
36 |
[sdl_pc=no])
|
slouken@3340
|
37 |
else
|
slouken@3340
|
38 |
sdl_pc=no
|
slouken@3340
|
39 |
if test x$sdl_exec_prefix != x ; then
|
slouken@3340
|
40 |
sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix"
|
slouken@7492
|
41 |
if test x${SDL2_CONFIG+set} != xset ; then
|
slouken@7492
|
42 |
SDL2_CONFIG=$sdl_exec_prefix/bin/sdl2-config
|
slouken@3340
|
43 |
fi
|
slouken@1755
|
44 |
fi
|
slouken@3340
|
45 |
if test x$sdl_prefix != x ; then
|
slouken@3340
|
46 |
sdl_config_args="$sdl_config_args --prefix=$sdl_prefix"
|
slouken@7492
|
47 |
if test x${SDL2_CONFIG+set} != xset ; then
|
slouken@7492
|
48 |
SDL2_CONFIG=$sdl_prefix/bin/sdl2-config
|
slouken@3340
|
49 |
fi
|
slouken@1755
|
50 |
fi
|
slouken@0
|
51 |
fi
|
slouken@0
|
52 |
|
slouken@3340
|
53 |
if test "x$sdl_pc" = xyes ; then
|
slouken@3340
|
54 |
no_sdl=""
|
slouken@7492
|
55 |
SDL2_CONFIG="pkg-config sdl2"
|
slouken@0
|
56 |
else
|
slouken@3340
|
57 |
as_save_PATH="$PATH"
|
slouken@3340
|
58 |
if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then
|
slouken@3340
|
59 |
PATH="$prefix/bin:$prefix/usr/bin:$PATH"
|
slouken@3340
|
60 |
fi
|
slouken@7492
|
61 |
AC_PATH_PROG(SDL2_CONFIG, sdl2-config, no, [$PATH])
|
slouken@3340
|
62 |
PATH="$as_save_PATH"
|
slouken@3340
|
63 |
no_sdl=""
|
slouken@0
|
64 |
|
slouken@10382
|
65 |
if test "$SDL2_CONFIG" = "no" -a "x$search_sdl_framework" = "xyes"; then
|
slouken@10382
|
66 |
AC_MSG_CHECKING(for SDL2.framework)
|
slouken@10382
|
67 |
if test "x$SDL2_FRAMEWORK" != x; then
|
slouken@10382
|
68 |
sdl_framework=$SDL2_FRAMEWORK
|
slouken@10382
|
69 |
else
|
slouken@10382
|
70 |
for d in / ~/ /System/; do
|
slouken@10382
|
71 |
if test -d "$dLibrary/Frameworks/SDL2.framework"; then
|
slouken@10382
|
72 |
sdl_framework="$dLibrary/Frameworks/SDL2.framework"
|
slouken@10382
|
73 |
fi
|
slouken@10382
|
74 |
done
|
slouken@10382
|
75 |
fi
|
slouken@10382
|
76 |
|
slouken@10382
|
77 |
if test -d $sdl_framework; then
|
slouken@10382
|
78 |
AC_MSG_RESULT($sdl_framework)
|
slouken@10382
|
79 |
sdl_framework_dir=`dirname $sdl_framework`
|
slouken@10382
|
80 |
SDL_CFLAGS="-F$sdl_framework_dir -Wl,-framework,SDL2 -I$sdl_framework/include"
|
slouken@10382
|
81 |
SDL_LIBS="-F$sdl_framework_dir -Wl,-framework,SDL2"
|
slouken@10382
|
82 |
else
|
slouken@10382
|
83 |
no_sdl=yes
|
slouken@10382
|
84 |
fi
|
slouken@10382
|
85 |
fi
|
slouken@10382
|
86 |
|
slouken@10382
|
87 |
if test "$SDL2_CONFIG" != "no"; then
|
slouken@10382
|
88 |
if test "x$sdl_pc" = "xno"; then
|
slouken@10382
|
89 |
AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
|
slouken@10382
|
90 |
SDL_CFLAGS=`$SDL2_CONFIG $sdl_config_args --cflags`
|
slouken@10382
|
91 |
SDL_LIBS=`$SDL2_CONFIG $sdl_config_args --libs`
|
slouken@10382
|
92 |
fi
|
slouken@3340
|
93 |
|
slouken@7492
|
94 |
sdl_major_version=`$SDL2_CONFIG $sdl_config_args --version | \
|
slouken@3340
|
95 |
sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
|
slouken@7492
|
96 |
sdl_minor_version=`$SDL2_CONFIG $sdl_config_args --version | \
|
slouken@3340
|
97 |
sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
|
slouken@7492
|
98 |
sdl_micro_version=`$SDL2_CONFIG $sdl_config_args --version | \
|
slouken@3340
|
99 |
sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
|
slouken@3340
|
100 |
if test "x$enable_sdltest" = "xyes" ; then
|
slouken@3340
|
101 |
ac_save_CFLAGS="$CFLAGS"
|
slouken@3340
|
102 |
ac_save_CXXFLAGS="$CXXFLAGS"
|
slouken@3340
|
103 |
ac_save_LIBS="$LIBS"
|
slouken@3340
|
104 |
CFLAGS="$CFLAGS $SDL_CFLAGS"
|
slouken@3340
|
105 |
CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
|
slouken@3340
|
106 |
LIBS="$LIBS $SDL_LIBS"
|
slouken@0
|
107 |
dnl
|
slouken@0
|
108 |
dnl Now check if the installed SDL is sufficiently new. (Also sanity
|
slouken@6250
|
109 |
dnl checks the results of sdl2-config to some extent
|
slouken@0
|
110 |
dnl
|
slouken@0
|
111 |
rm -f conf.sdltest
|
slouken@0
|
112 |
AC_TRY_RUN([
|
slouken@0
|
113 |
#include <stdio.h>
|
slouken@0
|
114 |
#include <stdlib.h>
|
slouken@0
|
115 |
#include <string.h>
|
slouken@0
|
116 |
#include "SDL.h"
|
slouken@0
|
117 |
|
slouken@0
|
118 |
char*
|
slouken@0
|
119 |
my_strdup (char *str)
|
slouken@0
|
120 |
{
|
slouken@0
|
121 |
char *new_str;
|
slouken@0
|
122 |
|
slouken@0
|
123 |
if (str)
|
slouken@0
|
124 |
{
|
slouken@0
|
125 |
new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
|
slouken@0
|
126 |
strcpy (new_str, str);
|
slouken@0
|
127 |
}
|
slouken@0
|
128 |
else
|
slouken@0
|
129 |
new_str = NULL;
|
slouken@0
|
130 |
|
slouken@0
|
131 |
return new_str;
|
slouken@0
|
132 |
}
|
slouken@0
|
133 |
|
slouken@0
|
134 |
int main (int argc, char *argv[])
|
slouken@0
|
135 |
{
|
slouken@0
|
136 |
int major, minor, micro;
|
slouken@0
|
137 |
char *tmp_version;
|
slouken@0
|
138 |
|
slouken@0
|
139 |
/* This hangs on some systems (?)
|
slouken@0
|
140 |
system ("touch conf.sdltest");
|
slouken@0
|
141 |
*/
|
slouken@0
|
142 |
{ FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); }
|
slouken@0
|
143 |
|
slouken@0
|
144 |
/* HP/UX 9 (%@#!) writes to sscanf strings */
|
slouken@0
|
145 |
tmp_version = my_strdup("$min_sdl_version");
|
slouken@0
|
146 |
if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) {
|
slouken@0
|
147 |
printf("%s, bad version string\n", "$min_sdl_version");
|
slouken@0
|
148 |
exit(1);
|
slouken@0
|
149 |
}
|
slouken@0
|
150 |
|
slouken@0
|
151 |
if (($sdl_major_version > major) ||
|
slouken@0
|
152 |
(($sdl_major_version == major) && ($sdl_minor_version > minor)) ||
|
slouken@0
|
153 |
(($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro)))
|
slouken@0
|
154 |
{
|
slouken@0
|
155 |
return 0;
|
slouken@0
|
156 |
}
|
slouken@0
|
157 |
else
|
slouken@0
|
158 |
{
|
slouken@6250
|
159 |
printf("\n*** 'sdl2-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
|
slouken@6250
|
160 |
printf("*** of SDL required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro);
|
slouken@0
|
161 |
printf("*** best to upgrade to the required version.\n");
|
slouken@7492
|
162 |
printf("*** If sdl2-config was wrong, set the environment variable SDL2_CONFIG\n");
|
slouken@6250
|
163 |
printf("*** to point to the correct copy of sdl2-config, and remove the file\n");
|
slouken@0
|
164 |
printf("*** config.cache before re-running configure\n");
|
slouken@0
|
165 |
return 1;
|
slouken@0
|
166 |
}
|
slouken@0
|
167 |
}
|
slouken@0
|
168 |
|
slouken@0
|
169 |
],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
|
slouken@3340
|
170 |
CFLAGS="$ac_save_CFLAGS"
|
slouken@3340
|
171 |
CXXFLAGS="$ac_save_CXXFLAGS"
|
slouken@3340
|
172 |
LIBS="$ac_save_LIBS"
|
slouken@10382
|
173 |
|
slouken@3340
|
174 |
fi
|
slouken@10382
|
175 |
if test "x$sdl_pc" = "xno"; then
|
slouken@10382
|
176 |
if test "x$no_sdl" = "xyes"; then
|
slouken@10382
|
177 |
AC_MSG_RESULT(no)
|
slouken@10382
|
178 |
else
|
slouken@10382
|
179 |
AC_MSG_RESULT(yes)
|
slouken@10382
|
180 |
fi
|
slouken@10382
|
181 |
fi
|
slouken@3340
|
182 |
fi
|
slouken@0
|
183 |
fi
|
slouken@0
|
184 |
if test "x$no_sdl" = x ; then
|
slouken@3340
|
185 |
ifelse([$2], , :, [$2])
|
slouken@0
|
186 |
else
|
slouken@7492
|
187 |
if test "$SDL2_CONFIG" = "no" ; then
|
slouken@6250
|
188 |
echo "*** The sdl2-config script installed by SDL could not be found"
|
slouken@0
|
189 |
echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
|
slouken@7492
|
190 |
echo "*** your path, or set the SDL2_CONFIG environment variable to the"
|
slouken@6250
|
191 |
echo "*** full path to sdl2-config."
|
slouken@0
|
192 |
else
|
slouken@0
|
193 |
if test -f conf.sdltest ; then
|
slouken@0
|
194 |
:
|
slouken@0
|
195 |
else
|
slouken@0
|
196 |
echo "*** Could not run SDL test program, checking why..."
|
slouken@0
|
197 |
CFLAGS="$CFLAGS $SDL_CFLAGS"
|
icculus@1118
|
198 |
CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
|
slouken@0
|
199 |
LIBS="$LIBS $SDL_LIBS"
|
slouken@0
|
200 |
AC_TRY_LINK([
|
slouken@0
|
201 |
#include <stdio.h>
|
slouken@0
|
202 |
#include "SDL.h"
|
slouken@1
|
203 |
|
slouken@1
|
204 |
int main(int argc, char *argv[])
|
slouken@1
|
205 |
{ return 0; }
|
slouken@1
|
206 |
#undef main
|
slouken@1
|
207 |
#define main K_and_R_C_main
|
slouken@0
|
208 |
], [ return 0; ],
|
slouken@0
|
209 |
[ echo "*** The test program compiled, but did not run. This usually means"
|
slouken@0
|
210 |
echo "*** that the run-time linker is not finding SDL or finding the wrong"
|
slouken@0
|
211 |
echo "*** version of SDL. If it is not finding SDL, you'll need to set your"
|
slouken@0
|
212 |
echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
|
slouken@0
|
213 |
echo "*** to the installed location Also, make sure you have run ldconfig if that"
|
slouken@0
|
214 |
echo "*** is required on your system"
|
slouken@0
|
215 |
echo "***"
|
slouken@0
|
216 |
echo "*** If you have an old version installed, it is best to remove it, although"
|
slouken@0
|
217 |
echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
|
slouken@0
|
218 |
[ echo "*** The test program failed to compile or link. See the file config.log for the"
|
slouken@0
|
219 |
echo "*** exact error that occured. This usually means SDL was incorrectly installed"
|
slouken@0
|
220 |
echo "*** or that you have moved SDL since it was installed. In the latter case, you"
|
slouken@7492
|
221 |
echo "*** may want to edit the sdl2-config script: $SDL2_CONFIG" ])
|
slouken@0
|
222 |
CFLAGS="$ac_save_CFLAGS"
|
icculus@1118
|
223 |
CXXFLAGS="$ac_save_CXXFLAGS"
|
slouken@0
|
224 |
LIBS="$ac_save_LIBS"
|
slouken@0
|
225 |
fi
|
slouken@0
|
226 |
fi
|
slouken@0
|
227 |
SDL_CFLAGS=""
|
slouken@0
|
228 |
SDL_LIBS=""
|
slouken@0
|
229 |
ifelse([$3], , :, [$3])
|
slouken@0
|
230 |
fi
|
slouken@0
|
231 |
AC_SUBST(SDL_CFLAGS)
|
slouken@0
|
232 |
AC_SUBST(SDL_LIBS)
|
slouken@0
|
233 |
rm -f conf.sdltest
|
slouken@0
|
234 |
])
|