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