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 / d_dlsymun.U
1 ?RCS: $Id: d_dlsymun.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: d_dlsymun.U,v $
9 ?RCS:
10 ?RCS:
11 ?MAKE:d_dlsymun: cat cc ccflags ldflags ld rm Setvar dlsrc i_dlfcn i_stdlib \
12         cccdlflags ccdlflags lddlflags libs dlext _o run to
13 ?MAKE:  -pick add $@ %<
14 ?X: This is specific to perl5.
15 ?S:d_dlsymun:
16 ?S:     This variable conditionally defines DLSYM_NEEDS_UNDERSCORE, which
17 ?S:     indicates that we need to prepend an underscore to the symbol
18 ?S:     name before calling dlsym().
19 ?S:.
20 ?C:DLSYM_NEEDS_UNDERSCORE:
21 ?C:     This symbol, if defined, indicates that we need to prepend an
22 ?C:     underscore to the symbol name before calling dlsym().  This only
23 ?C:     makes sense if you *have* dlsym, which we will presume is the
24 ?C:     case if you're using dl_dlopen.xs.
25 ?C:.
26 ?H:#$d_dlsymun  DLSYM_NEEDS_UNDERSCORE  /**/
27 ?H:.
28 ?LINT:set d_dlsymun
29 ?T: xxx
30 ?F:!fred
31 : Check if dlsym need a leading underscore
32 echo " "
33 val="$undef"
34
35 case "$dlsrc" in
36 dl_dlopen.xs)
37         echo "Checking whether your dlsym() needs a leading underscore ..." >&4
38         $cat >dyna.c <<'EOM'
39 fred () { }
40 EOM
41
42 $cat >fred.c<<EOM
43
44 #include <stdio.h>
45 #$i_stdlib I_STDLIB
46 #ifdef I_STDLIB
47 #include <stdlib.h>
48 #endif
49 #$i_dlfcn I_DLFCN
50 #ifdef I_DLFCN
51 #include <dlfcn.h>      /* the dynamic linker include file for SunOS/Solaris */
52 #else
53 #include <sys/types.h>
54 #include <nlist.h>
55 #include <link.h>
56 #endif
57
58 extern int fred() ;
59
60 int main()
61 {
62     void * handle ;
63     void * symbol ;
64 #ifndef RTLD_LAZY
65     int mode = 1 ;
66 #else
67     int mode = RTLD_LAZY ;
68 #endif
69     handle = dlopen("./dyna.$dlext", mode) ;
70     if (handle == NULL) {
71         printf ("1\n") ;
72         fflush (stdout) ;
73         exit(0);
74     }
75     symbol = dlsym(handle, "fred") ;
76     if (symbol == NULL) {
77         /* try putting a leading underscore */
78         symbol = dlsym(handle, "_fred") ;
79         if (symbol == NULL) {
80             printf ("2\n") ;
81             fflush (stdout) ;
82             exit(0);
83         }
84         printf ("3\n") ;
85     }
86     else
87         printf ("4\n") ;
88     fflush (stdout) ;
89     exit(0);
90 }
91 EOM
92         : Call the object file tmp-dyna.o in case dlext=o.
93         if $cc $ccflags $cccdlflags -c dyna.c > /dev/null 2>&1 &&
94                 mv dyna${_o} tmp-dyna${_o} > /dev/null 2>&1 &&
95                 $ld -o dyna.$dlext $ldflags $lddlflags tmp-dyna${_o} > /dev/null 2>&1 &&
96                 $cc -o fred $ccflags $ldflags $cccdlflags $ccdlflags fred.c $libs > /dev/null 2>&1 && $to dyna.$dlext; then
97                 xxx=`$run ./fred`
98                 case $xxx in
99                 1)      echo "Test program failed using dlopen." >&4
100                         echo "Perhaps you should not use dynamic loading." >&4;;
101                 2)      echo "Test program failed using dlsym." >&4
102                         echo "Perhaps you should not use dynamic loading." >&4;;
103                 3)      echo "dlsym needs a leading underscore" >&4
104                         val="$define" ;;
105                 4)      echo "dlsym doesn't need a leading underscore." >&4;;
106                 esac
107         else
108                 echo "I can't compile and run the test program." >&4
109                 echo "I'm guessing that dlsym doesn't need a leading underscore." >&4
110         fi
111         ;;
112 esac
113
114 $rm -f fred fred.* dyna.$dlext dyna.* tmp-dyna.*
115
116 set d_dlsymun
117 eval $setvar
118