acinclude.m4
author Ozkan Sezer <sezero@users.sourceforge.net>
Wed, 24 May 2017 11:28:05 -0400
changeset 599 f0d57c9b72d8
parent 595 7ba87def9569
permissions -rw-r--r--
timidity.c: fix potential buffer overrun in RWgets

(num_read check was off-by-one.) also simplify the procedure a bit.
(transplanted from 0c4026dd32742e8b7d33fb96d40fe3c03b02f90c)
icculus@68
     1
dnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
icculus@68
     2
dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
icculus@68
     3
dnl
icculus@497
     4
AC_DEFUN([AM_PATH_SDL],
icculus@68
     5
[dnl 
icculus@68
     6
dnl Get the cflags and libraries from the sdl-config script
icculus@68
     7
dnl
icculus@68
     8
AC_ARG_WITH(sdl-prefix,[  --with-sdl-prefix=PFX   Prefix where SDL is installed (optional)],
icculus@68
     9
            sdl_prefix="$withval", sdl_prefix="")
icculus@68
    10
AC_ARG_WITH(sdl-exec-prefix,[  --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)],
icculus@68
    11
            sdl_exec_prefix="$withval", sdl_exec_prefix="")
icculus@68
    12
AC_ARG_ENABLE(sdltest, [  --disable-sdltest       Do not try to compile and run a test SDL program],
icculus@68
    13
		    , enable_sdltest=yes)
icculus@68
    14
icculus@68
    15
  if test x$sdl_exec_prefix != x ; then
icculus@68
    16
     sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix"
icculus@68
    17
     if test x${SDL_CONFIG+set} != xset ; then
icculus@68
    18
        SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config
icculus@68
    19
     fi
icculus@68
    20
  fi
icculus@68
    21
  if test x$sdl_prefix != x ; then
icculus@68
    22
     sdl_args="$sdl_args --prefix=$sdl_prefix"
icculus@68
    23
     if test x${SDL_CONFIG+set} != xset ; then
icculus@68
    24
        SDL_CONFIG=$sdl_prefix/bin/sdl-config
icculus@68
    25
     fi
icculus@68
    26
  fi
icculus@68
    27
icculus@497
    28
  AC_REQUIRE([AC_CANONICAL_TARGET])
icculus@497
    29
  PATH="$prefix/bin:$prefix/usr/bin:$PATH"
icculus@595
    30
  AC_PATH_PROG(SDL1_CONFIG, sdl-config, no, [$PATH])
icculus@595
    31
  AC_PATH_PROG(SDL2_CONFIG, sdl2-config, no, [$PATH])
icculus@595
    32
icculus@595
    33
  if test "$SDL2_CONFIG" != "no" ; then
icculus@595
    34
    SDL_CONFIG=$SDL2_CONFIG
icculus@595
    35
  else
icculus@595
    36
    SDL_CONFIG=$SDL1_CONFIG
icculus@595
    37
  fi
icculus@595
    38
icculus@68
    39
  min_sdl_version=ifelse([$1], ,0.11.0,$1)
icculus@68
    40
  AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
icculus@68
    41
  no_sdl=""
icculus@68
    42
  if test "$SDL_CONFIG" = "no" ; then
icculus@68
    43
    no_sdl=yes
icculus@68
    44
  else
icculus@68
    45
    SDL_CFLAGS=`$SDL_CONFIG $sdlconf_args --cflags`
icculus@68
    46
    SDL_LIBS=`$SDL_CONFIG $sdlconf_args --libs`
icculus@68
    47
icculus@68
    48
    sdl_major_version=`$SDL_CONFIG $sdl_args --version | \
icculus@68
    49
           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
icculus@68
    50
    sdl_minor_version=`$SDL_CONFIG $sdl_args --version | \
icculus@68
    51
           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
icculus@68
    52
    sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \
icculus@68
    53
           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
icculus@68
    54
    if test "x$enable_sdltest" = "xyes" ; then
icculus@68
    55
      ac_save_CFLAGS="$CFLAGS"
icculus@497
    56
      ac_save_CXXFLAGS="$CXXFLAGS"
icculus@68
    57
      ac_save_LIBS="$LIBS"
icculus@68
    58
      CFLAGS="$CFLAGS $SDL_CFLAGS"
icculus@497
    59
      CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
icculus@68
    60
      LIBS="$LIBS $SDL_LIBS"
icculus@68
    61
dnl
icculus@68
    62
dnl Now check if the installed SDL is sufficiently new. (Also sanity
icculus@68
    63
dnl checks the results of sdl-config to some extent
icculus@68
    64
dnl
icculus@68
    65
      rm -f conf.sdltest
icculus@68
    66
      AC_TRY_RUN([
icculus@68
    67
#include <stdio.h>
icculus@68
    68
#include <stdlib.h>
icculus@68
    69
#include <string.h>
icculus@68
    70
#include "SDL.h"
icculus@68
    71
icculus@68
    72
char*
icculus@68
    73
my_strdup (char *str)
icculus@68
    74
{
icculus@68
    75
  char *new_str;
icculus@68
    76
  
icculus@68
    77
  if (str)
icculus@68
    78
    {
icculus@68
    79
      new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
icculus@68
    80
      strcpy (new_str, str);
icculus@68
    81
    }
icculus@68
    82
  else
icculus@68
    83
    new_str = NULL;
icculus@68
    84
  
icculus@68
    85
  return new_str;
icculus@68
    86
}
icculus@68
    87
icculus@68
    88
int main (int argc, char *argv[])
icculus@68
    89
{
icculus@68
    90
  int major, minor, micro;
icculus@68
    91
  char *tmp_version;
icculus@68
    92
icculus@68
    93
  /* This hangs on some systems (?)
icculus@68
    94
  system ("touch conf.sdltest");
icculus@68
    95
  */
icculus@68
    96
  { FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); }
icculus@68
    97
icculus@68
    98
  /* HP/UX 9 (%@#!) writes to sscanf strings */
icculus@68
    99
  tmp_version = my_strdup("$min_sdl_version");
icculus@68
   100
  if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
icculus@68
   101
     printf("%s, bad version string\n", "$min_sdl_version");
icculus@68
   102
     exit(1);
icculus@68
   103
   }
icculus@68
   104
icculus@68
   105
   if (($sdl_major_version > major) ||
icculus@68
   106
      (($sdl_major_version == major) && ($sdl_minor_version > minor)) ||
icculus@68
   107
      (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro)))
icculus@68
   108
    {
icculus@68
   109
      return 0;
icculus@68
   110
    }
icculus@68
   111
  else
icculus@68
   112
    {
icculus@68
   113
      printf("\n*** 'sdl-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
icculus@68
   114
      printf("*** of SDL required is %d.%d.%d. If sdl-config is correct, then it is\n", major, minor, micro);
icculus@68
   115
      printf("*** best to upgrade to the required version.\n");
icculus@68
   116
      printf("*** If sdl-config was wrong, set the environment variable SDL_CONFIG\n");
icculus@68
   117
      printf("*** to point to the correct copy of sdl-config, and remove the file\n");
icculus@68
   118
      printf("*** config.cache before re-running configure\n");
icculus@68
   119
      return 1;
icculus@68
   120
    }
icculus@68
   121
}
icculus@68
   122
icculus@68
   123
],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
icculus@68
   124
       CFLAGS="$ac_save_CFLAGS"
icculus@68
   125
       LIBS="$ac_save_LIBS"
icculus@68
   126
     fi
icculus@68
   127
  fi
icculus@68
   128
  if test "x$no_sdl" = x ; then
icculus@68
   129
     AC_MSG_RESULT(yes)
icculus@68
   130
     ifelse([$2], , :, [$2])     
icculus@68
   131
  else
icculus@68
   132
     AC_MSG_RESULT(no)
icculus@68
   133
     if test "$SDL_CONFIG" = "no" ; then
icculus@68
   134
       echo "*** The sdl-config script installed by SDL could not be found"
icculus@68
   135
       echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
icculus@68
   136
       echo "*** your path, or set the SDL_CONFIG environment variable to the"
icculus@68
   137
       echo "*** full path to sdl-config."
icculus@68
   138
     else
icculus@68
   139
       if test -f conf.sdltest ; then
icculus@68
   140
        :
icculus@68
   141
       else
icculus@68
   142
          echo "*** Could not run SDL test program, checking why..."
icculus@68
   143
          CFLAGS="$CFLAGS $SDL_CFLAGS"
icculus@497
   144
          CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
icculus@68
   145
          LIBS="$LIBS $SDL_LIBS"
icculus@68
   146
          AC_TRY_LINK([
icculus@68
   147
#include <stdio.h>
icculus@68
   148
#include "SDL.h"
icculus@68
   149
icculus@68
   150
int main(int argc, char *argv[])
icculus@68
   151
{ return 0; }
icculus@68
   152
#undef  main
icculus@68
   153
#define main K_and_R_C_main
icculus@68
   154
],      [ return 0; ],
icculus@68
   155
        [ echo "*** The test program compiled, but did not run. This usually means"
icculus@68
   156
          echo "*** that the run-time linker is not finding SDL or finding the wrong"
icculus@68
   157
          echo "*** version of SDL. If it is not finding SDL, you'll need to set your"
icculus@68
   158
          echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
icculus@68
   159
          echo "*** to the installed location  Also, make sure you have run ldconfig if that"
icculus@68
   160
          echo "*** is required on your system"
icculus@68
   161
	  echo "***"
icculus@68
   162
          echo "*** If you have an old version installed, it is best to remove it, although"
icculus@68
   163
          echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
icculus@68
   164
        [ echo "*** The test program failed to compile or link. See the file config.log for the"
icculus@68
   165
          echo "*** exact error that occured. This usually means SDL was incorrectly installed"
icculus@68
   166
          echo "*** or that you have moved SDL since it was installed. In the latter case, you"
icculus@68
   167
          echo "*** may want to edit the sdl-config script: $SDL_CONFIG" ])
icculus@68
   168
          CFLAGS="$ac_save_CFLAGS"
icculus@497
   169
          CXXFLAGS="$ac_save_CXXFLAGS"
icculus@68
   170
          LIBS="$ac_save_LIBS"
icculus@68
   171
       fi
icculus@68
   172
     fi
icculus@68
   173
     SDL_CFLAGS=""
icculus@497
   174
     SDL_CXXFLAGS=""
icculus@68
   175
     SDL_LIBS=""
icculus@68
   176
     ifelse([$3], , :, [$3])
icculus@68
   177
  fi
icculus@68
   178
  AC_SUBST(SDL_CFLAGS)
icculus@68
   179
  AC_SUBST(SDL_LIBS)
icculus@68
   180
  rm -f conf.sdltest
icculus@68
   181
])