?X: cc -c +z module_b.c
?X: ld -b module_a.o module_b.o -o module.sl
?X:
-?MAKE:usedl ld dlsrc cccdlflags lddlflags ccdlflags: \
- Getfile Myread test osname sed i_dld d_dlopen Findhdr Setvar \
- cc ccflags ldflags ls gccversion cat rsrc src
+?MAKE:usedl ld dlsrc cccdlflags lddlflags ccdlflags bin_ELF ld_can_script: \
+ rm_try Getfile Myread test osname sed i_dld d_dlopen Findhdr Setvar \
+ src run cc ccflags ldflags optimize ls gccversion cat rsrc i_stdlib \
+ i_unistd
?MAKE: -pick add $@ %<
?Y:BOTTOM
?S:usedl:
?S: It is up to the makefile to use it. For sunos 4.1, it should
?S: be empty.
?S:.
+?S:bin_ELF:
+?S: This variable saves the result from configure if generated binaries
+?S: are in ELF format. Only set to defined when the test has actually
+?S: been performed, and the result was positive.
+?S:.
+?S:ld_can_script:
+?S: This variable shows if the loader accepts scripts in the form of
+?S: -Wl,--version-script=ld.script. This is currently only supported
+?S: for GNU ld on ELF in dynamic loading builds.
+?S:.
?C:USE_DYNAMIC_LOADING ~ %<:
?C: This symbol, if defined, indicates that dynamic loading of
?C: some sort is available.
?H:.
?W:%<:dlopen
?T:dldir thisflag tdir
+?F:!a.out
: determine which dynamic loading, if any, to compile in
echo " "
dldir="ext/DynaLoader"
dflt='n'
usedl="$undef"
;;
-*)
+*)
dflt='n'
case "$d_dlopen" in
$define) dflt='y' ;;
rp="Do you wish to use dynamic loading?"
. ./myread
usedl="$ans"
+bin_ELF="$undef"
case "$ans" in
y*) usedl="$define"
case "$dlsrc" in
esac
echo "The following dynamic loading files are available:"
: Can not go over to $dldir because getfile has path hard-coded in.
- tdir=`pwd`; cd $rsrc; $ls -C $dldir/dl*.xs; cd $tdir
+ tdir=`pwd`; cd "$rsrc"; $ls -C $dldir/dl*.xs; cd "$tdir"
rp="Source file to use for dynamic loading"
fn="fne"
gfpth="$src"
hpux) dflt='+z' ;;
next) dflt='none' ;;
irix*) dflt='-KPIC' ;;
- svr4*|esix*|solaris) dflt='-KPIC' ;;
+ svr4*|esix*|solaris|nonstopux) dflt='-KPIC' ;;
sunos) dflt='-pic' ;;
*) dflt='none' ;;
esac
;;
*) case "$osname" in
- svr4*|esix*|solaris) dflt='-fPIC' ;;
+ darwin) dflt='none' ;;
+ linux*|svr4*|esix*|solaris|nonstopux) dflt='-fPIC' ;;
*) dflt='-fpic' ;;
esac ;;
esac ;;
while other systems (such as those using ELF) use $cc.
EOM
- case "$ld" in
- '') $cat >try.c <<'EOM'
+
+: Determine if this is ELF
+ $cat >try.c <<EOM
/* Test for whether ELF binaries are produced */
#include <fcntl.h>
+#$i_stdlib I_STDLIB
+#ifdef I_STDLIB
#include <stdlib.h>
+#endif
+#$i_unistd I_UNISTD
+#ifdef I_UNISTD
+#include <unistd.h>
+#endif
int main() {
char b[4];
int i = open("a.out",O_RDONLY);
- if(i == -1)
+ if(i == -1)
exit(1); /* fail */
if(read(i,b,4)==4 && b[0]==127 && b[1]=='E' && b[2]=='L' && b[3]=='F')
- exit(0); /* succeed (yes, it's ELF) */
+ exit(0); /* succeed (yes, it is ELF) */
else
exit(1); /* fail */
}
EOM
- if $cc $ccflags try.c >/dev/null 2>&1 && ./a.out; then
+ if $cc $ccflags $ldflags try.c >/dev/null 2>&1 && $run ./a.out; then
+ bin_ELF="$define"
+ fi
+ $rm_try
+
+ case "$ld" in
+ '') if $test $bin_ELF = "$define"; then
cat <<EOM
You appear to have ELF support. I'll use $cc to build dynamic libraries.
EOM
echo "I'll use ld to build dynamic libraries."
dflt='ld'
fi
- rm -f try.c a.out
;;
*) dflt="$ld"
;;
case "$lddlflags" in
'') case "$osname" in
beos) dflt='-nostart' ;;
- hpux) case "$gccversion" in
- '') dflt='-b +vnocompatwarnings' ;;
+ haiku) dflt='-shared' ;;
+ hpux) dflt='-b';
+ case "$gccversion" in
+ '') dflt="$dflt +vnocompatwarnings" ;;
esac
- ;;
- linux|irix*) dflt='-shared' ;;
+ ;;
+ linux|irix*|gnu*) dflt="-shared $optimize" ;;
next) dflt='none' ;;
solaris) dflt='-G' ;;
sunos) dflt='-assert nodefinitions' ;;
- svr4*|esix*) dflt="-G $ldflags" ;;
+ svr4*|esix*|nonstopux) dflt="-G $ldflags" ;;
*) dflt='none' ;;
esac
;;
esac
for thisflag in $ldflags; do
case "$thisflag" in
- -L*)
+ -L*|-R*|-Wl,-R*)
case " $dflt " in
*" $thisflag "*) ;;
*) dflt="$dflt $thisflag" ;;
''|' ') dflt='none' ;;
esac
+ case "$ldflags" in
+ *-fstack-protector*)
+ case "$dflt" in
+ *-fstack-protector*) ;; # Don't add it again
+ *) dflt="$dflt -fstack-protector" ;;
+ esac
+ ;;
+ esac
+
+
rp="Any special flags to pass to $ld to create a dynamically loaded library?"
. ./myread
case "$ans" in
EOM
case "$ccdlflags" in
'') case "$osname" in
- hpux) dflt='-Wl,-E' ;;
- linux) dflt='-rdynamic' ;;
- next) dflt='none' ;;
- sunos) dflt='none' ;;
- *) dflt='none' ;;
+ linux|hpux|gnu*) dflt='-Wl,-E' ;;
+ next|sunos) dflt='none' ;;
+ *) dflt='none' ;;
esac ;;
' ') dflt='none' ;;
*) dflt="$ccdlflags" ;;
;;
esac
+ld_can_script="$undef"
+case "$bin_ELF$usedl" in
+$define$define)
+ # Abuse try.h and a.out names for neat cleanup
+ $cat >try.c <<EOM
+void foo() {}
+void bar() {}
+EOM
+ $cat >try.h <<EOM
+LIBTEST_42 {
+ global:
+ foo;
+ local: *;
+ };
+EOM
+ if $cc $cccdlflags $ccdlflags $ccflags \
+ $ldflags $lddlflags -o a.out try.c \
+ -Wl,--version-script=try.h >/dev/null 2>&1 \
+ && $test -s a.out ; then
+ echo "ld supports scripting" >&4
+ ld_can_script="$define"
+ else
+ echo "ld does not support scripting" >&4
+ fi
+ $rm_try
+ ;;
+esac
+