e8503b3bb04e5f6c9142194f3b2382044ad57910
[platform/upstream/rpm.git] / autodeps / aix.req
1 #! /usr/bin/ksh
2
3 # Original Author: Ralph Goers(rgoer@Candle.Com)
4 # Borrowed heavily from Tim Mooney's HP version.
5 # This file is distributed under the terms of the GNU General Public License
6 #
7 # find-requires is part of RPM, the RedHat Package Manager.  find-requires
8 # reads a list of full pathnames (in a package) on stdin, and outputs all
9 # shared libraries the package requires to run correctly.
10 #
11
12 find_req_power ()
13 {
14    # On AIX Power, use `dump -H' to find the library dependencies 
15    # for an executable
16    #
17    # Example dump output:
18    #
19    #$dump -H /usr/bin/dump
20    #
21    #/usr/bin/dump:
22    #
23    #                        ***Loader Section***
24    #                      Loader Header Information
25    #VERSION#         #SYMtableENT     #RELOCent        LENidSTR
26    #0x00000001       0x00000021       0x0000006c       0x0000002f
27    #
28    ##IMPfilID        OFFidSTR         LENstrTBL        OFFstrTBL
29    #0x00000002       0x00000848       0x00000049       0x00000877
30    #
31    #
32    #                        ***Import File Strings***
33    #INDEX  PATH                          BASE                MEMBER
34    #0      /usr/lib:/lib:/usr/lpp/xlC/lib
35    #1                                    libc.a              shr.o
36    
37    #
38    #
39
40    while read f
41     do
42      # Find the required symbols in executables and the required shells in 
43      # scripts
44      LANG=C /usr/bin/file $f | /usr/bin/grep -q -e ":.*shell script" 
45
46      if [ $? -ne 0 ]  # Use dump to examine executables
47      then
48         LANG=C /usr/bin/dump -H $f 2>/dev/null | awk '
49    
50                 #
51                 # Since this entire awk script is enclosed in single quotes,
52                 # you need to be careful to not use single quotes, even in awk
53                 # comments, if you modify this script.
54                 #
55
56         BEGIN {
57             in_shlib_list = 0;
58             in_file_strings = 0;
59             FS = " ";
60             RS = "\n";
61         }
62
63         in_shlib_list == 1 && /^$/ {
64             in_shlib_list = 0;
65             in_file_strings = 0;
66         }
67
68         in_shlib_list == 1 {
69             pos = index($2, "/")
70             numfields = split($0, fields, " ")
71
72             if (pos == 0)  {
73               namevar = 2
74             }
75             else {
76               namevar = 3
77             }
78             if (namevar < numfields) {
79               printf("%s(%s)\n", fields[namevar], fields[namevar+1])
80             }
81             else {
82               if ((fields[namevar] != ".") && (fields[namevar] != "..")) {
83                   print fields[namevar]
84               }
85             }
86         }
87
88         in_file_strings == 1 && $1 == "0" {
89             in_shlib_list = 1
90         }
91
92         /\*Import File Strings\*/ {
93             in_file_strings = 1
94         }
95       ' # end of awk
96      else # shell scripts
97         if [ -x $f ]; then 
98             /usr/bin/head -1 $f | /usr/bin/sed -e 's/^\#\![   ]*//' | /usr/bin/cut -d" " -f1
99         fi
100      fi
101     done | sort -u
102 }
103
104 find_req_ia64 ()
105 {
106    # On AIX IA64, use `dump -Lv' to find the library dependencies 
107    # for an executable
108    #
109    # Example dump output:
110    #
111    #$dump -Lv /usr/bin/dump
112    #
113    #   
114    #/usr/bin/dump:
115    #
116    #            ****  DYNAMIC SECTION INFORMATION ****
117    #[INDEX]   Tag         Value
118    #
119    #.dynamic:
120    #[1]       NEEDED      libC.so.1
121    #[2]       NEEDED      libelf.so
122    #[3]       NEEDED      /usr/lib/ia64l32/libc.so.1
123    #[4]       INIT        0x1001d6c0
124    #[5]       FINI        0x1001d700
125    #[6]       HASH        0x1000011c
126    #[7]       STRTAB      0x10000914
127    #[8]       SYMTAB      0x10000364
128    #[9]       STRSZ       0x3dd
129    #[10]      SYMENT      0x10
130    #[11]      PLTGOT      0x20018994
131    #[12]      PLT_RESERVE 0x20018a00
132    #[13]      PLTSZ       0x1c0
133    #[14]      PLTREL      REL
134    #[15]      JMPREL      0x100024bc
135    #[16]      REL         0x10000cf4
136    #[17]      RELSZ       0x17c8
137    #[18]      RELENT      0x8
138    #
139    #
140
141    while read f
142    do
143      # Find the required symbols in executables and the required shells in 
144      # scripts
145      LANG=C /usr/bin/file $f | /usr/bin/grep -q -e ":.*shell script" 
146
147      if [ $? -ne 0 ]  # Use dump to examine executables
148      then
149            LANG=C /usr/bin/dump -Lv $f 2>/dev/null | \
150            awk '$2=="NEEDED" {print $3}' | xargs -i basename {}
151    
152      else  # Extract the exec module from shell scripts
153            if [ -x $f ]; then
154                head -1 $f | sed -e 's/^\#\![   ]*//' | cut -d" " -f1
155            fi
156      fi
157    done | sort -u
158 }
159
160 machinetype=`uname -m`
161 if [[ $machinetype = "ia64" ]]
162 then
163    /usr/bin/sed "s/['\"]/\\\&/g" | LANG=C /usr/bin/xargs /usr/bin/file | \
164       /usr/bin/grep -e ":.*executable" -e ":.*archive" -e ":.*shell script" | /usr/bin/cut -d: -f1 |
165    find_req_ia64
166 else
167    /usr/bin/sed "s/['\"]/\\\&/g" | LANG=C /usr/bin/xargs /usr/bin/file | \
168       /usr/bin/grep -e ":.*executable" -e ":.*archive" -e ":.*shell script" | /usr/bin/cut -d: -f1 |
169    find_req_power
170 fi
171