acinclude/smpeg.m4
author Sam Lantinga <slouken@libsdl.org>
Tue, 13 Apr 2010 22:28:38 -0700
changeset 487 485a29de2b2d
parent 351 f020187cf5b2
permissions -rw-r--r--
Fixed uninitialized variable which could definitely have caused problems.
     1 ##############################################################################
     2 # Configure paths for SMPEG
     3 # Nicolas Vignal 11/19/2000
     4 # stolen from Sam Lantinga
     5 # stolen from Manish Singh
     6 # stolen back from Frank Belew
     7 # stolen from Manish Singh
     8 # Shamelessly stolen from Owen Taylor
     9 
    10 dnl AM_PATH_SMPEG([MINIMUM-VERSION, [ACTION-IF-FOUND [, 
    11 ACTION-IF-NOT-FOUND]]])
    12 dnl Test for SMPEG, and define SMPEG_CFLAGS and SMPEG_LIBS
    13 dnl
    14 AC_DEFUN([AM_PATH_SMPEG],
    15 [dnl
    16 dnl Get the cflags and libraries from the smpeg-config script
    17 dnl
    18 AC_ARG_WITH(smpeg-prefix,[  --with-smpeg-prefix=PFX   Prefix where SMPEG is installed (optional)],
    19             smpeg_prefix="$withval", smpeg_prefix="")
    20 AC_ARG_WITH(smpeg-exec-prefix,[  --with-smpeg-exec-prefix=PFX Exec prefix where SMPEG is installed (optional)],
    21             smpeg_exec_prefix="$withval", smpeg_exec_prefix="")
    22 AC_ARG_ENABLE(smpegtest, [  --disable-smpegtest       Do not try to compile and run a test SMPEG program],
    23                     , enable_smpegtest=yes)
    24 
    25   if test x$smpeg_exec_prefix != x ; then
    26      smpeg_args="$smpeg_args --exec-prefix=$smpeg_exec_prefix"
    27      if test x${SMPEG_CONFIG+set} != xset ; then
    28         SMPEG_CONFIG=$smpeg_exec_prefix/bin/smpeg-config
    29      fi
    30   fi
    31   if test x$smpeg_prefix != x ; then
    32      smpeg_args="$smpeg_args --prefix=$smpeg_prefix"
    33      if test x${SMPEG_CONFIG+set} != xset ; then
    34         SMPEG_CONFIG=$smpeg_prefix/bin/smpeg-config
    35      fi
    36   fi
    37 
    38   AC_PATH_PROG(SMPEG_CONFIG, smpeg-config, no)
    39   min_smpeg_version=ifelse([$1], ,0.2.7,$1)
    40   AC_MSG_CHECKING(for SMPEG - version >= $min_smpeg_version)
    41   no_smpeg=""
    42   if test "$SMPEG_CONFIG" = "no" ; then
    43     no_smpeg=yes
    44   else
    45     SMPEG_CFLAGS=`$SMPEG_CONFIG $smpegconf_args --cflags`
    46     SMPEG_LIBS=`$SMPEG_CONFIG $smpegconf_args --libs`
    47 
    48     smpeg_major_version=`$SMPEG_CONFIG $smpeg_args --version | \
    49            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
    50     smpeg_minor_version=`$SMPEG_CONFIG $smpeg_args --version | \
    51            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
    52     smpeg_micro_version=`$SMPEG_CONFIG $smpeg_config_args --version | \
    53            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
    54     if test "x$enable_smpegtest" = "xyes" ; then
    55       ac_save_CFLAGS="$CFLAGS"
    56       ac_save_LIBS="$LIBS"
    57       CFLAGS="$CFLAGS $SMPEG_CFLAGS $SDL_CFLAGS"
    58       LIBS="$LIBS $SMPEG_LIBS $SDL_LIBS"
    59 dnl
    60 dnl Now check if the installed SMPEG is sufficiently new. (Also sanity
    61 dnl checks the results of smpeg-config to some extent
    62 dnl
    63       rm -f conf.smpegtest
    64       AC_TRY_RUN([
    65 #include <stdio.h>
    66 #include <stdlib.h>
    67 #include <string.h>
    68 #include "smpeg.h"
    69 
    70 char*
    71 my_strdup (char *str)
    72 {
    73   char *new_str;
    74 
    75   if (str)
    76     {
    77       new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
    78       strcpy (new_str, str);
    79     }
    80   else
    81     new_str = NULL;
    82 
    83   return new_str;
    84 }
    85 
    86 int main (int argc, char *argv[])
    87 {
    88   int major, minor, micro;
    89   char *tmp_version;
    90 
    91   /* This hangs on some systems (?)
    92   system ("touch conf.smpegtest");
    93   */
    94   { FILE *fp = fopen("conf.smpegtest", "a"); if ( fp ) fclose(fp); }
    95 
    96   /* HP/UX 9 (%@#!) writes to sscanf strings */
    97   tmp_version = my_strdup("$min_smpeg_version");
    98   if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
    99      printf("%s, bad version string\n", "$min_smpeg_version");
   100      exit(1);
   101    }
   102 
   103    if (($smpeg_major_version > major) ||
   104       (($smpeg_major_version == major) && ($smpeg_minor_version > minor)) ||
   105       (($smpeg_major_version == major) && ($smpeg_minor_version == minor) && ($smpeg_micro_version >= micro)))
   106     {
   107       return 0;
   108     }
   109   else
   110     {
   111       printf("\n*** 'smpeg-config --version' returned %d.%d.%d, but the minimum version\n", $smpeg_major_version, $smpeg_minor_version, $smpeg_micro_version);
   112       printf("*** of SMPEG required is %d.%d.%d. If smpeg-config is correct, then it is\n", major, minor, micro);
   113       printf("*** best to upgrade to the required version.\n");
   114       printf("*** If smpeg-config was wrong, set the environment variable SMPEG_CONFIG\n");
   115       printf("*** to point to the correct copy of smpeg-config, and remove the file\n");
   116       printf("*** config.cache before re-running configure\n");
   117       return 1;
   118     }
   119 }
   120 
   121 ],, no_smpeg=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
   122        CFLAGS="$ac_save_CFLAGS"
   123        LIBS="$ac_save_LIBS"
   124      fi
   125   fi
   126   if test "x$no_smpeg" = x ; then
   127      AC_MSG_RESULT(yes)
   128      ifelse([$2], , :, [$2])
   129   else
   130      AC_MSG_RESULT(no)
   131      if test "$SMPEG_CONFIG" = "no" ; then
   132        echo "*** The smpeg-config script installed by SMPEG could not be found"
   133        echo "*** If SMPEG was installed in PREFIX, make sure PREFIX/bin is in"
   134        echo "*** your path, or set the SMPEG_CONFIG environment variable to the"
   135        echo "*** full path to smpeg-config."
   136      else
   137        if test -f conf.smpegtest ; then
   138         :
   139        else
   140           echo "*** Could not run SMPEG test program, checking why..."
   141           CFLAGS="$CFLAGS $SMPEG_CFLAGS $SDL_CFLAGS"
   142           LIBS="$LIBS $SMPEG_LIBS $SDL_LIBS"
   143           AC_TRY_LINK([
   144 #include <stdio.h>
   145 #include "smpeg.h"
   146 ],      [ return 0; ],
   147         [ echo "*** The test program compiled, but did not run. This usually means"
   148           echo "*** that the run-time linker is not finding SMPEG or finding the wrong"
   149           echo "*** version of SMPEG. If it is not finding SMPEG, you'll need to set your"
   150           echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
   151           echo "*** to the installed location  Also, make sure you have run ldconfig if that"
   152           echo "*** is required on your system"
   153           echo "***"
   154           echo "*** If you have an old version installed, it is best to remove it, although"
   155           echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
   156         [ echo "*** The test program failed to compile or link. See the file config.log for the"
   157           echo "*** exact error that occured. This usually means SMPEG was incorrectly installed"
   158           echo "*** or that you have moved SMPEG since it was installed. In the latter case, you"
   159           echo "*** may want to edit the smpeg-config script: $SMPEG_CONFIG" ])
   160           CFLAGS="$ac_save_CFLAGS"
   161           LIBS="$ac_save_LIBS"
   162        fi
   163      fi
   164      SMPEG_CFLAGS=""
   165      SMPEG_LIBS=""
   166      ifelse([$3], , :, [$3])
   167   fi
   168   AC_SUBST(SMPEG_CFLAGS)
   169   AC_SUBST(SMPEG_LIBS)
   170   rm -f conf.smpegtest
   171 ])