summaryrefslogtreecommitdiff
path: root/mcon/U/Trylink.U
blob: 4ed912822802ebea53b97fd9d4be9a2ecbd6bace (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
?RCS: $Id$
?RCS:
?RCS: Copyright (c) 1991-1997, 2004-2006, 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 4.0.
?X:
?X: This unit tries to compile and link a test program.
?X:
?X: To use it, put the program to compile in try.c, then say:
?X:
?X:		cyn=func
?X:		set d_func [optional cc flags to try in sequence]
?X:		eval $trylink
?X:
?X: A log of all attempts is kept in the trylink.log file, within the UU
?X: directory (where Configure runs).  This directory is only cleaned-up
?X: at the end of the Configure run, so do not supply -e to Configure in order
?X: to stop after the production of the config.sh file and be able to
?X: inspect the UU/trylink.log file.
?X:
?X: Before calling $trylink, on can also set the $cyn variable (check yes/no)
?X: with a message that will be printed before the test is made and which
?X: will indicate whether the test was successful or not.  The string
?X: "Checking $cyn..." is emitted and will be followed by "yes." if the
?X: compilation succeeds, and "no." otherwise.
?X:
?X: If there are no space in the $cyn variable, then it is expected to hold
?X: the name of a routine if the variable to test starts with d_, or
?X: the name of an include file if the variable to test starts with i_.
?X: In which case the message for success are changed to "found." and
?X: "missing." on failure.
?X:
?X: The "$cyn" variable is explicitly reset at the end, and nothing is
?X: printed if it is empty upon entry.
?X:
?MAKE:Trylink: Setvar Oldconfig cat rm test +cc +ccflags +ldflags echo c n
?MAKE:	-pick add $@ %<
?LINT:define trylink
?V:trylink:cyn
?S:trylink:
?S:	This shell variable is used internally by Configure to check
?S:	wether a given function is defined or not. A typical use is:
?S:		create try.c
?S:		set d_func [optional cc flags to try in sequence]
?S:		eval $trylink
?S:	That will print a message, saying wether function was found or
?S:	not and set d_func accordingly.
?S:.
?T:var file val nparams msg yes no
: see whether the try.c file compiles and links
trylink='
var=$1;
shift;
val=$undef;
file=trylink.log;
nparams=$#;
?X: If they supplied a $cyn, display it now.
case "$cyn" in
"") msg="";;
*" "*) msg="$cyn"; yes=yes; no=no;;
*)
	case "$var" in
	d_*) msg="for $cyn()"; yes=found; no=missing;;
	i_*) msg="for <$cyn>"; yes=found; no=missing;;
	*) msg="$cyn"; yes=yes; no=no;;
	esac
	;;
esac;
case "$cyn" in
"") echo "--- $var ---" >> "$file";;
*)
	echo " "; $echo $n "Checking $msg...$c" >&4;
	echo "--- $var --- ($msg)" >> "$file"
	;;
esac;
$cat try.c >> "$file";
while :; do
	$rm -f try$_exe;
	if $cc $ccflags -o try try.c $ldflags $1 >> "$file" 2>&1; then
		case "$nparams" in 0) ;; *) echo "==> OK with \"$1\"" >> "$file";; esac;
		val=$define;
		break;
	fi;
	if $test $# -lt 1; then
		break;
	fi;
	echo "==> FAILED with \"$1\"" >> "$file";
	shift;
done;
$rm -rf try try.*;
echo "==> $var=$val" >> "$file";
?X: Show feedback if they supplied a $cyn
case "$cyn" in
"") ;;
*)
	case "$val" in
	"$define") echo " $yes." >&4;;
	*) echo " $no." >&4;;
	esac
	;;
esac;
set $var; eval $setvar;
?X: Cleanup so that next unit using $trylink does not have to do that
cyn=""
'