This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
47978c1b0e67333433bfd95a9838b4b1f7af4c39
[metaconfig.git] / U / perl / dlsrc.U
1 ?RCS: $Id: dlsrc.U,v$
2 ?RCS:
3 ?RCS: Copyright (c) 1996-1998, Andy Dougherty
4 ?RCS:
5 ?RCS: You may distribute under the terms of either the GNU General Public
6 ?RCS: License or the Artistic License, as specified in the README file.
7 ?RCS:
8 ?RCS: $Log: dlsrc.U,v $
9 ?RCS:
10 ?X:  hpux support thanks to Jeff Okamoto <okamoto@hpcc101.corp.hp.com>
11 ?X:
12 ?X:  To create a shared library, you must compile ALL source files in the
13 ?X:  library with +z (or possibly +Z if the library is whopping huge),
14 ?X:  then link the library with -b.  Example:
15 ?X:       cc -c +z module_a.c
16 ?X:       cc -c +z module_b.c
17 ?X:       ld -b module_a.o module_b.o -o module.sl
18 ?X:
19 ?MAKE:usedl ld dlsrc cccdlflags lddlflags ccdlflags: \
20         Getfile Myread test osname sed i_dld d_dlopen Findhdr Setvar \
21         cc ccflags ldflags ls gccversion cat rsrc src run
22 ?MAKE:  -pick add $@ %<
23 ?Y:BOTTOM
24 ?S:usedl:
25 ?S:     This variable indicates if the system supports dynamic
26 ?S:     loading of some sort.  See also dlsrc and dlobj.
27 ?S:.
28 ?S:ld:
29 ?S:     This variable indicates the program to be used to link
30 ?S:     libraries for dynamic loading.  On some systems, it is 'ld'.
31 ?S:     On ELF systems, it should be $cc.  Mostly, we'll try to respect
32 ?S:     the hint file setting.
33 ?S:.
34 ?S:dlsrc:
35 ?S:     This variable contains the name of the dynamic loading file that
36 ?S:     will be used with the package.
37 ?S:.
38 ?S:cccdlflags:
39 ?S:     This variable contains any special flags that might need to be
40 ?S:     passed with 'cc -c' to compile modules to be used to create a shared
41 ?S:     library that will be used for dynamic loading.  For hpux, this
42 ?S:     should be +z.  It is up to the makefile to use it.
43 ?S:.
44 ?S:lddlflags:
45 ?S:     This variable contains any special flags that might need to be
46 ?S:     passed to $ld to create a shared library suitable for dynamic
47 ?S:     loading.  It is up to the makefile to use it.  For hpux, it
48 ?S:     should be '-b'.  For sunos 4.1, it is empty.
49 ?S:.
50 ?S:ccdlflags:
51 ?S:     This variable contains any special flags that might need to be
52 ?S:     passed to cc to link with a shared library for dynamic loading.
53 ?S:     It is up to the makefile to use it.  For sunos 4.1, it should
54 ?S:     be empty.
55 ?S:.
56 ?C:USE_DYNAMIC_LOADING ~ %<:
57 ?C:     This symbol, if defined, indicates that dynamic loading of
58 ?C:     some sort is available.
59 ?C:.
60 ?H:?%<:#$usedl USE_DYNAMIC_LOADING              /**/
61 ?H:.
62 ?W:%<:dlopen
63 ?T:dldir thisflag tdir
64 : determine which dynamic loading, if any, to compile in
65 echo " "
66 dldir="ext/DynaLoader"
67 case "$usedl" in
68 $define|y|true)
69         dflt='y'
70         usedl="$define"
71         ;;
72 $undef|n|false)
73         dflt='n'
74         usedl="$undef"
75         ;;
76 *) 
77         dflt='n'
78         case "$d_dlopen" in
79             $define) dflt='y' ;;
80         esac
81         case "$i_dld" in
82             $define) dflt='y' ;;
83         esac
84         : Does a dl_xxx.xs file exist for this operating system
85         $test -f $rsrc/$dldir/dl_${osname}.xs && dflt='y'
86         ;;
87 esac
88 rp="Do you wish to use dynamic loading?"
89 . ./myread
90 usedl="$ans"
91 case "$ans" in
92 y*) usedl="$define"
93         case "$dlsrc" in
94         '')
95                 if $test -f $rsrc/$dldir/dl_${osname}.xs ; then
96                         dflt="$dldir/dl_${osname}.xs"
97                 elif $test "$d_dlopen" = "$define" ; then
98                         dflt="$dldir/dl_dlopen.xs"
99                 elif $test "$i_dld" = "$define" ; then
100                         dflt="$dldir/dl_dld.xs"
101                 else
102                         dflt=''
103                 fi
104                 ;;
105         *)      dflt="$dldir/$dlsrc"
106                 ;;
107         esac
108     echo "The following dynamic loading files are available:"
109         : Can not go over to $dldir because getfile has path hard-coded in.
110         tdir=`pwd`; cd $rsrc; $ls -C $dldir/dl*.xs; cd $tdir
111         rp="Source file to use for dynamic loading"
112         fn="fne"
113         gfpth="$src"
114         . ./getfile
115         usedl="$define"
116         : emulate basename
117         dlsrc=`echo $ans | $sed -e 's%.*/\([^/]*\)$%\1%'`
118
119         $cat << EOM
120
121 Some systems may require passing special flags to $cc -c to
122 compile modules that will be used to create a shared library.
123 To use no flags, say "none".
124
125 EOM
126     case "$cccdlflags" in
127     '') case "$gccversion" in
128                 '') case "$osname" in
129                         hpux)   dflt='+z' ;;
130                         next)   dflt='none' ;;
131                         irix*)  dflt='-KPIC' ;;
132                         svr4*|esix*|solaris|nonstopux) dflt='-KPIC' ;;
133                         sunos)  dflt='-pic' ;;
134                         *)      dflt='none' ;;
135                     esac
136                         ;;
137                 *)  case "$osname" in
138                         darwin) dflt='none' ;;
139                         svr4*|esix*|solaris|nonstopux) dflt='-fPIC' ;;
140                         *)      dflt='-fpic' ;;
141                     esac ;;
142             esac ;;
143         ' ') dflt='none' ;;
144     *)  dflt="$cccdlflags" ;;
145     esac
146     rp="Any special flags to pass to $cc -c to compile shared library modules?"
147     . ./myread
148     case "$ans" in
149 ?X: Use ' ' so that a subsequent Configure run preserves the old state.
150     none) cccdlflags=' ' ;;
151     *) cccdlflags="$ans" ;;
152     esac
153
154     cat << EOM
155
156 Some systems use ld to create libraries that can be dynamically loaded,
157 while other systems (such as those using ELF) use $cc.
158
159 EOM
160         case "$ld" in
161         '')     $cat >try.c <<'EOM'
162 /* Test for whether ELF binaries are produced */
163 #include <fcntl.h>
164 #include <stdlib.h>
165 int main() {
166         char b[4];
167         int i = open("a.out",O_RDONLY);
168         if(i == -1) 
169                 exit(1); /* fail */
170         if(read(i,b,4)==4 && b[0]==127 && b[1]=='E' && b[2]=='L' && b[3]=='F')
171                 exit(0); /* succeed (yes, it's ELF) */
172         else
173                 exit(1); /* fail */
174 }
175 EOM
176                 if $cc $ccflags $ldflags try.c >/dev/null 2>&1 && $run ./a.out; then
177                         cat <<EOM
178 You appear to have ELF support.  I'll use $cc to build dynamic libraries.
179 EOM
180                         dflt="$cc"
181                 else
182                         echo "I'll use ld to build dynamic libraries."
183                         dflt='ld'
184                 fi
185                 rm -f try.c a.out
186                 ;;
187         *)      dflt="$ld"
188                 ;;
189         esac
190
191     rp="What command should be used to create dynamic libraries?"
192     . ./myread
193         ld="$ans"
194
195     cat << EOM
196
197 Some systems may require passing special flags to $ld to create a
198 library that can be dynamically loaded.  If your ld flags include
199 -L/other/path options to locate libraries outside your loader's normal
200 search path, you may need to specify those -L options here as well.  To
201 use no flags, say "none".
202
203 EOM
204     case "$lddlflags" in
205     '') case "$osname" in
206                         beos) dflt='-nostart' ;;
207                         hpux) dflt='-b';
208                               case "$gccversion" in
209                               '') dflt="$dflt +vnocompatwarnings" ;;
210                               esac
211                               ;;        
212                         linux|irix*)    dflt='-shared' ;;
213                         next)  dflt='none' ;;
214                         solaris) dflt='-G' ;;
215                         sunos) dflt='-assert nodefinitions' ;;
216                         svr4*|esix*|nonstopux) dflt="-G $ldflags" ;;
217                 *)     dflt='none' ;;
218                         esac
219                         ;;
220     *) dflt="$lddlflags" ;;
221     esac
222
223         : Try to guess additional flags to pick up local libraries.
224         : Be careful not to append to a plain 'none'
225         case "$dflt" in
226         none) dflt='' ;;
227         esac
228         for thisflag in $ldflags; do
229                 case "$thisflag" in
230                 -L*|-R*|-Wl,-R*)
231                         case " $dflt " in
232                         *" $thisflag "*) ;;
233                         *) dflt="$dflt $thisflag" ;;
234                         esac
235                         ;;
236                 esac
237         done
238
239         case "$dflt" in
240         ''|' ') dflt='none' ;;
241         esac
242
243     rp="Any special flags to pass to $ld to create a dynamically loaded library?"
244     . ./myread
245     case "$ans" in
246 ?X: Use ' ' so that a subsequent Configure run preserves the old state.
247     none) lddlflags=' ' ;;
248     *) lddlflags="$ans" ;;
249     esac
250
251         cat <<EOM
252
253 Some systems may require passing special flags to $cc to indicate that
254 the resulting executable will use dynamic linking.  To use no flags,
255 say "none".
256
257 EOM
258     case "$ccdlflags" in
259     '') case "$osname" in
260                 hpux)   dflt='-Wl,-E' ;;
261                 linux)  dflt='-rdynamic' ;;
262                 next)   dflt='none' ;;
263                 sunos)  dflt='none' ;;
264                 *)      dflt='none' ;;
265             esac ;;
266     ' ')  dflt='none' ;;
267     *)  dflt="$ccdlflags" ;;
268     esac
269     rp="Any special flags to pass to $cc to use dynamic linking?"
270     . ./myread
271     case "$ans" in
272 ?X: Use ' ' so that a subsequent Configure run preserves the old state.
273     none) ccdlflags=' ' ;;
274     *) ccdlflags="$ans" ;;
275     esac
276     ;;
277 ?X: End of usedl=y section
278 *)  usedl="$undef"
279         ld='ld'
280     dlsrc='dl_none.xs'
281     lddlflags=''
282     ccdlflags=''
283     ;;
284 esac
285