1 ?RCS: $Id: libc.U,v 3.0.1.3 1994/01/24 14:12:17 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.3 1994/01/24 14:12:17 ram
13 ?RCS: patch16: can now export nm_extract as an internal-use only variable
15 ?RCS: Revision 3.0.1.2 1993/09/13 16:09:03 ram
16 ?RCS: patch10: added special handling for Apollo systems (WAD)
18 ?RCS: Revision 3.0.1.1 1993/08/27 14:40:03 ram
19 ?RCS: patch7: added entry for /usr/shlib/libc.so (OSF/1 machines)
21 ?RCS: Revision 3.0 1993/08/18 12:08:57 ram
22 ?RCS: Baseline for dist 3.0 netwide release.
24 ?MAKE:libc +nm_extract: echo n c rm test grep Getfile Myread Oldconfig Loc \
25 sed libs incpath libpth runnm nm_opt contains plibpth xlibpth
26 ?MAKE: -pick add $@ %<
28 ?S: This variable contains the location of the C library.
31 ?S: This variable holds the name of the extraction command used to process
32 ?S: the output of nm and yield the list of defined symbols. It is used
33 ?S: internally by Configure.
35 ?T:thislib try libnames xxx xscan xrun thisname com tans
36 ?LINT:change libpth nm_opt
39 ?X: indentation is wrong on purpose--RAM
40 : get list of predefined functions in a handy place
45 *-lc_s*) libc=`./loc libc_s.a $libc $libpth`
49 libpth="$plibpth $libpth"
53 *) for thislib in $libs; do
56 thislib=`expr X$thislib : 'X-l\(.*\)'`
57 try=`./loc lib$thislib.a blurfl/dyick $libpth`
58 if test ! -f $try; then
59 try=`./loc lib$thislib blurfl/dyick $libpth`
60 if test ! -f $try; then
61 try=`./loc lib$thislib.so.'*' blurfl/dyick $libpth`
62 if test ! -f $try; then
63 try=`./loc $thislib blurfl/dyick $libpth`
64 if test ! -f $try; then
65 try=`./loc Slib$thislib.a blurfl/dyick $xlibpth`
66 if test ! -f $try; then
73 libnames="$libnames $try"
75 *) libnames="$libnames $thislib" ;;
81 ?X: Some systems (e.g. DG/UX) use "environmental" links, which make the test
82 ?X: -f fail. Ditto for symbolic links. So in order to reliably check the
83 ?X: existence of a file, we use test -r. It will still fail with DG/UX links
84 ?X: though, but at least it will detect symbolic links. At some strategic
85 ?X: points, we make use of (test -h), using a sub-shell in case builtin test
86 ?X: does not implement the -h check for symbolic links. This makes it
87 ?X: possible to preset libc in a hint file for instance and have it show up
88 ?X: as-is in the question.
93 set /usr/ccs/lib/libc.so
94 $test -r $1 || set /usr/lib/libc.so
95 $test -r $1 || set /usr/shlib/libc.so
96 $test -r $1 || set /usr/lib/libc.so.[0-9]*
97 $test -r $1 || set /lib/libsys_s.a
101 ?X: ensure the test below for the (shared) C library will fail
105 if $test -r "$1"; then
106 echo "Your (shared) C library seems to be in $1."
108 elif $test -r /lib/libc && $test -r /lib/clib; then
110 ?X: Apollo has its C library in /lib/clib AND /lib/libc
111 ?X: not to mention its math library in /lib/syslib...
113 echo "Your C library seems to be in both /lib/clib and /lib/libc."
115 libc='/lib/clib /lib/libc'
116 if $test -r /lib/syslib; then
117 echo "(Your math library is in /lib/syslib.)"
118 ?X: Put syslib in libc -- not quite right, but won't hurt
119 libc="$libc /lib/syslib"
121 elif $test -r "$libc" || (test -h "$libc") >/dev/null 2>&1; then
122 echo "Your C library seems to be in $libc, as you said before."
124 elif $test -r $incpath/usr/lib/libc.a; then
125 libc=$incpath/usr/lib/libc.a;
126 echo "Your C library seems to be in $libc. That's fine."
127 elif $test -r /lib/libc.a; then
129 echo "Your C library seems to be in $libc. You're normal."
131 if tans=`./loc libc.a blurfl/dyick $libpth`; $test -r "$tans"; then
133 elif tans=`./loc libc blurfl/dyick $libpth`; $test -r "$tans"; then
134 libnames="$libnames "`./loc clib blurfl/dyick $libpth`
135 elif tans=`./loc clib blurfl/dyick $libpth`; $test -r "$tans"; then
137 elif tans=`./loc Slibc.a blurfl/dyick $xlibpth`; $test -r "$tans"; then
139 elif tans=`./loc Mlibc.a blurfl/dyick $xlibpth`; $test -r "$tans"; then
142 tans=`./loc Llibc.a blurfl/dyick $xlibpth`
144 if $test -r "$tans"; then
145 echo "Your C library seems to be in $tans, of all places."
151 if $test $xxx = apollo -o -r "$libc" || (test -h "$libc") >/dev/null 2>&1; then
155 If the guess above is wrong (which it might be if you're using a strange
156 compiler, or your machine supports multiple models), you can override it here.
161 echo $libpth | tr ' ' '\012' | sort | uniq > libpath
163 I can't seem to find your C library. I've looked in the following places:
166 $sed 's/^/ /' libpath
169 None of these seems to contain your C library. I need to get its name...
174 rp='Where is your C library?'
179 echo $libc $libnames | tr ' ' '\012' | sort | uniq > libnames
183 case $# in 1) xxx=file; esac
184 echo "Extracting names from the following $xxx for later perusal:" >&4
186 $sed 's/^/ /' libnames >&4
188 $echo $n "This may take a while...$c" >&4
190 nm $nm_opt $* 2>/dev/null >libc.tmp
193 ?X: To accelerate processing, we look at the correct 'sed' command
194 ?X: by using a small subset of libc.tmp, i.e. fprintf function.
195 ?X: When we know which sed command to use, do the name extraction
197 $grep fprintf libc.tmp > libc.ptf
199 ?X: In order to ehance readability and save some space, we define
200 ?X: some variables that will be "eval"ed.
202 xscan='eval "<libc.ptf $com >libc.list"; $echo $n ".$c" >&4'
203 xrun='eval "<libc.tmp $com >libc.list"; echo "done" >&4'
205 if com="$sed -n -e 's/^.* [ADTS] *_[_.]*//p' -e 's/^.* [ADTS] //p'";\
207 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
210 elif com="$sed -n -e 's/^__*//' -e 's/^\([a-zA-Z_0-9$]*\).*xtern.*/\1/p'";\
212 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
214 elif com="$sed -n -e '/|UNDEF/d' -e '/FUNC..GL/s/^.*|__*//p'";\
216 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
218 elif com="$sed -n -e 's/^.* D __*//p' -e 's/^.* D //p'";\
220 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
222 elif com="$sed -n -e 's/^_//' -e 's/^\([a-zA-Z_0-9]*\).*xtern.*text.*/\1/p'";\
224 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
226 elif com="$sed -n -e 's/^.*|FUNC |GLOB .*|//p'";\
228 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
230 elif com="$grep '|' | $sed -n -e '/|COMMON/d' -e '/|DATA/d' \
231 -e '/ file/d' -e 's/^\([^ ]*\).*/\1/p'";\
233 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
235 elif com="$sed -n -e 's/^.*|FUNC |GLOB .*|//p' -e 's/^.*|FUNC |WEAK .*|//p'";\
237 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
239 ?X: mips nm output (sysV)
240 elif com="$sed -n -e 's/^__//' -e '/|Undef/d' -e '/|Proc/s/ .*//p'";\
242 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
245 nm -p $* 2>/dev/null >libc.tmp
246 com="$sed -n -e 's/^.* [ADTS] *_[_.]*//p' -e 's/^.* [ADTS] //p'";\
247 eval "<libc.tmp $com >libc.list"
248 if $contains '^fprintf$' libc.list >/dev/null 2>&1; then
253 echo "nm didn't seem to work right. Trying ar instead..." >&4
255 if ar t $libc > libc.tmp; then
256 for thisname in $libnames; do
257 ar t $thisname >>libc.tmp
259 $sed -e 's/\.o$//' < libc.tmp > libc.list
262 echo "ar didn't seem to work right." >&4
263 echo "Maybe this is a Cray...trying bld instead..." >&4
264 if bld t $libc | $sed -e 's/.*\///' -e 's/\.o:.*$//' > libc.list; then
265 for thisname in $libnames; do
267 $sed -e 's/.*\///' -e 's/\.o:.*$//' >>libc.list
268 ar t $thisname >>libc.tmp
272 echo "That didn't work either. Giving up." >&4
279 if $test -f /lib/syscalls.exp; then
281 echo "Also extracting names from /lib/syscalls.exp for good ole AIX..." >&4
282 $sed -n 's/^\([^ ]*\)[ ]*syscall$/\1/p' /lib/syscalls.exp >>libc.list
284 ?X: remember, indentation is wrong on purpose--RAM
287 $rm -f libnames libpath