e394c79
#!/bin/bash
e394c79
#
e394c79
# mono-find-requires
e394c79
#
e394c79
# Authors:
e394c79
#       Ben Maurer (bmaurer@ximian.com)
e394c79
#
e394c79
# (C) 2005 Novell (http://www.novell.com)
e394c79
#
e394c79
# Args: builddir buildroot libdir
e394c79
e394c79
IFS=$'\n'
e394c79
filelist=($(grep -Ev '/usr/doc/|/usr/share/doc/'))
e394c79
monolist=($(printf "%s\n" "${filelist[@]}" | egrep "\\.(exe|dll)\$"))
e394c79
e394c79
# If monodis is in the package being installed, use that one
e394c79
# This is to support building mono
e394c79
build_bindir="$2/usr/bin"
e394c79
build_libdir="$2$3"
e394c79
e394c79
if [ -x $build_bindir/monodis ]; then
e394c79
    monodis="$build_bindir/monodis"
e394c79
    export LD_LIBRARY_PATH=$build_libdir${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
e394c79
elif [ -x /usr/bin/monodis ]; then
e394c79
    monodis="/usr/bin/monodis"
e394c79
else
e394c79
    exit 0;
e394c79
fi
e394c79
e394c79
export MONO_SHARED_DIR=$1
e394c79
e394c79
REQUIRES=$(
e394c79
	for i in "${monolist[@]}"; do
e394c79
		($monodis --assemblyref $i | awk '
e394c79
			BEGIN { START=0; LIBNAME=""; VERSION=""; }
e394c79
			(START==0) && /^[0-9]+: Version=/ {
e394c79
				START=1;
e394c79
				sub(/Version=/, "", $2);
e394c79
				VERSION=$2
e394c79
			}
e394c79
	
e394c79
			(START==1) && /^\tName=/ {
e394c79
				sub(/Name=/, "", $1);
e394c79
				LIBNAME=$1
e394c79
	
e394c79
				print "mono(" LIBNAME ") = " VERSION
e394c79
				START=0
e394c79
			}
e394c79
		    ') 2> /dev/null
e394c79
	done
e394c79
)
e394c79
e394c79
PROVIDES=$(
e394c79
	for i in "${monolist[@]}"; do
e394c79
		($monodis --assembly $i | awk '
e394c79
			BEGIN { LIBNAME=""; VERSION=""; }
e394c79
			/^Version:/ { VERSION=$2 }
e394c79
			/^Name:/    { LIBNAME=$2 }
e394c79
			END {
e394c79
				if (VERSION && LIBNAME)
e394c79
					print "mono(" LIBNAME ") = " VERSION
e394c79
			}
e394c79
		    ') 2>/dev/null
e394c79
	done
e394c79
)
e394c79
#
e394c79
# This is a little magic trick to get all REQUIRES that are not
e394c79
# in PROVIDES. While RPM functions correctly when such deps exist,
e394c79
# they make the metadata a bit bloated.
e394c79
#
e394c79
e394c79
# Filter out dups from both lists
e394c79
REQUIRES=$(echo "$REQUIRES" | sort | uniq)
e394c79
PROVIDES=$(echo "$PROVIDES" | sort | uniq)
e394c79
e394c79
#
e394c79
# Get a list of elements that exist in exactly one of PROVIDES or REQUIRES
e394c79
#
e394c79
UNIQ=$(echo "$PROVIDES
e394c79
$REQUIRES" | sort | uniq -u)
e394c79
e394c79
#
e394c79
# Of those, only chose the ones that are in REQUIRES
e394c79
#
e394c79
echo "$UNIQ
e394c79
$REQUIRES" | sort | uniq -d