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