* scripts/mono-find-requires.in: add special 64bit case for ia64.
[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 # parse .config files to find which native libraries to depend on 
16 #  (target attribute must have double quotes for this to work, ie: target="file" )
17 # Add /etc/mono/config ?
18 configlist=($(printf "%s\n" "${filelist[@]}" | egrep "\\.config\$"))
19
20 # Set the prefix, unless it is overriden (used when building mono rpms)
21 : ${prefix=@prefix@}
22
23 libdir=$prefix/@reloc_libdir@
24 bindir=$prefix/bin
25
26 # Bail out if monodis or libmono is missing
27 if [ ! -x $bindir/monodis ] || [ ! -f $libdir/libmono.so ] ; then
28         echo "monodis missing or unusable, exiting..." 1>&2
29         exit 1
30 fi
31
32 # special case for 64bit archs
33 if test "x@reloc_libdir@" = "xlib64" ; then
34         libext="()(64bit)"
35 else
36         # (note, this works on ppc64 since we only have 32bit mono)
37         libext=""
38 fi
39
40 # Exceptions:
41 case `uname -m` in
42         # ia64 doesn't use lib64 for 'libdir' (sles 9 rpm used to provide both... no longer)
43         ia64)   libext="()(64bit)" ;;
44 esac
45
46 # set LD_LIBRARY_PATH to ensure that libmono.so is found
47 export LD_LIBRARY_PATH=$libdir${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
48
49 REQUIRES=$(
50         for i in "${monolist[@]}"; do
51                 ($bindir/monodis --assemblyref $i | awk '
52                         BEGIN { START=0; LIBNAME=""; VERSION=""; }
53                         (START==0) && /^[0-9]+: Version=/ {
54                                 START=1;
55                                 sub(/Version=/, "", $2);
56                                 VERSION=$2
57                         }
58
59                         (START==1) && /^\tName=/ {
60                                 sub(/Name=/, "", $1);
61                                 LIBNAME=$1
62                                 # Allow rpm deps to be resolved for 1.0 profile version
63                                 if (VERSION=="1.0.3300.0")
64                                         OP=">="
65                                 else
66                                         OP="="
67                                 print "mono(" LIBNAME ") " OP " " VERSION
68                                 START=0
69                         }
70                     ') 2> /dev/null
71         done
72         # Parse the xml .config files to see what native binaries we call into
73         # TODO: also check monodis --moduleref
74         for i in "${configlist[@]}"; do
75                 awk 'match($_, /<dllmap .*target=.*/) {
76                         ignore=0
77                         req=""
78                         split($_, toks, "\"")
79                         toks_size=0
80                         for(tok in toks) { toks_size++ }
81                         for(i=1; i <= toks_size; i++) {
82                                 if(toks[i] ~ /target=/) {
83                                         req=toks[i+1]
84                                 }
85                                 if(toks[i] ~ /os=/) {
86                                         negate=0
87                                         found=0
88
89                                         attr=toks[i+1]
90                                         if(attr ~ /^!/) {
91                                                 attr=substr(attr, 2, length(attr)-1)
92                                                 negate=1
93                                         }
94
95                                         split(attr, os_targets, ",")
96                                         os_targets_size=0
97                                         for(os_target in os_targets) { os_targets_size++ }
98                                         for(j=1; j <= os_targets_size; j++) {
99                                                 if(os_targets[j] == "linux") {
100                                                         found=1
101                                                 }
102                                         }
103
104                                         if(negate) {
105                                                 found=!found
106                                         }
107                                         if (!found) {
108                                                 ignore=1
109                                         } 
110                                 }
111                         }
112                         if(!ignore) {
113                                 system("rpm -q --whatprovides --queryformat \"%{NAME}\n\" ""\""req"'$libext'""\"")
114                         }
115                 } ' $i 2>/dev/null
116         done
117 )
118
119 # Note about above:
120 #  Use to do: system("rpm -q --whatprovides --queryformat \"%{NAME}\n\" ""\""req"'$libext'""\"")
121 #  rpmlint prefers to have lib names instead of package names.  There was a reason I was using package names but it slips me now...
122 #  Ah... now I remember... it's for noarch packs.  The noarch packages can be built on either 32 or 64 bit... so we have to depend
123 #   on the package name instead.
124
125 PROVIDES=$(
126         for i in "${monolist[@]}"; do
127                 ($bindir/monodis --assembly $i | awk '
128                         BEGIN { LIBNAME=""; VERSION=""; }
129                         /^Version:/ { VERSION=$2 }
130                         /^Name:/    { LIBNAME=$2 }
131                         END {
132                                 if (VERSION && LIBNAME)
133                                         print "mono(" LIBNAME ") = " VERSION
134                         }
135                     ') 2>/dev/null
136         done
137 )
138 #
139 # This is a little magic trick to get all REQUIRES that are not
140 # in PROVIDES. While RPM functions correctly when such deps exist,
141 # they make the metadata a bit bloated.
142 #
143
144 # Filter out dups from both lists
145 REQUIRES=$(echo "$REQUIRES" | sort | uniq)
146 PROVIDES=$(echo "$PROVIDES" | sort | uniq)
147
148 #
149 # Get a list of elements that exist in exactly one of PROVIDES or REQUIRES
150 #
151 UNIQ=$(echo "$PROVIDES
152 $REQUIRES" | sort | uniq -u)
153
154 #
155 # Of those, only choose the ones that are in REQUIRES
156 #
157 echo "$UNIQ
158 $REQUIRES" | sort | uniq -d