?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: You may redistribute only under the terms of the Artistic License,
?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: that same Artistic License; a copy of which may be found at the root
?RCS: of the source tree for dist 3.0.
?RCS:
?RCS: $Log: Csym.U,v $
?RCS: Revision 3.0.1.4  1995/07/25  13:36:29  ram
?RCS: patch56: re-arranged compile line to include ldflags before objects
?RCS: patch56: added quotes for OS/2 support
?RCS:
?RCS: Revision 3.0.1.3  1995/05/12  12:00:33  ram
?RCS: patch54: fixed C test program to bypass gcc builtin type checks (ADO)
?RCS:
?RCS: Revision 3.0.1.2  1994/10/31  09:34:13  ram
?RCS: patch44: added Options to the MAKE line since it's no longer in Init.U
?RCS:
?RCS: Revision 3.0.1.1  1993/08/25  14:00:05  ram
?RCS: patch6: added ldflags as a conditional dependency and to compile line
?RCS: patch6: a final double quote was missing in csym variable after eval
?RCS:
?RCS: Revision 3.0  1993/08/18  12:04:50  ram
?RCS: Baseline for dist 3.0 netwide release.
?RCS:
?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:	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:	or array [-a] is defined, 'false' otherwise. If a previous value is
?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
?F:!try
: is a C symbol defined?
csym='tlook=$1;
case "$3" in
-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
true-) ;;
true-*) tx=no; eval "tval=\$$4"; case "$tval" in "") tx=yes;; esac;;
esac;
case "$tx" in
yes)
?X:
?X: Put symbol inside a printf to fool optimizing compilers...
?X:
?X: We use 'short' instead of 'int' to try to circumvent overzealous
?X: optimizing compilers using built-in prototypes for commonly used
?X: routines to complain when seeing a different external declaration. For
?X: instance, gcc 2.6.3 fails if we use 'int' and we attempt a test against
?X: memcpy() on machines where sizeof(int) == sizeof(char *) (the usual return
?X: type), the compiler assuming it's a built-in declaration given that the
?X: returned size matches. At least with 'short' we are safe! -- RAM, for ADO
?X:
?X: Let's thank GNU cc for making our lives so easy! :-)
?X: (An alternative for the future would be to use our knowledge about gcc
?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:
	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(int argc, char **argv) { if(p() && p() != (void *)argv[0]) 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;
	else
		echo "$extern_C void *$1$tdc; void *(*(p()))$tdc { return &$1; } int main(int argc, char **argv) { if(p() && p() != (void *)argv[0]) 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;
eval "$2=$tval"'

