test/acinclude.m4
changeset 0 74212992fb08
child 1 cf2af46e9e2a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/acinclude.m4	Thu Apr 26 16:45:43 2001 +0000
     1.3 @@ -0,0 +1,168 @@
     1.4 +# Configure paths for SDL
     1.5 +# Sam Lantinga 9/21/99
     1.6 +# stolen from Manish Singh
     1.7 +# stolen back from Frank Belew
     1.8 +# stolen from Manish Singh
     1.9 +# Shamelessly stolen from Owen Taylor
    1.10 +
    1.11 +dnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
    1.12 +dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
    1.13 +dnl
    1.14 +AC_DEFUN(AM_PATH_SDL,
    1.15 +[dnl 
    1.16 +dnl Get the cflags and libraries from the sdl-config script
    1.17 +dnl
    1.18 +AC_ARG_WITH(sdl-prefix,[  --with-sdl-prefix=PFX   Prefix where SDL is installed (optional)],
    1.19 +            sdl_prefix="$withval", sdl_prefix="")
    1.20 +AC_ARG_WITH(sdl-exec-prefix,[  --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)],
    1.21 +            sdl_exec_prefix="$withval", sdl_exec_prefix="")
    1.22 +AC_ARG_ENABLE(sdltest, [  --disable-sdltest       Do not try to compile and run a test SDL program],
    1.23 +		    , enable_sdltest=yes)
    1.24 +
    1.25 +  if test x$sdl_exec_prefix != x ; then
    1.26 +     sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix"
    1.27 +     if test x${SDL_CONFIG+set} != xset ; then
    1.28 +        SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config
    1.29 +     fi
    1.30 +  fi
    1.31 +  if test x$sdl_prefix != x ; then
    1.32 +     sdl_args="$sdl_args --prefix=$sdl_prefix"
    1.33 +     if test x${SDL_CONFIG+set} != xset ; then
    1.34 +        SDL_CONFIG=$sdl_prefix/bin/sdl-config
    1.35 +     fi
    1.36 +  fi
    1.37 +
    1.38 +  AC_PATH_PROG(SDL_CONFIG, sdl-config, no)
    1.39 +  min_sdl_version=ifelse([$1], ,0.11.0,$1)
    1.40 +  AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
    1.41 +  no_sdl=""
    1.42 +  if test "$SDL_CONFIG" = "no" ; then
    1.43 +    no_sdl=yes
    1.44 +  else
    1.45 +    SDL_CFLAGS=`$SDL_CONFIG $sdlconf_args --cflags`
    1.46 +    SDL_LIBS=`$SDL_CONFIG $sdlconf_args --libs`
    1.47 +
    1.48 +    sdl_major_version=`$SDL_CONFIG $sdl_args --version | \
    1.49 +           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
    1.50 +    sdl_minor_version=`$SDL_CONFIG $sdl_args --version | \
    1.51 +           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
    1.52 +    sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \
    1.53 +           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
    1.54 +    if test "x$enable_sdltest" = "xyes" ; then
    1.55 +      ac_save_CFLAGS="$CFLAGS"
    1.56 +      ac_save_LIBS="$LIBS"
    1.57 +      CFLAGS="$CFLAGS $SDL_CFLAGS"
    1.58 +      LIBS="$LIBS $SDL_LIBS"
    1.59 +dnl
    1.60 +dnl Now check if the installed SDL is sufficiently new. (Also sanity
    1.61 +dnl checks the results of sdl-config to some extent
    1.62 +dnl
    1.63 +      rm -f conf.sdltest
    1.64 +      AC_TRY_RUN([
    1.65 +#include <stdio.h>
    1.66 +#include <stdlib.h>
    1.67 +#include <string.h>
    1.68 +#include "SDL.h"
    1.69 +
    1.70 +char*
    1.71 +my_strdup (char *str)
    1.72 +{
    1.73 +  char *new_str;
    1.74 +  
    1.75 +  if (str)
    1.76 +    {
    1.77 +      new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
    1.78 +      strcpy (new_str, str);
    1.79 +    }
    1.80 +  else
    1.81 +    new_str = NULL;
    1.82 +  
    1.83 +  return new_str;
    1.84 +}
    1.85 +
    1.86 +int main (int argc, char *argv[])
    1.87 +{
    1.88 +  int major, minor, micro;
    1.89 +  char *tmp_version;
    1.90 +
    1.91 +  /* This hangs on some systems (?)
    1.92 +  system ("touch conf.sdltest");
    1.93 +  */
    1.94 +  { FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); }
    1.95 +
    1.96 +  /* HP/UX 9 (%@#!) writes to sscanf strings */
    1.97 +  tmp_version = my_strdup("$min_sdl_version");
    1.98 +  if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
    1.99 +     printf("%s, bad version string\n", "$min_sdl_version");
   1.100 +     exit(1);
   1.101 +   }
   1.102 +
   1.103 +   if (($sdl_major_version > major) ||
   1.104 +      (($sdl_major_version == major) && ($sdl_minor_version > minor)) ||
   1.105 +      (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro)))
   1.106 +    {
   1.107 +      return 0;
   1.108 +    }
   1.109 +  else
   1.110 +    {
   1.111 +      printf("\n*** 'sdl-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
   1.112 +      printf("*** of SDL required is %d.%d.%d. If sdl-config is correct, then it is\n", major, minor, micro);
   1.113 +      printf("*** best to upgrade to the required version.\n");
   1.114 +      printf("*** If sdl-config was wrong, set the environment variable SDL_CONFIG\n");
   1.115 +      printf("*** to point to the correct copy of sdl-config, and remove the file\n");
   1.116 +      printf("*** config.cache before re-running configure\n");
   1.117 +      return 1;
   1.118 +    }
   1.119 +}
   1.120 +
   1.121 +],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
   1.122 +       CFLAGS="$ac_save_CFLAGS"
   1.123 +       LIBS="$ac_save_LIBS"
   1.124 +     fi
   1.125 +  fi
   1.126 +  if test "x$no_sdl" = x ; then
   1.127 +     AC_MSG_RESULT(yes)
   1.128 +     ifelse([$2], , :, [$2])     
   1.129 +  else
   1.130 +     AC_MSG_RESULT(no)
   1.131 +     if test "$SDL_CONFIG" = "no" ; then
   1.132 +       echo "*** The sdl-config script installed by SDL could not be found"
   1.133 +       echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
   1.134 +       echo "*** your path, or set the SDL_CONFIG environment variable to the"
   1.135 +       echo "*** full path to sdl-config."
   1.136 +     else
   1.137 +       if test -f conf.sdltest ; then
   1.138 +        :
   1.139 +       else
   1.140 +          echo "*** Could not run SDL test program, checking why..."
   1.141 +          CFLAGS="$CFLAGS $SDL_CFLAGS"
   1.142 +          LIBS="$LIBS $SDL_LIBS"
   1.143 +          AC_TRY_LINK([
   1.144 +#include <stdio.h>
   1.145 +#include "SDL.h"
   1.146 +],      [ return 0; ],
   1.147 +        [ echo "*** The test program compiled, but did not run. This usually means"
   1.148 +          echo "*** that the run-time linker is not finding SDL or finding the wrong"
   1.149 +          echo "*** version of SDL. If it is not finding SDL, you'll need to set your"
   1.150 +          echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
   1.151 +          echo "*** to the installed location  Also, make sure you have run ldconfig if that"
   1.152 +          echo "*** is required on your system"
   1.153 +	  echo "***"
   1.154 +          echo "*** If you have an old version installed, it is best to remove it, although"
   1.155 +          echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
   1.156 +        [ echo "*** The test program failed to compile or link. See the file config.log for the"
   1.157 +          echo "*** exact error that occured. This usually means SDL was incorrectly installed"
   1.158 +          echo "*** or that you have moved SDL since it was installed. In the latter case, you"
   1.159 +          echo "*** may want to edit the sdl-config script: $SDL_CONFIG" ])
   1.160 +          CFLAGS="$ac_save_CFLAGS"
   1.161 +          LIBS="$ac_save_LIBS"
   1.162 +       fi
   1.163 +     fi
   1.164 +     SDL_CFLAGS=""
   1.165 +     SDL_LIBS=""
   1.166 +     ifelse([$3], , :, [$3])
   1.167 +  fi
   1.168 +  AC_SUBST(SDL_CFLAGS)
   1.169 +  AC_SUBST(SDL_LIBS)
   1.170 +  rm -f conf.sdltest
   1.171 +])