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