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