2007-06-15 Wade Berrier <wberrier@novell.com>
[mono.git] / scripts / mono-find-requires.in
index c2b8832f95674a575135d95cc768ae4528ebcacf..63e3c03a6f37500f6b2ff97e2d57aebff687cbb4 100644 (file)
@@ -12,19 +12,29 @@ IFS=$'\n'
 filelist=($(grep -Ev '/usr/doc/|/usr/share/doc/'))
 monolist=($(printf "%s\n" "${filelist[@]}" | egrep "\\.(exe|dll)\$"))
 
-a=`which "$0"`
-d=`dirname "$a"`
+# parse .config files to find which native libraries to depend on 
+#  (target attribute must have double quotes for this to work, ie: target="file" )
+# Add /etc/mono/config ?
+configlist=($(printf "%s\n" "${filelist[@]}" | egrep "\\.config\$"))
 
 # Set the prefix, unless it is overriden (used when building mono rpms)
-: ${prefix=$d/..}
+: ${prefix=@prefix@}
 
-exec_prefix=$d/..
 libdir=$prefix/@reloc_libdir@
-bindir=$d
+bindir=$prefix/bin
 
-[ -x $bindir/monodis ] || exit 0;
-[ -f $libdir/libmono.so ] || exit 0;
+# Bail out if monodis or libmono is missing
+if [ ! -x $bindir/monodis ] || [ ! -f $libdir/libmono.so ] ; then
+       echo "monodis missing or unusable, exiting..." 1>&2
+       exit 1
+fi
 
+# special case for 64bit archs
+if test "x@reloc_libdir@" = "xlib64" ; then
+        libext="()(64bit)"
+else
+        libext=""
+fi
 
 # set LD_LIBRARY_PATH to ensure that libmono.so is found
 export LD_LIBRARY_PATH=$libdir${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
@@ -52,8 +62,59 @@ REQUIRES=$(
                        }
                    ') 2> /dev/null
        done
+       # Parse the xml .config files to see what native binaries we call into
+       # TODO: also check monodis --moduleref
+       for i in "${configlist[@]}"; do
+               awk 'match($_, /<dllmap .*target=.*/) {
+                       ignore=0
+                       req=""
+                       split($_, toks, "\"")
+                       toks_size=0
+                        for(tok in toks) { toks_size++ }
+                       for(i=1; i <= toks_size; i++) {
+                               if(toks[i] ~ /target=/) {
+                                       req=toks[i+1]
+                               }
+                               if(toks[i] ~ /os=/) {
+                                       negate=0
+                                       found=0
+
+                                       attr=toks[i+1]
+                                       if(attr ~ /^!/) {
+                                               attr=substr(attr, 2, length(attr)-1)
+                                               negate=1
+                                       }
+
+                                       split(attr, os_targets, ",")
+                                       os_targets_size=0
+                                        for(os_target in os_targets) { os_targets_size++ }
+                                       for(j=1; j <= os_targets_size; j++) {
+                                               if(os_targets[j] == "linux") {
+                                                       found=1
+                                               }
+                                       }
+
+                                       if(negate) {
+                                               found=!found
+                                       }
+                                       if (!found) {
+                                               ignore=1
+                                       } 
+                               }
+                       }
+                       if(!ignore) {
+                               system("rpm -q --whatprovides --queryformat \"%{NAME}\n\" ""\""req"'$libext'""\"")
+                       }
+               } ' $i 2>/dev/null
+       done
 )
 
+# Note about above:
+#  Use to do: system("rpm -q --whatprovides --queryformat \"%{NAME}\n\" ""\""req"'$libext'""\"")
+#  rpmlint prefers to have lib names instead of package names.  There was a reason I was using package names but it slips me now...
+#  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
+#   on the package name instead.
+
 PROVIDES=$(
        for i in "${monolist[@]}"; do
                ($bindir/monodis --assembly $i | awk '