This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Generate a valid config.h even if stdarg.h and varargs.h are both missing.
[metaconfig.git] / U / compline / Csym.U
index 12d0318..c9bef1c 100644 (file)
@@ -1,7 +1,7 @@
 ?RCS: $Id: Csym.U,v 3.0.1.4 1995/07/25 13:36:29 ram Exp $
 ?RCS:
 ?RCS: Copyright (c) 1991-1993, Raphael Manfredi
-?RCS: 
+?RCS:
 ?RCS: You may redistribute only under the terms of the Artistic Licence,
 ?RCS: as specified in the README file that comes with the distribution.
 ?RCS: You may reuse parts of this distribution only within the terms of
 ?RCS: Revision 3.0  1993/08/18  12:04:50  ram
 ?RCS: Baseline for dist 3.0 netwide release.
 ?RCS:
-?MAKE:Csym: Options contains libc libs runnm +cc +optimize +ccflags +ldflags rm
+?MAKE:Csym mistrustnm extern_C: Options contains libc libs runnm test \
+       +cc +optimize +ccflags +ldflags run rm_try _exe d_cplusplus
 ?MAKE: -pick add $@ %<
 ?LINT:define csym
 ?LINT:use libc
+?LINT:extern mistrustnm
+?LINT:set mistrustnm
 ?S:csym:
 ?S:    This shell variable is used internally by Configure to check
-?S:    wether a given C symbol is defined or not. A typical use is:
+?S:    whether a given C symbol is defined or not. A typical use is:
 ?S:            set symbol result [-fva] [previous]
 ?S:            eval $csym
 ?S:    That will set result to 'true' if the function [-f], variable [-v]
 ?S:    given and the -r flag was provided on the command line, that value
 ?S:    is reused without questioning.
 ?S:.
+?S:extern_C:
+?S:    ANSI C requires 'extern' where C++ requires 'extern "C"'. This
+?S:    variable can be used in Configure to do the right thing.
+?S:.
+?S:mistrustnm:
+?S:    This variable can be used to establish a fallthrough for the cases
+?S:    where nm fails to find a symbol.  If usenm is false or usenm is true
+?S:    and mistrustnm is false, this variable has no effect.  If usenm is true
+?S:    and mistrustnm is "compile", a test program will be compiled to try to
+?S:    find any symbol that can't be located via nm lookup.  If mistrustnm is
+?S:    "run", the test program will be run as well as being compiled.
+?S:.
 ?V:csym
-?T:tval tx tlook tf tdc tc
+?T:tval tx tlook tf tdc
+?F:!try
 : is a C symbol defined?
 csym='tlook=$1;
 case "$3" in
--v) tf=libc.tmp; tc=""; tdc="";;
--a) tf=libc.tmp; tc="[0]"; tdc="[]";;
-*) tlook="^$1\$"; tf=libc.list; tc="()"; tdc="()";;
+-v) tf=libc.tmp; tdc="";;
+-a) tf=libc.tmp; tdc="[]";;
+*) tlook="^$1\$"; tf=libc.list; tdc="()";;
+esac;
+case "$d_cplusplus" in
+    $define)   extern_C="extern \"C\"" ;;
+    *)         extern_C="extern"       ;;
 esac;
 tx=yes;
 case "$reuseval-$4" in
@@ -56,13 +76,6 @@ true-*) tx=no; eval "tval=\$$4"; case "$tval" in "") tx=yes;; esac;;
 esac;
 case "$tx" in
 yes)
-       case "$runnm" in
-       true)
-               if $contains $tlook $tf >/dev/null 2>&1;
-               then tval=true;
-               else tval=false;
-               fi;;
-       *)
 ?X:
 ?X: Put symbol inside a printf to fool optimizing compilers...
 ?X:
@@ -79,18 +92,28 @@ yes)
 ?X: to force a -fno-builtin option in the compile test, in case the 'short'
 ?X: trick is obsoleted by future gcc releases). -- RAM
 ?X:
-               echo "int main() { extern short $1$tdc; printf(\"%hd\", $1$tc); }" > t.c;
-               if $cc -o t $optimize $ccflags $ldflags t.c $libs >/dev/null 2>&1;
-               then tval=true;
-               else tval=false;
+       tval=false;
+       if $test "$runnm" = true; then
+               if $contains $tlook $tf >/dev/null 2>&1; then
+                       tval=true;
+               elif $test "$mistrustnm" = compile -o "$mistrustnm" = run; then
+                       echo "$extern_C void *$1$tdc; void *(*(p()))$tdc { return &$1; } int main() { if(p()) return(0); else return(1); }"> try.c;
+                       $cc -o try $optimize $ccflags $ldflags try.c >/dev/null 2>&1 $libs && tval=true;
+                       $test "$mistrustnm" = run -a -x try && { $run ./try$_exe >/dev/null 2>&1 || tval=false; };
+                       $rm_try;
                fi;
-               $rm -f t t.c;;
-       esac;;
+       else
+               echo "$extern_C void *$1$tdc; void *(*(p()))$tdc { return &$1; } int main() { if(p()) return(0); else return(1); }"> try.c;
+               $cc -o try $optimize $ccflags $ldflags try.c $libs >/dev/null 2>&1 && tval=true;
+               $rm_try;
+       fi;
+       ;;
 *)
        case "$tval" in
        $define) tval=true;;
        *) tval=false;;
-       esac;;
+       esac;
+       ;;
 esac;
 eval "$2=$tval"'