summaryrefslogtreecommitdiff
path: root/autodeps/aix.req
blob: e8503b3bb04e5f6c9142194f3b2382044ad57910 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#! /usr/bin/ksh

# Original Author: Ralph Goers(rgoer@Candle.Com)
# Borrowed heavily from Tim Mooney's HP version.
# This file is distributed under the terms of the GNU General Public License
#
# find-requires is part of RPM, the RedHat Package Manager.  find-requires
# reads a list of full pathnames (in a package) on stdin, and outputs all
# shared libraries the package requires to run correctly.
#

find_req_power ()
{
   # On AIX Power, use `dump -H' to find the library dependencies 
   # for an executable
   #
   # Example dump output:
   #
   #$dump -H /usr/bin/dump
   #
   #/usr/bin/dump:
   #
   #                        ***Loader Section***
   #                      Loader Header Information
   #VERSION#         #SYMtableENT     #RELOCent        LENidSTR
   #0x00000001       0x00000021       0x0000006c       0x0000002f
   #
   ##IMPfilID        OFFidSTR         LENstrTBL        OFFstrTBL
   #0x00000002       0x00000848       0x00000049       0x00000877
   #
   #
   #                        ***Import File Strings***
   #INDEX  PATH                          BASE                MEMBER
   #0      /usr/lib:/lib:/usr/lpp/xlC/lib
   #1                                    libc.a              shr.o
   
   #
   #

   while read f
    do
     # Find the required symbols in executables and the required shells in 
     # scripts
     LANG=C /usr/bin/file $f | /usr/bin/grep -q -e ":.*shell script" 

     if [ $? -ne 0 ]  # Use dump to examine executables
     then
        LANG=C /usr/bin/dump -H $f 2>/dev/null | awk '
   
		#
		# Since this entire awk script is enclosed in single quotes,
		# you need to be careful to not use single quotes, even in awk
		# comments, if you modify this script.
		#

        BEGIN {
            in_shlib_list = 0;
            in_file_strings = 0;
            FS = " ";
            RS = "\n";
        }

        in_shlib_list == 1 && /^$/ {
            in_shlib_list = 0;
            in_file_strings = 0;
        }

        in_shlib_list == 1 {
            pos = index($2, "/")
            numfields = split($0, fields, " ")

            if (pos == 0)  {
              namevar = 2
            }
            else {
              namevar = 3
            }
            if (namevar < numfields) {
              printf("%s(%s)\n", fields[namevar], fields[namevar+1])
            }
            else {
	      if ((fields[namevar] != ".") && (fields[namevar] != "..")) {
                  print fields[namevar]
	      }
            }
        }

        in_file_strings == 1 && $1 == "0" {
            in_shlib_list = 1
        }

        /\*Import File Strings\*/ {
            in_file_strings = 1
        }
      ' # end of awk
     else # shell scripts
        if [ -x $f ]; then 
            /usr/bin/head -1 $f | /usr/bin/sed -e 's/^\#\![   ]*//' | /usr/bin/cut -d" " -f1
        fi
     fi
    done | sort -u
}

find_req_ia64 ()
{
   # On AIX IA64, use `dump -Lv' to find the library dependencies 
   # for an executable
   #
   # Example dump output:
   #
   #$dump -Lv /usr/bin/dump
   #
   #   
   #/usr/bin/dump:
   #
   #		****  DYNAMIC SECTION INFORMATION ****
   #[INDEX]   Tag         Value
   #
   #.dynamic:
   #[1]       NEEDED      libC.so.1
   #[2]       NEEDED      libelf.so
   #[3]       NEEDED      /usr/lib/ia64l32/libc.so.1
   #[4]       INIT        0x1001d6c0
   #[5]       FINI        0x1001d700
   #[6]       HASH        0x1000011c
   #[7]       STRTAB      0x10000914
   #[8]       SYMTAB      0x10000364
   #[9]       STRSZ       0x3dd
   #[10]      SYMENT      0x10
   #[11]      PLTGOT      0x20018994
   #[12]      PLT_RESERVE 0x20018a00
   #[13]      PLTSZ       0x1c0
   #[14]      PLTREL      REL
   #[15]      JMPREL      0x100024bc
   #[16]      REL         0x10000cf4
   #[17]      RELSZ       0x17c8
   #[18]      RELENT      0x8
   #
   #

   while read f
   do
     # Find the required symbols in executables and the required shells in 
     # scripts
     LANG=C /usr/bin/file $f | /usr/bin/grep -q -e ":.*shell script" 

     if [ $? -ne 0 ]  # Use dump to examine executables
     then
           LANG=C /usr/bin/dump -Lv $f 2>/dev/null | \
	   awk '$2=="NEEDED" {print $3}' | xargs -i basename {}
   
     else  # Extract the exec module from shell scripts
           if [ -x $f ]; then
               head -1 $f | sed -e 's/^\#\![   ]*//' | cut -d" " -f1
           fi
     fi
   done | sort -u
}

machinetype=`uname -m`
if [[ $machinetype = "ia64" ]]
then
   /usr/bin/sed "s/['\"]/\\\&/g" | LANG=C /usr/bin/xargs /usr/bin/file | \
      /usr/bin/grep -e ":.*executable" -e ":.*archive" -e ":.*shell script" | /usr/bin/cut -d: -f1 |
   find_req_ia64
else
   /usr/bin/sed "s/['\"]/\\\&/g" | LANG=C /usr/bin/xargs /usr/bin/file | \
      /usr/bin/grep -e ":.*executable" -e ":.*archive" -e ":.*shell script" | /usr/bin/cut -d: -f1 |
   find_req_power
fi