merge r67228-r67235, r67237, r67251 and r67256-67259 to trunk (they are
[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 [ -x $bindir/monodis ] || exit 0;
26 [ -f $libdir/libmono.so ] || exit 0;
27
28
29 # set LD_LIBRARY_PATH to ensure that libmono.so is found
30 export LD_LIBRARY_PATH=$libdir${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
31
32 REQUIRES=$(
33         for i in "${monolist[@]}"; do
34                 ($bindir/monodis --assemblyref $i | awk '
35                         BEGIN { START=0; LIBNAME=""; VERSION=""; }
36                         (START==0) && /^[0-9]+: Version=/ {
37                                 START=1;
38                                 sub(/Version=/, "", $2);
39                                 VERSION=$2
40                         }
41
42                         (START==1) && /^\tName=/ {
43                                 sub(/Name=/, "", $1);
44                                 LIBNAME=$1
45                                 # Allow rpm deps to be resolved for 1.0 profile version
46                                 if (VERSION=="1.0.3300.0")
47                                         OP=">="
48                                 else
49                                         OP="="
50                                 print "mono(" LIBNAME ") " OP " " VERSION
51                                 START=0
52                         }
53                     ') 2> /dev/null
54         done
55 )
56
57 PROVIDES=$(
58         for i in "${monolist[@]}"; do
59                 ($bindir/monodis --assembly $i | awk '
60                         BEGIN { LIBNAME=""; VERSION=""; }
61                         /^Version:/ { VERSION=$2 }
62                         /^Name:/    { LIBNAME=$2 }
63                         END {
64                                 if (VERSION && LIBNAME)
65                                         print "mono(" LIBNAME ") = " VERSION
66                         }
67                     ') 2>/dev/null
68         done
69 )
70 #
71 # This is a little magic trick to get all REQUIRES that are not
72 # in PROVIDES. While RPM functions correctly when such deps exist,
73 # they make the metadata a bit bloated.
74 #
75
76 # Filter out dups from both lists
77 REQUIRES=$(echo "$REQUIRES" | sort | uniq)
78 PROVIDES=$(echo "$PROVIDES" | sort | uniq)
79
80 #
81 # Get a list of elements that exist in exactly one of PROVIDES or REQUIRES
82 #
83 UNIQ=$(echo "$PROVIDES
84 $REQUIRES" | sort | uniq -u)
85
86 #
87 # Of those, only choose the ones that are in REQUIRES
88 #
89 echo "$UNIQ
90 $REQUIRES" | sort | uniq -d