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