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 | |
0065f4af | 4 | ?RCS: |
65a32477 | 5 | ?RCS: You may redistribute only under the terms of the Artistic License, |
959f3c4c JH |
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 | |
65a32477 | 8 | ?RCS: that same Artistic License; a copy of which may be found at the root |
959f3c4c JH |
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 | |
65a32477 | 17 | ?RCS: patch54: fixed C test program to bypass gcc builtin type checks (ADO) |
959f3c4c JH |
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: | |
cce04e58 | 29 | ?MAKE:Csym mistrustnm extern_C: Options contains libc libs runnm test \ |
2cb64bf6 | 30 | +cc +optimize +ccflags +ldflags run rm_try _exe d_cplusplus |
959f3c4c | 31 | ?MAKE: -pick add $@ %< |
4c9adfe2 | 32 | ?LINT:define csym |
959f3c4c | 33 | ?LINT:use libc |
e3a6a689 | 34 | ?LINT:extern mistrustnm |
86bce830 | 35 | ?LINT:set mistrustnm |
959f3c4c JH |
36 | ?S:csym: |
37 | ?S: This shell variable is used internally by Configure to check | |
4dd7201d | 38 | ?S: whether a given C symbol is defined or not. A typical use is: |
959f3c4c JH |
39 | ?S: set symbol result [-fva] [previous] |
40 | ?S: eval $csym | |
41 | ?S: That will set result to 'true' if the function [-f], variable [-v] | |
42 | ?S: or array [-a] is defined, 'false' otherwise. If a previous value is | |
43 | ?S: given and the -r flag was provided on the command line, that value | |
44 | ?S: is reused without questioning. | |
45 | ?S:. | |
cce04e58 MB |
46 | ?S:extern_C: |
47 | ?S: ANSI C requires 'extern' where C++ requires 'extern "C"'. This | |
48 | ?S: variable can be used in Configure to do the right thing. | |
49 | ?S:. | |
e3a6a689 JH |
50 | ?S:mistrustnm: |
51 | ?S: This variable can be used to establish a fallthrough for the cases | |
52 | ?S: where nm fails to find a symbol. If usenm is false or usenm is true | |
53 | ?S: and mistrustnm is false, this variable has no effect. If usenm is true | |
54 | ?S: and mistrustnm is "compile", a test program will be compiled to try to | |
55 | ?S: find any symbol that can't be located via nm lookup. If mistrustnm is | |
56 | ?S: "run", the test program will be run as well as being compiled. | |
57 | ?S:. | |
959f3c4c | 58 | ?V:csym |
cce04e58 | 59 | ?T:tval tx tlook tf tdc |
0065f4af | 60 | ?F:!try |
959f3c4c JH |
61 | : is a C symbol defined? |
62 | csym='tlook=$1; | |
63 | case "$3" in | |
15dfe1a4 JH |
64 | -v) tf=libc.tmp; tdc="";; |
65 | -a) tf=libc.tmp; tdc="[]";; | |
66 | *) tlook="^$1\$"; tf=libc.list; tdc="()";; | |
959f3c4c | 67 | esac; |
cce04e58 MB |
68 | case "$d_cplusplus" in |
69 | $define) extern_C="extern \"C\"" ;; | |
70 | *) extern_C="extern" ;; | |
71 | esac; | |
959f3c4c JH |
72 | tx=yes; |
73 | case "$reuseval-$4" in | |
74 | true-) ;; | |
75 | true-*) tx=no; eval "tval=\$$4"; case "$tval" in "") tx=yes;; esac;; | |
76 | esac; | |
77 | case "$tx" in | |
78 | yes) | |
959f3c4c JH |
79 | ?X: |
80 | ?X: Put symbol inside a printf to fool optimizing compilers... | |
81 | ?X: | |
82 | ?X: We use 'short' instead of 'int' to try to circumvent overzealous | |
83 | ?X: optimizing compilers using built-in prototypes for commonly used | |
84 | ?X: routines to complain when seeing a different external declaration. For | |
85 | ?X: instance, gcc 2.6.3 fails if we use 'int' and we attempt a test against | |
86 | ?X: memcpy() on machines where sizeof(int) == sizeof(char *) (the usual return | |
87 | ?X: type), the compiler assuming it's a built-in declaration given that the | |
88 | ?X: returned size matches. At least with 'short' we are safe! -- RAM, for ADO | |
89 | ?X: | |
65a32477 | 90 | ?X: Let's thank GNU cc for making our lives so easy! :-) |
959f3c4c JH |
91 | ?X: (An alternative for the future would be to use our knowledge about gcc |
92 | ?X: to force a -fno-builtin option in the compile test, in case the 'short' | |
93 | ?X: trick is obsoleted by future gcc releases). -- RAM | |
94 | ?X: | |
868ab49f | 95 | tval=false; |
e3a6a689 JH |
96 | if $test "$runnm" = true; then |
97 | if $contains $tlook $tf >/dev/null 2>&1; then | |
868ab49f | 98 | tval=true; |
e3a6a689 | 99 | elif $test "$mistrustnm" = compile -o "$mistrustnm" = run; then |
dd5cb3b6 | 100 | echo "$extern_C void *$1$tdc; void *(*(p()))$tdc { return &$1; } int main() { if(p()) return(0); else return(1); }"> try.c; |
e3a6a689 | 101 | $cc -o try $optimize $ccflags $ldflags try.c >/dev/null 2>&1 $libs && tval=true; |
15dfe1a4 | 102 | $test "$mistrustnm" = run -a -x try && { $run ./try$_exe >/dev/null 2>&1 || tval=false; }; |
2cb64bf6 | 103 | $rm_try; |
959f3c4c | 104 | fi; |
e3a6a689 | 105 | else |
dd5cb3b6 | 106 | echo "$extern_C void *$1$tdc; void *(*(p()))$tdc { return &$1; } int main() { if(p()) return(0); else return(1); }"> try.c; |
e3a6a689 | 107 | $cc -o try $optimize $ccflags $ldflags try.c $libs >/dev/null 2>&1 && tval=true; |
2cb64bf6 | 108 | $rm_try; |
868ab49f JH |
109 | fi; |
110 | ;; | |
959f3c4c JH |
111 | *) |
112 | case "$tval" in | |
113 | $define) tval=true;; | |
114 | *) tval=false;; | |
868ab49f JH |
115 | esac; |
116 | ;; | |
959f3c4c JH |
117 | esac; |
118 | eval "$2=$tval"' | |
119 |