This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove references to GNU DLD from Configure and config.sh scripts.
[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:
35a1617b 19?MAKE:usedl ld dlsrc cccdlflags lddlflags ccdlflags bin_ELF ld_can_script: \
5f0d0842 20 rm_try Getfile Myread test osname sed d_dlopen Findhdr Setvar \
35a1617b 21 src run cc ccflags ldflags optimize ls gccversion cat rsrc i_stdlib \
823b08d5 22 i_unistd osvers
959f3c4c
JH
23?MAKE: -pick add $@ %<
24?Y:BOTTOM
25?S:usedl:
edd6115f 26?S: This variable indicates if the system supports dynamic
959f3c4c
JH
27?S: loading of some sort. See also dlsrc and dlobj.
28?S:.
29?S:ld:
30?S: This variable indicates the program to be used to link
31?S: libraries for dynamic loading. On some systems, it is 'ld'.
32?S: On ELF systems, it should be $cc. Mostly, we'll try to respect
33?S: the hint file setting.
34?S:.
35?S:dlsrc:
36?S: This variable contains the name of the dynamic loading file that
37?S: will be used with the package.
38?S:.
39?S:cccdlflags:
40?S: This variable contains any special flags that might need to be
41?S: passed with 'cc -c' to compile modules to be used to create a shared
42?S: library that will be used for dynamic loading. For hpux, this
43?S: should be +z. It is up to the makefile to use it.
44?S:.
45?S:lddlflags:
46?S: This variable contains any special flags that might need to be
47?S: passed to $ld to create a shared library suitable for dynamic
48?S: loading. It is up to the makefile to use it. For hpux, it
49?S: should be '-b'. For sunos 4.1, it is empty.
50?S:.
51?S:ccdlflags:
52?S: This variable contains any special flags that might need to be
53?S: passed to cc to link with a shared library for dynamic loading.
54?S: It is up to the makefile to use it. For sunos 4.1, it should
55?S: be empty.
56?S:.
9b2a83fd
MB
57?S:bin_ELF:
58?S: This variable saves the result from configure if generated binaries
59?S: are in ELF format. Only set to defined when the test has actually
60?S: been performed, and the result was positive.
61?S:.
35a1617b
MB
62?S:ld_can_script:
63?S: This variable shows if the loader accepts scripts in the form of
64?S: -Wl,--version-script=ld.script. This is currently only supported
65?S: for GNU ld on ELF in dynamic loading builds.
66?S:.
959f3c4c
JH
67?C:USE_DYNAMIC_LOADING ~ %<:
68?C: This symbol, if defined, indicates that dynamic loading of
69?C: some sort is available.
70?C:.
71?H:?%<:#$usedl USE_DYNAMIC_LOADING /**/
72?H:.
73?W:%<:dlopen
74?T:dldir thisflag tdir
41322e17 75?F:!a.out
959f3c4c
JH
76: determine which dynamic loading, if any, to compile in
77echo " "
78dldir="ext/DynaLoader"
79case "$usedl" in
80$define|y|true)
81 dflt='y'
82 usedl="$define"
83 ;;
84$undef|n|false)
85 dflt='n'
86 usedl="$undef"
87 ;;
2cb64bf6 88*)
959f3c4c
JH
89 dflt='n'
90 case "$d_dlopen" in
91 $define) dflt='y' ;;
92 esac
959f3c4c
JH
93 : Does a dl_xxx.xs file exist for this operating system
94 $test -f $rsrc/$dldir/dl_${osname}.xs && dflt='y'
95 ;;
96esac
97rp="Do you wish to use dynamic loading?"
98. ./myread
99usedl="$ans"
9b2a83fd 100bin_ELF="$undef"
959f3c4c
JH
101case "$ans" in
102y*) usedl="$define"
103 case "$dlsrc" in
104 '')
105 if $test -f $rsrc/$dldir/dl_${osname}.xs ; then
106 dflt="$dldir/dl_${osname}.xs"
107 elif $test "$d_dlopen" = "$define" ; then
108 dflt="$dldir/dl_dlopen.xs"
959f3c4c
JH
109 else
110 dflt=''
111 fi
112 ;;
113 *) dflt="$dldir/$dlsrc"
114 ;;
115 esac
116 echo "The following dynamic loading files are available:"
117 : Can not go over to $dldir because getfile has path hard-coded in.
3720fc47 118 tdir=`pwd`; cd "$rsrc"; $ls -C $dldir/dl*.xs; cd "$tdir"
959f3c4c
JH
119 rp="Source file to use for dynamic loading"
120 fn="fne"
121 gfpth="$src"
122 . ./getfile
123 usedl="$define"
124 : emulate basename
70ffff07 125 dlsrc=`echo $ans | $sed -e 's%.*/\([^/]*\)$%\1%'`
959f3c4c
JH
126
127 $cat << EOM
128
129Some systems may require passing special flags to $cc -c to
130compile modules that will be used to create a shared library.
131To use no flags, say "none".
132
133EOM
134 case "$cccdlflags" in
135 '') case "$gccversion" in
136 '') case "$osname" in
137 hpux) dflt='+z' ;;
138 next) dflt='none' ;;
139 irix*) dflt='-KPIC' ;;
5bcf820f 140 svr4*|esix*|solaris|nonstopux) dflt='-KPIC' ;;
959f3c4c
JH
141 sunos) dflt='-pic' ;;
142 *) dflt='none' ;;
143 esac
144 ;;
145 *) case "$osname" in
5e191ef7 146 darwin) dflt='none' ;;
4b3d7136 147 linux*|svr4*|esix*|solaris|nonstopux) dflt='-fPIC' ;;
959f3c4c
JH
148 *) dflt='-fpic' ;;
149 esac ;;
150 esac ;;
151 ' ') dflt='none' ;;
152 *) dflt="$cccdlflags" ;;
153 esac
154 rp="Any special flags to pass to $cc -c to compile shared library modules?"
155 . ./myread
156 case "$ans" in
157?X: Use ' ' so that a subsequent Configure run preserves the old state.
158 none) cccdlflags=' ' ;;
159 *) cccdlflags="$ans" ;;
160 esac
161
162 cat << EOM
163
164Some systems use ld to create libraries that can be dynamically loaded,
165while other systems (such as those using ELF) use $cc.
166
167EOM
71afd850
MB
168
169: Determine if this is ELF
170 $cat >try.c <<EOM
959f3c4c
JH
171/* Test for whether ELF binaries are produced */
172#include <fcntl.h>
1273bb5e
JH
173#$i_stdlib I_STDLIB
174#ifdef I_STDLIB
959f3c4c 175#include <stdlib.h>
1273bb5e 176#endif
20376335
JH
177#$i_unistd I_UNISTD
178#ifdef I_UNISTD
179#include <unistd.h>
180#endif
959f3c4c
JH
181int main() {
182 char b[4];
183 int i = open("a.out",O_RDONLY);
2cb64bf6 184 if(i == -1)
959f3c4c
JH
185 exit(1); /* fail */
186 if(read(i,b,4)==4 && b[0]==127 && b[1]=='E' && b[2]=='L' && b[3]=='F')
71afd850 187 exit(0); /* succeed (yes, it is ELF) */
959f3c4c
JH
188 else
189 exit(1); /* fail */
190}
191EOM
71afd850
MB
192 if $cc $ccflags $ldflags try.c >/dev/null 2>&1 && $run ./a.out; then
193 bin_ELF="$define"
194 fi
195 $rm_try
196
197 case "$ld" in
198 '') if $test $bin_ELF = "$define"; then
959f3c4c
JH
199 cat <<EOM
200You appear to have ELF support. I'll use $cc to build dynamic libraries.
201EOM
202 dflt="$cc"
203 else
204 echo "I'll use ld to build dynamic libraries."
205 dflt='ld'
206 fi
959f3c4c
JH
207 ;;
208 *) dflt="$ld"
209 ;;
210 esac
211
212 rp="What command should be used to create dynamic libraries?"
213 . ./myread
214 ld="$ans"
215
216 cat << EOM
217
218Some systems may require passing special flags to $ld to create a
219library that can be dynamically loaded. If your ld flags include
220-L/other/path options to locate libraries outside your loader's normal
221search path, you may need to specify those -L options here as well. To
222use no flags, say "none".
223
224EOM
225 case "$lddlflags" in
226 '') case "$osname" in
b880f9b6 227 haiku) dflt='-shared' ;;
8b424337
JH
228 hpux) dflt='-b';
229 case "$gccversion" in
230 '') dflt="$dflt +vnocompatwarnings" ;;
f27d6ab9 231 esac
2cb64bf6 232 ;;
3c617870 233 linux|irix*|gnu*) dflt="-shared $optimize" ;;
959f3c4c 234 next) dflt='none' ;;
823b08d5
MBT
235 solaris) # See [perl #66604].
236 # On Solaris 11, gcc -m64 on amd64
237 # appears not to understand -G. gcc versions at
238 # least as old as 3.4.3 support -shared, so just
239 # use that with Solaris 11 and later, but keep
240 # the old behavior for older Solaris versions.
241 case "$gccversion" in
242 '') dflt='-G' ;;
243 *) case "$osvers" in
244 2.?|2.10) dflt='-G' ;;
245 *) dflt='-shared' ;;
246 esac
247 ;;
248 esac
249 ;;
959f3c4c 250 sunos) dflt='-assert nodefinitions' ;;
5bcf820f 251 svr4*|esix*|nonstopux) dflt="-G $ldflags" ;;
959f3c4c
JH
252 *) dflt='none' ;;
253 esac
254 ;;
255 *) dflt="$lddlflags" ;;
256 esac
257
258 : Try to guess additional flags to pick up local libraries.
259 : Be careful not to append to a plain 'none'
260 case "$dflt" in
261 none) dflt='' ;;
262 esac
263 for thisflag in $ldflags; do
264 case "$thisflag" in
4d5de5cd 265 -L*|-R*|-Wl,-R*)
959f3c4c
JH
266 case " $dflt " in
267 *" $thisflag "*) ;;
268 *) dflt="$dflt $thisflag" ;;
269 esac
270 ;;
271 esac
272 done
273
274 case "$dflt" in
275 ''|' ') dflt='none' ;;
276 esac
277
f9f39285
AD
278 case "$ldflags" in
279 *-fstack-protector*)
280 case "$dflt" in
281 *-fstack-protector*) ;; # Don't add it again
282 *) dflt="$dflt -fstack-protector" ;;
283 esac
284 ;;
285 esac
286
287
959f3c4c
JH
288 rp="Any special flags to pass to $ld to create a dynamically loaded library?"
289 . ./myread
290 case "$ans" in
291?X: Use ' ' so that a subsequent Configure run preserves the old state.
292 none) lddlflags=' ' ;;
293 *) lddlflags="$ans" ;;
294 esac
295
296 cat <<EOM
297
298Some systems may require passing special flags to $cc to indicate that
299the resulting executable will use dynamic linking. To use no flags,
300say "none".
301
302EOM
303 case "$ccdlflags" in
304 '') case "$osname" in
76ba8ff9 305 linux|hpux|gnu*) dflt='-Wl,-E' ;;
2c3385d3
AH
306 next|sunos) dflt='none' ;;
307 *) dflt='none' ;;
959f3c4c
JH
308 esac ;;
309 ' ') dflt='none' ;;
310 *) dflt="$ccdlflags" ;;
311 esac
ec0d834e 312 rp="Any special flags to pass to $cc to use dynamic linking?"
959f3c4c
JH
313 . ./myread
314 case "$ans" in
315?X: Use ' ' so that a subsequent Configure run preserves the old state.
316 none) ccdlflags=' ' ;;
317 *) ccdlflags="$ans" ;;
318 esac
319 ;;
320?X: End of usedl=y section
321*) usedl="$undef"
322 ld='ld'
323 dlsrc='dl_none.xs'
324 lddlflags=''
325 ccdlflags=''
326 ;;
327esac
328
35a1617b
MB
329ld_can_script="$undef"
330case "$bin_ELF$usedl" in
331$define$define)
332 # Abuse try.h and a.out names for neat cleanup
333 $cat >try.c <<EOM
334void foo() {}
335void bar() {}
336EOM
337 $cat >try.h <<EOM
338LIBTEST_42 {
339 global:
340 foo;
341 local: *;
342 };
343EOM
344 if $cc $cccdlflags $ccdlflags $ccflags \
345 $ldflags $lddlflags -o a.out try.c \
346 -Wl,--version-script=try.h >/dev/null 2>&1 \
347 && $test -s a.out ; then
348 echo "ld supports scripting" >&4
349 ld_can_script="$define"
350 else
351 echo "ld does not support scripting" >&4
352 fi
353 $rm_try
354 ;;
355esac
356