perl 5.0 alpha 8
[p5sagit/p5-mst-13.2.git] / U / libc.U
CommitLineData
2304df62 1?X: These units are based on the ones supplied with dist-3.0
2?X: patchlevel 22. They have been changed or enhanced to work with
3?X: perl5alpha. I would appreciate hearing about any changes,
4?X: corrections, or enhancements.
5?X: Andy Dougherty doughera@lafcol.lafayette.edu
6?X: Dept. of Physics
7?X: Lafayette College
8?X: Easton, PA 18042-1782
9?X: Sat Apr 2 15:45:17 EST 1994
10?RCS: $Id: libc.U,v 3.0.1.3 1994/01/24 14:12:17 ram Exp $
11?RCS:
12?RCS: Copyright (c) 1991-1993, Raphael Manfredi
13?RCS:
14?RCS: You may redistribute only under the terms of the Artistic Licence,
15?RCS: as specified in the README file that comes with the distribution.
16?RCS: You may reuse parts of this distribution only within the terms of
17?RCS: that same Artistic Licence; a copy of which may be found at the root
18?RCS: of the source tree for dist 3.0.
19?RCS:
20?RCS: $Log: libc.U,v $
21?RCS: Revision 3.0.1.3 1994/01/24 14:12:17 ram
22?RCS: patch16: can now export nm_extract as an internal-use only variable
23?RCS:
24?RCS: Revision 3.0.1.2 1993/09/13 16:09:03 ram
25?RCS: patch10: added special handling for Apollo systems (WAD)
26?RCS:
27?RCS: Revision 3.0.1.1 1993/08/27 14:40:03 ram
28?RCS: patch7: added entry for /usr/shlib/libc.so (OSF/1 machines)
29?RCS:
30?RCS: Revision 3.0 1993/08/18 12:08:57 ram
31?RCS: Baseline for dist 3.0 netwide release.
32?RCS:
33?MAKE:libc +nm_extract: echo n c rm test grep Getfile Myread Oldconfig Loc \
34 sed libs incpath libpth runnm nm_opt contains plibpth xlibpth
35?MAKE: -pick add $@ %<
36?S:libc:
37?S: This variable contains the location of the C library.
38?S:.
39?S:nm_extract:
40?S: This variable holds the name of the extraction command used to process
41?S: the output of nm and yield the list of defined symbols. It is used
42?S: internally by Configure.
43?S:.
44?T:thislib try libnames xxx xscan xrun thisname com tans
45?LINT:change libpth nm_opt
46case "$runnm" in
47true)
48?X: indentation is wrong on purpose--RAM
49: get list of predefined functions in a handy place
50echo " "
51case "$libc" in
52'') libc=unknown
53 case "$libs" in
54 *-lc_s*) libc=`./loc libc_s.a $libc $libpth`
55 esac
56 ;;
57esac
58libpth="$plibpth $libpth"
59libnames='';
60case "$libs" in
61'') ;;
62*) for thislib in $libs; do
63 case "$thislib" in
64 -l*)
65 thislib=`expr X$thislib : 'X-l\(.*\)'`
66 try=`./loc lib$thislib.a blurfl/dyick $libpth`
67 if test ! -f $try; then
68 try=`./loc lib$thislib blurfl/dyick $libpth`
69 if test ! -f $try; then
70 try=`./loc lib$thislib.so.'*' blurfl/dyick $libpth`
71 if test ! -f $try; then
72 try=`./loc $thislib blurfl/dyick $libpth`
73 if test ! -f $try; then
74 try=`./loc Slib$thislib.a blurfl/dyick $xlibpth`
75 if test ! -f $try; then
76 try=''
77 fi
78 fi
79 fi
80 fi
81 fi
82 libnames="$libnames $try"
83 ;;
84 *) libnames="$libnames $thislib" ;;
85 esac
86 done
87 ;;
88esac
89?X:
90?X: Some systems (e.g. DG/UX) use "environmental" links, which make the test
91?X: -f fail. Ditto for symbolic links. So in order to reliably check the
92?X: existence of a file, we use test -r. It will still fail with DG/UX links
93?X: though, but at least it will detect symbolic links. At some strategic
94?X: points, we make use of (test -h), using a sub-shell in case builtin test
95?X: does not implement the -h check for symbolic links. This makes it
96?X: possible to preset libc in a hint file for instance and have it show up
97?X: as-is in the question.
98?X:
99xxx=normal
100case "$libc" in
101unknown)
102 set /usr/ccs/lib/libc.so
103 $test -r $1 || set /usr/lib/libc.so
104 $test -r $1 || set /usr/shlib/libc.so
105 $test -r $1 || set /usr/lib/libc.so.[0-9]*
106 $test -r $1 || set /lib/libsys_s.a
107 eval set \$$#
108 ;;
109*)
110?X: ensure the test below for the (shared) C library will fail
111 set blurfl
112 ;;
113esac
114if $test -r "$1"; then
115 echo "Your (shared) C library seems to be in $1."
116 libc="$1"
117elif $test -r /lib/libc && $test -r /lib/clib; then
118?X:
119?X: Apollo has its C library in /lib/clib AND /lib/libc
120?X: not to mention its math library in /lib/syslib...
121?X:
122 echo "Your C library seems to be in both /lib/clib and /lib/libc."
123 xxx=apollo
124 libc='/lib/clib /lib/libc'
125 if $test -r /lib/syslib; then
126 echo "(Your math library is in /lib/syslib.)"
127?X: Put syslib in libc -- not quite right, but won't hurt
128 libc="$libc /lib/syslib"
129 fi
130elif $test -r "$libc" || (test -h "$libc") >/dev/null 2>&1; then
131 echo "Your C library seems to be in $libc, as you said before."
132?X: For mips, and...
133elif $test -r $incpath/usr/lib/libc.a; then
134 libc=$incpath/usr/lib/libc.a;
135 echo "Your C library seems to be in $libc. That's fine."
136elif $test -r /lib/libc.a; then
137 libc=/lib/libc.a;
138 echo "Your C library seems to be in $libc. You're normal."
139else
140 if tans=`./loc libc.a blurfl/dyick $libpth`; $test -r "$tans"; then
141 :
142 elif tans=`./loc libc blurfl/dyick $libpth`; $test -r "$tans"; then
143 libnames="$libnames "`./loc clib blurfl/dyick $libpth`
144 elif tans=`./loc clib blurfl/dyick $libpth`; $test -r "$tans"; then
145 :
146 elif tans=`./loc Slibc.a blurfl/dyick $xlibpth`; $test -r "$tans"; then
147 :
148 elif tans=`./loc Mlibc.a blurfl/dyick $xlibpth`; $test -r "$tans"; then
149 :
150 else
151 tans=`./loc Llibc.a blurfl/dyick $xlibpth`
152 fi
153 if $test -r "$tans"; then
154 echo "Your C library seems to be in $tans, of all places."
155 libc=$tans
156 else
157 libc='blurfl'
158 fi
159fi
160if $test $xxx = apollo -o -r "$libc" || (test -h "$libc") >/dev/null 2>&1; then
161 dflt="$libc"
162 cat <<EOM
163
164If the guess above is wrong (which it might be if you're using a strange
165compiler, or your machine supports multiple models), you can override it here.
166
167EOM
168else
169 dflt=''
170 echo $libpth | tr ' ' '\012' | sort | uniq > libpath
171 cat >&4 <<EOM
172I can't seem to find your C library. I've looked in the following places:
173
174EOM
175 $sed 's/^/ /' libpath
176 cat <<EOM
177
178None of these seems to contain your C library. I need to get its name...
179
180EOM
181fi
182fn=f
183rp='Where is your C library?'
184. ./getfile
185libc="$ans"
186
187echo " "
188echo $libc $libnames | tr ' ' '\012' | sort | uniq > libnames
189set X `cat libnames`
190shift
191xxx=files
192case $# in 1) xxx=file; esac
193echo "Extracting names from the following $xxx for later perusal:" >&4
194echo " "
195$sed 's/^/ /' libnames >&4
196echo " "
197$echo $n "This may take a while...$c" >&4
198
199nm $nm_opt $* 2>/dev/null >libc.tmp
200$echo $n ".$c"
201?X:
202?X: To accelerate processing, we look at the correct 'sed' command
203?X: by using a small subset of libc.tmp, i.e. fprintf function.
204?X: When we know which sed command to use, do the name extraction
205?X:
206$grep fprintf libc.tmp > libc.ptf
207?X:
208?X: In order to ehance readability and save some space, we define
209?X: some variables that will be "eval"ed.
210?X:
211xscan='eval "<libc.ptf $com >libc.list"; $echo $n ".$c" >&4'
212xrun='eval "<libc.tmp $com >libc.list"; echo "done" >&4'
213?X: BSD-like output
214if com="$sed -n -e 's/^.* [ADTS] *_[_.]*//p' -e 's/^.* [ADTS] //p'";\
215 eval $xscan;\
216 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
217 eval $xrun
218?X: SYSV-like output
219elif com="$sed -n -e 's/^__*//' -e 's/^\([a-zA-Z_0-9$]*\).*xtern.*/\1/p'";\
220 eval $xscan;\
221 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
222 eval $xrun
223elif com="$sed -n -e '/|UNDEF/d' -e '/FUNC..GL/s/^.*|__*//p'";\
224 eval $xscan;\
225 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
226 eval $xrun
227elif com="$sed -n -e 's/^.* D __*//p' -e 's/^.* D //p'";\
228 eval $xscan;\
229 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
230 eval $xrun
231elif com="$sed -n -e 's/^_//' -e 's/^\([a-zA-Z_0-9]*\).*xtern.*text.*/\1/p'";\
232 eval $xscan;\
233 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
234 eval $xrun
235elif com="$sed -n -e 's/^.*|FUNC |GLOB .*|//p'";\
236 eval $xscan;\
237 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
238 eval $xrun
239elif com="$grep '|' | $sed -n -e '/|COMMON/d' -e '/|DATA/d' \
240 -e '/ file/d' -e 's/^\([^ ]*\).*/\1/p'";\
241 eval $xscan;\
242 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
243 eval $xrun
244elif com="$sed -n -e 's/^.*|FUNC |GLOB .*|//p' -e 's/^.*|FUNC |WEAK .*|//p'";\
245 eval $xscan;\
246 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
247 eval $xrun
248?X: mips nm output (sysV)
249elif com="$sed -n -e 's/^__//' -e '/|Undef/d' -e '/|Proc/s/ .*//p'";\
250 eval $xscan;\
251 $contains '^fprintf$' libc.list >/dev/null 2>&1; then
252 eval $xrun
253else
254 nm -p $* 2>/dev/null >libc.tmp
255 com="$sed -n -e 's/^.* [ADTS] *_[_.]*//p' -e 's/^.* [ADTS] //p'";\
256 eval "<libc.tmp $com >libc.list"
257 if $contains '^fprintf$' libc.list >/dev/null 2>&1; then
258 nm_opt='-p'
259 echo "done" >&4
260 else
261 echo " "
262 echo "nm didn't seem to work right. Trying ar instead..." >&4
263 com=''
264 if ar t $libc > libc.tmp; then
265 for thisname in $libnames; do
266 ar t $thisname >>libc.tmp
267 done
268 $sed -e 's/\.o$//' < libc.tmp > libc.list
269 echo "Ok." >&4
270 else
271 echo "ar didn't seem to work right." >&4
272 echo "Maybe this is a Cray...trying bld instead..." >&4
273 if bld t $libc | $sed -e 's/.*\///' -e 's/\.o:.*$//' > libc.list; then
274 for thisname in $libnames; do
275 bld t $libnames | \
276 $sed -e 's/.*\///' -e 's/\.o:.*$//' >>libc.list
277 ar t $thisname >>libc.tmp
278 done
279 echo "Ok." >&4
280 else
281 echo "That didn't work either. Giving up." >&4
282 exit 1
283 fi
284 fi
285 fi
286fi
287nm_extract="$com"
288if $test -f /lib/syscalls.exp; then
289 echo " "
290 echo "Also extracting names from /lib/syscalls.exp for good ole AIX..." >&4
291 $sed -n 's/^\([^ ]*\)[ ]*syscall$/\1/p' /lib/syscalls.exp >>libc.list
292fi
293?X: remember, indentation is wrong on purpose--RAM
294;;
295esac
296$rm -f libnames libpath
297