1AC_PREREQ([2.58])
2AC_INIT([ffms2],[esyscmd([sh version.sh])])
3AC_CONFIG_SRCDIR([src/core/ffms.cpp])
4AC_CONFIG_MACRO_DIR([m4])
5AM_INIT_AUTOMAKE([1.11 subdir-objects])
6AM_SILENT_RULES([yes])
7AM_MAINTAINER_MODE([disable])
8
9VERSION_INFO="4:0:0"
10
11AC_MSG_CHECKING([if debug build is enabled])
12
13AC_ARG_ENABLE([debug],
14        [AC_HELP_STRING([--enable-debug],
15            [Enable debug build. [default=no]])],
16        [enable_debug=yes],
17        [enable_debug=no]
18        )
19
20AC_MSG_RESULT([$enable_debug])
21
22if test "$enable_debug" = yes; then
23    OPT_FLAGS="-O0 -g"
24else
25    OPT_FLAGS="-O3"
26fi
27
28if test -z "$CFLAGS"; then
29    CFLAGS="$OPT_FLAGS -Wall -Wextra"
30fi
31
32if test -z "$CXXFLAGS"; then
33    CXXFLAGS="$OPT_FLAGS -Wall -Wextra"
34fi
35
36AC_ARG_ENABLE([avisynth],
37        [AC_HELP_STRING([--enable-avisynth],
38            [Enable AviSynth+ plugin. [default=no]])],
39        [enable_avisynth=yes],
40        [enable_avisynth=no]
41        )
42
43AC_MSG_RESULT([$enable_avisynth])
44AM_CONDITIONAL([AVISYNTH], [test "x$enable_avisynth" != "xno"])
45
46AC_CONFIG_HEADERS([src/config/config.h])
47AC_PROG_CC
48AC_PROG_CXX
49AC_PROG_LN_S
50AC_PROG_MKDIR_P
51
52AC_CANONICAL_HOST
53AS_CASE([$host],
54        [*mingw* | *cygwin*], [
55            AC_ENABLE_STATIC
56            AC_DISABLE_SHARED
57         ], [
58            AC_ENABLE_SHARED
59            AC_DISABLE_STATIC])
60
61AC_PROG_LIBTOOL
62
63if echo "$host" | $GREP "cygwin" >/dev/null 2>&1 && test "$enable_shared" = "yes"; then
64    AC_MSG_ERROR([Shared build is broken on cygwin.
65                  Please remove --enable-shared from your configure options or build with another --host.])
66fi
67
68dnl Workaround for a bug in libtool
69dnl The windows libtool uses a file magic checking method that only accepts
70dnl dynamic libraries. Change it for libtool's alternative checking method.
71if test "$lt_cv_file_magic_cmd" = "func_win32_libid" ; then
72    deplibs_check_method='file_magic file format pei*-(i386|x86-64)|(.*architecture: i386)?'
73    file_magic_cmd='$OBJDUMP -f'
74fi
75
76FFMS_VERSION="$(sh $(dirname -- "$0")/version.sh)"
77AC_SUBST([FFMS_VERSION])
78
79CHECK_ZLIB
80
81dnl Save CFLAGS and LIBS for later, as anything else we add will be from pkg-config
82dnl and thus should be separate in our .pc file.
83_CFLAGS="$CFLAGS"
84_CPPFLAGS="$CPPFLAGS"
85_LIBS="$LIBS"
86
87PKG_PROG_PKG_CONFIG([0.22])
88pkgconfigdir="\$(libdir)/pkgconfig"
89AC_SUBST(pkgconfigdir)
90
91PKG_CHECK_MODULES(FFMPEG, [libavformat >= 53.20.0 libavcodec >= 53.24.0 libswscale >= 0.7.0 libavutil >= 51.21.0 libswresample >= 1.0.0])
92
93dnl As of 0eec06ed8747923faa6a98e474f224d922dc487d ffmpeg only adds -lrt to lavc's
94dnl LIBS, but lavu needs it, so move it to the end if it's present
95FFMPEG_LIBS=$(echo $FFMPEG_LIBS | sed 's/\(.*\)-lrt \(.*\)/\1\2 -lrt/')
96
97AC_SUBST([FFMPEG_CFLAGS])
98AC_SUBST([FFMPEG_LIBS])
99
100CPPFLAGS="$CPPFLAGS -D__STDC_CONSTANT_MACROS"
101CFLAGS="$_CFLAGS $FFMPEG_CFLAGS"
102
103AC_DEFUN([TEST_FFMPEG],
104         [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
105            #include <libavcodec/avcodec.h>
106            #include <libswscale/swscale.h>
107            ]],[[
108                avcodec_register_all();
109                swscale_version();
110            ]])], [eval $1=yes], [eval $1=no])
111        ])
112
113AC_MSG_CHECKING([whether FFmpeg works])
114LIBS="$_LIBS $FFMPEG_LIBS"
115TEST_FFMPEG([FFMPEG_WORKS])
116AC_MSG_RESULT([$FFMPEG_WORKS])
117if test "$FFMPEG_WORKS" = no; then
118AC_MSG_FAILURE([cannot link with FFmpeg])
119fi
120
121src_core_libffms2_la_LDFLAGS=""
122AC_MSG_CHECKING([whether -Wl,-Bsymbolic is needed])
123if test "$enable_shared" = yes; then
124    _LDFLAGS="$LDFLAGS"
125    LDFLAGS="$LDFLAGS -shared $lt_prog_compiler_pic"
126    TEST_FFMPEG([no_bsymbolic])
127    if test "$no_bsymbolic" = "no"; then
128        LDFLAGS="$LDFLAGS -Wl,-Bsymbolic"
129        TEST_FFMPEG([bsymbolic])
130        if test "$bsymbolic" = "yes"; then
131            src_core_libffms2_la_LDFLAGS="$src_core_libffms2_la_LDFLAGS -Wl,-Bsymbolic"
132        else
133            AC_MSG_RESULT($bsymbolic)
134            AC_MSG_FAILURE([cannot build ffms2 as a shared library])
135        fi
136    else
137        bsymbolic=no
138    fi
139    LDFLAGS="$_LDFLAGS"
140    src_core_libffms2_la_LDFLAGS="$src_core_libffms2_la_LDFLAGS -version-info $VERSION_INFO"
141else
142    bsymbolic=no
143fi
144AC_SUBST([src_core_libffms2_la_LDFLAGS])
145
146CFLAGS="$_CFLAGS"
147CPPFLAGS="$_CPPFLAGS"
148LIBS="$_LIBS"
149AC_MSG_RESULT($bsymbolic)
150
151if echo "$host" | $GREP "mingw" >/dev/null 2>&1; then
152    LTUNDEF="-no-undefined"
153fi
154AC_SUBST([LTUNDEF])
155
156AC_CONFIG_FILES([
157Makefile
158ffms2.pc
159])
160AC_OUTPUT
161
162