0c1e1f9
#!/bin/bash
0c1e1f9
0c1e1f9
# This script reads filenames from STDIN and outputs any relevant provides
0c1e1f9
# information that needs to be included in the package.
0c1e1f9
0c1e1f9
[ -z "$OBJDUMP" ] && OBJDUMP=mingw-objdump
0c1e1f9
0c1e1f9
targets=$@
0c1e1f9
if [ -z "$targets" ] ; then
0c1e1f9
    echo "Usage: $0 [ mingw32 ] [ mingw64 ]"
0c1e1f9
    exit 1
0c1e1f9
fi
0c1e1f9
0c1e1f9
# Get the list of files.
0c1e1f9
0c1e1f9
filelist=`sed "s/['\"]/\\\&/g"`
0c1e1f9
0c1e1f9
dlls=$(echo $filelist | tr [:blank:] '\n' | grep -Ei '\.(dll|exe)$')
ba33411
pkgconfig_files=$(echo $filelist | tr [:blank:] '\n' | grep -Ei '\.(pc)$')
0c1e1f9
0c1e1f9
for target in $targets; do
0c1e1f9
	dll_found=false
0c1e1f9
	host_triplet=`rpm --eval "%{${target}_target}"`
0c1e1f9
	for f in $dlls; do
0c1e1f9
		if [[ $f =~ .*$host_triplet.* ]]; then
0c1e1f9
			$OBJDUMP -p $f | grep 'DLL Name' | grep -Eio '[-._\+[:alnum:]]+\.dll' |
0c1e1f9
				tr [:upper:] [:lower:] |
0c1e1f9
				sed "s/\(.*\)/$target(\1)/"
0c1e1f9
			dll_found=true
0c1e1f9
		fi
0c1e1f9
	done
ba33411
0c1e1f9
	# Add a dependency on filesystem and crt if necessary
0c1e1f9
	if [ $dll_found = true ]; then
d6d7154
		echo "${target}-filesystem >= 95"
0c1e1f9
		echo "${target}-crt"
0c1e1f9
	fi
ba33411
ba33411
	pkgconfig_files_found=false
ba33411
	for f in $pkgconfig_files; do
ba33411
		if [[ $f =~ .*$host_triplet.* ]]; then
ba33411
			pkgconfig_files_found=true
ba33411
		fi
ba33411
	done
ba33411
ba33411
	# Add a dependency on $target-pkg-config if necessary
ba33411
	if [ $pkgconfig_files_found = true ]; then
ba33411
		echo "${target}-pkg-config"
ba33411
	fi
0c1e1f9
done | sort -u