#!/usr/bin/bash
# ff-c++ `./ff-get-dep -ff metis.cpp`
#  add stuff to remove double , -Wl,-rpath, -L*, -l*   in link ...  F. Hecht 8/4/25 
#  suppose [[  ]]  works ..
case "$1" in
    -dlib)
	shift
	awk -F:  '/^[\/]+ff-c[+][+]-LIBRARY-dep:/  { printf("%s",$2); exit 0;}' $@
	exit 0; 
	;;
    -dcpp)
	shift
	awk -F:  '/^[\/]+ff-c[+][+]-cpp-dep:/  { if( $2 ~ /[ \n\r]*/) printf("%s",$2); exit 0;}' $@
	exit 0; 
	;;
    -ff)
	shift;
#  ajout  de lib  with check
	libs=`$0 -dlib $@`
	cpp=`$0 -dcpp $@`" $@"
	;;
esac 
dircommand=`dirname $0`
if [   -f "WHERE_LIBRARY-download" ] ; then
    dirwhere="./"
elif [   -f "$dircommand/WHERE_LIBRARY-download" ] ; then
    dirwhere=$dircommand
elif [ -f '/usr/lib64/ff++/4.16/lib/WHERE_LIBRARY-download' ] ; then
    dirwhere='/usr/lib64/ff++/4.16/lib'
else
   echo " error no WHERE_LIBRARY  file "
   exit 1;
fi
cd "$dirwhere"
wherel=''
test -f WHERE_LIBRARY && wherel="$wherel WHERE_LIBRARY"
test -f WHERE_LIBRARY-config && wherel="$wherel  WHERE_LIBRARY-config"
test -f WHERE_LIBRARY-download && wherel="$wherel  WHERE_LIBRARY-download"
awk -f ff-get-dep.awk -v libs="$libs"  -v cpp="$cpp" $wherel |  for i in `cat -`; do ii="i";case "$i" in -Wl,-rpath,*|.-[Ll]*) k=$i; [[ "$j" == *"$i"* ]] && k="";    j="$j:$k:"; test -n "$k" &&  echo $k ;; *) echo $i;; esac;  done
exit $?
