2010-04-16 Sebastien Pouliot <sebastien@ximian.com>
[mono/afaerber.git] / scripts / mono-find-requires.in
blob452456ed5e96d754d5f9aa5b4f68790e5ac80529
1 #!/bin/bash
3 # mono-find-requires
5 # Authors:
6 # Ben Maurer (bmaurer@ximian.com)
7 # Wade Berrier (wberrier@novell.com)
9 # (C) 2008 Novell (http://www.novell.com)
12 IFS=$'\n'
13 filelist=($(grep -Ev '/usr/doc/|/usr/share/doc/'))
14 monolist=($(printf "%s\n" "${filelist[@]}" | egrep "\\.(exe|dll)\$"))
16 # parse .config files to find which native libraries to depend on
17 # (target attribute must have double quotes for this to work, ie: target="file" )
18 # Add /etc/mono/config ?
19 configlist=($(printf "%s\n" "${filelist[@]}" | egrep "\\.config\$"))
21 # Set the prefix, unless it is overriden (used when building mono rpms)
22 : ${prefix=@prefix@}
24 # Can override .config scanning if specified
25 : ${IGNORE_CONFIG_SCAN=0}
27 libdir=$prefix/@reloc_libdir@
28 bindir=$prefix/bin
30 # Bail out if monodis or libmono is missing
31 if [ ! -x $bindir/monodis ] || [ ! -f $libdir/libmono.so ] ; then
32 echo "monodis missing or unusable, exiting..." 1>&2
33 exit 1
36 # special case for 64bit archs
37 if test "x@reloc_libdir@" = "xlib64" ; then
38 libext="()(64bit)"
39 else
40 # (note, this works on ppc64 since we only have 32bit mono)
41 libext=""
44 # Exceptions:
45 case `uname -m` in
46 # ia64 doesn't use lib64 for 'libdir' (sles 9 rpm used to provide both... no longer)
47 ia64) libext="()(64bit)" ;;
48 esac
50 # set LD_LIBRARY_PATH to ensure that libmono.so is found
51 export LD_LIBRARY_PATH=$libdir${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
53 REQUIRES=$(
54 for i in "${monolist[@]}"; do
55 ($bindir/monodis --assemblyref $i | awk '
56 BEGIN { START=0; LIBNAME=""; VERSION=""; }
57 (START==0) && /^[0-9]+: Version=/ {
58 START=1;
59 sub(/Version=/, "", $2);
60 VERSION=$2
63 (START==1) && /^\tName=/ {
64 sub(/Name=/, "", $1);
65 LIBNAME=$1
66 # Allow rpm deps to be resolved for 1.0 profile version
67 if (VERSION=="1.0.3300.0")
68 OP=">="
69 else
70 OP="="
71 print "mono(" LIBNAME ") " OP " " VERSION
72 START=0
74 ') 2> /dev/null
75 done
78 if [ $IGNORE_CONFIG_SCAN -eq 0 ] ; then
80 rpm_config_REQUIRES=$(
81 # Parse the xml .config files to see what native binaries we call into
82 # TODO: also check monodis --moduleref
83 for i in "${configlist[@]}"; do
84 awk 'match($_, /<dllmap .*target=.*/) {
85 ignore=0
86 req=""
87 split($_, toks, "\"")
88 toks_size=0
89 for(tok in toks) { toks_size++ }
90 for(i=1; i <= toks_size; i++) {
91 if(toks[i] ~ /target=/) {
92 req=toks[i+1]
94 if(toks[i] ~ /os=/) {
95 negate=0
96 found=0
98 attr=toks[i+1]
99 if(attr ~ /^!/) {
100 attr=substr(attr, 2, length(attr)-1)
101 negate=1
104 split(attr, os_targets, ",")
105 os_targets_size=0
106 for(os_target in os_targets) { os_targets_size++ }
107 for(j=1; j <= os_targets_size; j++) {
108 if(os_targets[j] == "linux") {
109 found=1
113 if(negate) {
114 found=!found
116 if (!found) {
117 ignore=1
121 if(!ignore) {
122 print req"'$libext'"
124 } ' $i 2>/dev/null
125 done
128 # Resolve provides to packages, warning on missing to stderr
129 config_REQUIRES=$(
130 first=1 # avoid an empty line if no .config reqs are found
131 for i in ${rpm_config_REQUIRES[@]} ; do
132 out=$(rpm -q --whatprovides --queryformat "%{NAME}\n" $i)
133 if [ $? -eq 0 ] ; then
134 if [ $first -eq 1 ] ; then
135 echo ""
136 first=0
138 echo $out
139 else
140 # echo to stderr
141 echo "mono-find-requires: Warning, could not find package that provides: $i" >&2
143 done
148 # Note about above:
149 # Use to do: system("rpm -q --whatprovides --queryformat \"%{NAME}\n\" ""\""req"'$libext'""\"")
150 # rpmlint prefers to have lib names instead of package names. There was a reason I was using package names but it slips me now...
151 # 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
152 # on the package name instead.
154 PROVIDES=$(
155 for i in "${monolist[@]}"; do
156 ($bindir/monodis --assembly $i | awk '
157 BEGIN { LIBNAME=""; VERSION=""; }
158 /^Version:/ { VERSION=$2 }
159 /^Name:/ { LIBNAME=$2 }
160 END {
161 if (VERSION && LIBNAME)
162 print "mono(" LIBNAME ") = " VERSION
164 ') 2>/dev/null
165 done
168 # This is a little magic trick to get all REQUIRES that are not
169 # in PROVIDES. While RPM functions correctly when such deps exist,
170 # they make the metadata a bit bloated.
172 # TODO: make this use the mono-find-provides script, to share code
174 # Filter out dups from both lists
175 REQUIRES=$(echo "$REQUIRES $config_REQUIRES" | sort | uniq)
176 PROVIDES=$(echo "$PROVIDES" | sort | uniq)
179 # Get a list of elements that exist in exactly one of PROVIDES or REQUIRES
181 UNIQ=$(echo "$PROVIDES
182 $REQUIRES" | sort | uniq -u)
185 # Of those, only choose the ones that are in REQUIRES
187 echo "$UNIQ
188 $REQUIRES" | sort | uniq -d