acinclude/smpeg.m4
author Sam Lantinga <slouken@libsdl.org>
Sun, 04 Oct 2009 18:09:12 +0000
changeset 425 d39ef8d550b6
parent 351 f020187cf5b2
permissions -rw-r--r--
Fixed bug #522

Mike Frysinger 2007-12-10 16:47:36 PST

it's much easier to manage .pc files for cross-compiling setups than it is for
random *-config scripts ... the cross-compiled pkg-config files can all be
easily/tightly controlled and separate from the host pkg-config files. the
*-config files however are to be found in $PATH and can easily pick the wrong
one.

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