dnl
dnl  Lol Engine
dnl
dnl  Copyright © 2010—2017 Sam Hocevar <sam@hocevar.net>
dnl
dnl  Lol Engine is free software. It comes without any warranty, to
dnl  the extent permitted by applicable law. You can redistribute it
dnl  and/or modify it under the terms of the Do What the Fuck You Want
dnl  to Public License, Version 2, as published by the WTFPL Task Force.
dnl  See http://www.wtfpl.net/ for more details.
dnl


# LOL_AC_CHECK_FFMPEG()
# ---------------------
AC_DEFUN([LOL_AC_CHECK_FFMPEG],
[
ac_cv_my_have_ffmpeg="no"
if test "${enable_ffmpeg}" != "no"; then
  LOL_AC_CHECK_FFMPEG_INNER()
fi
AM_CONDITIONAL(LOL_USE_FFMPEG, test "${ac_cv_my_have_ffmpeg}" != "no")
])

# LOL_AC_CHECK_FFMPEG_INNER()
# ---------------------------
AC_DEFUN([LOL_AC_CHECK_FFMPEG_INNER],
[
ac_cv_my_have_ffmpeg="yes"
PKG_CHECK_MODULES([LIBAVCODEC], [libavcodec], [:], [ac_cv_my_have_ffmpeg=no])
PKG_CHECK_MODULES([LIBAVUTIL], [libavutil], [:], [ac_cv_my_have_ffmpeg=no])
PKG_CHECK_MODULES([LIBAVFORMAT], [libavformat], [:], [ac_cv_my_have_ffmpeg=no])
PKG_CHECK_MODULES([LIBSWSCALE], [libswscale], [:], [ac_cv_my_have_ffmpeg=no])
LOL_FFMPEG_EXTRA_LIBS=""
if test "${ac_cv_my_have_ffmpeg}" != "yes"; then
  ac_cv_my_have_ffmpeg="yes"
  AC_CHECK_HEADERS(libavcodec/avcodec.h, [:], [ac_cv_my_have_ffmpeg=no])
  AC_CHECK_HEADERS(libavformat/avformat.h, [:], [ac_cv_my_have_ffmpeg=no])
  AC_CHECK_HEADERS(libswscale/swscale.h, [:], [ac_cv_my_have_ffmpeg=no])
  if test "${ac_cv_my_have_ffmpeg}" = "yes"; then
    LIBAVCODEC_LIBS="-lavcodec"
    LIBAVUTIL_LIBS="-lavutil"
    LIBAVFORMAT_LIBS="-lavformat"
    LIBSWSCALE_LIBS="-lswscale"
    LIBSWRESAMPLE_LIBS="-lswresample"
    dnl  Required by avformat/network.c
    AC_CHECK_LIB(ws2_32, main, LOL_FFMPEG_EXTRA_LIBS="${LOL_FFMPEG_EXTRA_LIBS} -lws2_32")
    dnl  Required by avformat/tls_schannel.c
    AC_CHECK_LIB(secur32, main, LOL_FFMPEG_EXTRA_LIBS="${LOL_FFMPEG_EXTRA_LIBS} -lsecur32")
    dnl  Required by avutil/random_seed.c
    AC_CHECK_LIB(bcrypt, main, LOL_FFMPEG_EXTRA_LIBS="${LOL_FFMPEG_EXTRA_LIBS} -lbcrypt")
    dnl  Required by avcodec/dxva2.c
    AC_CHECK_LIB(ole32, main, LOL_FFMPEG_EXTRA_LIBS="${LOL_FFMPEG_EXTRA_LIBS} -lole32")
  fi
fi
if test "${ac_cv_my_have_ffmpeg}" = "yes"; then
  AC_DEFINE(LOL_USE_FFMPEG, 1, Define to 1 to use FFmpeg)
  LOL_CFLAGS="${LOL_CFLAGS} ${LIBAVFORMAT_CFLAGS} ${LIBAVUTIL_CFLAGS} ${LIBAVCODEC_CFLAGS} ${LIBSWSCALE_CFLAGS}"
  LOL_LIBS="${LOL_LIBS} ${LIBAVFORMAT_LIBS} ${LIBAVCODEC_LIBS} ${LIBAVUTIL_LIBS} ${LIBSWSCALE_LIBS} ${LIBSWRESAMPLE_LIBS} ${LOL_FFMPEG_EXTRA_LIBS}"
fi

]) # LOL_AC_CHECK_FFMPEG_INNER

