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