merged Sys.Web.Services 2.0 support in my branch:
[mono.git] / scripts / mono-find-requires.in
1 #!/bin/bash
2 #
3 # mono-find-requires
4 #
5 # Authors:
6 #       Ben Maurer (bmaurer@ximian.com)
7 #
8 # (C) 2005 Novell (http://www.novell.com)
9 #
10
11 IFS=$'\n'
12 filelist=($(grep -Ev '/usr/doc/|/usr/share/doc/'))
13 monolist=($(printf "%s\n" "${filelist[@]}" | egrep "\\.(exe|dll)\$"))
14
15 a=`which "$0"`
16 d=`dirname "$a"`
17
18 # Set the prefix, unless it is overriden (used when building mono rpms)
19 : ${prefix=$d/..}
20
21 exec_prefix=$d/..
22 libdir=$prefix/@reloc_libdir@
23 bindir=$d
24
25 # Bail out if monodis or libmono is missing
26 if [ ! -x $bindir/monodis ] || [ ! -f $libdir/libmono.so ] ; then
27         echo "monodis missing or unusable, exiting..."
28         exit 1
29 fi
30
31
32 # set LD_LIBRARY_PATH to ensure that libmono.so is found
33 export LD_LIBRARY_PATH=$libdir${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
34
35 REQUIRES=$(
36         for i in "${monolist[@]}"; do
37                 ($bindir/monodis --assemblyref $i | awk '
38                         BEGIN { START=0; LIBNAME=""; VERSION=""; }
39                         (START==0) && /^[0-9]+: Version=/ {
40                                 START=1;
41                                 sub(/Version=/, "", $2);
42                                 VERSION=$2
43                         }
44
45                         (START==1) && /^\tName=/ {
46                                 sub(/Name=/, "", $1);
47                                 LIBNAME=$1
48                                 # Allow rpm deps to be resolved for 1.0 profile version
49                                 if (VERSION=="1.0.3300.0")
50                                         OP=">="
51                                 else
52                                         OP="="
53                                 print "mono(" LIBNAME ") " OP " " VERSION
54                                 START=0
55                         }
56                     ') 2> /dev/null
57         done
58 )
59
60 PROVIDES=$(
61         for i in "${monolist[@]}"; do
62                 ($bindir/monodis --assembly $i | awk '
63                         BEGIN { LIBNAME=""; VERSION=""; }
64                         /^Version:/ { VERSION=$2 }
65                         /^Name:/    { LIBNAME=$2 }
66                         END {
67                                 if (VERSION && LIBNAME)
68                                         print "mono(" LIBNAME ") = " VERSION
69                         }
70                     ') 2>/dev/null
71         done
72 )
73 #
74 # This is a little magic trick to get all REQUIRES that are not
75 # in PROVIDES. While RPM functions correctly when such deps exist,
76 # they make the metadata a bit bloated.
77 #
78
79 # Filter out dups from both lists
80 REQUIRES=$(echo "$REQUIRES" | sort | uniq)
81 PROVIDES=$(echo "$PROVIDES" | sort | uniq)
82
83 #
84 # Get a list of elements that exist in exactly one of PROVIDES or REQUIRES
85 #
86 UNIQ=$(echo "$PROVIDES
87 $REQUIRES" | sort | uniq -u)
88
89 #
90 # Of those, only choose the ones that are in REQUIRES
91 #
92 echo "$UNIQ
93 $REQUIRES" | sort | uniq -d