3 ?RCS: Copyright (c) 1996-1998, Andy Dougherty
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.
8 ?RCS: $Log: dlsrc.U,v $
10 ?X: hpux support thanks to Jeff Okamoto <okamoto@hpcc101.corp.hp.com>
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
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 \
23 ?MAKE: -pick add $@ %<
26 ?S: This variable indicates if the system supports dynamic
27 ?S: loading of some sort. See also dlsrc and dlobj.
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.
36 ?S: This variable contains the name of the dynamic loading file that
37 ?S: will be used with the package.
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.
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.
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
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.
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.
67 ?C:USE_DYNAMIC_LOADING ~ %<:
68 ?C: This symbol, if defined, indicates that dynamic loading of
69 ?C: some sort is available.
71 ?H:?%<:#$usedl USE_DYNAMIC_LOADING /**/
74 ?T:dldir thisflag tdir
76 : determine which dynamic loading, if any, to compile in
78 dldir="ext/DynaLoader"
96 : Does a dl_xxx.xs file exist for this operating system
97 $test -f $rsrc/$dldir/dl_${osname}.xs && dflt='y'
100 rp="Do you wish to use dynamic loading?"
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"
118 *) dflt="$dldir/$dlsrc"
121 echo "The following dynamic loading files are available:"
122 : Can not go over to $dldir because getfile has path hard-coded in.
123 tdir=`pwd`; cd "$rsrc"; $ls -C $dldir/dl*.xs; cd "$tdir"
124 rp="Source file to use for dynamic loading"
130 dlsrc=`echo $ans | $sed -e 's%.*/\([^/]*\)$%\1%'`
134 Some systems may require passing special flags to $cc -c to
135 compile modules that will be used to create a shared library.
136 To use no flags, say "none".
139 case "$cccdlflags" in
140 '') case "$gccversion" in
141 '') case "$osname" in
144 irix*) dflt='-KPIC' ;;
145 svr4*|esix*|solaris|nonstopux) dflt='-KPIC' ;;
146 sunos) dflt='-pic' ;;
151 darwin) dflt='none' ;;
152 linux*|svr4*|esix*|solaris|nonstopux) dflt='-fPIC' ;;
157 *) dflt="$cccdlflags" ;;
159 rp="Any special flags to pass to $cc -c to compile shared library modules?"
162 ?X: Use ' ' so that a subsequent Configure run preserves the old state.
163 none) cccdlflags=' ' ;;
164 *) cccdlflags="$ans" ;;
169 Some systems use ld to create libraries that can be dynamically loaded,
170 while other systems (such as those using ELF) use $cc.
174 : Determine if this is ELF
176 /* Test for whether ELF binaries are produced */
188 int i = open("a.out",O_RDONLY);
191 if(read(i,b,4)==4 && b[0]==127 && b[1]=='E' && b[2]=='L' && b[3]=='F')
192 exit(0); /* succeed (yes, it is ELF) */
197 if $cc $ccflags $ldflags try.c >/dev/null 2>&1 && $run ./a.out; then
203 '') if $test $bin_ELF = "$define"; then
205 You appear to have ELF support. I'll use $cc to build dynamic libraries.
209 echo "I'll use ld to build dynamic libraries."
217 rp="What command should be used to create dynamic libraries?"
223 Some systems may require passing special flags to $ld to create a
224 library that can be dynamically loaded. If your ld flags include
225 -L/other/path options to locate libraries outside your loader's normal
226 search path, you may need to specify those -L options here as well. To
227 use no flags, say "none".
231 '') case "$osname" in
232 haiku) dflt='-shared' ;;
234 case "$gccversion" in
235 '') dflt="$dflt +vnocompatwarnings" ;;
238 linux|irix*|gnu*) dflt="-shared $optimize" ;;
240 solaris) dflt='-G' ;;
241 sunos) dflt='-assert nodefinitions' ;;
242 svr4*|esix*|nonstopux) dflt="-G $ldflags" ;;
246 *) dflt="$lddlflags" ;;
249 : Try to guess additional flags to pick up local libraries.
250 : Be careful not to append to a plain 'none'
254 for thisflag in $ldflags; do
259 *) dflt="$dflt $thisflag" ;;
266 ''|' ') dflt='none' ;;
272 *-fstack-protector*) ;; # Don't add it again
273 *) dflt="$dflt -fstack-protector" ;;
279 rp="Any special flags to pass to $ld to create a dynamically loaded library?"
282 ?X: Use ' ' so that a subsequent Configure run preserves the old state.
283 none) lddlflags=' ' ;;
284 *) lddlflags="$ans" ;;
289 Some systems may require passing special flags to $cc to indicate that
290 the resulting executable will use dynamic linking. To use no flags,
295 '') case "$osname" in
296 linux|hpux|gnu*) dflt='-Wl,-E' ;;
297 next|sunos) dflt='none' ;;
301 *) dflt="$ccdlflags" ;;
303 rp="Any special flags to pass to $cc to use dynamic linking?"
306 ?X: Use ' ' so that a subsequent Configure run preserves the old state.
307 none) ccdlflags=' ' ;;
308 *) ccdlflags="$ans" ;;
311 ?X: End of usedl=y section
320 ld_can_script="$undef"
321 case "$bin_ELF$usedl" in
323 # Abuse try.h and a.out names for neat cleanup
335 if $cc $cccdlflags $ccdlflags $ccflags \
336 $ldflags $lddlflags -o a.out try.c \
337 -Wl,--version-script=try.h >/dev/null 2>&1 \
338 && $test -s a.out ; then
339 echo "ld supports scripting" >&4
340 ld_can_script="$define"
342 echo "ld does not support scripting" >&4