Allow using things that were deprecated in gtk+-3.22.
[freeciv.git] / m4 / sdl2.m4
blobc10cbbae06984c72e6ae544c1fe6e847b3ed6935
1 # Configure paths for SDL2
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 # Taken to Freeciv from SDL release 2.0.0 - modified to work together with sdl1.2
9 # serial 1.0.1
11 dnl AM_PATH_SDL2([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
12 dnl Test for SDL, and define SDL2_CFLAGS and SDL2_LIBS
13 dnl
14 AC_DEFUN([AM_PATH_SDL2],
15 [dnl 
16 dnl Get the cflags and libraries from the sdl2-config script
17 dnl
18 AC_ARG_WITH([sdl2-prefix],
19   AS_HELP_STRING([--with-sdl2-prefix=PFX], [Prefix where SDL2 is installed (optional)]),
20 [sdl2_prefix="$withval"], [sdl2_prefix=""])
22 AC_ARG_WITH([sdl2-exec-prefix],
23   AS_HELP_STRING([--with-sdl2-exec-prefix=PFX], [Exec prefix where SDL2 is installed (optional)]),
24 [sdl2_exec_prefix="$withval"], [sdl2_exec_prefix=""])
26 AC_ARG_ENABLE([sdl2test],
27   AS_HELP_STRING([--disable-sdl2test], [Do not try to compile and run a test SDL2 program]),
28 [], [enable_sdl2test=yes])
30   min_sdl2_version=ifelse([$1], ,2.0.0,$1)
32   if test "x$sdl2_prefix$sdl2_exec_prefix" = x ; then
33     PKG_CHECK_MODULES([SDL2], [sdl2 >= $min_sdl2_version],
34            [sdl2_pc=yes],
35            [sdl2_pc=no])
36   else
37     sdl2_pc=no
38     if test x$sdl2_exec_prefix != x ; then
39       sdl2_config_args="$sdl2_config_args --exec-prefix=$sdl2_exec_prefix"
40       if test x${SDL2_CONFIG+set} != xset ; then
41         SDL2_CONFIG=$sdl2_exec_prefix/bin/sdl2-config
42       fi
43     fi
44     if test x$sdl2_prefix != x ; then
45       sdl2_config_args="$sdl2_config_args --prefix=$sdl2_prefix"
46       if test x${SDL2_CONFIG+set} != xset ; then
47         SDL2_CONFIG=$sdl2_prefix/bin/sdl2-config
48       fi
49     fi
50   fi
52   if test "x$sdl2_pc" = xyes ; then
53     no_sdl2=""
54     SDL2_CONFIG="pkg-config sdl2"
55   else
56     as_save_PATH="$PATH"
57     if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then
58       PATH="$prefix/bin:$prefix/usr/bin:$PATH"
59     fi
60     AC_PATH_PROG(SDL2_CONFIG, sdl2-config, no, [$PATH])
61     PATH="$as_save_PATH"
62     AC_MSG_CHECKING(for SDL2 - version >= $min_sdl2_version)
63     no_sdl2=""
65     if test "$SDL2_CONFIG" = "no" ; then
66       no_sdl2=yes
67     else
68       SDL2_CFLAGS=`$SDL2_CONFIG $sdl2_config_args --cflags`
69       SDL2_LIBS=`$SDL2_CONFIG $sdl2_config_args --libs`
71       sdl2_major_version=`$SDL2_CONFIG $sdl2_config_args --version | \
72              sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
73       sdl2_minor_version=`$SDL2_CONFIG $sdl2_config_args --version | \
74              sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
75       sdl2_micro_version=`$SDL2_CONFIG $sdl2_config_args --version | \
76              sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
77       if test "x$enable_sdl2test" = "xyes" ; then
78         ac_save_CFLAGS="$CFLAGS"
79         ac_save_CXXFLAGS="$CXXFLAGS"
80         ac_save_LIBS="$LIBS"
81         CFLAGS="$CFLAGS $SDL2_CFLAGS"
82         CXXFLAGS="$CXXFLAGS $SDL2_CFLAGS"
83         LIBS="$LIBS $SDL2_LIBS"
84 dnl
85 dnl Now check if the installed SDL2 is sufficiently new. (Also sanity
86 dnl checks the results of sdl2-config to some extent
87 dnl
88       rm -f conf.sdl2test
89       AC_RUN_IFELSE([AC_LANG_SOURCE([[
90 #include <stdio.h>
91 #include <stdlib.h>
92 #include <string.h>
93 #include "SDL.h"
95 char*
96 my_strdup (char *str)
98   char *new_str;
99   
100   if (str)
101     {
102       new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
103       strcpy (new_str, str);
104     }
105   else
106     new_str = NULL;
107   
108   return new_str;
111 int main (int argc, char *argv[])
113   int major, minor, micro;
114   char *tmp_version;
116   /* This hangs on some systems (?)
117   system ("touch conf.sdl2test");
118   */
119   { FILE *fp = fopen("conf.sdl2test", "a"); if ( fp ) fclose(fp); }
121   /* HP/UX 9 writes to sscanf strings */
122   tmp_version = my_strdup("$min_sdl2_version");
123   if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
124      printf("%s, bad version string\n", "$min_sdl2_version");
125      exit(1);
126    }
128    if (($sdl2_major_version > major) ||
129       (($sdl2_major_version == major) && ($sdl2_minor_version > minor)) ||
130       (($sdl2_major_version == major) && ($sdl2_minor_version == minor) && ($sdl2_micro_version >= micro)))
131     {
132       return 0;
133     }
134   else
135     {
136       printf("\n*** 'sdl2-config --version' returned %d.%d.%d, but the minimum version\n", $sdl2_major_version, $sdl2_minor_version, $sdl2_micro_version);
137       printf("*** of SDL2 required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro);
138       printf("*** best to upgrade to the required version.\n");
139       printf("*** If sdl2-config was wrong, set the environment variable SDL2_CONFIG\n");
140       printf("*** to point to the correct copy of sdl2-config, and remove the file\n");
141       printf("*** config.cache before re-running configure\n");
142       return 1;
143     }
146 ]])], [], [no_sdl2=yes], [echo $ac_n "cross compiling; assumed OK... $ac_c"])
147         CFLAGS="$ac_save_CFLAGS"
148         CXXFLAGS="$ac_save_CXXFLAGS"
149         LIBS="$ac_save_LIBS"
150       fi
151     fi
152     if test "x$no_sdl" = x ; then
153       AC_MSG_RESULT(yes)
154     else
155       AC_MSG_RESULT(no)
156     fi
157   fi
158   if test "x$no_sdl2" = x ; then
159      ifelse([$2], , :, [$2])
160   else
161      if test "$SDL2_CONFIG" = "no" ; then
162        echo "*** The sdl2-config script installed by SDL2 could not be found"
163        echo "*** If SDL2 was installed in PREFIX, make sure PREFIX/bin is in"
164        echo "*** your path, or set the SDL2_CONFIG environment variable to the"
165        echo "*** full path to sdl2-config."
166      else
167        if test -f conf.sdl2test ; then
168         :
169        else
170           echo "*** Could not run SDL2 test program, checking why..."
171           CFLAGS="$CFLAGS $SDL2_CFLAGS"
172           CXXFLAGS="$CXXFLAGS $SDL2_CFLAGS"
173           LIBS="$LIBS $SDL2_LIBS"
174           AC_LINK_IFELSE([AC_LANG_PROGRAM([[
175 #include <stdio.h>
176 #include "SDL.h"
178 int main(int argc, char *argv[])
179 { return 0; }
180 #undef  main
181 #define main K_and_R_C_main
182 ]], [[ return 0; ]])],
183         [ echo "*** The test program compiled, but did not run. This usually means"
184           echo "*** that the run-time linker is not finding SDL2 or finding the wrong"
185           echo "*** version of SDL2. If it is not finding SDL2, you'll need to set your"
186           echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
187           echo "*** to the installed location  Also, make sure you have run ldconfig if that"
188           echo "*** is required on your system"
189           echo "***"
190           echo "*** If you have an old version installed, it is best to remove it, although"
191           echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
192         [ echo "*** The test program failed to compile or link. See the file config.log for the"
193           echo "*** exact error that occurred. This usually means SDL2 was incorrectly installed"
194           echo "*** or that you have moved SDL2 since it was installed. In the latter case, you"
195           echo "*** may want to edit the sdl2-config script: $SDL2_CONFIG" ])
196           CFLAGS="$ac_save_CFLAGS"
197           CXXFLAGS="$ac_save_CXXFLAGS"
198           LIBS="$ac_save_LIBS"
199        fi
200      fi
201      SDL2_CFLAGS=""
202      SDL2_LIBS=""
203      ifelse([$3], , :, [$3])
204   fi
205   AC_SUBST(SDL2_CFLAGS)
206   AC_SUBST(SDL2_LIBS)
207   rm -f conf.sdl2test