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