1 dnl CHECK_CFLAG taken from dia http://www.lysator.liu.se/~alla/dia/
3 dnl Check if the C compiler accepts a certain C flag, and if so adds it to CFLAGS
4 AC_DEFUN(MY_CHECK_CFLAG, [
5 AC_MSG_CHECKING(if C compiler accepts $1)
10 AC_TRY_COMPILE([#include <stdio.h>], [printf("hello");],
11 [AC_MSG_RESULT(yes)],dnl
18 dnl Check if the C++ compiler accepts a certain flag, and if so adds it to CXXFLAGS
19 AC_DEFUN(MY_CHECK_CXXFLAG, [
20 AC_MSG_CHECKING(if C++ compiler accepts $1)
21 save_CXXFLAGS="$CXXFLAGS"
22 CXXFLAGS="$CXXFLAGS $1"
25 AC_TRY_COMPILE([#include <iostream.h>], [cout << "hello";],
26 [AC_MSG_RESULT(yes)],dnl
28 CXXFLAGS="$save_CXXFLAGS"
33 dnl Check if the C and the C++ compilers accept a certain flag, and if so add it to flags.
34 AC_DEFUN(MY_CHECK_BOTH_FLAG, [
40 # Configure paths for SDL
41 # Sam Lantinga 9/21/99
42 # stolen from Manish Singh
43 # stolen back from Frank Belew
44 # stolen from Manish Singh
45 # Shamelessly stolen from Owen Taylor
47 dnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
48 dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
52 dnl Get the cflags and libraries from the sdl-config script
54 AC_ARG_WITH(sdl-prefix,[ --with-sdl-prefix=PFX Prefix where SDL is installed (optional)],
55 sdl_prefix="$withval", sdl_prefix="")
56 AC_ARG_WITH(sdl-exec-prefix,[ --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)],
57 sdl_exec_prefix="$withval", sdl_exec_prefix="")
58 AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run a test SDL program],
61 if test x$sdl_exec_prefix != x ; then
62 sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix"
63 if test x${SDL_CONFIG+set} != xset ; then
64 SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config
67 if test x$sdl_prefix != x ; then
68 sdl_args="$sdl_args --prefix=$sdl_prefix"
69 if test x${SDL_CONFIG+set} != xset ; then
70 SDL_CONFIG=$sdl_prefix/bin/sdl-config
74 AC_REQUIRE([AC_CANONICAL_TARGET])
75 AC_PATH_PROG(SDL_CONFIG, sdl-config, no)
76 min_sdl_version=ifelse([$1], ,0.11.0,$1)
77 AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
79 if test "$SDL_CONFIG" = "no" ; then
82 SDL_CFLAGS=`$SDL_CONFIG $sdlconf_args --cflags`
83 SDL_LIBS=`$SDL_CONFIG $sdlconf_args --libs`
85 sdl_major_version=`$SDL_CONFIG $sdl_args --version | \
86 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
87 sdl_minor_version=`$SDL_CONFIG $sdl_args --version | \
88 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
89 sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \
90 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
91 if test "x$enable_sdltest" = "xyes" ; then
92 ac_save_CFLAGS="$CFLAGS"
94 CFLAGS="$CFLAGS $SDL_CFLAGS"
95 LIBS="$LIBS $SDL_LIBS"
97 dnl Now check if the installed SDL is sufficiently new. (Also sanity
98 dnl checks the results of sdl-config to some extent
108 my_strdup (char *str)
114 new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
115 strcpy (new_str, str);
123 int main (int argc, char *argv[])
125 int major, minor, micro;
128 /* This hangs on some systems (?)
129 system ("touch conf.sdltest");
131 { FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); }
133 /* HP/UX 9 (%@#!) writes to sscanf strings */
134 tmp_version = my_strdup("$min_sdl_version");
135 if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) {
136 printf("%s, bad version string\n", "$min_sdl_version");
140 if (($sdl_major_version > major) ||
141 (($sdl_major_version == major) && ($sdl_minor_version > minor)) ||
142 (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro)))
148 printf("\n*** 'sdl-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
149 printf("*** of SDL required is %d.%d.%d. If sdl-config is correct, then it is\n", major, minor, micro);
150 printf("*** best to upgrade to the required version.\n");
151 printf("*** If sdl-config was wrong, set the environment variable SDL_CONFIG\n");
152 printf("*** to point to the correct copy of sdl-config, and remove the file\n");
153 printf("*** config.cache before re-running configure\n");
158 ],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
159 CFLAGS="$ac_save_CFLAGS"
163 if test "x$no_sdl" = x ; then
165 ifelse([$2], , :, [$2])
168 if test "$SDL_CONFIG" = "no" ; then
169 echo "*** The sdl-config script installed by SDL could not be found"
170 echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
171 echo "*** your path, or set the SDL_CONFIG environment variable to the"
172 echo "*** full path to sdl-config."
174 if test -f conf.sdltest ; then
177 echo "*** Could not run SDL test program, checking why..."
178 CFLAGS="$CFLAGS $SDL_CFLAGS"
179 LIBS="$LIBS $SDL_LIBS"
184 int main(int argc, char *argv[])
187 #define main K_and_R_C_main
189 [ echo "*** The test program compiled, but did not run. This usually means"
190 echo "*** that the run-time linker is not finding SDL or finding the wrong"
191 echo "*** version of SDL. If it is not finding SDL, you'll need to set your"
192 echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
193 echo "*** to the installed location Also, make sure you have run ldconfig if that"
194 echo "*** is required on your system"
196 echo "*** If you have an old version installed, it is best to remove it, although"
197 echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
198 [ echo "*** The test program failed to compile or link. See the file config.log for the"
199 echo "*** exact error that occured. This usually means SDL was incorrectly installed"
200 echo "*** or that you have moved SDL since it was installed. In the latter case, you"
201 echo "*** may want to edit the sdl-config script: $SDL_CONFIG" ])
202 CFLAGS="$ac_save_CFLAGS"
208 ifelse([$3], , :, [$3])