This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove spurious LINT: directives
[metaconfig.git] / U / modified / libc.U
1 ?RCS: $Id: libc.U,v 3.0.1.10 1997/02/28 15:56:48 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.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 \
53         so _a _o osname trnl tr sort uniq
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
64 ?F:!libnames
65 ?LINT:extern PASE
66 ?LINT:extern libnames
67 ?LINT:change nm_opt
68 ?INIT:libnames=''
69 case "$runnm" in
70 true)
71 ?X: indentation is wrong on purpose--RAM
72 : get list of predefined functions in a handy place
73 echo " "
74 case "$libc" in
75 '') libc=unknown
76         case "$libs" in
77         *-lc_s*) libc=`./loc libc_s$_a $libc $libpth`
78         esac
79         ;;
80 esac
81 case "$libs" in
82 '') ;;
83 *)  for thislib in $libs; do
84         case "$thislib" in
85         -lc|-lc_s)
86                 : Handle C library specially below.
87                 ;;
88         -l*)
89                 thislib=`echo $thislib | $sed -e 's/^-l//'`
90                 if try=`./loc lib$thislib.$so.'*' X $libpth`; $test -f "$try"; then
91                         :
92                 elif try=`./loc lib$thislib.$so X $libpth`; $test -f "$try"; then
93                         :
94                 elif try=`./loc lib$thislib$_a X $libpth`; $test -f "$try"; then
95                         :
96                 elif try=`./loc $thislib$_a X $libpth`; $test -f "$try"; then
97                         :
98                 elif try=`./loc lib$thislib X $libpth`; $test -f "$try"; then
99                         :
100                 elif try=`./loc $thislib X $libpth`; $test -f "$try"; then
101                         :
102                 elif try=`./loc Slib$thislib$_a X $xlibpth`; $test -f "$try"; then
103                         :
104                 else
105                         try=''
106                 fi
107                 libnames="$libnames $try"
108                 ;;
109         *) libnames="$libnames $thislib" ;;
110         esac
111         done
112         ;;
113 esac
114 ?X:
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.
123 ?X:
124 xxx=normal
125 case "$libc" in
126 unknown)
127 ?X:
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!
135 ?X:
136         set /lib/libc.$so
137         for xxx in $libpth; do
138                 $test -r $1 || set $xxx/libc.$so
139                 : The messy sed command sorts on library version numbers.
140                 $test -r $1 || \
141                         set `echo blurfl; echo $xxx/libc.$so.[0-9]* | \
142                         tr ' ' $trnl | egrep -v '\.[A-Za-z]*$' | $sed -e '
143                                 h
144                                 s/[0-9][0-9]*/0000&/g
145                                 s/0*\([0-9][0-9][0-9][0-9][0-9]\)/\1/g
146                                 G
147                                 s/\n/ /' | \
148                          $sort | $sed -e 's/^.* //'`
149                 eval set \$$#
150         done
151         $test -r $1 || set /usr/ccs/lib/libc.$so
152         $test -r $1 || set /lib/libsys_s$_a
153         ;;
154 *)
155 ?X: ensure the test below for the (shared) C library will fail
156         set blurfl
157         ;;
158 esac
159 if $test -r "$1"; then
160         echo "Your (shared) C library seems to be in $1."
161         libc="$1"
162 elif $test -r /lib/libc && $test -r /lib/clib; then
163 ?X:
164 ?X: Apollo has its C library in /lib/clib AND /lib/libc
165 ?X: not to mention its math library in /lib/syslib...
166 ?X:
167         echo "Your C library seems to be in both /lib/clib and /lib/libc."
168         xxx=apollo
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"
174         fi
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."
177 ?X: For mips, and...
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
182         libc=/lib/libc$_a;
183         echo "Your C library seems to be in $libc.  You're normal."
184 else
185         if tans=`./loc libc$_a blurfl/dyick $libpth`; $test -r "$tans"; then
186                 :
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
190                 :
191         elif tans=`./loc Slibc$_a blurfl/dyick $xlibpth`; $test -r "$tans"; then
192                 :
193         elif tans=`./loc Mlibc$_a blurfl/dyick $xlibpth`; $test -r "$tans"; then
194                 :
195         else
196                 tans=`./loc Llibc$_a blurfl/dyick $xlibpth`
197         fi
198         if $test -r "$tans"; then
199                 echo "Your C library seems to be in $tans, of all places."
200                 libc=$tans
201         else
202                 libc='blurfl'
203         fi
204 fi
205 if $test $xxx = apollo -o -r "$libc" || (test -h "$libc") >/dev/null 2>&1; then
206         dflt="$libc"
207         cat <<EOM
208
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.
211
212 EOM
213 else
214         dflt=''
215         echo $libpth | $tr ' ' $trnl | $sort | $uniq > libpath
216         cat >&4 <<EOM
217 I can't seem to find your C library.  I've looked in the following places:
218
219 EOM
220         $sed 's/^/      /' libpath
221         cat <<EOM
222
223 None of these seems to contain your C library. I need to get its name...
224
225 EOM
226 fi
227 fn=f
228 rp='Where is your C library?'
229 . ./getfile
230 libc="$ans"
231
232 echo " "
233 echo $libc $libnames | $tr ' ' $trnl | $sort | $uniq > libnames
234 set X `cat libnames`
235 shift
236 xxx=files
237 case $# in 1) xxx=file; esac
238 echo "Extracting names from the following $xxx for later perusal:" >&4
239 echo " "
240 $sed 's/^/      /' libnames >&4
241 echo " "
242 $echo $n "This may take a while...$c" >&4
243
244 ?X:
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.
248 ?X:
249 for file in $*; do
250         case $file in
251         *$so*) $nm $nm_so_opt $nm_opt $file 2>/dev/null;;
252         *) $nm $nm_opt $file 2>/dev/null;;
253         esac
254 done >libc.tmp
255
256 $echo $n ".$c"
257 ?X:
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
261 ?X:
262 $grep fprintf libc.tmp > libc.ptf
263 ?X:
264 ?X: In order to ehance readability and save some space, we define
265 ?X:     some variables that will be "eval"ed.
266 ?X:
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).
273 xxx='[ADTSIW]'
274 if com="$sed -n -e 's/__IO//' -e 's/^.* $xxx  *//p'";\
275         eval $xscan;\
276         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
277                 eval $xrun
278 ?X: SYSV-like output
279 elif com="$sed -n -e 's/^__*//' -e 's/^\([a-zA-Z_0-9$]*\).*xtern.*/\1/p'";\
280         eval $xscan;\
281         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
282                 eval $xrun
283 elif com="$sed -n -e '/|UNDEF/d' -e '/FUNC..GL/s/^.*|__*//p'";\
284         eval $xscan;\
285         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
286                 eval $xrun
287 elif com="$sed -n -e 's/^.* D __*//p' -e 's/^.* D //p'";\
288         eval $xscan;\
289         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
290                 eval $xrun
291 elif com="$sed -n -e 's/^_//' -e 's/^\([a-zA-Z_0-9]*\).*xtern.*text.*/\1/p'";\
292         eval $xscan;\
293         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
294                 eval $xrun
295 elif com="$sed -n -e 's/^.*|FUNC |GLOB .*|//p'";\
296         eval $xscan;\
297         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
298                 eval $xrun
299 elif com="$grep '|' | $sed -n -e '/|COMMON/d' -e '/|DATA/d' \
300                                 -e '/ file/d' -e 's/^\([^       ]*\).*/\1/p'";\
301         eval $xscan;\
302         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
303                 eval $xrun
304 elif com="$sed -n -e 's/^.*|FUNC |GLOB .*|//p' -e 's/^.*|FUNC |WEAK .*|//p'";\
305         eval $xscan;\
306         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
307                 eval $xrun
308 ?X: mips nm output (sysV)
309 elif com="$sed -n -e 's/^__//' -e '/|Undef/d' -e '/|Proc/s/ .*//p'";\
310         eval $xscan;\
311         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
312                 eval $xrun
313 elif com="$sed -n -e 's/^.*|Proc .*|Text *| *//p'";\
314         eval $xscan;\
315         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
316                 eval $xrun
317 elif com="$sed -n -e '/Def. Text/s/.* \([^ ]*\)\$/\1/p'";\
318         eval $xscan;\
319         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
320                 eval $xrun
321 ?X: OS/2 nm output
322 elif com="$sed -n -e 's/^[-0-9a-f ]*_\(.*\)=.*/\1/p'";\
323         eval $xscan;\
324         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
325                 eval $xrun
326 elif com="$sed -n -e 's/.*\.text n\ \ \ \.//p'";\
327         eval $xscan;\
328         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
329                 eval $xrun
330 ?X: AIX nm output
331 elif com="sed -n -e 's/^__.*//' -e 's/[       ]*D[    ]*[0-9]*.*//p'";\
332         eval $xscan;\
333         $contains '^fprintf$' libc.list >/dev/null 2>&1; then
334                 eval $xrun
335 else
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
340         then
341                 nm_opt='-p'
342                 eval $xrun
343         else
344                 echo " "
345                 echo "$nm didn't seem to work right. Trying $ar instead..." >&4
346                 com=''
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
350                         done
351                         $sed -e "s/\\$_o\$//" < libc.tmp > libc.list
352                         echo "Ok." >&4
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 \
361                                     2>/dev/null && \
362                                     $sed -e 's/^\([_a-zA-Z0-9]*\) .*$/\1/p' \
363                                     < tmp.imp >>libc.tmp
364                                 $rm tmp.imp
365                         done
366                         $sed -e "s/\\$_o\$//" -e 's/^ \+//' < libc.tmp > libc.list
367                         echo "Ok." >&4
368                 else
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
372                         then
373                                 for thisname in $libnames; do
374                                         bld t $libnames | \
375                                         $sed -e 's/.*\///' -e "s/\\$_o:.*\$//" >>libc.list
376                                         $ar t $thisname >>libc.tmp
377                                 done
378                                 echo "Ok." >&4
379                         else
380                                 echo "That didn't work either.  Giving up." >&4
381                                 exit 1
382                         fi
383                 fi
384         fi
385 fi
386 nm_extract="$com"
387 case "$PASE" in
388 define)
389     echo " "
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
392     ;;
393 *)  if $test -f /lib/syscalls.exp; then
394         echo " "
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
397     fi
398     ;;
399 esac
400 ;;
401 esac
402 $rm -f libnames libpath
403