]> git.draconx.ca Git - gentoo-draconx.git/blob - sys-devel/gcc/files/awk/scanforssp.awk
Add gcc with fixed POD dependencies.
[gentoo-draconx.git] / sys-devel / gcc / files / awk / scanforssp.awk
1 # Copyright 1999-2004 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # Author:  Martin Schlemmer <azarah@gentoo.org>
4 # Contributor: Ned Ludd <solar@gentoo.org>
5 # Contributor: Natanael Copa  <nat@c2i.net>
6 # Contributor: Carter Smithhart <derheld42@derheld.net>
7 # $Header: /var/cvsroot/gentoo-x86/sys-devel/gcc/files/awk/scanforssp.awk,v 1.7 2004/07/15 00:59:02 agriffis Exp $
8
9
10 # Does not seem to be used in this script.
11 function printn(string)
12 {
13         printf("%s", string)
14 }
15
16 function einfo(string)
17 {
18         printf(" %s %s%s", "\033[32;01m*\033[0m", string, "\n")
19 }
20
21 # Does not seem to be used in this script.
22 function einfon(string)
23 {
24         printf(" %s %s" , "\033[32;01m*\033[0m", string)
25 }
26
27 function ewarn(string)
28 {
29         printf(" %s %s%s" , "\033[33;01m*\033[0m", string, "\n")
30 }
31
32 # Does not seem to be used in this script.
33 function ewarnn(string)
34 {
35         printf("%s %s" , "\032[33;01m*\033[0m", string)
36 }
37
38 function eerror(string)
39 {
40         printf(" %s %s%s" , "\033[31;01m*\033[0m", string, "\n")
41 }
42
43                                                                 # These are private, else wierd things
44                                                                 # might happen ...
45 function iself(scan_files,              scan_file_pipe, scan_data) {
46         # Can we open() a file and read() 4 bytes?
47         scan_file_pipe = ("head -c 4 " scan_files " 2>/dev/null | tail -c 3")
48         scan_file_pipe | getline scan_data
49         close(scan_file_pipe)
50         return ((scan_data == "ELF") ? 0 : 1)
51 }
52
53 BEGIN {
54         # Do we have etcat ?
55         pipe = ("which etcat 2>/dev/null")
56         if ((((pipe) | getline etcat_data) > 0) && (etcat_data != ""))
57                 auto_etcat = 1
58         else
59                 auto_etcat = 0
60
61         # Fix bug that causes script to fail when pipe is not closed. Closes bug #36792
62         close(pipe)
63
64         DIRCOUNT = 0
65         # Add the two default library paths
66         DIRLIST[1] = "/lib"
67         DIRLIST[2] = "/usr/lib"
68
69         # Walk /etc/ld.so.conf line for line and get any library paths
70         pipe = ("cat /etc/ld.so.conf 2>/dev/null | sort")
71         while(((pipe) | getline ldsoconf_data) > 0) {
72
73                 if (ldsoconf_data !~ /^[[:space:]]*#/) {
74
75                         if (ldsoconf_data == "") continue
76
77                         # Remove any trailing comments
78                         sub(/#.*$/, "", ldsoconf_data)
79                         # Remove any trailing spaces
80                         sub(/[[:space:]]+$/, "", ldsoconf_data)
81
82                         split(ldsoconf_data, nodes, /[:,[:space:]]/)
83
84                         # Now add the rest from ld.so.conf
85                         for (x in nodes) {
86
87                                 sub(/=.*/, "", nodes[x])
88                                 sub(/\/$/, "", nodes[x])
89
90                                 if (nodes[x] == "") continue
91
92                                 CHILD = 0
93
94                                 # Drop the directory if its a child directory of
95                                 # one that was already added ...
96                                 for (y in DIRLIST) {
97
98                                         if (nodes[x] ~ "^" DIRLIST[y]) {
99
100                                                 CHILD = 1
101                                                 break
102                                         }
103                                 }
104
105                                 if (CHILD) continue
106
107                                 DIRLIST[++DIRCOUNT + 2] = nodes[x]
108                         }
109                 }
110         }
111
112 # We have no guarantee that ld.so.conf have more library paths than
113 # the default, and its better scan files only in /lib and /usr/lib
114 # than nothing at all ...
115 #
116 #       exit_val = close(pipe)
117 #       if (exit_val != 0)
118 #       print(exit_val " - " ERRNO)
119 #
120 #       if (DIRCOUNT == 0) {
121 #               eerror("Could not read from /etc/ld.so.conf!")
122 #               exit 1
123 #       }
124
125         # Correct DIRCOUNT, as we already added /lib and /usr/lib
126         DIRCOUNT += 2
127
128         # Add all the dirs in $PATH
129         split(ENVIRON["PATH"], TMPPATHLIST, ":")
130         count = asort(TMPPATHLIST, PATHLIST)
131         for (x = 1;x <= count;x++) {
132
133                 ADDED = 0
134
135                 # Already added?
136                 for (dnode in DIRLIST)
137                         if (PATHLIST[x] == DIRLIST[dnode])
138                                 ADDED = 1
139
140                 if (ADDED)
141                         continue
142
143                 # Valid?  If so, add it ...
144                 if (((PATHLIST[x] != "") && (PATHLIST[x] != "/") && (PATHLIST[x] != ".")))
145                         DIRLIST[++DIRCOUNT] = PATHLIST[x]
146
147         }
148
149         GCCLIBPREFIX = "/usr/lib/gcc-lib/"
150
151         for (x = 1;x <= DIRCOUNT;x++) {
152
153                 # Do nothing if the target dir is gcc's internal library path
154                 if (DIRLIST[x] ~ GCCLIBPREFIX) continue
155
156                 einfo(" Scanning " ((x <= 9) ? "0"x : x)" of " DIRCOUNT " " DIRLIST[x] "...")
157
158                 pipe = ("find " DIRLIST[x] "/ -type f -perm -1 2>/dev/null")
159                 while ( (pipe | getline scan_files) > 0) {
160
161                     #print scan_files
162                         # Do nothing if the file is located in gcc's internal lib path ...
163                         if (scan_files ~ GCCLIBPREFIX) continue
164                         # Or if its hardend files ...
165                         if (scan_files ~ "/lib/libgcc-3" ) continue
166                         # Or not a elf image ...
167                         if (iself(scan_files)) continue
168
169                         scan_file_pipe = ("readelf -s " scan_files " 2>&1")
170                         while (((scan_file_pipe) | getline scan_data) > 0) {
171                             bad = 0;
172                                 if (scan_data ~ /__guard@GCC/ || scan_data ~ /__guard@@GCC/) {
173                                 bad = 1;
174                                         print
175
176                                         # 194: 00000000    32 OBJECT  GLOBAL DEFAULT  UND __guard@GCC_3.0 (3)
177                                         # 59: 00008ee0    32 OBJECT  GLOBAL DEFAULT   22 __guard@@GCC_3.0
178                                         split(scan_data, scan_data_nodes)
179                                         ewarn("Found " scan_data_nodes[8] " in " scan_files "!")
180                                         print
181                             }
182                             if (scan_data ~ /readelf: Error: Unable to seek/) {
183                                 bad = 1;
184                                 print
185                                 ewarn("Error executing readelf. Bad block? Filesystem error? in " scan_files)
186                                 print
187                             }
188
189                             if (bad) {
190
191                                         if (auto_etcat) {
192
193                                                 # Use etcat that comes with gentoolkit if auto_etcat is true.
194                                                 etcat_pipe = ("etcat belongs " scan_files)
195                                                 (etcat_pipe) | getline etcat_belongs
196
197                                                 while(((etcat_pipe) | getline etcat_belongs) > 0)
198                                                         eerror(etcat_belongs != "" ? "Please emerge '>=" etcat_belongs "'": "")
199                                                 close(etcat_pipe)
200                                         } else {
201
202                                                 eerror("You need to remerge package that above file belongs to!")
203                                                 eerror("To find out what package it is, please emerge gentoolkit,")
204                                                 eerror("and then run:")
205                                                 print
206                                                 print "    # etcat belongs " scan_files
207                                         }
208
209                                         print
210
211                                         close(scan_file_pipe)
212                                         close(pipe)
213                                         exit(1)
214                                 }
215                         }
216                         close(scan_file_pipe)
217                 }
218                 close(pipe)
219         }
220
221         exit(0)
222 }
223
224
225 # vim:ts=4