1# Check for binary relocation support.
2# Written by Hongli Lai
3# http://autopackage.org/
4
5AC_DEFUN([AM_BINRELOC],
6[
7	AC_ARG_ENABLE(binreloc,
8		[  --enable-binreloc       compile with binary relocation support
9                          (default=enable when available)],
10		enable_binreloc=$enableval,enable_binreloc=auto)
11
12	BINRELOC_CFLAGS=
13	BINRELOC_LIBS=
14	if test "x$enable_binreloc" = "xauto"; then
15		AC_CHECK_FILE([/proc/self/maps])
16		AC_CACHE_CHECK([whether everything is installed to the same prefix],
17			       [br_cv_valid_prefixes], [
18				if test "$bindir" = '${exec_prefix}/bin' -a "$sbindir" = '${exec_prefix}/sbin' -a \
19					"$datadir" = '${prefix}/share' -a "$libdir" = '${exec_prefix}/lib' -a \
20					"$libexecdir" = '${exec_prefix}/libexec' -a "$sysconfdir" = '${prefix}/etc'
21				then
22					br_cv_valid_prefixes=yes
23				else
24					br_cv_valid_prefixes=no
25				fi
26				])
27	fi
28	AC_CACHE_CHECK([whether binary relocation support should be enabled],
29		       [br_cv_binreloc],
30		       [if test "x$enable_binreloc" = "xyes"; then
31		       	       br_cv_binreloc=yes
32		       elif test "x$enable_binreloc" = "xauto"; then
33			       if test "x$br_cv_valid_prefixes" = "xyes" -a \
34			       	       "x$ac_cv_file__proc_self_maps" = "xyes"; then
35				       br_cv_binreloc=yes
36			       else
37				       br_cv_binreloc=no
38			       fi
39		       else
40			       br_cv_binreloc=no
41		       fi])
42
43	if test "x$br_cv_binreloc" = "xyes"; then
44		BINRELOC_CFLAGS="-DENABLE_BINRELOC"
45		AC_DEFINE(ENABLE_BINRELOC,,[Use binary relocation?])
46	fi
47	AC_SUBST(BINRELOC_CFLAGS)
48	AC_SUBST(BINRELOC_LIBS)
49])
50
51
52# Configure paths for SDL
53# Sam Lantinga 9/21/99
54# stolen from Manish Singh
55# stolen back from Frank Belew
56# stolen from Manish Singh
57# Shamelessly stolen from Owen Taylor
58
59dnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
60dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
61dnl
62AC_DEFUN([AM_PATH_SDL],
63[dnl
64dnl Get the cflags and libraries from the sdl-config script
65dnl
66AC_ARG_WITH(sdl-prefix,[  --with-sdl-prefix=PFX   Prefix where SDL is installed (optional)],
67            sdl_prefix="$withval", sdl_prefix="")
68AC_ARG_WITH(sdl-exec-prefix,[  --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)],
69            sdl_exec_prefix="$withval", sdl_exec_prefix="")
70AC_ARG_ENABLE(sdltest, [  --disable-sdltest       Do not try to compile and run a test SDL program],
71		    , enable_sdltest=yes)
72
73  if test x$sdl_exec_prefix != x ; then
74     sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix"
75     if test x${SDL_CONFIG+set} != xset ; then
76        SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config
77     fi
78  fi
79  if test x$sdl_prefix != x ; then
80     sdl_args="$sdl_args --prefix=$sdl_prefix"
81     if test x${SDL_CONFIG+set} != xset ; then
82        SDL_CONFIG=$sdl_prefix/bin/sdl-config
83     fi
84  fi
85
86  AC_PATH_PROG(SDL_CONFIG, sdl-config, no)
87  min_sdl_version=ifelse([$1], ,0.11.0,$1)
88  AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
89  no_sdl=""
90  if test "$SDL_CONFIG" = "no" ; then
91    no_sdl=yes
92  else
93    SDL_CFLAGS=`$SDL_CONFIG $sdlconf_args --cflags`
94    SDL_LIBS=`$SDL_CONFIG $sdlconf_args --libs`
95
96    sdl_major_version=`$SDL_CONFIG $sdl_args --version | \
97           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
98    sdl_minor_version=`$SDL_CONFIG $sdl_args --version | \
99           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
100    sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \
101           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
102    if test "x$enable_sdltest" = "xyes" ; then
103      ac_save_CFLAGS="$CFLAGS"
104      ac_save_LIBS="$LIBS"
105      CFLAGS="$CFLAGS $SDL_CFLAGS"
106      LIBS="$LIBS $SDL_LIBS"
107dnl
108dnl Now check if the installed SDL is sufficiently new. (Also sanity
109dnl checks the results of sdl-config to some extent
110dnl
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
118char*
119my_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
134int 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*** 'sdl-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 sdl-config is correct, then it is\n", major, minor, micro);
161      printf("*** best to upgrade to the required version.\n");
162      printf("*** If sdl-config was wrong, set the environment variable SDL_CONFIG\n");
163      printf("*** to point to the correct copy of sdl-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       LIBS="$ac_save_LIBS"
172     fi
173  fi
174  if test "x$no_sdl" = x ; then
175     AC_MSG_RESULT(yes)
176     ifelse([$2], , :, [$2])
177  else
178     AC_MSG_RESULT(no)
179     if test "$SDL_CONFIG" = "no" ; then
180       echo "*** The sdl-config script installed by SDL could not be found"
181       echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
182       echo "*** your path, or set the SDL_CONFIG environment variable to the"
183       echo "*** full path to sdl-config."
184     else
185       if test -f conf.sdltest ; then
186        :
187       else
188          echo "*** Could not run SDL test program, checking why..."
189          CFLAGS="$CFLAGS $SDL_CFLAGS"
190          LIBS="$LIBS $SDL_LIBS"
191          AC_TRY_LINK([
192#include <stdio.h>
193#include "SDL.h"
194],      [ return 0; ],
195        [ echo "*** The test program compiled, but did not run. This usually means"
196          echo "*** that the run-time linker is not finding SDL or finding the wrong"
197          echo "*** version of SDL. If it is not finding SDL, you'll need to set your"
198          echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
199          echo "*** to the installed location  Also, make sure you have run ldconfig if that"
200          echo "*** is required on your system"
201	  echo "***"
202          echo "*** If you have an old version installed, it is best to remove it, although"
203          echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
204        [ echo "*** The test program failed to compile or link. See the file config.log for the"
205          echo "*** exact error that occured. This usually means SDL was incorrectly installed"
206          echo "*** or that you have moved SDL since it was installed. In the latter case, you"
207          echo "*** may want to edit the sdl-config script: $SDL_CONFIG" ])
208          CFLAGS="$ac_save_CFLAGS"
209          LIBS="$ac_save_LIBS"
210       fi
211     fi
212     SDL_CFLAGS=""
213     SDL_LIBS=""
214     ifelse([$3], , :, [$3])
215  fi
216  AC_SUBST(SDL_CFLAGS)
217  AC_SUBST(SDL_LIBS)
218  rm -f conf.sdltest
219])
220