1 ?RCS: $Id: libc.U,v 3.0.1.10 1997/02/28 15:56:48 ram Exp $
3 ?RCS: Copyright (c) 1991-1993, Raphael Manfredi
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
9 ?RCS: of the source tree for dist 3.0.
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
16 ?RCS: Revision 3.0.1.9 1995/07/25 14:11:56 ram
17 ?RCS: patch56: now knows about OS/2 platforms
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)
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)
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
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
36 ?RCS: Revision 3.0.1.4 1994/05/06 15:06:33 ram
37 ?RCS: patch23: added shared library knowledge (ADO and WED)
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
42 ?RCS: Revision 3.0.1.2 1993/09/13 16:09:03 ram
43 ?RCS: patch10: added special handling for Apollo systems (WAD)
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)
48 ?RCS: Revision 3.0 1993/08/18 12:08:57 ram
49 ?RCS: Baseline for dist 3.0 netwide release.
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 \
53 so _a _o osname trnl tr sort uniq
54 ?MAKE: -pick add $@ %<
56 ?S: This variable contains the location of the C library.
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.
63 ?T:thislib try libnames xxx xscan xrun thisname com tans file
71 ?X: indentation is wrong on purpose--RAM
72 : get list of predefined functions in a handy place
77 *-lc_s*) libc=`./loc libc_s$_a $libc $libpth`
83 *) for thislib in $libs; do
86 : Handle C library specially below.
89 thislib=`echo $thislib | $sed -e 's/^-l//'`
90 if try=`./loc lib$thislib.$so.'*' X $libpth`; $test -f "$try"; then
92 elif try=`./loc lib$thislib.$so X $libpth`; $test -f "$try"; then
94 elif try=`./loc lib$thislib$_a X $libpth`; $test -f "$try"; then
96 elif try=`./loc $thislib$_a X $libpth`; $test -f "$try"; then
98 elif try=`./loc lib$thislib X $libpth`; $test -f "$try"; then
100 elif try=`./loc $thislib X $libpth`; $test -f "$try"; then
102 elif try=`./loc Slib$thislib$_a X $xlibpth`; $test -f "$try"; then
107 libnames="$libnames $try"
109 *) libnames="$libnames $thislib" ;;
115 ?X: Some systems (e.g. DG/UX) use "environmental" links, which make the test
116 ?X: -f fail. Ditto for symbolic links. So in order to reliably check the
117 ?X: existence of a file, we use test -r. It will still fail with DG/UX links
118 ?X: though, but at least it will detect symbolic links. At some strategic
119 ?X: points, we make use of (test -h), using a sub-shell in case builtin test
120 ?X: does not implement the -h check for symbolic links. This makes it
121 ?X: possible to preset libc in a hint file for instance and have it show up
122 ?X: as-is in the question.
128 ?X: The sed below transforms .so.9 .so.12 into something like .so.0009 .so.0012,
129 ?X: then sorts on it to allow keeping .so.12 instead of .so.9 as the latest
130 ?X: up-to-date library. The initial filename (before sed munging, saved in hold
131 ?X: space via 'h') is appended via 'G' before sorting, then the leading munged
132 ?X: part is removed after sorting. Nice efficient work from Tye McQueen.
133 ?X: The initial blurfl is here to prevent the trailing pipe from producing an
134 ?X: empty string, causing Configure to output all its set variables!
137 for xxx in $libpth; do
138 $test -r $1 || set $xxx/libc.$so
139 : The messy sed command sorts on library version numbers.
141 set `echo blurfl; echo $xxx/libc.$so.[0-9]* | \
142 tr ' ' $trnl | egrep -v '\.[A-Za-z]*$' | $sed -e '
144 s/[0-9][0-9]*/0000&/g
145 s/0*\([0-9][0-9][0-9][0-9][0-9]\)/\1/g
148 $sort | $sed -e 's/^.* //'`
151 $test -r $1 || set /usr/ccs/lib/libc.$so
152 $test -r $1 || set /lib/libsys_s$_a
155 ?X: ensure the test below for the (shared) C library will fail
159 if $test -r "$1"; then
160 echo "Your (shared) C library seems to be in $1."
162 elif $test -r /lib/libc && $test -r /lib/clib; then
164 ?X: Apollo has its C library in /lib/clib AND /lib/libc
165 ?X: not to mention its math library in /lib/syslib...
167 echo "Your C library seems to be in both /lib/clib and /lib/libc."
169 libc='/lib/clib /lib/libc'
170 if $test -r /lib/syslib; then
171 echo "(Your math library is in /lib/syslib.)"
172 ?X: Put syslib in libc -- not quite right, but won't hurt
173 libc="$libc /lib/syslib"
175 elif $test -r "$libc" || (test -h "$libc") >/dev/null 2>&1; then
176 echo "Your C library seems to be in $libc, as you said before."
178 elif $test -r $incpath/usr/lib/libc$_a; then
179 libc=$incpath/usr/lib/libc$_a;
180 echo "Your C library seems to be in $libc. That's fine."
181 elif $test -r /lib/libc$_a; then
183 echo "Your C library seems to be in $libc. You're normal."
185 if tans=`./loc libc$_a blurfl/dyick $libpth`; $test -r "$tans"; then
187 elif tans=`./loc libc blurfl/dyick $libpth`; $test -r "$tans"; then
188 libnames="$libnames "`./loc clib blurfl/dyick $libpth`
189 elif tans=`./loc clib blurfl/dyick $libpth`; $test -r "$tans"; then
191 elif tans=`./loc Slibc$_a blurfl/dyick $xlibpth`; $test -r "$tans"; then
193 elif tans=`./loc Mlibc$_a blurfl/dyick $xlibpth`; $test -r "$tans"; then
196 tans=`./loc Llibc$_a blurfl/dyick $xlibpth`
198 if $test -r "$tans"; then
199 echo "Your C library seems to be in $tans, of all places."
205 if $test $xxx = apollo -o -r "$libc" || (test -h "$libc") >/dev/null 2>&1; then
209 If the guess above is wrong (which it might be if you're using a strange
210 compiler, or your machine supports multiple models), you can override it here.
215 echo $libpth | $tr ' ' $trnl | $sort | $uniq > libpath
217 I can't seem to find your C library. I've looked in the following places:
220 $sed 's/^/ /' libpath
223 None of these seems to contain your C library. I need to get its name...
228 rp='Where is your C library?'
233 echo $libc $libnames | $tr ' ' $trnl | $sort | $uniq > libnames
237 case $# in 1) xxx=file; esac
238 echo "Extracting names from the following $xxx for later perusal:" >&4
240 $sed 's/^/ /' libnames >&4
242 $echo $n "This may take a while...$c" >&4
245 ?X: Linux may need the special Dynamic option to nm for shared libraries.
246 ?X: In general, this is stored in the nm_so_opt variable.
247 ?X: Unfortunately, that option may be fatal on non-shared libraries.
251 *$so*) $nm $nm_so_opt $nm_opt $file 2>/dev/null;;
252 *) $nm $nm_opt $file 2>/dev/null;;
258 ?X: To accelerate processing, we look at the correct 'sed' command
259 ?X: by using a small subset of libc.tmp, i.e. fprintf function.
260 ?X: When we know which sed command to use, do the name extraction
262 $grep fprintf libc.tmp > libc.ptf
264 ?X: In order to ehance readability and save some space, we define
265 ?X: some variables that will be "eval"ed.
267 xscan='eval "<libc.ptf $com >libc.list"; $echo $n ".$c" >&4'
268 xrun='eval "<libc.tmp $com >libc.list"; echo "done." >&4'
269 ?X: BSD-like output, I and W types added for Linux
270 ?X: Some versions of Linux include a leading __IO in the symbol name.
271 ?X: HPUX10 reportedly has trailing spaces, though I'm suprised it has
272 ?X: BSD-like output. (AD).
274 if com="$sed -n -e 's/__IO//' -e 's/^.* $xxx *//p'";\
276 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
279 elif com="$sed -n -e 's/^__*//' -e 's/^\([a-zA-Z_0-9$]*\).*xtern.*/\1/p'";\
281 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
283 elif com="$sed -n -e '/|UNDEF/d' -e '/FUNC..GL/s/^.*|__*//p'";\
285 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
287 elif com="$sed -n -e 's/^.* D __*//p' -e 's/^.* D //p'";\
289 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
291 elif com="$sed -n -e 's/^_//' -e 's/^\([a-zA-Z_0-9]*\).*xtern.*text.*/\1/p'";\
293 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
295 elif com="$sed -n -e 's/^.*|FUNC |GLOB .*|//p'";\
297 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
299 elif com="$grep '|' | $sed -n -e '/|COMMON/d' -e '/|DATA/d' \
300 -e '/ file/d' -e 's/^\([^ ]*\).*/\1/p'";\
302 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
304 elif com="$sed -n -e 's/^.*|FUNC |GLOB .*|//p' -e 's/^.*|FUNC |WEAK .*|//p'";\
306 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
308 ?X: mips nm output (sysV)
309 elif com="$sed -n -e 's/^__//' -e '/|Undef/d' -e '/|Proc/s/ .*//p'";\
311 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
313 elif com="$sed -n -e 's/^.*|Proc .*|Text *| *//p'";\
315 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
317 elif com="$sed -n -e '/Def. Text/s/.* \([^ ]*\)\$/\1/p'";\
319 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
322 elif com="$sed -n -e 's/^[-0-9a-f ]*_\(.*\)=.*/\1/p'";\
324 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
326 elif com="$sed -n -e 's/.*\.text n\ \ \ \.//p'";\
328 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
331 elif com="sed -n -e 's/^__.*//' -e 's/[ ]*D[ ]*[0-9]*.*//p'";\
333 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
336 $nm -p $* 2>/dev/null >libc.tmp
337 $grep fprintf libc.tmp > libc.ptf
338 if com="$sed -n -e 's/^.* [ADTSIW] *_[_.]*//p' -e 's/^.* [ADTSIW] //p'";\
339 eval $xscan; $contains '^fprintf$' libc.list >/dev/null 2>&1
345 echo "$nm didn't seem to work right. Trying $ar instead..." >&4
347 if $ar t $libc > libc.tmp && $contains '^fprintf$' libc.tmp >/dev/null 2>&1; then
348 for thisname in $libnames $libc; do
349 $ar t $thisname >>libc.tmp
351 $sed -e "s/\\$_o\$//" < libc.tmp > libc.list
353 elif test "X$osname" = "Xos2" && $ar tv $libc > libc.tmp; then
354 # Repeat libc to extract forwarders to DLL entries too
355 for thisname in $libnames $libc; do
356 $ar tv $thisname >>libc.tmp
357 # Revision 50 of EMX has bug in $ar.
358 # it will not extract forwarders to DLL entries
359 # Use emximp which will extract exactly them.
360 emximp -o tmp.imp $thisname \
362 $sed -e 's/^\([_a-zA-Z0-9]*\) .*$/\1/p' \
366 $sed -e "s/\\$_o\$//" -e 's/^ \+//' < libc.tmp > libc.list
369 echo "$ar didn't seem to work right." >&4
370 echo "Maybe this is a Cray...trying bld instead..." >&4
371 if bld t $libc | $sed -e 's/.*\///' -e "s/\\$_o:.*\$//" > libc.list
373 for thisname in $libnames; do
375 $sed -e 's/.*\///' -e "s/\\$_o:.*\$//" >>libc.list
376 $ar t $thisname >>libc.tmp
380 echo "That didn't work either. Giving up." >&4
390 echo "Since you are compiling for PASE, extracting more symbols from libc.a ...">&4
391 dump -Tv /lib/libc.a | awk '$7 == "/unix" {print $5 " " $8}' | grep "^SV" | awk '{print $2}' >> libc.list
393 *) if $test -f /lib/syscalls.exp; then
395 echo "Also extracting names from /lib/syscalls.exp for good ole AIX..." >&4
396 $sed -n 's/^\([^ ]*\)[ ]*syscall[0-9]*[ ]*$/\1/p' /lib/syscalls.exp >>libc.list
402 $rm -f libnames libpath