3f7a752eb2846378b41863b7d872478aede3ba39
[massrebuild.git] / dtneededsizerpmsone
1 #! /bin/bash
2 set -e
3 # build/znc-1.8.1-2.fc33.src.rpm.rpms
4 which readelf >/dev/null
5 for rpms in "$@";do
6   srcrpm="${rpms%.rpms}"
7   if [ "$rpms" = "$srcrpm" ];then
8     echo >&2 "$rpms is not *.rpms"
9     exit 1
10   fi
11   if [ "$srcrpm" != "${srcrpm%.dt5.rpm}" ];then
12     # The non-.dt5.rpm run will handle both.
13     continue
14   fi
15   if [ "$srcrpm" != "${srcrpm%.dt.rpm}" ];then
16     # Ignore.
17     continue
18   fi
19   if [ ! -e $srcrpm.rpms ];then
20     echo >&2 "! $srcrpm.rpms"
21     continue
22   fi
23   if [ ! -e $srcrpm.dt5.rpm.rpms ];then
24     echo >&2 "! $srcrpm.dt5.rpm.rpms"
25     continue
26   fi
27   if [ -e $srcrpm.dtneeded ];then
28     continue
29   fi
30   test ! -e $srcrpm.rpms.d || (echo >&2 "$srcrpm.rpms.d";exit 1)
31   t=/tmp/dtneededsizerpms.$$
32   rm -f $t
33   mkdir $srcrpm.rpms.d
34   pushd $srcrpm.rpms.d >/dev/null
35     rpmsbase=../../`basename $srcrpm`
36     dwzrpms=$rpmsbase.rpms
37     dtrpms=$rpmsbase.dt5.rpm.rpms
38     mkdir empty
39     cd empty
40       if [ -z "$(find $dwzrpms $dtrpms -maxdepth 1 -type f)" ];then
41         popd >/dev/null
42         rm -rf $srcrpm.rpms.d
43         continue
44       fi
45     cd ..
46     function extract
47     {
48       for i in $1/*-debuginfo*.rpm;do
49         test ! -e $i.tgz
50         rpm2archive $i
51         test -e $i.tgz
52         tar xzf $i.tgz
53         rm -f $i.tgz
54       done
55     }
56     mkdir dwz;(cd dwz;extract $dwzrpms)
57     mkdir  dt;(cd  dt;extract  $dtrpms)
58     dwzcommonname="$(find dwz/usr/lib/debug/.dwz/ -type f 2>/dev/null || :)"
59     if [ -z "$dwzcommonname" ];then
60       dwzcommonname="nodwzcommon"
61       dwzcommon=0
62     else
63       dwzcommon="$(find "$dwzcommonname" -maxdepth 0 -printf "%s")"
64       dwzcommonname="/${dwzcommonname#dwz/}"
65       dwzcommonname2="$(echo "$dwzcommonname"|sed 's/-[^-]*-[^-]*$//')"
66       if [ "$dwzcommonname2" = "$dwzcommonname" ];then
67         echo >&2 "No VR dwzcommon suffix: $dwzcommonname"
68         exit 1
69       fi
70       dwzcommonname="$dwzcommonname2"
71       echo >>$t "$dwzcommonname isdwzcommon $dwzcommon NA"
72     fi
73     pushd dwz >/dev/null
74       for i in `find -type f -name "*.debug*"`;do
75         dwz=$(find $i      -maxdepth 0 -printf "%s")
76         dt=$(find ../dt/$i -maxdepth 0 -printf "%s")
77         if readelf -WS $i 2>/dev/null|fgrep -q .gnu_debugaltlink;then
78           if [ $dwzcommon -eq 0 ];then
79             echo >&2 "Excessive .gnu_debugaltlink: $i"
80             exit 1
81           fi
82         fi
83         i="${i#.}"
84         i2="${i#/usr/lib/debug/}"
85         if [ "$i" = "$i2" ];then
86           echo >&2 "No /usr/lib/debug/ prefix: $i"
87           i="$i2"
88         else
89           i="/$i2"
90         fi
91         i2="$(echo "$i"|sed 's/-[^-]*-[^-]*$//')"
92         if [ "$i2" = "$i" ];then
93           echo >&2 "No VR suffix: $i"
94         fi
95         i="$i2"
96         echo "${i%.debug} $dwzcommonname $dwz $dt"|sed 's#^\./#/#' >>$t
97       done
98     popd >/dev/null
99   popd >/dev/null
100   rm -rf $srcrpm.rpms.d
101   mv $t $srcrpm.dtneeded
102 done