This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix .gitignore: only ignore 'perl' in root of repo, not U/perl subdir
[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 \
9c11722e 22 i_unistd osvers sysroot
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
9c11722e 80 $define|y|true)
959f3c4c
JH
81 dflt='y'
82 usedl="$define"
83 ;;
9c11722e 84 $undef|n|false)
959f3c4c
JH
85 dflt='n'
86 usedl="$undef"
87 ;;
9c11722e 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 101case "$ans" in
9c11722e 102 y*) usedl="$define"
959f3c4c 103 case "$dlsrc" in
9c11722e
MB
104 '') if $test -f $rsrc/$dldir/dl_${osname}.xs ; then
105 dflt="$dldir/dl_${osname}.xs"
959f3c4c 106 elif $test "$d_dlopen" = "$define" ; then
9c11722e 107 dflt="$dldir/dl_dlopen.xs"
959f3c4c 108 else
9c11722e 109 dflt=''
959f3c4c
JH
110 fi
111 ;;
9c11722e 112 *) dflt="$dldir/$dlsrc"
959f3c4c
JH
113 ;;
114 esac
9c11722e 115 echo "The following dynamic loading files are available:"
959f3c4c 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
9c11722e
MB
133 case "$cccdlflags" in
134 '') case "$gccversion" in
959f3c4c
JH
135 '') case "$osname" in
136 hpux) dflt='+z' ;;
959f3c4c 137 irix*) dflt='-KPIC' ;;
5bcf820f 138 svr4*|esix*|solaris|nonstopux) dflt='-KPIC' ;;
959f3c4c
JH
139 sunos) dflt='-pic' ;;
140 *) dflt='none' ;;
141 esac
9c11722e 142 ;;
959f3c4c 143 *) case "$osname" in
9c11722e
MB
144 darwin) dflt='none' ;;
145 *linux*|svr4*|esix*|solaris|nonstopux) dflt='-fPIC' ;;
959f3c4c
JH
146 *) dflt='-fpic' ;;
147 esac ;;
9c11722e
MB
148 esac ;;
149 ' ') dflt='none' ;;
150 *) dflt="$cccdlflags" ;;
151 esac
152
153 case "$dflt" in
154 none) dflt='' ;;
155 esac
156
157 # If -Dsysroot was specified, now's the time to add it
158 # to cccdlflags
159 if test "X$sysroot" != X; then
160 case "$gccversion" in
161 '') ;;
162 *) case "$dflt" in
163 *sysroot*) ;;
164 'undef'|*)
165 dflt="$dflt --sysroot=$sysroot" ;;
166 esac
167 ;;
168 esac
169 fi
170
171 case "$dflt" in
172 '') dflt='none';;
173 esac
174
175 rp="Any special flags to pass to $cc -c to compile shared library modules?"
176 . ./myread
177 case "$ans" in
959f3c4c 178?X: Use ' ' so that a subsequent Configure run preserves the old state.
9c11722e
MB
179 none) cccdlflags=' ' ;;
180 *) cccdlflags="$ans" ;;
181 esac
959f3c4c 182
9c11722e 183 cat << EOM
959f3c4c
JH
184
185Some systems use ld to create libraries that can be dynamically loaded,
186while other systems (such as those using ELF) use $cc.
187
188EOM
71afd850
MB
189
190: Determine if this is ELF
191 $cat >try.c <<EOM
959f3c4c
JH
192/* Test for whether ELF binaries are produced */
193#include <fcntl.h>
1273bb5e
JH
194#$i_stdlib I_STDLIB
195#ifdef I_STDLIB
959f3c4c 196#include <stdlib.h>
1273bb5e 197#endif
20376335
JH
198#$i_unistd I_UNISTD
199#ifdef I_UNISTD
200#include <unistd.h>
201#endif
959f3c4c 202int main() {
9c11722e
MB
203 char b[4];
204 int i = open("a.out",O_RDONLY);
205 if(i == -1)
206 exit(1); /* fail */
207 if(read(i,b,4)==4 && b[0]==127 && b[1]=='E' && b[2]=='L' && b[3]=='F')
208 exit(0); /* succeed (yes, it is ELF) */
209 exit(1); /* fail */
959f3c4c
JH
210}
211EOM
b18fd6df 212 if $cc $ccflags $ldflags -o a.out try.c >/dev/null 2>&1 && $run ./a.out; then
9c11722e 213 bin_ELF="$define"
71afd850
MB
214 fi
215 $rm_try
216
217 case "$ld" in
9c11722e
MB
218 '') if $test $bin_ELF = "$define"; then
219 cat <<EOM
959f3c4c
JH
220You appear to have ELF support. I'll use $cc to build dynamic libraries.
221EOM
9c11722e 222 dflt="$cc"
959f3c4c 223 else
9c11722e
MB
224 echo "I'll use ld to build dynamic libraries."
225 dflt='ld'
959f3c4c 226 fi
959f3c4c 227 ;;
9c11722e 228 *) dflt="$ld"
959f3c4c
JH
229 ;;
230 esac
231
9c11722e
MB
232 rp="What command should be used to create dynamic libraries?"
233 . ./myread
959f3c4c
JH
234 ld="$ans"
235
9c11722e 236 cat << EOM
959f3c4c
JH
237
238Some systems may require passing special flags to $ld to create a
239library that can be dynamically loaded. If your ld flags include
240-L/other/path options to locate libraries outside your loader's normal
241search path, you may need to specify those -L options here as well. To
242use no flags, say "none".
243
244EOM
9c11722e
MB
245 case "$lddlflags" in
246 '') case "$osname" in
247 haiku) dflt='-shared' ;;
248 hpux) dflt='-b';
249 case "$gccversion" in
8b424337 250 '') dflt="$dflt +vnocompatwarnings" ;;
9c11722e
MB
251 esac
252 ;;
253 *linux*|irix*|gnu*) dflt="-shared $optimize" ;;
9c11722e
MB
254 solaris) # See [perl #66604].
255 # On Solaris 11, gcc -m64 on amd64
256 # appears not to understand -G. gcc versions at
257 # least as old as 3.4.3 support -shared, so just
258 # use that with Solaris 11 and later, but keep
259 # the old behavior for older Solaris versions.
260 case "$gccversion" in
261 '') dflt='-G' ;;
262 *) case "$osvers" in
263 2.?|2.10) dflt='-G' ;;
264 *) dflt='-shared' ;;
265 esac
266 ;;
267 esac
268 ;;
269 sunos) dflt='-assert nodefinitions' ;;
270 svr4*|esix*|nonstopux) dflt="-G $ldflags" ;;
271 *) dflt='none' ;;
272 esac
273 ;;
274 *) dflt="$lddlflags" ;;
275 esac
276
277 : Only do this for gcc, since, for example, qcc has no concept
278 : of --sysroot.
279 if $test "X$sysroot" != X; then
280 case "$gccversion" in
281 '') ;;
282 *) dflt="$dflt --sysroot $sysroot" ;;
283 esac
284 fi
959f3c4c
JH
285
286 : Try to guess additional flags to pick up local libraries.
287 : Be careful not to append to a plain 'none'
288 case "$dflt" in
9c11722e 289 none) dflt='' ;;
959f3c4c
JH
290 esac
291 for thisflag in $ldflags; do
9c11722e 292 case "$thisflag" in
4d5de5cd 293 -L*|-R*|-Wl,-R*)
9c11722e 294 case " $dflt " in
959f3c4c
JH
295 *" $thisflag "*) ;;
296 *) dflt="$dflt $thisflag" ;;
9c11722e
MB
297 esac
298 ;;
299 esac
959f3c4c
JH
300 done
301
302 case "$dflt" in
9c11722e 303 ''|' ') dflt='none' ;;
959f3c4c
JH
304 esac
305
f9f39285 306 case "$ldflags" in
0c7f0563
MBT
307 *-fstack-protector-strong*)
308 case "$dflt" in
309 *-fstack-protector-strong*) ;; # Don't add it again
310 *) dflt="$dflt -fstack-protector-strong" ;;
311 esac
312 ;;
9c11722e
MB
313 *-fstack-protector*)
314 case "$dflt" in
315 *-fstack-protector*) ;; # Don't add it again
316 *) dflt="$dflt -fstack-protector" ;;
f9f39285
AD
317 esac
318 ;;
319 esac
320
9c11722e
MB
321 rp="Any special flags to pass to $ld to create a dynamically loaded library?"
322 . ./myread
323 case "$ans" in
959f3c4c 324?X: Use ' ' so that a subsequent Configure run preserves the old state.
9c11722e
MB
325 none) lddlflags=' ' ;;
326 *) lddlflags="$ans" ;;
327 esac
959f3c4c
JH
328
329 cat <<EOM
330
331Some systems may require passing special flags to $cc to indicate that
332the resulting executable will use dynamic linking. To use no flags,
333say "none".
334
335EOM
9c11722e
MB
336 case "$ccdlflags" in
337 '') case "$osname" in
338 *linux*|hpux|gnu*) dflt='-Wl,-E' ;;
70a7cd5e
MBT
339 sunos) dflt='none' ;;
340 *) dflt='none' ;;
9c11722e
MB
341 esac ;;
342 ' ') dflt='none' ;;
343 *) dflt="$ccdlflags" ;;
344 esac
345 rp="Any special flags to pass to $cc to use dynamic linking?"
346 . ./myread
347 case "$ans" in
959f3c4c 348?X: Use ' ' so that a subsequent Configure run preserves the old state.
9c11722e
MB
349 none) ccdlflags=' ' ;;
350 *) ccdlflags="$ans" ;;
351 esac
352 ;;
959f3c4c 353?X: End of usedl=y section
9c11722e
MB
354
355 *) usedl="$undef"
959f3c4c 356 ld='ld'
9c11722e
MB
357 dlsrc='dl_none.xs'
358 lddlflags=''
359 ccdlflags=''
360 ;;
959f3c4c
JH
361esac
362
35a1617b
MB
363ld_can_script="$undef"
364case "$bin_ELF$usedl" in
9c11722e
MB
365 $define$define)
366 # Abuse try.h and a.out names for neat cleanup
367 $cat >try.c <<EOM
35a1617b
MB
368void foo() {}
369void bar() {}
370EOM
9c11722e 371 $cat >try.h <<EOM
35a1617b
MB
372LIBTEST_42 {
373 global:
374 foo;
375 local: *;
376 };
377EOM
9c11722e
MB
378 if $cc $cccdlflags $ccdlflags $ccflags \
379 $ldflags $lddlflags -o a.out try.c \
380 -Wl,--version-script=try.h >/dev/null 2>&1 \
381 && $test -s a.out ; then
382 echo "ld supports scripting" >&4
383 ld_can_script="$define"
384 else
385 echo "ld does not support scripting" >&4
386 fi
387 $rm_try
388 ;;
35a1617b
MB
389esac
390