2005-06-06 Ben Maurer <bmaurer@ximian.com>
[mono.git] / scripts / mono-find-requires.in
1 #!/bin/sh
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 # Set the prefix, unless it is overriden (used when building mono rpms)
16 : ${prefix=@prefix@}
17
18 exec_prefix=@exec_prefix@
19 libdir=@libdir@
20 bindir=@bindir@
21
22 [ -x $bindir/monodis ] || exit 0;
23 [ -f $libdir/libmono.so ] || exit 0;
24
25
26 # set LD_LIBRARY_PATH to ensure that libmono.so is found
27 export LD_LIBRARY_PATH=$libdir${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
28
29 REQUIRES=$(
30         for i in "${monolist[@]}"; do
31                 ($bindir/monodis --assemblyref $i | awk '
32                         BEGIN { START=0; LIBNAME=""; VERSION=""; }
33                         (START==0) && /^[0-9]+: Version=/ {
34                                 START=1;
35                                 sub(/Version=/, "", $2);
36                                 VERSION=$2
37                         }
38         
39                         (START==1) && /^\tName=/ {
40                                 sub(/Name=/, "", $1);
41                                 LIBNAME=$1
42         
43                                 print "mono(" LIBNAME ") = " VERSION
44                                 START=0
45                         }
46                     ') 2> /dev/null
47         done
48 )
49
50 PROVIDES=$(
51         for i in "${monolist[@]}"; do
52                 ($bindir/monodis --assembly $i | awk '
53                         BEGIN { LIBNAME=""; VERSION=""; }
54                         /^Version:/ { VERSION=$2 }
55                         /^Name:/    { LIBNAME=$2 }
56                         END {
57                                 if (VERSION && LIBNAME)
58                                         print "mono(" LIBNAME ") = " VERSION
59                         }
60                     ') 2>/dev/null
61         done
62 )
63 #
64 # This is a little magic trick to get all REQUIRES that are not
65 # in PROVIDES. While RPM functions correctly when such deps exist,
66 # they make the metadata a bit bloated.
67 #
68
69 # Filter out dups from both lists
70 REQUIRES=$(echo "$REQUIRES" | sort | uniq)
71 PROVIDES=$(echo "$PROVIDES" | sort | uniq)
72
73 #
74 # Get a list of elements that exist in exactly one of PROVIDES or REQUIRES
75 #
76 UNIQ=$(echo "$PROVIDES
77 $REQUIRES" | sort | uniq -u)
78
79 #
80 # Of those, only chose the ones that are in REQUIRES
81 #
82 echo "$UNIQ
83 $REQUIRES" | sort | uniq -d