perl 5.0 alpha 9
[p5sagit/p5-mst-13.2.git] / U / libc.U
1 ?RCS: $Id: libc.U,v 3.0.1.3 1994/01/24 14:12:17 ram Exp $
2 ?RCS:
3 ?RCS: Copyright (c) 1991-1993, Raphael Manfredi
4 ?RCS: 
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.
10 ?RCS:
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
14 ?RCS:
15 ?RCS: Revision 3.0.1.2  1993/09/13  16:09:03  ram
16 ?RCS: patch10: added special handling for Apollo systems (WAD)
17 ?RCS:
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)
20 ?RCS:
21 ?RCS: Revision 3.0  1993/08/18  12:08:57  ram
22 ?RCS: Baseline for dist 3.0 netwide release.
23 ?RCS:
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 $@ %<
27 ?S:libc:
28 ?S:     This variable contains the location of the C library.
29 ?S:.
30 ?S:nm_extract:
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.
34 ?S:.
35 ?T:thislib try libnames xxx xscan xrun thisname com tans
36 ?LINT:change libpth nm_opt
37 case "$runnm" in
38 true)
39 ?X: indentation is wrong on purpose--RAM
40 : get list of predefined functions in a handy place
41 echo " "
42 case "$libc" in
43 '') libc=unknown
44         case "$libs" in
45         *-lc_s*) libc=`./loc libc_s.a $libc $libpth`
46         esac
47         ;;
48 esac
49 libpth="$plibpth $libpth"
50 libnames='';
51 case "$libs" in
52 '') ;;
53 *)  for thislib in $libs; do
54         case "$thislib" in
55         -l*)
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
67                                                         try=''
68                                                 fi
69                                         fi
70                                 fi
71                         fi
72                 fi
73                 libnames="$libnames $try"
74                 ;;
75         *) libnames="$libnames $thislib" ;;
76         esac
77         done
78         ;;
79 esac
80 ?X:
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.
89 ?X:
90 xxx=normal
91 case "$libc" in
92 unknown)
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
98         eval set \$$#
99         ;;
100 *)
101 ?X: ensure the test below for the (shared) C library will fail
102         set blurfl
103         ;;
104 esac
105 if $test -r "$1"; then
106         echo "Your (shared) C library seems to be in $1."
107         libc="$1"
108 elif $test -r /lib/libc && $test -r /lib/clib; then
109 ?X:
110 ?X: Apollo has its C library in /lib/clib AND /lib/libc
111 ?X: not to mention its math library in /lib/syslib...
112 ?X:
113         echo "Your C library seems to be in both /lib/clib and /lib/libc."
114         xxx=apollo
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"
120         fi
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."
123 ?X: For mips, and...
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
128         libc=/lib/libc.a;
129         echo "Your C library seems to be in $libc.  You're normal."
130 else
131         if tans=`./loc libc.a blurfl/dyick $libpth`; $test -r "$tans"; then
132                 :
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
136                 :
137         elif tans=`./loc Slibc.a blurfl/dyick $xlibpth`; $test -r "$tans"; then
138                 :
139         elif tans=`./loc Mlibc.a blurfl/dyick $xlibpth`; $test -r "$tans"; then
140                 :
141         else
142                 tans=`./loc Llibc.a blurfl/dyick $xlibpth`
143         fi
144         if $test -r "$tans"; then
145                 echo "Your C library seems to be in $tans, of all places."
146                 libc=$tans
147         else
148                 libc='blurfl'
149         fi
150 fi
151 if $test $xxx = apollo -o -r "$libc" || (test -h "$libc") >/dev/null 2>&1; then
152         dflt="$libc"
153         cat <<EOM
154
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.
157
158 EOM
159 else
160         dflt=''
161         echo $libpth | tr ' ' '\012' | sort | uniq > libpath
162         cat >&4 <<EOM
163 I can't seem to find your C library.  I've looked in the following places:
164
165 EOM
166         $sed 's/^/      /' libpath
167         cat <<EOM
168
169 None of these seems to contain your C library. I need to get its name...
170
171 EOM
172 fi
173 fn=f
174 rp='Where is your C library?'
175 . ./getfile
176 libc="$ans"
177
178 echo " "
179 echo $libc $libnames | tr ' ' '\012' | sort | uniq > libnames
180 set X `cat libnames`
181 shift
182 xxx=files
183 case $# in 1) xxx=file; esac
184 echo "Extracting names from the following $xxx for later perusal:" >&4
185 echo " "
186 $sed 's/^/      /' libnames >&4
187 echo " "
188 $echo $n "This may take a while...$c" >&4
189
190 nm $nm_opt $* 2>/dev/null >libc.tmp
191 $echo $n ".$c"
192 ?X:
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
196 ?X:
197 $grep fprintf libc.tmp > libc.ptf
198 ?X:
199 ?X: In order to ehance readability and save some space, we define
200 ?X:     some variables that will be "eval"ed.
201 ?X:
202 xscan='eval "<libc.ptf $com >libc.list"; $echo $n ".$c" >&4'
203 xrun='eval "<libc.tmp $com >libc.list"; echo "done" >&4'
204 ?X: BSD-like output
205 if com="$sed -n -e 's/^.* [ADTS]  *_[_.]*//p' -e 's/^.* [ADTS] //p'";\
206         eval $xscan;\
207         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
208                 eval $xrun
209 ?X: SYSV-like output
210 elif com="$sed -n -e 's/^__*//' -e 's/^\([a-zA-Z_0-9$]*\).*xtern.*/\1/p'";\
211         eval $xscan;\
212         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
213                 eval $xrun
214 elif com="$sed -n -e '/|UNDEF/d' -e '/FUNC..GL/s/^.*|__*//p'";\
215         eval $xscan;\
216         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
217                 eval $xrun
218 elif com="$sed -n -e 's/^.* D __*//p' -e 's/^.* D //p'";\
219         eval $xscan;\
220         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
221                 eval $xrun
222 elif com="$sed -n -e 's/^_//' -e 's/^\([a-zA-Z_0-9]*\).*xtern.*text.*/\1/p'";\
223         eval $xscan;\
224         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
225                 eval $xrun
226 elif com="$sed -n -e 's/^.*|FUNC |GLOB .*|//p'";\
227         eval $xscan;\
228         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
229                 eval $xrun
230 elif com="$grep '|' | $sed -n -e '/|COMMON/d' -e '/|DATA/d' \
231                                 -e '/ file/d' -e 's/^\([^       ]*\).*/\1/p'";\
232         eval $xscan;\
233         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
234                 eval $xrun
235 elif com="$sed -n -e 's/^.*|FUNC |GLOB .*|//p' -e 's/^.*|FUNC |WEAK .*|//p'";\
236         eval $xscan;\
237         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
238                 eval $xrun
239 ?X: mips nm output (sysV)
240 elif com="$sed -n -e 's/^__//' -e '/|Undef/d' -e '/|Proc/s/ .*//p'";\
241         eval $xscan;\
242         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
243                 eval $xrun
244 else
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
249                 nm_opt='-p'
250                 echo "done" >&4
251         else
252                 echo " "
253                 echo "nm didn't seem to work right. Trying ar instead..." >&4
254                 com=''
255                 if ar t $libc > libc.tmp; then
256                         for thisname in $libnames; do
257                                 ar t $thisname >>libc.tmp
258                         done
259                         $sed -e 's/\.o$//' < libc.tmp > libc.list
260                         echo "Ok." >&4
261                 else
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
266                                         bld t $libnames | \
267                                         $sed -e 's/.*\///' -e 's/\.o:.*$//' >>libc.list
268                                         ar t $thisname >>libc.tmp
269                                 done
270                                 echo "Ok." >&4
271                         else
272                                 echo "That didn't work either.  Giving up." >&4
273                                 exit 1
274                         fi
275                 fi
276         fi
277 fi
278 nm_extract="$com"
279 if $test -f /lib/syscalls.exp; then
280         echo " "
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
283 fi
284 ?X: remember, indentation is wrong on purpose--RAM
285 ;;
286 esac
287 $rm -f libnames libpath
288