Commit | Line | Data |
---|---|---|
33a01fd2 | 1 | ?RCS: $Id$ |
d8875586 MBT |
2 | ?RCS: |
3 | ?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi | |
cf39bd7e | 4 | ?RCS: |
33a01fd2 | 5 | ?RCS: You may redistribute only under the terms of the Artistic License, |
d8875586 MBT |
6 | ?RCS: as specified in the README file that comes with the distribution. |
7 | ?RCS: You may reuse parts of this distribution only within the terms of | |
33a01fd2 | 8 | ?RCS: that same Artistic License; a copy of which may be found at the root |
d8875586 MBT |
9 | ?RCS: of the source tree for dist 4.0. |
10 | ?RCS: | |
11 | ?RCS: $Log: libc.U,v $ | |
12 | ?RCS: Revision 3.0.1.10 1997/02/28 15:56:48 ram | |
13 | ?RCS: patch61: replaced .a with $_a all over the place | |
14 | ?RCS: patch61: added support for HPUX-10 nm output | |
15 | ?RCS: | |
16 | ?RCS: Revision 3.0.1.9 1995/07/25 14:11:56 ram | |
17 | ?RCS: patch56: now knows about OS/2 platforms | |
18 | ?RCS: | |
19 | ?RCS: Revision 3.0.1.8 1995/05/12 12:20:47 ram | |
20 | ?RCS: patch54: made sure only most recent version of shared lib is picked | |
21 | ?RCS: patch54: final "nm -p" check now uses xscan and xrun like everybody | |
22 | ?RCS: patch54: can now grok linux nm output with lead __IO (ADO) | |
23 | ?RCS: patch54: added support for linux ELF output, using 'W' for alias (ADO) | |
24 | ?RCS: | |
25 | ?RCS: Revision 3.0.1.7 1994/10/29 16:23:40 ram | |
26 | ?RCS: patch36: now looks for shared libraries before anything else (ADO) | |
27 | ?RCS: patch36: added new nm output format (ADO) | |
28 | ?RCS: | |
29 | ?RCS: Revision 3.0.1.6 1994/08/29 16:28:10 ram | |
30 | ?RCS: patch32: added I-type symbols for nm output parsing on Linux | |
31 | ?RCS: | |
32 | ?RCS: Revision 3.0.1.5 1994/06/20 07:03:24 ram | |
33 | ?RCS: patch30: checks are now presented by succession of if/elif | |
34 | ?RCS: patch30: uniformized checks for shared objects with new so symbol | |
35 | ?RCS: | |
36 | ?RCS: Revision 3.0.1.4 1994/05/06 15:06:33 ram | |
37 | ?RCS: patch23: added shared library knowledge (ADO and WED) | |
38 | ?RCS: | |
39 | ?RCS: Revision 3.0.1.3 1994/01/24 14:12:17 ram | |
40 | ?RCS: patch16: can now export nm_extract as an internal-use only variable | |
41 | ?RCS: | |
42 | ?RCS: Revision 3.0.1.2 1993/09/13 16:09:03 ram | |
43 | ?RCS: patch10: added special handling for Apollo systems (WAD) | |
44 | ?RCS: | |
45 | ?RCS: Revision 3.0.1.1 1993/08/27 14:40:03 ram | |
46 | ?RCS: patch7: added entry for /usr/shlib/libc.so (OSF/1 machines) | |
47 | ?RCS: | |
48 | ?RCS: Revision 3.0 1993/08/18 12:08:57 ram | |
49 | ?RCS: Baseline for dist 3.0 netwide release. | |
50 | ?RCS: | |
51 | ?MAKE:libc libnames +nm_extract: echo n c rm test grep Getfile Myread \ | |
52 | Oldconfig Loc sed libs incpath libpth ar runnm nm nm_opt nm_so_opt \ | |
53 | contains xlibpth so osname trnl tr sort uniq _o _a | |
54 | ?MAKE: -pick add $@ %< | |
55 | ?S:libc: | |
56 | ?S: This variable contains the location of the C library. | |
57 | ?S:. | |
58 | ?S:libnames: | |
59 | ?S: The constructed list of library names. Normally empty, but hint files | |
60 | ?S: may set this for later perusal by Configure. | |
61 | ?S:. | |
62 | ?S:nm_extract: | |
63 | ?S: This variable holds the name of the extraction command used to process | |
64 | ?S: the output of nm and yield the list of defined symbols. It is used | |
65 | ?S: internally by Configure. | |
66 | ?S:. | |
67 | ?T:thislib try libnames xxx xscan xrun thisname com tans file | |
68 | ?F:!libnames !libc.tmp !tmp.imp | |
69 | ?LINT:change nm_opt runnm | |
70 | ?INIT:libnames='' | |
71 | : Figure out where the libc is located | |
72 | case "$runnm" in | |
73 | true) | |
74 | ?X: indentation is wrong on purpose--RAM | |
75 | : get list of predefined functions in a handy place | |
76 | echo " " | |
77 | case "$libc" in | |
78 | '') libc=unknown | |
79 | case "$libs" in | |
80 | *-lc_s*) libc=`./loc libc_s$_a $libc $libpth` | |
81 | esac | |
82 | ;; | |
83 | esac | |
84 | case "$libs" in | |
85 | '') ;; | |
86 | *) for thislib in $libs; do | |
87 | case "$thislib" in | |
88 | -lc|-lc_s) | |
89 | : Handle C library specially below. | |
90 | ;; | |
91 | -l*) | |
92 | thislib=`echo $thislib | $sed -e 's/^-l//'` | |
93 | if try=`./loc lib$thislib.$so.'*' X $libpth`; $test -f "$try"; then | |
94 | : | |
95 | elif try=`./loc lib$thislib.$so X $libpth`; $test -f "$try"; then | |
96 | : | |
97 | elif try=`./loc lib$thislib$_a X $libpth`; $test -f "$try"; then | |
98 | : | |
99 | elif try=`./loc $thislib$_a X $libpth`; $test -f "$try"; then | |
100 | : | |
101 | elif try=`./loc lib$thislib X $libpth`; $test -f "$try"; then | |
102 | : | |
103 | elif try=`./loc $thislib X $libpth`; $test -f "$try"; then | |
104 | : | |
105 | elif try=`./loc Slib$thislib$_a X $xlibpth`; $test -f "$try"; then | |
106 | : | |
107 | else | |
108 | try='' | |
109 | fi | |
110 | libnames="$libnames $try" | |
111 | ;; | |
112 | *) libnames="$libnames $thislib" ;; | |
113 | esac | |
114 | done | |
115 | ;; | |
116 | esac | |
117 | ?X: | |
118 | ?X: Some systems (e.g. DG/UX) use "environmental" links, which make the test | |
119 | ?X: -f fail. Ditto for symbolic links. So in order to reliably check the | |
cf39bd7e | 120 | ?X: existence of a file, we use test -r. It will still fail with DG/UX links |
d8875586 MBT |
121 | ?X: though, but at least it will detect symbolic links. At some strategic |
122 | ?X: points, we make use of (test -h), using a sub-shell in case builtin test | |
123 | ?X: does not implement the -h check for symbolic links. This makes it | |
124 | ?X: possible to preset libc in a hint file for instance and have it show up | |
125 | ?X: as-is in the question. | |
126 | ?X: | |
127 | xxx=normal | |
128 | case "$libc" in | |
129 | unknown) | |
130 | ?X: | |
131 | ?X: The sed below transforms .so.9 .so.12 into something like .so.0009 .so.0012, | |
132 | ?X: then sorts on it to allow keeping .so.12 instead of .so.9 as the latest | |
133 | ?X: up-to-date library. The initial filename (before sed munging, saved in hold | |
134 | ?X: space via 'h') is appended via 'G' before sorting, then the leading munged | |
135 | ?X: part is removed after sorting. Nice efficient work from Tye McQueen. | |
136 | ?X: The initial blurfl is here to prevent the trailing pipe from producing an | |
137 | ?X: empty string, causing Configure to output all its set variables! | |
138 | ?X: | |
139 | set /lib/libc.$so | |
140 | for xxx in $libpth; do | |
141 | $test -r $1 || set $xxx/libc.$so | |
142 | : The messy sed command sorts on library version numbers. | |
143 | $test -r $1 || \ | |
144 | set `echo blurfl; echo $xxx/libc.$so.[0-9]* | \ | |
145 | tr ' ' $trnl | egrep -v '\.[A-Za-z]*$' | $sed -e ' | |
146 | h | |
147 | s/[0-9][0-9]*/0000&/g | |
148 | s/0*\([0-9][0-9][0-9][0-9][0-9]\)/\1/g | |
149 | G | |
150 | s/\n/ /' | \ | |
151 | $sort | $sed -e 's/^.* //'` | |
152 | eval set \$$# | |
153 | done | |
154 | $test -r $1 || set /usr/ccs/lib/libc.$so | |
155 | $test -r $1 || set /lib/libsys_s$_a | |
156 | ;; | |
157 | *) | |
158 | ?X: ensure the test below for the (shared) C library will fail | |
159 | set blurfl | |
160 | ;; | |
161 | esac | |
162 | if $test -r "$1"; then | |
163 | echo "Your (shared) C library seems to be in $1." | |
164 | libc="$1" | |
165 | elif $test -r /lib/libc && $test -r /lib/clib; then | |
166 | ?X: | |
167 | ?X: Apollo has its C library in /lib/clib AND /lib/libc | |
168 | ?X: not to mention its math library in /lib/syslib... | |
169 | ?X: | |
170 | echo "Your C library seems to be in both /lib/clib and /lib/libc." | |
171 | xxx=apollo | |
172 | libc='/lib/clib /lib/libc' | |
173 | if $test -r /lib/syslib; then | |
174 | echo "(Your math library is in /lib/syslib.)" | |
175 | ?X: Put syslib in libc -- not quite right, but won't hurt | |
176 | libc="$libc /lib/syslib" | |
177 | fi | |
178 | elif $test -r "$libc" || (test -h "$libc") >/dev/null 2>&1; then | |
179 | echo "Your C library seems to be in $libc, as you said before." | |
180 | ?X: For mips, and... | |
181 | elif $test -r $incpath/usr/lib/libc$_a; then | |
182 | libc=$incpath/usr/lib/libc$_a; | |
183 | echo "Your C library seems to be in $libc. That's fine." | |
184 | elif $test -r /lib/libc$_a; then | |
185 | libc=/lib/libc$_a; | |
186 | echo "Your C library seems to be in $libc. You're normal." | |
187 | else | |
188 | if tans=`./loc libc$_a blurfl/dyick $libpth`; $test -r "$tans"; then | |
189 | : | |
190 | elif tans=`./loc libc blurfl/dyick $libpth`; $test -r "$tans"; then | |
191 | libnames="$libnames "`./loc clib blurfl/dyick $libpth` | |
192 | elif tans=`./loc clib blurfl/dyick $libpth`; $test -r "$tans"; then | |
193 | : | |
194 | elif tans=`./loc Slibc$_a blurfl/dyick $xlibpth`; $test -r "$tans"; then | |
195 | : | |
196 | elif tans=`./loc Mlibc$_a blurfl/dyick $xlibpth`; $test -r "$tans"; then | |
197 | : | |
198 | else | |
199 | tans=`./loc Llibc$_a blurfl/dyick $xlibpth` | |
200 | fi | |
201 | if $test -r "$tans"; then | |
202 | echo "Your C library seems to be in $tans, of all places." | |
203 | libc=$tans | |
204 | else | |
205 | libc='blurfl' | |
206 | fi | |
207 | fi | |
208 | if $test $xxx = apollo -o -r "$libc" || (test -h "$libc") >/dev/null 2>&1; then | |
209 | dflt="$libc" | |
210 | cat <<EOM | |
211 | ||
212 | If the guess above is wrong (which it might be if you're using a strange | |
213 | compiler, or your machine supports multiple models), you can override it here. | |
214 | ||
215 | EOM | |
216 | else | |
217 | dflt='' | |
218 | echo $libpth | $tr ' ' $trnl | $sort | $uniq > libpath | |
219 | cat >&4 <<EOM | |
220 | I can't seem to find your C library. I've looked in the following places: | |
221 | ||
222 | EOM | |
223 | $sed 's/^/ /' libpath | |
224 | cat <<EOM | |
225 | ||
226 | None of these seems to contain your C library. I need to get its name... | |
227 | ||
228 | EOM | |
229 | fi | |
230 | fn=f | |
231 | rp='Where is your C library?' | |
232 | . ./getfile | |
233 | libc="$ans" | |
234 | ||
235 | echo " " | |
236 | echo $libc $libnames | $tr ' ' $trnl | $sort | $uniq > libnames | |
237 | set X `cat libnames` | |
238 | shift | |
239 | xxx=files | |
240 | case $# in 1) xxx=file; esac | |
241 | echo "Extracting names from the following $xxx for later perusal:" >&4 | |
242 | echo " " | |
243 | $sed 's/^/ /' libnames >&4 | |
244 | echo " " | |
245 | $echo $n "This may take a while...$c" >&4 | |
246 | ||
247 | ?X: | |
248 | ?X: Linux may need the special Dynamic option to nm for shared libraries. | |
249 | ?X: In general, this is stored in the nm_so_opt variable. | |
250 | ?X: Unfortunately, that option may be fatal on non-shared libraries. | |
251 | ?X: | |
252 | for file in $*; do | |
253 | case $file in | |
254 | *$so*) $nm $nm_so_opt $nm_opt $file 2>/dev/null;; | |
255 | *) $nm $nm_opt $file 2>/dev/null;; | |
256 | esac | |
257 | done >libc.tmp | |
258 | ||
259 | $echo $n ".$c" | |
260 | ?X: | |
261 | ?X: To accelerate processing, we look at the correct 'sed' command | |
262 | ?X: by using a small subset of libc.tmp, i.e. fprintf function. | |
263 | ?X: When we know which sed command to use, do the name extraction | |
264 | ?X: | |
265 | $grep fprintf libc.tmp > libc.ptf | |
266 | ?X: | |
7bfb7bd7 | 267 | ?X: In order to enhance readability and save some space, we define |
d8875586 MBT |
268 | ?X: some variables that will be "eval"ed. |
269 | ?X: | |
270 | xscan='eval "<libc.ptf $com >libc.list"; $echo $n ".$c" >&4' | |
271 | xrun='eval "<libc.tmp $com >libc.list"; echo "done." >&4' | |
272 | ?X: BSD-like output, I and W types added for Linux | |
273 | ?X: Some versions of Linux include a leading __IO in the symbol name. | |
7bfb7bd7 | 274 | ?X: HPUX10 reportedly has trailing spaces, though I'm surprised it has |
d8875586 MBT |
275 | ?X: BSD-like output. (AD). |
276 | xxx='[ADTSIW]' | |
277 | if com="$sed -n -e 's/__IO//' -e 's/^.* $xxx *_[_.]*//p' -e 's/^.* $xxx *//p'";\ | |
278 | eval $xscan;\ | |
279 | $contains '^fprintf$' libc.list >/dev/null 2>&1; then | |
280 | eval $xrun | |
281 | ?X: SYSV-like output | |
282 | elif com="$sed -n -e 's/^__*//' -e 's/^\([a-zA-Z_0-9$]*\).*xtern.*/\1/p'";\ | |
283 | eval $xscan;\ | |
284 | $contains '^fprintf$' libc.list >/dev/null 2>&1; then | |
285 | eval $xrun | |
286 | elif com="$sed -n -e '/|UNDEF/d' -e '/FUNC..GL/s/^.*|__*//p'";\ | |
287 | eval $xscan;\ | |
288 | $contains '^fprintf$' libc.list >/dev/null 2>&1; then | |
289 | eval $xrun | |
290 | elif com="$sed -n -e 's/^.* D __*//p' -e 's/^.* D //p'";\ | |
291 | eval $xscan;\ | |
292 | $contains '^fprintf$' libc.list >/dev/null 2>&1; then | |
293 | eval $xrun | |
294 | elif com="$sed -n -e 's/^_//' -e 's/^\([a-zA-Z_0-9]*\).*xtern.*text.*/\1/p'";\ | |
295 | eval $xscan;\ | |
296 | $contains '^fprintf$' libc.list >/dev/null 2>&1; then | |
297 | eval $xrun | |
298 | elif com="$sed -n -e 's/^.*|FUNC |GLOB .*|//p'";\ | |
299 | eval $xscan;\ | |
300 | $contains '^fprintf$' libc.list >/dev/null 2>&1; then | |
301 | eval $xrun | |
302 | elif com="$grep '|' | $sed -n -e '/|COMMON/d' -e '/|DATA/d' \ | |
303 | -e '/ file/d' -e 's/^\([^ ]*\).*/\1/p'";\ | |
304 | eval $xscan;\ | |
305 | $contains '^fprintf$' libc.list >/dev/null 2>&1; then | |
306 | eval $xrun | |
307 | elif com="$sed -n -e 's/^.*|FUNC |GLOB .*|//p' -e 's/^.*|FUNC |WEAK .*|//p'";\ | |
308 | eval $xscan;\ | |
309 | $contains '^fprintf$' libc.list >/dev/null 2>&1; then | |
310 | eval $xrun | |
311 | ?X: mips nm output (sysV) | |
312 | elif com="$sed -n -e 's/^__//' -e '/|Undef/d' -e '/|Proc/s/ .*//p'";\ | |
313 | eval $xscan;\ | |
314 | $contains '^fprintf$' libc.list >/dev/null 2>&1; then | |
315 | eval $xrun | |
316 | elif com="$sed -n -e 's/^.*|Proc .*|Text *| *//p'";\ | |
317 | eval $xscan;\ | |
318 | $contains '^fprintf$' libc.list >/dev/null 2>&1; then | |
319 | eval $xrun | |
320 | elif com="$sed -n -e '/Def. Text/s/.* \([^ ]*\)\$/\1/p'";\ | |
321 | eval $xscan;\ | |
322 | $contains '^fprintf$' libc.list >/dev/null 2>&1; then | |
323 | eval $xrun | |
324 | ?X: OS/2 nm output | |
325 | elif com="$sed -n -e 's/^[-0-9a-f ]*_\(.*\)=.*/\1/p'";\ | |
326 | eval $xscan;\ | |
327 | $contains '^fprintf$' libc.list >/dev/null 2>&1; then | |
328 | eval $xrun | |
329 | elif com="$sed -n -e 's/.*\.text n\ \ \ \.//p'";\ | |
330 | eval $xscan;\ | |
331 | $contains '^fprintf$' libc.list >/dev/null 2>&1; then | |
332 | eval $xrun | |
333 | ?X: AIX nm output | |
334 | elif com="sed -n -e 's/^__.*//' -e 's/[ ]*D[ ]*[0-9]*.*//p'";\ | |
335 | eval $xscan;\ | |
336 | $contains '^fprintf$' libc.list >/dev/null 2>&1; then | |
337 | eval $xrun | |
338 | else | |
339 | $nm -p $* 2>/dev/null >libc.tmp | |
340 | $grep fprintf libc.tmp > libc.ptf | |
341 | if com="$sed -n -e 's/^.* [ADTSIW] *_[_.]*//p' -e 's/^.* [ADTSIW] //p'";\ | |
342 | eval $xscan; $contains '^fprintf$' libc.list >/dev/null 2>&1 | |
343 | then | |
344 | nm_opt='-p' | |
345 | eval $xrun | |
346 | else | |
347 | echo " " | |
348 | echo "$nm didn't seem to work right. Trying $ar instead..." >&4 | |
349 | com='' | |
350 | if $ar t $libc > libc.tmp && \ | |
351 | $contains '^fprintf$' libc.tmp >/dev/null 2>&1 | |
352 | then | |
353 | for thisname in $libnames $libc; do | |
354 | $ar t $thisname >>libc.tmp | |
355 | done | |
356 | $sed -e "s/\\$_o\$//" < libc.tmp > libc.list | |
357 | echo "Ok." >&4 | |
358 | elif test "X$osname" = "Xos2" && $ar tv $libc > libc.tmp; then | |
359 | ?X: Repeat libc to extract forwarders to DLL entries too | |
360 | for thisname in $libnames $libc; do | |
361 | $ar tv $thisname >>libc.tmp | |
362 | ?X: Revision 50 of EMX has bug in ar: it will not extract forwarders | |
363 | ?X: to DLL entries. Use emximp which will extract exactly them. | |
364 | emximp -o tmp.imp $thisname \ | |
365 | 2>/dev/null && \ | |
366 | $sed -e 's/^\([_a-zA-Z0-9]*\) .*$/\1/p' \ | |
367 | < tmp.imp >>libc.tmp | |
368 | $rm -f tmp.imp | |
369 | done | |
370 | $sed -e "s/\\$_o\$//" -e 's/^ \+//' < libc.tmp > libc.list | |
371 | echo "Ok." >&4 | |
372 | else | |
373 | echo "$ar didn't seem to work right." >&4 | |
374 | echo "Maybe this is a Cray...trying bld instead..." >&4 | |
375 | if | |
376 | bld t $libc | \ | |
377 | $sed -e 's/.*\///' -e "s/\\$_o:.*\$//" > libc.list && | |
378 | $test -s libc.list | |
379 | then | |
380 | for thisname in $libnames; do | |
381 | bld t $libnames | \ | |
382 | $sed -e 's/.*\///' -e "s/\\$_o:.*\$//" >>libc.list | |
383 | $ar t $thisname >>libc.tmp | |
384 | done | |
385 | echo "Ok." >&4 | |
386 | else | |
387 | echo "That didn't work either." >&4 | |
388 | echo "No problem, I'll be compiling test programs then..." >&4 | |
389 | runnm=false | |
390 | fi | |
391 | fi | |
392 | fi | |
393 | fi | |
394 | nm_extract="$com" | |
395 | if $test -f /lib/syscalls.exp; then | |
396 | echo " " | |
397 | echo "Also extracting names from /lib/syscalls.exp for good ole AIX..." >&4 | |
398 | $sed -n 's/^\([^ ]*\)[ ]*syscall[0-9]*[ ]*$/\1/p' \ | |
399 | /lib/syscalls.exp >>libc.list | |
400 | fi | |
401 | ?X: remember, indentation is wrong on purpose--RAM | |
402 | ;; | |
403 | esac | |
404 | $rm -f libnames libpath | |
405 |