1# CFLAGS and library paths for FFMPEG
2# taken from Autostar Sandbox, http://autostars.sourceforge.net/
3
4dnl Usage:
5dnl AM_PATH_FFMPEG([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
6dnl FIXME: version checking does not work currently
7dnl
8dnl Example:
9dnl AM_PATH_FFMPEG(0.4.6, , AC_MSG_ERROR([*** FFMPEG >= 0.4.6 not installed))
10dnl
11dnl Defines FFMPEG_LIBS
12dnl FIXME: should define FFMPEG_VERSION
13dnl
14
15AC_DEFUN([AM_PATH_FFMPEG],
16[
17  dnl allow for specification of a source path (for uninstalled)
18  AC_ARG_WITH(ffmpeg-source,
19    AC_HELP_STRING([--with-ffmpeg-source=DIR],
20                   [Directory where FFmpeg source is (optional)]),
21    ffmpeg_source="$withval")
22
23  dnl save CFLAGS and LIBS here
24  CFLAGS_save=$CFLAGS
25  LIBS_save=$LIBS
26  if test "x$ffmpeg_source" != "x"; then
27    dnl uninstalled FFmpeg copy
28    AC_MSG_NOTICE([Looking for FFmpeg source in $ffmpeg_source])
29    CFLAGS="-I$ffmpeg_source/libav -I$ffmpeg_source/libavcodec"
30    LIBS="-L$ffmpeg_source/libav -L$ffmpeg_source/libavcodec"
31    AC_DEFINE_UNQUOTED(HAVE_FFMPEG_UNINSTALLED, 1,
32                       [defined if we compile against uninstalled FFmpeg])
33    FFMPEG_COMMON_INCLUDE="#include <common.h>"
34  else
35    FFMPEG_COMMON_INCLUDE="#include <ffmpeg/common.h>"
36  fi
37
38  dnl check for libavcodec
39  AC_CHECK_LIB(avcodec, avcodec_init, HAVE_FFMPEG=yes, HAVE_FFMPEG=no)
40
41  dnl check for avcodec.h and avformat.h
42  if test "x$ffmpeg_source" != "x"; then
43    dnl uninstalled
44    AC_CHECK_HEADER(avcodec.h, , HAVE_FFMPEG=no, [/* only compile */])
45    AC_CHECK_HEADER(avformat.h, , HAVE_FFMPEG=no, [/* only compile */])
46  else
47    AC_CHECK_HEADER(ffmpeg/avcodec.h, , HAVE_FFMPEG=no)
48    AC_CHECK_HEADER(ffmpeg/avformat.h, , HAVE_FFMPEG=no)
49  fi
50
51dnl now check if it's sufficiently new
52
53  AC_LANG_SAVE()
54  AC_LANG_C()
55
56  dnl FIXME: we use strcmp, which we know is going to break if ffmpeg ever uses
57  dnl two digits for any of their version numbers.  It makes the test so much
58  dnl easier though so let's ignore that
59  AC_TRY_RUN([
60$FFMPEG_COMMON_INCLUDE
61#include <stdio.h>
62#include <string.h>
63
64int
65main ()
66{
67  if (strcmp (FFMPEG_VERSION, "$1") == -1)
68  {
69    fprintf (stderr,
70             "ERROR: your copy of ffmpeg is too old (%s)\n", FFMPEG_VERSION);
71    return 1;
72  }
73  else
74    return 0;
75}
76], , HAVE_FFMPEG=no)
77
78dnl now do the actual "do we have it ?" test
79  if test "x$HAVE_FFMPEG" = "xyes"; then
80    FFMPEG_LIBS="$LIBS -lavcodec -lavformat"
81    FFMPEG_CFLAGS="$CFLAGS"
82    AC_MSG_NOTICE(we have ffmpeg)
83    dnl execute what we have to because it's found
84    ifelse([$2], , :, [$2])
85  else
86    FFMPEG_LIBS=""
87    FFMPEG_CFLAGS=""
88    dnl execute what we have to because it's not found
89    ifelse([$3], , :, [$3])
90  fi
91
92dnl make variables available
93  AC_SUBST(FFMPEG_LIBS)
94  AC_SUBST(FFMPEG_CFLAGS)
95  AC_SUBST(HAVE_FFMPEG)
96  AC_LANG_RESTORE()
97  CFLAGS=$CFLAGS_save
98  LIBS=$LIBS_save
99])
100