This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl5.000 patch.0i: fix glaring mistakes in patches a-h
[perl5.git] / ext / util / extliblist
1 case $CONFIG in
2 '')
3         if test -f config.sh; then TOP=.;
4         elif test -f ../config.sh; then TOP=..;
5         elif test -f ../../config.sh; then TOP=../..;
6         elif test -f ../../../config.sh; then TOP=../../..;
7         elif test -f ../../../../config.sh; then TOP=../../../..;
8         else
9                 echo "Can't find config.sh."; exit 1
10         fi
11         . $TOP/config.sh
12         ;;
13 esac
14 : extliblist
15 :
16 : Author:  Andy Dougherty    doughera@lafcol.lafayette.edu
17 :
18 : This utility takes a list of libraries in the form
19 : -llib1 -llib2 -llib3
20 : and prints out lines suitable for inclusion in an extension
21 : Makefile.  
22 : Extra library paths may be included with the form -L/another/path
23 : this will affect the searches for all subsequent libraries.
24 :
25 : It is intended to be "dotted" from within an extension Makefile.SH.
26 : see ext/POSIX/Makefile.SH for an example.
27 : Prior to calling this, the variable potential_libs should be set 
28 : to the potential list of libraries
29 :
30 : It sets the following
31 : extralibs = full list of libraries needed for static linking.
32 :               Only those libraries that actually exist are included.
33 : dynaloadlibs = full path names of those libraries that are needed 
34 :               but can be linked in dynamically on this platform.  On 
35 :               SunOS, for example, this would be .so* libraries, 
36 :               but not archive libraries.
37 :               Eventually, this list can be used to write a bootstrap file.
38 : statloadlibs = list of those libraries which must be statically
39 :               linked into the shared library.  On SunOS 4.1.3, 
40 :               for example,  I have only an archive version of
41 :               -lm, and it must be linked in statically.
42 :
43 :  This script uses config.sh variables libs, libpth, and so.  It is mostly
44 :  taken from the metaconfig libs.U unit.
45 extralibs=''
46 dynaloadlibs=''
47 statloadlibs=''
48 Llibpth=''
49 for thislib in `echo "XXX $potential_libs " | $sed 's/ -l/ /g'` ; do
50         case "$thislib" in
51         XXX)
52                 : Handle case where potential_libs is empty.
53                 ;;
54         -L*)
55                 : Handle possible linker path arguments.
56                 newpath=`echo $thislib | $sed 's/^-L//'`
57                 if $test -d $newpath; then
58                         Llibpth="$Llibpth $newpath"
59                         extralibs="$extralibs $thislib"
60                         statloadlibs="$statloadlibs $thislib"
61                 fi
62                 ;;
63         *)
64                 : Handle possible library arguments.
65                 for thispth in $Llibpth $libpth; do
66                         : Loop over possible wildcards and take the last one.
67                         for fullname in $thispth/lib$thislib.$so.[0-9]* ; do
68                                 :
69                         done
70                         if $test -f $fullname; then
71                                 break
72                         elif fullname=$thispth/lib$thislib.$so && $test -f $fullname; then
73                                 break
74                         elif fullname=$thispth/lib${thislib}_s.a && $test -f $fullname; then
75                                 thislib=${thislib}_s
76                                 break
77                         elif fullname=$thispth/lib${thislib}.a && $test -f $fullname; then
78                                 break
79                         elif fullname=$thispth/Slib${thislib}.a && $test -f $fullname; then
80                                 break
81                         else
82                                 fullname=''
83                         fi
84                 done
85                 : Now update library lists
86                 case "$fullname" in
87                 '') 
88                         : Skip nonexistent files
89                         ;;
90                 *)
91                         : Do not add it into the extralibs if it is already linked in
92                         : with the main perl executable.
93                         case " $libs " in
94                         *" -l$thislib "*|*" -l${thislib}_s "*) ;;
95                         *)      extralibs="$extralibs -l$thislib" ;;
96                         esac
97                         :
98                         : For NeXT and DLD, put files into DYNALOADLIBS to be
99                         : converted into a boostrap file.  For other systems,
100                         : we will use ld with what I have misnamed STATLOADLIBS
101                         : to assemble the shared object.
102                         case "$dlsrc" in
103                         dl_dld*|dl_next*)
104                                 dynaloadlibs="$dynaloadlibs $fullname"   ;;
105                         *)
106                                 case "$fullname" in
107                                 *.a)
108                                         statloadlibs="$statloadlibs -l$thislib" 
109                                         ;;
110                                 *)   
111                                         : For SunOS4, do not add in this shared library
112                                         : if it is already linked in the main
113                                         : perl executable
114                                         case "$osname" in
115                                         sunos)
116                                                 case " $libs " in
117                                                 *" -l$thislib "*) ;;
118                                                 *)      statloadlibs="$statloadlibs -l$thislib" ;;
119                                                 esac
120                                                 ;;
121                                         *)
122                                                 statloadlibs="$statloadlibs -l$thislib" 
123                                                 ;;
124                                         esac
125                                         ;;
126                                 esac
127                                 ;;
128                         esac
129                         ;;
130                 esac
131                 ;;
132         esac
133 done
134
135 case "$dlsrc" in
136 dl_next*)
137         extralibs=`echo " $extralibs "| $sed -e 's/ -lm / /'` ;;
138 esac
139
140 set X $extralibs
141 shift
142 extralibs="$*"
143
144 set X $dynaloadlibs
145 shift
146 dynaloadlibs="$*"
147
148 set X $statloadlibs
149 shift
150 statloadlibs="$*"
151