#!/bin/bash

# This script reads filenames from STDIN and outputs any relevant provides
# information that needs to be included in the package.

if [ "$1" ]
then
   package_name="$1"
fi

[ -z "$OBJDUMP" ] && OBJDUMP=x86_64-w64-mingw32-objdump

filelist=`sed "s/['\"]/\\\&/g"`

dlls=$(echo $filelist | tr [:blank:] '\n' | grep '\.dll$')
pcs=$(echo $filelist | tr [:blank:] '\n' | grep '\.pc$')
implibs=$(echo $filelist | tr [:blank:] '\n' | grep '\.a$')

for f in $dlls; do
    basename=`basename $f | tr [:upper:] [:lower:]`
    echo "mingw64($basename)"
done

for g in $pcs; do
    dirname=`dirname $g`
	PKG_CONFIG_PATH=$dirname x86_64-w64-mingw32-pkg-config --print-errors --print-provides $g | awk '{ print "mingw64(pkg:"$1")", $2, $3 }'
done | sort -u

for h in $implibs; do
    libname=`basename $h | sed 's#^lib##g' | sed 's#\.dll\.#\.#g' | sed 's#\.a##g'`
	echo "mingw64(lib:$libname)"
done
