#!/bin/sh
#
# libplayer configure script - (c) 2006 Benjamin Zores
#
#  (fully inspirated from ffmpeg configure script, thanks to Fabrice Bellard
#                    from omc configure script, thanks to Alexis Saettler)
#

# make sure we are running under a compatible shell
unset foo
(: ${foo%%bar}) 2>/dev/null && ! (: ${foo?}) 2>/dev/null
if test "$?" != 0; then
    if test "x$OMC_CONFIGURE_EXEC" = x; then
        OMC_CONFIGURE_EXEC=1
        export OMC_CONFIGURE_EXEC
        exec bash "$0" "$@"
        exec ksh "$0" "$@"
        exec /usr/xpg4/bin/sh "$0" "$@"
    fi
    echo "No compatible shell script interpreter found."
    exit 1
fi

show_help(){
  echo "Usage: configure [options]"
  echo "Options: [defaults in brackets after descriptions]"
  echo
  echo "Standard options:"
  echo "  --help                      print this message"
  echo "  --log[=FILE|yes|no]         log tests and output to FILE [config.log]"
  echo "  --prefix=PREFIX             install in PREFIX [$PREFIX]"
  echo "  --bindir=DIR                install bins in DIR [PREFIX/bin]"
  echo "  --libdir=DIR                install libs in DIR [PREFIX/lib]"
  echo "  --includedir=DIR            install includes in DIR [PREFIX/include]"
  echo "  --docdir=DIR                install docs in DIR [PREFIX/share/doc]"
  echo "  --enable-static             build static libraries [default=yes]"
  echo "  --disable-static            do not build static libraries [default=no]"
  echo "  --enable-shared             build shared libraries [default=yes]"
  echo "  --disable-shared            do not build shared libraries [default=no]"
  echo ""
  echo "Wrappers options:"
  echo "  --enable-gstreamer          build GStreamer wrapper"
  echo "  --disable-gstreamer         do not build GStreamer wrapper"
  echo "  --enable-mplayer            build MPlayer wrapper"
  echo "  --disable-mplayer           do not build MPlayer wrapper"
  echo "  --enable-vlc                build VLC wrapper"
  echo "  --disable-vlc               do not build VLC wrapper"
  echo "  --enable-xine               build xine wrapper"
  echo "  --disable-xine              do not build xine wrapper"
  echo ""
  echo "Optional features:"
  echo "  --enable-binding-python     build Python bindings"
  echo ""
  echo "Search paths:"
  echo "  --with-gstreamer-dir=DIR    check for libgstreamer installed in DIR"
  echo "  --with-vlc-dir=DIR          check for libvlc installed in DIR"
  echo "  --with-xine-dir=DIR         check for libxine installed in DIR"
  echo "  --with-X11-dir=DIR          check for libX11 installed in DIR"
  echo ""
  echo "Advanced options (experts only):"
  echo "  --disable-debug             disable debugging symbols"
  echo "  --disable-strip             disable stripping of executables at installation"
  echo "  --disable-optimize          disable compiler optimization"
  echo "  --cross-prefix=PREFIX       use PREFIX for compilation tools [$cross_prefix]"
  echo "  --cross-compile             assume a cross-compiler is used"
  echo "  --disable-x11               disable X11 support"
  echo ""
  echo "Miscellaneous:"
  echo "  --disable-logcolor          disable colorful console output on terminals"
  echo "  --enable-doc                build Doxygen documentation"
  exit 1
}

log(){
    echo "$@" >>$logfile
}

log_file(){
    log BEGIN $1
    cat -n $1 >>$logfile
    log END $1
}

echolog(){
    log "$@"
    echo "$@"
}

clean(){
    rm -f $TMPC $TMPO $TMPE $TMPS
}

die(){
    echolog "$@"
    if enabled logging; then
      echo "See file \"$logfile\" produced by configure for more details."
    else
      echo "Rerun configure with logging enabled (do not use --log=no) for more details."
    fi
    clean
    exit 1
}

enabled(){
    eval test "x\$$1" = "xyes"
}

flags_saved(){
    (: ${SAVE_CFLAGS?}) 2>/dev/null
}

save_flags(){
    flags_saved && return
    SAVE_CFLAGS="$CFLAGS"
    SAVE_extracflags="$extracflags"
    SAVE_LDFLAGS="$LDFLAGS"
    SAVE_extralibs="$extralibs"
}

restore_flags(){
    CFLAGS="$SAVE_CFLAGS"
    extracflags="$SAVE_extracflags"
    LDFLAGS="$SAVE_LDFLAGS"
    extralibs="$SAVE_extralibs"
    unset SAVE_CFLAGS
    unset SAVE_extracflags
    unset SAVE_LDFLAGS
    unset SAVE_extralibs
}

temp_cflags(){
    temp_append CFLAGS "$@"
}

temp_extracflags(){
    temp_append extracflags "$@"
}

temp_ldflags(){
    temp_append LDFLAGS "$@"
}

temp_extralibs(){
    temp_append extralibs "$@"
}

temp_append(){
    local var
    var=$1
    shift
    save_flags
    append_var "$var" "$@"
}

append_var(){
    local var f
    var=$1
    shift
    for f in $@; do
      if eval echo \$$var | grep -qv -e "$f"; then
        test -n "$(eval echo \$$var)" && eval "$var=\"\$$var $f\"" || eval "$var=\"$f\""
      fi
    done
}

append(){
    local var
    var=$1
    shift
    flags_saved && append_var "SAVE_$var" "$@"
    append_var "$var" "$@"
}

add_cflags(){
    append CFLAGS "$@"
}

add_extracflags(){
    append extracflags "$@"
}

add_ldflags(){
    append LDFLAGS "$@"
}

add_extralibs(){
    append extralibs "$@"
}

add_pkgconfig_requires(){
    append pkgconfig_requires "$@"
}

check_cmd(){
    log "$@"
    "$@" >>$logfile 2>&1
}

check_cc(){
    log check_cc "$@"
    cat >$TMPC
    log_file $TMPC
    check_cmd $cc $CFLAGS "$@" -c -o $TMPO $TMPC
}

check_cpp(){
    log check_cpp "$@"
    cat >$TMPC
    log_file $TMPC
    check_cmd $cc $CFLAGS "$@" -E -o $TMPO $TMPC
}

check_ld(){
    log check_ld "$@"
    check_cc || return
    check_cmd $cc $LDFLAGS "$@" -o $TMPE $TMPO $extralibs
}

check_exec(){
    check_ld "$@" && { enabled cross_compile || $TMPE >>$logfile 2>&1; }
}

check_cflags(){
    log check_cflags "$@"
    check_cc "$@" <<EOF && add_cflags "$@"
int x;
EOF
}

check_ldflags(){
    log check_ldflags "$@"
    check_ld "$@" <<EOF && add_ldflags "$@"
int main(){
    return 0;
}
EOF
}

check_header(){
    local header
    log check_header "$@"
    header=$1
    shift
    check_cpp "$@" <<EOF
#include <$header>
int x;
EOF
}

check_func(){
    local func
    log check_func "$@"
    func=$1
    shift
    check_ld "$@" <<EOF
extern int $func();
int main(){
    $func();
    return 0;
}
EOF
}

check_lib(){
    local header func err
    log check_lib "$@"
    header="$1"
    func="$2"
    shift 2
    temp_extralibs "$@"
    check_header $header && check_func $func && add_extralibs "$@"
    err=$?
    restore_flags
    return $err
}

check_libconfig(){
    local config func ccflags clibs err
    log check_libconfig "$@"
    config="$1"
    func="$2"
    ccflags="${3:---cflags}"
    clibs="${4:---libs}"
    err=1
    if `which "$config" 1>/dev/null 2>&1`; then
      cflags=`$config $ccflags`
      [ -n "$cflags" ] && check_cflags "$cflags"
      libs=`$config $clibs`
      if [ -n "$libs" ]; then
        temp_extralibs "$libs"
        check_func $func && add_extralibs "$libs"
        err=$?
        restore_flags
      fi
    fi
    return $err
}

check_libconfig_exists(){
    local config func ccflags clibs err
    log check_libconfig_exists "$@"
    config="$1"
    func="$2"
    ccflags="${3:---cflags}"
    clibs="${4:---libs}"
    err=1
    if `which "$config" 1>/dev/null 2>&1`; then
      cflags=`$config $ccflags`
      [ -n "$cflags" ] && temp_cflags "$cflags"
      libs=`$config $clibs`
      if [ -n "$libs" ]; then
        temp_extralibs "$libs"
        check_func $func
        err=$?
        restore_flags
      fi
    fi
    return $err
}

append_config(){
    echo "$@" >> $CONFIGFILE
}

pkgconfig_generate(){
    name=$1
    comment=$2
    version=$3
    libs=$4
    libs_private=$5
    cflags=$6
    requires=$7
    requires_private=$8

    cat <<EOF >$name.pc
PREFIX=$PREFIX
libdir=$libdir
includedir=$includedir

Name: $name
Description: $comment
Version: $version
Requires: $requires
Requires.private: $requires_private
Conflicts:
Libs: -L\${libdir} $libs
Libs.private: $libs_private
Cflags: -I\${includedir} $cflags
EOF
}

# set temporary file name
if test ! -z "$TMPDIR" ; then
    TMPDIR1="${TMPDIR}"
elif test ! -z "$TEMPDIR" ; then
    TMPDIR1="${TEMPDIR}"
else
    TMPDIR1="/tmp"
fi

TMPC="${TMPDIR1}/libplayer-${RANDOM}-$$-${RANDOM}.c"
TMPO="${TMPDIR1}/libplayer-${RANDOM}-$$-${RANDOM}.o"
TMPE="${TMPDIR1}/libplayer-${RANDOM}-$$-${RANDOM}"
TMPS="${TMPDIR1}/libplayer-${RANDOM}-$$-${RANDOM}.S"

CONFIGFILE="config.mak"

#################################################
#   set default parameters
#################################################
logging="yes"
logfile="config.log"
PREFIX="/usr/local"
bindir='${PREFIX}/bin'
libdir='${PREFIX}/lib'
includedir='${PREFIX}/include'
docdir='${PREFIX}/share/doc'
static="yes"
shared="yes"
cc="gcc"
ar="ar"
ranlib="ranlib"
make="make"
strip="strip"
cpu=`uname -m`
optimize="yes"
debug="yes"
dostrip="yes"
extralibs=""
installstrip="-s"
cross_compile="no"
wrapper_xine="auto"
wrapper_mplayer="auto"
wrapper_vlc="auto"
wrapper_gstreamer="auto"
binding_python="auto"
x11="auto"
INSTALL="install"
libplayer_version=`grep '#define LIBPLAYER_VERSION[[:space:]]' src/player.h | sed 's/[^0-9\.]//g'`
pkgconfig_requires=""
logcolor="yes"
doc="no"

#################################################
#   set cpu variable and specific cpu flags
#################################################
case "$cpu" in
  i386|i486|i586|i686|i86pc|BePC)
    cpu="x86"
  ;;
  x86_64|amd64)
    cpu="x86"
    canon_arch="`$cc -dumpmachine | sed -e 's,\([^-]*\)-.*,\1,'`"
    if [ x"$canon_arch" = x"x86_64" -o x"$canon_arch" = x"amd64" ]; then
      if [ -z "`echo $CFLAGS | grep -- -m32`"  ]; then
        cpu="x86_64"
      fi
    fi
  ;;
# armv4l is a subset of armv5tel
  arm|armv4l|armv5tel)
    cpu="armv4l"
  ;;
  alpha)
    cpu="alpha"
  ;;
  "Power Macintosh"|ppc|ppc64|powerpc)
    cpu="powerpc"
  ;;
  mips|mipsel|IP*)
    cpu="mips"
  ;;
  sun4u|sparc64)
    cpu="sparc64"
  ;;
  sparc)
    cpu="sparc"
  ;;
  sh4)
    cpu="sh4"
  ;;
  parisc|parisc64)
    cpu="parisc"
  ;;
  s390|s390x)
    cpu="s390"
  ;;
  m68k)
    cpu="m68k"
  ;;
  ia64)
    cpu="ia64"
  ;;
  bfin)
    cpu="bfin"
  ;;
  *)
    cpu="unknown"
  ;;
esac


#################################################
#   check options
#################################################
for opt do
  optval="${opt#*=}"
  case "$opt" in
  --log)
  ;;
  --log=*) logging="$optval"
  ;;
  --prefix=*) PREFIX="$optval"; force_prefix=yes
  ;;
  --bindir=*) bindir="$optval"
  ;;
  --libdir=*) libdir="$optval"; force_libdir=yes
  ;;
  --includedir=*) includedir="$optval"
  ;;
  --docdir=*) docdir="$optval"; force_docdir=yes
  ;;
  --enable-static) static="yes"
  ;;
  --disable-static) static="no"
  ;;
  --enable-shared) shared="yes"
  ;;
  --disable-shared) shared="no"
  ;;
  --enable-debug) debug="yes"
  ;;
  --disable-debug) debug="no"
  ;;
  --enable-strip) dostrip="yes"
  ;;
  --disable-strip) dostrip="no"
  ;;
  --enable-optimize) optimize="yes"
  ;;
  --disable-optimize) optimize="no"
  ;;
  --cross-prefix=*) cross_prefix="$optval"
  ;;
  --cross-compile) cross_compile="yes"
  ;;
  --enable-xine) wrapper_xine="yes";
  ;;
  --disable-xine) wrapper_xine="no";
  ;;
  --enable-binding-python) binding_python="yes";
  ;;
  --disable-binding-python) binding_python="no";
  ;;
  --with-xine-dir=*) libxinedir="$optval";
  ;;
  --enable-mplayer) wrapper_mplayer="yes";
  ;;
  --disable-mplayer) wrapper_mplayer="no";
  ;;
  --enable-vlc) wrapper_vlc="yes";
  ;;
  --disable-vlc) wrapper_vlc="no";
  ;;
  --with-vlc-dir=*) libvlcdir="$optval";
  ;;
  --enable-gstreamer) wrapper_gstreamer="yes";
  ;;
  --disable-gstreamer) wrapper_gstreamer="no";
  ;;
  --with-gstreamer-dir=*) libgstreamerdir="$optval";
  ;;
  --with-X11-dir=*) libX11dir="$optval";
  ;;
  --enable-x11) x11="yes";
  ;;
  --disable-x11) x11="no";
  ;;
  --enable-logcolor) logcolor="yes";
  ;;
  --disable-logcolor) logcolor="no";
  ;;
  --enable-doc) doc="yes";
  ;;
  --disable-doc) doc="no";
  ;;
  --help) show_help
  ;;
  *)
  echo "Unknown option \"$opt\"."
  echo "See $0 --help for available options."
  exit 1
  ;;
  esac
done

# Check for conflictual build options
if [ "$shared" = no -a "$static" = no ]; then
  echo "At least one library type must be built."
  echo "Specify --enable-static to build the static libraries or"
  echo "--enable-shared to build the shared libraries as well."
  exit 1
fi

if [ -n "$cross_prefix" ]; then
  cross_compile="yes"
  cc="${cross_prefix}${cc}"
  ar="${cross_prefix}${ar}"
  ranlib="${cross_prefix}${ranlib}"
  strip="${cross_prefix}${strip}"
else
  [ -n "$CC" ] && cc="$CC"
  [ -n "$AR" ] && ar="$AR"
  [ -n "$RANLIB" ] && ranlib="$RANLIB"
  [ -n "$STRIP" ] && strip="$STRIP"
fi
[ -n "$MAKE" ] && make="$MAKE"

#################################################
#   create logging file
#################################################
if test "$logging" != no; then
  enabled logging || logfile="$logging"
  echo "# $0 $@" >$logfile
  set >>$logfile
else
  logfile=/dev/null
fi


#################################################
#   compiler sanity check
#################################################
echolog "Checking for compiler available..."
check_exec <<EOF
int main(){
    return 0;
}
EOF
if test "$?" != 0; then
  echo "$cc is unable to create an executable file."
  if test -z "$cross_prefix" -a "$cross_compile" = no; then
    echo "If $cc is a cross-compiler, use the --cross-compile option."
  fi
  die "C compiler test failed."
fi


#################################################
#   check for target specific flags
#################################################
# check for SIMD availability

# AltiVec flags: The FSF version of GCC differs from the Apple version
if test $cpu = "powerpc"; then
  if test $altivec = "yes"; then
    if test -n "`$cc -v 2>&1 | grep version | grep Apple`"; then
      add_cflags "-faltivec"
    else
      add_cflags "-maltivec -mabi=altivec"
    fi
  fi
fi

check_header altivec.h && _altivec_h=yes || _altivec_h=no

# check if our compiler supports Motorola AltiVec C API
if enabled altivec; then
  if enabled _altivec_h; then
    inc_altivec_h="#include <altivec.h>"
  else
    inc_altivec_h=
  fi
  check_cc <<EOF || altivec=no
$inc_altivec_h
int main(void) {
    vector signed int v1, v2, v3;
    v1 = vec_add(v2,v3);
    return 0;
}
EOF
fi

# mmi only available on mips
if [ "$mmi" = "default" ]; then
  if [ "$cpu" = "mips" ]; then
    mmi="yes"
  else
    mmi="no"
  fi
fi

# check if our compiler supports mmi
enabled mmi && check_cc <<EOF || mmi="no"
int main(void) {
    __asm__ ("lq \$2, 0(\$2)");
    return 0;
}
EOF

# test gcc version to see if vector builtins can be used
# currently only used on i386 for MMX builtins
check_cc -msse <<EOF && builtin_vector=yes || builtin_vector=no
#include <xmmintrin.h>
int main(void) {
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)
return 0;
#else
#error no vector builtins
#endif
}
EOF

# test for mm3dnow.h
test "$cpu" = "x86_64" && march=k8 || march=athlon
check_cc -march=$march <<EOF && mm3dnow=yes || mm3dnow=no
#include <mm3dnow.h>
int main(void) {
__m64 b1;
b1 = _m_pswapd(b1);
_m_femms();
return 0;
}
EOF

# ---
# big/little-endian test
if test "$cross_compile" = "no"; then
  check_ld <<EOF || die "endian test failed" && $TMPE && bigendian="yes"
#include <inttypes.h>
int main(int argc, char ** argv){
        volatile uint32_t i=0x01234567;
        return (*((uint8_t*)(&i))) == 0x67;
}
EOF
else
# programs cannot be launched if cross compiling, so make a static guess
  if test "$cpu" = "powerpc" -o "$cpu" = "mips" ; then
    bigendian="yes"
  fi
fi

# add some useful compiler flags if supported
check_cflags -W
check_cflags -Wall
check_cflags -D_LARGEFILE_SOURCE
check_cflags -D_FILE_OFFSET_BITS=64
check_cflags -D_REENTRANT

# default extralibs
add_extralibs -lpthread
add_extralibs -lm

#################################################
#   check for debug symbols
#################################################
if enabled debug; then
  add_cflags -g3 -O0
  add_cflags -DHAVE_DEBUG
  optimize="no"
fi

if enabled optimize; then
  if test -n "`$cc -v 2>&1 | grep xlc`"; then
    add_cflags  "-O5"
    add_ldflags "-O5"
  else
    add_cflags "-O3"
  fi
fi

#################################################
#   check for shared library build
#################################################
if enabled shared; then
  case "$cpu" in
    x86_64|ia64|alpha|sparc*|power*) add_cflags "-fPIC" ;;
  esac
fi

#################################################
#   check for libxine
#################################################
if test "$wrapper_xine" = "auto" -o "$wrapper_xine" = "yes"; then
  wrapper_xine="no"
  echolog "Checking for libxine ..."
  if [ -n "$libxinedir" ]; then
    check_cflags -I$libxinedir/include
    check_ldflags -L$libxinedir/lib
  fi
  check_lib xine.h xine_init -lxine
  if [ "$?" = 0 ]; then
    add_extracflags -DHAVE_XINE
    add_pkgconfig_requires libxine
    wrapper_xine="yes"
  fi
fi

#################################################
#   check for mplayer
#################################################
if test "$wrapper_mplayer" = "auto"; then
  wrapper_mplayer="no"
  echolog "Checking for MPlayer ..."
  which mplayer 2>&1 > /dev/null
  if [ "$?" = 0 ]; then
    wrapper_mplayer="yes"
  fi
fi
if test "$wrapper_mplayer" = "yes"; then
  add_extracflags -DHAVE_MPLAYER
  add_extralibs -lm
fi

#################################################
#   check for libvlc
#################################################
if test "$wrapper_vlc" = "auto" -o "$wrapper_vlc" = "yes"; then
  wrapper_vlc="no"
  echolog "Checking for libvlc ..."
  if [ -n "$libvlcdir" ]; then
    check_cflags -I$libvlcdir/include
    check_ldflags -L$libvlcdir/lib
  fi
  check_lib vlc/vlc.h libvlc_media_new -lvlc
  if [ "$?" = 0 ]; then
    add_extracflags -DHAVE_VLC
    wrapper_vlc="yes"
  fi
fi

#################################################
#   check for libgstreamer
#################################################
if test "$wrapper_gstreamer" = "auto" -o "$wrapper_gstreamer" = "yes"; then
  wrapper_gstreamer="no"
  echolog "Checking for libgstreamer ..."
  check_cflags `pkg-config gstreamer-0.10 --cflags`
  check_ldflags `pkg-config gstreamer-0.10 --libs`
  if [ -n "$libgstreamerdir" ]; then
    check_cflags -I$libgstreamerdir/include
    check_ldflags -L$libgstreamerdir/lib
  fi
  check_lib gst/gst.h gst_init -lgstreamer-0.10
  if [ "$?" = 0 ]; then
    add_extracflags -DHAVE_GSTREAMER
    add_pkgconfig_requires gstreamer-0.10
    wrapper_gstreamer="yes"
  fi
fi

#################################################
#   check for libX11
#################################################
if test "$x11" = "auto" -o "$x11" = "yes"; then
  if test "$wrapper_xine" = "yes" -o "$wrapper_mplayer" = "yes"; then
    x11="no"
    echolog "Checking for libX11 ..."
    if [ -n "$libX11dir" ]; then
      check_cflags -I$libX11dir/include
      check_ldflags -L$libX11dir/lib
    fi
    check_lib X11/X.h XInitThreads -lX11
    if [ "$?" = 0 ]; then
      add_extracflags -DUSE_X11
      add_pkgconfig_requires x11
      x11="yes"
    fi
  fi
fi

#################################################
#   check for Python
#################################################
if test "$binding_python" = "auto" -o "$binding_python" = "yes"; then
  binding_python="no"
  echolog "Checking for Python ..."
  check_libconfig_exists python-config _PyObject_New
  [ "$?" = 0 ] && binding_python="yes"
fi

#################################################
#   Miscellaneous
#################################################
if enabled logcolor; then
  add_cflags -DUSE_LOGCOLOR
fi

# Doxygen
if enabled doc; then
  doc="no"
  which doxygen 2>&1 > /dev/null
  [ "$?" = 0 ] && doc="yes"
fi

#################################################
#   logging result
#################################################
echolog ""
echolog "libplayer: configure is OK"
echolog "  version            $libplayer_version"
echolog "configuration:"
echolog "  install prefix     $PREFIX"
echolog "  C compiler         $cc"
echolog "  AR                 $ar"
echolog "  RANLIB             $ranlib"
echolog "  STRIP              $strip"
echolog "  make               $make"
echolog "  CPU                $cpu"
echolog "  debug symbols      $debug"
echolog "  strip symbols      $dostrip"
echolog "  optimize           $optimize"
echolog "  static             ${static}"
echolog "  shared             ${shared}"
echolog ""
echolog "  CFLAGS             $CFLAGS $extracflags"
echolog "  LDFLAGS            $LDFLAGS"
echolog "  extralibs          $extralibs"
echolog ""
echolog "built-in wrappers:"
echolog "  GStreamer:         $wrapper_gstreamer"
echolog "  MPlayer:           $wrapper_mplayer"
echolog "  VLC:               $wrapper_vlc"
echolog "  xine:              $wrapper_xine"
echolog ""
echolog "Bindings:"
echolog "  Python:            $binding_python"
echolog ""
echolog "Miscellaneous:"
echolog "  X11 support:       $x11"
echolog "  Documentation:     $doc"
echolog ""

#################################################
#   save configs attributes
#################################################
echolog "Creating config.mak ..."

echo "# Automatically generated by configure - do not modify!" > $CONFIGFILE

append_config "PREFIX=$PREFIX"
append_config "prefix=\$(DESTDIR)\$(PREFIX)"
append_config "bindir=\$(DESTDIR)$bindir"
append_config "libdir=\$(DESTDIR)$libdir"
append_config "includedir=\$(DESTDIR)$includedir"
append_config "docdir=\$(DESTDIR)$docdir"

append_config "MAKE=$make"
append_config "CC=$cc"
append_config "AR=$ar"
append_config "RANLIB=$ranlib"
append_config "LN=ln"

append_config "BUILD_STATIC=$static"
append_config "BUILD_SHARED=$shared"

append_config "LIBPLAYER_VERSION=$libplayer_version"

if enabled dostrip; then
  append_config "STRIP=$strip"
  append_config "INSTALLSTRIP=$installstrip"
else
  append_config "STRIP=echo ignoring strip"
  append_config "INSTALLSTRIP="
fi
append_config "EXTRALIBS=$extralibs"

append_config "EXTRACFLAGS=$extracflags"
append_config "OPTFLAGS=$CFLAGS"
append_config "LDFLAGS=$LDFLAGS"
append_config "INSTALL=$INSTALL"

append_config "DEBUG=$debug"
append_config "WRAPPER_XINE=$wrapper_xine"
append_config "WRAPPER_MPLAYER=$wrapper_mplayer"
append_config "WRAPPER_VLC=$wrapper_vlc"
append_config "WRAPPER_GSTREAMER=$wrapper_gstreamer"
append_config "BINDING_PYTHON=$binding_python"
append_config "X11=$x11"
append_config "DOC=$doc"

#################################################
#   make pkg-config files
#################################################
echolog "Creating libplayer.pc ..."

pkgconfig_generate libplayer \
                   "A multimedia A/V abstraction layer library" \
                   "$libplayer_version" \
                   "-lplayer" \
                   "$extralibs" \
                   "-D_FILE_OFFSET_BITS=64" \
                   "" \
                   "$pkgconfig_requires"

clean
exit 0
