#!/bin/bash

package=ffmpeg
version=-4.3.1

progname=$0

source ../cascade-make/lib/cascade-lib.bash GEXT_MARS ../.. $*

prefix=$GEXT_MARS_INSTALLED

export CFLAGS="$CFLAGS -fPIC"
export CXXFLAGS="$CXXFLAGS -fPIC"
export LDFLAGS="$LDFLAGS -fPIC"

export CFLAGS="$CFLAGS -I$GEXT_MARS_INSTALLED/include"
#export CPPFLAGS="$CPPFLAGS -I$GEXT_MARS_INSTALLED/include"
export CXXFLAGS="$CXXFLAGS -I$GEXT_MARS_INSTALLED/include"
export LDFLAGS="$LDFLAGS -L$GEXT_MARS_INSTALLED/lib"
#export LD_LIBRARY_PATH="$GEXT_MARS_INSTALLED/lib"

if [ "x$PKG_CONFIG_PATH" = "x" ] ; then
    export PKG_CONFIG_PATH="$GEXT_MARS_INSTALLED/lib/pkgconfig"
else
    export PKG_CONFIG_PATH="$GEXT_MARS_INSTALLED/lib/pkgconfig:$PKG_CONFIG_PATH"

fi

opt_run_untar $force_untar $auto_untar $package $version

# '--enable-shared' added in to help with -fPIC linking error in *chromaprint*
# Issue seems to be that -- despite having -fPIC on -- the libavcodec.a that
#   has been generated is *not* Position Independent Code (PIC), with the consequence
#   that when chromaprint tries to generate a '.so' file, it tries to link against
#   that libavcodec.a file, but then then produces the error about the file not
#   being PIC.
#
#   The file in question that is flagged (fft.o) within libavcodec.a is
#   itself generated from a x86/.asm (not .c) file.  It is not known
#   if this is a futher issue to content with or not.
#
#   An alternative strategy might be to look up how to prevent libchromaprint
#   (a cmake build) from generating .so files


#opt_run_configure $force_config $auto_config $package $version $prefix --enable-shared --enable-avresample --enable-pic
opt_run_configure $force_config $auto_config $package $version $prefix --disable-shared --enable-avresample --enable-pic

opt_run_make $compile $package $version
opt_run_make $install $package $version "install"
opt_run_make $clean $package $version "clean"
opt_run_make $distclean $package $version "distclean"

opt_run_tarclean $tarclean $package $version
