Commit | Line | Data |
---|---|---|
959f3c4c JH |
1 | ?RCS: $Id: Csym.U,v 3.0.1.4 1995/07/25 13:36:29 ram Exp $ |
2 | ?RCS: | |
3 | ?RCS: Copyright (c) 1991-1993, Raphael Manfredi | |
4 | ?RCS: | |
5 | ?RCS: You may redistribute only under the terms of the Artistic Licence, | |
6 | ?RCS: as specified in the README file that comes with the distribution. | |
7 | ?RCS: You may reuse parts of this distribution only within the terms of | |
8 | ?RCS: that same Artistic Licence; a copy of which may be found at the root | |
9 | ?RCS: of the source tree for dist 3.0. | |
10 | ?RCS: | |
11 | ?RCS: $Log: Csym.U,v $ | |
12 | ?RCS: Revision 3.0.1.4 1995/07/25 13:36:29 ram | |
13 | ?RCS: patch56: re-arranged compile line to include ldflags before objects | |
14 | ?RCS: patch56: added quotes for OS/2 support | |
15 | ?RCS: | |
16 | ?RCS: Revision 3.0.1.3 1995/05/12 12:00:33 ram | |
17 | ?RCS: patch54: fixed C test program to bypasss gcc builtin type checks (ADO) | |
18 | ?RCS: | |
19 | ?RCS: Revision 3.0.1.2 1994/10/31 09:34:13 ram | |
20 | ?RCS: patch44: added Options to the MAKE line since it's no longer in Init.U | |
21 | ?RCS: | |
22 | ?RCS: Revision 3.0.1.1 1993/08/25 14:00:05 ram | |
23 | ?RCS: patch6: added ldflags as a conditional dependency and to compile line | |
24 | ?RCS: patch6: a final double quote was missing in csym variable after eval | |
25 | ?RCS: | |
26 | ?RCS: Revision 3.0 1993/08/18 12:04:50 ram | |
27 | ?RCS: Baseline for dist 3.0 netwide release. | |
28 | ?RCS: | |
9f9921f7 JH |
29 | ?MAKE:Csym: Options contains libc libs runnm test \ |
30 | +cc +optimize +ccflags +ldflags rm | |
959f3c4c JH |
31 | ?MAKE: -pick add $@ %< |
32 | ?LINT:define csym | |
33 | ?LINT:use libc | |
34 | ?S:csym: | |
35 | ?S: This shell variable is used internally by Configure to check | |
36 | ?S: wether a given C symbol is defined or not. A typical use is: | |
37 | ?S: set symbol result [-fva] [previous] | |
38 | ?S: eval $csym | |
39 | ?S: That will set result to 'true' if the function [-f], variable [-v] | |
40 | ?S: or array [-a] is defined, 'false' otherwise. If a previous value is | |
41 | ?S: given and the -r flag was provided on the command line, that value | |
42 | ?S: is reused without questioning. | |
43 | ?S:. | |
44 | ?V:csym | |
45 | ?T:tval tx tlook tf tdc tc | |
46 | : is a C symbol defined? | |
47 | csym='tlook=$1; | |
48 | case "$3" in | |
49 | -v) tf=libc.tmp; tc=""; tdc="";; | |
50 | -a) tf=libc.tmp; tc="[0]"; tdc="[]";; | |
51 | *) tlook="^$1\$"; tf=libc.list; tc="()"; tdc="()";; | |
52 | esac; | |
53 | tx=yes; | |
54 | case "$reuseval-$4" in | |
55 | true-) ;; | |
56 | true-*) tx=no; eval "tval=\$$4"; case "$tval" in "") tx=yes;; esac;; | |
57 | esac; | |
58 | case "$tx" in | |
59 | yes) | |
959f3c4c JH |
60 | ?X: |
61 | ?X: Put symbol inside a printf to fool optimizing compilers... | |
62 | ?X: | |
63 | ?X: We use 'short' instead of 'int' to try to circumvent overzealous | |
64 | ?X: optimizing compilers using built-in prototypes for commonly used | |
65 | ?X: routines to complain when seeing a different external declaration. For | |
66 | ?X: instance, gcc 2.6.3 fails if we use 'int' and we attempt a test against | |
67 | ?X: memcpy() on machines where sizeof(int) == sizeof(char *) (the usual return | |
68 | ?X: type), the compiler assuming it's a built-in declaration given that the | |
69 | ?X: returned size matches. At least with 'short' we are safe! -- RAM, for ADO | |
70 | ?X: | |
71 | ?X: Let's thank GNU cc for making our lifes so easy! :-) | |
72 | ?X: (An alternative for the future would be to use our knowledge about gcc | |
73 | ?X: to force a -fno-builtin option in the compile test, in case the 'short' | |
74 | ?X: trick is obsoleted by future gcc releases). -- RAM | |
75 | ?X: | |
868ab49f JH |
76 | tval=false; |
77 | if $test "$runnm" = "true" && $contains $tlook $tf >/dev/null 2>&1; then | |
78 | tval=true; | |
79 | else | |
959f3c4c | 80 | echo "int main() { extern short $1$tdc; printf(\"%hd\", $1$tc); }" > t.c; |
868ab49f JH |
81 | if $cc -o t $optimize $ccflags $ldflags t.c $libs >/dev/null 2>&1; then |
82 | tval=true; | |
959f3c4c | 83 | fi; |
868ab49f JH |
84 | $rm -f t t.c; |
85 | fi; | |
86 | ;; | |
959f3c4c JH |
87 | *) |
88 | case "$tval" in | |
89 | $define) tval=true;; | |
90 | *) tval=false;; | |
868ab49f JH |
91 | esac; |
92 | ;; | |
959f3c4c JH |
93 | esac; |
94 | eval "$2=$tval"' | |
95 |