This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add new probes for IPv6 (LeoNerd)
[metaconfig.git] / U / perl / dlsrc.U
CommitLineData
959f3c4c
JH
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:
9b2a83fd 19?MAKE:usedl ld dlsrc cccdlflags lddlflags ccdlflags bin_ELF: rm_try \
3c617870
TC
20 Getfile Myread test osname sed i_dld d_dlopen Findhdr Setvar src run \
21 cc ccflags ldflags optimize ls gccversion cat rsrc i_stdlib i_unistd
959f3c4c
JH
22?MAKE: -pick add $@ %<
23?Y:BOTTOM
24?S:usedl:
edd6115f 25?S: This variable indicates if the system supports dynamic
959f3c4c
JH
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:.
9b2a83fd
MB
56?S:bin_ELF:
57?S: This variable saves the result from configure if generated binaries
58?S: are in ELF format. Only set to defined when the test has actually
59?S: been performed, and the result was positive.
60?S:.
959f3c4c
JH
61?C:USE_DYNAMIC_LOADING ~ %<:
62?C: This symbol, if defined, indicates that dynamic loading of
63?C: some sort is available.
64?C:.
65?H:?%<:#$usedl USE_DYNAMIC_LOADING /**/
66?H:.
67?W:%<:dlopen
68?T:dldir thisflag tdir
41322e17 69?F:!a.out
959f3c4c
JH
70: determine which dynamic loading, if any, to compile in
71echo " "
72dldir="ext/DynaLoader"
73case "$usedl" in
74$define|y|true)
75 dflt='y'
76 usedl="$define"
77 ;;
78$undef|n|false)
79 dflt='n'
80 usedl="$undef"
81 ;;
2cb64bf6 82*)
959f3c4c
JH
83 dflt='n'
84 case "$d_dlopen" in
85 $define) dflt='y' ;;
86 esac
87 case "$i_dld" in
88 $define) dflt='y' ;;
89 esac
90 : Does a dl_xxx.xs file exist for this operating system
91 $test -f $rsrc/$dldir/dl_${osname}.xs && dflt='y'
92 ;;
93esac
94rp="Do you wish to use dynamic loading?"
95. ./myread
96usedl="$ans"
9b2a83fd 97bin_ELF="$undef"
959f3c4c
JH
98case "$ans" in
99y*) usedl="$define"
100 case "$dlsrc" in
101 '')
102 if $test -f $rsrc/$dldir/dl_${osname}.xs ; then
103 dflt="$dldir/dl_${osname}.xs"
104 elif $test "$d_dlopen" = "$define" ; then
105 dflt="$dldir/dl_dlopen.xs"
106 elif $test "$i_dld" = "$define" ; then
107 dflt="$dldir/dl_dld.xs"
108 else
109 dflt=''
110 fi
111 ;;
112 *) dflt="$dldir/$dlsrc"
113 ;;
114 esac
115 echo "The following dynamic loading files are available:"
116 : Can not go over to $dldir because getfile has path hard-coded in.
3720fc47 117 tdir=`pwd`; cd "$rsrc"; $ls -C $dldir/dl*.xs; cd "$tdir"
959f3c4c
JH
118 rp="Source file to use for dynamic loading"
119 fn="fne"
120 gfpth="$src"
121 . ./getfile
122 usedl="$define"
123 : emulate basename
70ffff07 124 dlsrc=`echo $ans | $sed -e 's%.*/\([^/]*\)$%\1%'`
959f3c4c
JH
125
126 $cat << EOM
127
128Some systems may require passing special flags to $cc -c to
129compile modules that will be used to create a shared library.
130To use no flags, say "none".
131
132EOM
133 case "$cccdlflags" in
134 '') case "$gccversion" in
135 '') case "$osname" in
136 hpux) dflt='+z' ;;
137 next) dflt='none' ;;
138 irix*) dflt='-KPIC' ;;
5bcf820f 139 svr4*|esix*|solaris|nonstopux) dflt='-KPIC' ;;
959f3c4c
JH
140 sunos) dflt='-pic' ;;
141 *) dflt='none' ;;
142 esac
143 ;;
144 *) case "$osname" in
5e191ef7 145 darwin) dflt='none' ;;
4b3d7136 146 linux*|svr4*|esix*|solaris|nonstopux) dflt='-fPIC' ;;
959f3c4c
JH
147 *) dflt='-fpic' ;;
148 esac ;;
149 esac ;;
150 ' ') dflt='none' ;;
151 *) dflt="$cccdlflags" ;;
152 esac
153 rp="Any special flags to pass to $cc -c to compile shared library modules?"
154 . ./myread
155 case "$ans" in
156?X: Use ' ' so that a subsequent Configure run preserves the old state.
157 none) cccdlflags=' ' ;;
158 *) cccdlflags="$ans" ;;
159 esac
160
161 cat << EOM
162
163Some systems use ld to create libraries that can be dynamically loaded,
164while other systems (such as those using ELF) use $cc.
165
166EOM
167 case "$ld" in
1273bb5e 168 '') $cat >try.c <<EOM
959f3c4c
JH
169/* Test for whether ELF binaries are produced */
170#include <fcntl.h>
1273bb5e
JH
171#$i_stdlib I_STDLIB
172#ifdef I_STDLIB
959f3c4c 173#include <stdlib.h>
1273bb5e 174#endif
20376335
JH
175#$i_unistd I_UNISTD
176#ifdef I_UNISTD
177#include <unistd.h>
178#endif
959f3c4c
JH
179int main() {
180 char b[4];
181 int i = open("a.out",O_RDONLY);
2cb64bf6 182 if(i == -1)
959f3c4c
JH
183 exit(1); /* fail */
184 if(read(i,b,4)==4 && b[0]==127 && b[1]=='E' && b[2]=='L' && b[3]=='F')
185 exit(0); /* succeed (yes, it's ELF) */
186 else
187 exit(1); /* fail */
188}
189EOM
0f00356b 190 if $cc $ccflags $ldflags try.c >/dev/null 2>&1 && $run ./a.out; then
959f3c4c
JH
191 cat <<EOM
192You appear to have ELF support. I'll use $cc to build dynamic libraries.
193EOM
194 dflt="$cc"
9b2a83fd 195 bin_ELF="$define"
959f3c4c
JH
196 else
197 echo "I'll use ld to build dynamic libraries."
198 dflt='ld'
199 fi
2cb64bf6 200 $rm_try
959f3c4c
JH
201 ;;
202 *) dflt="$ld"
203 ;;
204 esac
205
206 rp="What command should be used to create dynamic libraries?"
207 . ./myread
208 ld="$ans"
209
210 cat << EOM
211
212Some systems may require passing special flags to $ld to create a
213library that can be dynamically loaded. If your ld flags include
214-L/other/path options to locate libraries outside your loader's normal
215search path, you may need to specify those -L options here as well. To
216use no flags, say "none".
217
218EOM
219 case "$lddlflags" in
220 '') case "$osname" in
221 beos) dflt='-nostart' ;;
b880f9b6 222 haiku) dflt='-shared' ;;
8b424337
JH
223 hpux) dflt='-b';
224 case "$gccversion" in
225 '') dflt="$dflt +vnocompatwarnings" ;;
f27d6ab9 226 esac
2cb64bf6 227 ;;
3c617870 228 linux|irix*|gnu*) dflt="-shared $optimize" ;;
959f3c4c
JH
229 next) dflt='none' ;;
230 solaris) dflt='-G' ;;
231 sunos) dflt='-assert nodefinitions' ;;
5bcf820f 232 svr4*|esix*|nonstopux) dflt="-G $ldflags" ;;
959f3c4c
JH
233 *) dflt='none' ;;
234 esac
235 ;;
236 *) dflt="$lddlflags" ;;
237 esac
238
239 : Try to guess additional flags to pick up local libraries.
240 : Be careful not to append to a plain 'none'
241 case "$dflt" in
242 none) dflt='' ;;
243 esac
244 for thisflag in $ldflags; do
245 case "$thisflag" in
4d5de5cd 246 -L*|-R*|-Wl,-R*)
959f3c4c
JH
247 case " $dflt " in
248 *" $thisflag "*) ;;
249 *) dflt="$dflt $thisflag" ;;
250 esac
251 ;;
252 esac
253 done
254
255 case "$dflt" in
256 ''|' ') dflt='none' ;;
257 esac
258
f9f39285
AD
259 case "$ldflags" in
260 *-fstack-protector*)
261 case "$dflt" in
262 *-fstack-protector*) ;; # Don't add it again
263 *) dflt="$dflt -fstack-protector" ;;
264 esac
265 ;;
266 esac
267
268
959f3c4c
JH
269 rp="Any special flags to pass to $ld to create a dynamically loaded library?"
270 . ./myread
271 case "$ans" in
272?X: Use ' ' so that a subsequent Configure run preserves the old state.
273 none) lddlflags=' ' ;;
274 *) lddlflags="$ans" ;;
275 esac
276
277 cat <<EOM
278
279Some systems may require passing special flags to $cc to indicate that
280the resulting executable will use dynamic linking. To use no flags,
281say "none".
282
283EOM
284 case "$ccdlflags" in
285 '') case "$osname" in
76ba8ff9 286 linux|hpux|gnu*) dflt='-Wl,-E' ;;
2c3385d3
AH
287 next|sunos) dflt='none' ;;
288 *) dflt='none' ;;
959f3c4c
JH
289 esac ;;
290 ' ') dflt='none' ;;
291 *) dflt="$ccdlflags" ;;
292 esac
ec0d834e 293 rp="Any special flags to pass to $cc to use dynamic linking?"
959f3c4c
JH
294 . ./myread
295 case "$ans" in
296?X: Use ' ' so that a subsequent Configure run preserves the old state.
297 none) ccdlflags=' ' ;;
298 *) ccdlflags="$ans" ;;
299 esac
300 ;;
301?X: End of usedl=y section
302*) usedl="$undef"
303 ld='ld'
304 dlsrc='dl_none.xs'
305 lddlflags=''
306 ccdlflags=''
307 ;;
308esac
309