Add masks to all channels in SDL_CreateRGBSurface calls
[sdl_tbmf.git] / acinclude.m4
blob7f0b7471525a3a07c8037dd58414a2c6e4f9a6d6
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)
6         save_CFLAGS="$CFLAGS"
7         CFLAGS="$CFLAGS $1"
8         AC_LANG_SAVE
9         AC_LANG_C
10         AC_TRY_COMPILE([#include <stdio.h>], [printf("hello");],
11                 [AC_MSG_RESULT(yes)],dnl
12                 [AC_MSG_RESULT(no)
13                 CFLAGS="$save_CFLAGS"
14         ])
15         AC_LANG_RESTORE
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"
23         AC_LANG_SAVE
24         AC_LANG_CPLUSPLUS
25         AC_TRY_COMPILE([#include <iostream.h>], [cout << "hello";],
26                 [AC_MSG_RESULT(yes)],dnl
27                 [AC_MSG_RESULT(no)
28                 CXXFLAGS="$save_CXXFLAGS"
29         ])
30         AC_LANG_RESTORE
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, [
35         MY_CHECK_CFLAG($1)
36         MY_CHECK_CXXFLAG($1)
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
49 dnl
50 AC_DEFUN(AM_PATH_SDL,
51 [dnl 
52 dnl Get the cflags and libraries from the sdl-config script
53 dnl
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],
59                     , enable_sdltest=yes)
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
65      fi
66   fi
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
71      fi
72   fi
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)
78   no_sdl=""
79   if test "$SDL_CONFIG" = "no" ; then
80     no_sdl=yes
81   else
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"
93       ac_save_LIBS="$LIBS"
94       CFLAGS="$CFLAGS $SDL_CFLAGS"
95       LIBS="$LIBS $SDL_LIBS"
96 dnl
97 dnl Now check if the installed SDL is sufficiently new. (Also sanity
98 dnl checks the results of sdl-config to some extent
99 dnl
100       rm -f conf.sdltest
101       AC_TRY_RUN([
102 #include <stdio.h>
103 #include <stdlib.h>
104 #include <string.h>
105 #include "SDL.h"
107 char*
108 my_strdup (char *str)
110   char *new_str;
111   
112   if (str)
113     {
114       new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
115       strcpy (new_str, str);
116     }
117   else
118     new_str = NULL;
119   
120   return new_str;
123 int main (int argc, char *argv[])
125   int major, minor, micro;
126   char *tmp_version;
128   /* This hangs on some systems (?)
129   system ("touch conf.sdltest");
130   */
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, &micro) != 3) {
136      printf("%s, bad version string\n", "$min_sdl_version");
137      exit(1);
138    }
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)))
143     {
144       return 0;
145     }
146   else
147     {
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");
154       return 1;
155     }
158 ],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
159        CFLAGS="$ac_save_CFLAGS"
160        LIBS="$ac_save_LIBS"
161      fi
162   fi
163   if test "x$no_sdl" = x ; then
164      AC_MSG_RESULT(yes)
165      ifelse([$2], , :, [$2])     
166   else
167      AC_MSG_RESULT(no)
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."
173      else
174        if test -f conf.sdltest ; then
175         :
176        else
177           echo "*** Could not run SDL test program, checking why..."
178           CFLAGS="$CFLAGS $SDL_CFLAGS"
179           LIBS="$LIBS $SDL_LIBS"
180           AC_TRY_LINK([
181 #include <stdio.h>
182 #include "SDL.h"
184 int main(int argc, char *argv[])
185 { return 0; }
186 #undef  main
187 #define main K_and_R_C_main
188 ],      [ return 0; ],
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"
195           echo "***"
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"
203           LIBS="$ac_save_LIBS"
204        fi
205      fi
206      SDL_CFLAGS=""
207      SDL_LIBS=""
208      ifelse([$3], , :, [$3])
209   fi
210   AC_SUBST(SDL_CFLAGS)
211   AC_SUBST(SDL_LIBS)
212   rm -f conf.sdltest