Commit | Line | Data |
---|---|---|
959f3c4c JH |
1 | ?RCS: $Id: Protochk.U,v $ |
2 | ?RCS: | |
3 | ?RCS: Copyright (c) 1998 Andy Dougherty | |
4 | ?RCS: | |
5 | ?RCS: You may distribute under the terms of either the GNU General Public | |
6 | ?RCS: License or the Artistic License, as specified in the README file. | |
7 | ?RCS: | |
2cb64bf6 MB |
8 | ?X: This unit generates a ./protochk script that is used internally |
9 | ?X: by Configure to check if this system will accept a particular | |
959f3c4c JH |
10 | ?X: prototype. |
11 | ?X: | |
12 | ?X: To use it, say something like: | |
13 | ?X: hdrs="$define sys/types.h | |
2cb64bf6 | 14 | ?X: $i_systime sys/time.h |
959f3c4c JH |
15 | ?X: $i_sysselct sys/select.h |
16 | ?X: $d_socket sys/socket.h" | |
17 | ?X: $xxx='fd_set *' | |
18 | ?X: try='extern int select _((int, $xxx, $xxx, $xxx, struct timeval *'));' | |
19 | ?X: if ./protochk "$try" $hdrs; then | |
20 | ?X: echo "Your system accepts $xxx for the arguments to select." | |
21 | ?X: fi | |
22 | ?X: (Of course select is harder, since the first arg can be int, | |
23 | ?X: size_t, or unsigned long, and the last arg may or may not have a | |
24 | ?X: 'const' before the 'struct timeval' :-(. Also SunOS 4.1.3 doesn't | |
25 | ?X: provide a select prototype so the compiler accepts anything :-). | |
26 | ?X: | |
27 | ?X: The C compiler on QNX warns about invalid pointer types, but | |
28 | ?X: still exits with a 0 exit status, so it's not much help here. | |
29 | ?X: (It does correctly detect incorrect non-pointer arguments). | |
2cb64bf6 | 30 | ?X: Still, since QNX is a POSIX-ish system, just make your first |
959f3c4c JH |
31 | ?X: a POSIX-ish one, and QNX will probably accept it. |
32 | ?X: | |
33 | ?X: For determining argument types, your compiler must support | |
34 | ?X: prototypes, and the header files must use them. Determining | |
65a32477 | 35 | ?X: return types, however, is easier. Just give an ridiculous |
959f3c4c | 36 | ?X: return type, something like |
2cb64bf6 | 37 | ?X: ./protochk 'extern int atof _((void));' $i_stdlib stdlib.h |
959f3c4c JH |
38 | ?X: that should surely fail if atof() is defined in <stdlib.h> |
39 | ?X: | |
40 | ?X: There is also an 'escape' hatch built in. If you have a pair | |
41 | ?X: of args 'literal 'stuff' then 'stuff' gets included literally | |
42 | ?X: into the test program. This could be useful for doing something | |
2cb64bf6 | 43 | ?X: like |
959f3c4c JH |
44 | ?X: hdrs="$define stdio.h |
45 | ?X: $define sys/types.h" | |
46 | ?X: ./protochk 'extern int fsetpos(FILE *, Fpos_t);' $args \ | |
47 | ?X: 'literal' '#define Fpos_t long long' | |
48 | ?X: but you have to be really careful about the spaces in "literal". | |
2cb64bf6 | 49 | ?X: |
959f3c4c | 50 | ?X: Andy Dougherty Feb. 1998 |
2cb64bf6 | 51 | ?MAKE:Protochk: cat rm_try startsh eunicefix +cc +optimize +ccflags \ |
a9f13d47 | 52 | i_pthread usethreads |
959f3c4c JH |
53 | ?MAKE: -pick add $@ %< |
54 | ?F:./protochk | |
55 | ?X: Comfort metalint. All these are actually used in the protochk script. | |
6f722ae2 | 56 | ?T:foo status pthread_h_done |
a9f13d47 | 57 | ?LINT: change cc optimize ccflags define rm_try |
6f722ae2 | 58 | ?LINT: extern pthread_h_first |
89d9cf69 JH |
59 | ?LINT: change pthread_h_first |
60 | ?LINT: change usethreads | |
61 | ?LINT: change i_pthread | |
04c34a22 | 62 | : define a function to check prototypes |
959f3c4c JH |
63 | $cat > protochk <<EOSH |
64 | $startsh | |
65 | cc="$cc" | |
66 | optimize="$optimize" | |
67 | ccflags="$ccflags" | |
959f3c4c | 68 | define="$define" |
95a2bb51 | 69 | rm_try="$rm_try" |
43ee3b36 JH |
70 | usethreads=$usethreads |
71 | i_pthread=$i_pthread | |
72 | pthread_h_first=$pthread_h_first | |
959f3c4c JH |
73 | EOSH |
74 | ||
75 | $cat >> protochk <<'EOSH' | |
76 | ||
2cb64bf6 | 77 | $rm_try |
959f3c4c JH |
78 | foo="$1" |
79 | shift | |
80 | while test $# -ge 2; do | |
81 | case "$1" in | |
82 | $define) echo "#include <$2>" >> try.c ;; | |
83 | literal) echo "$2" >> try.c ;; | |
84 | esac | |
6f722ae2 JH |
85 | # Extra magic for the benefit of systems that need pthread.h |
86 | # to be included early to correctly detect threadsafe functions. | |
87 | # Such functions must guarantee themselves, though, that the usethreads | |
88 | # and i_pthread have been defined, before calling protochk. | |
89 | if test "$usethreads" = "$define" -a "$i_pthread" = "$define" -a "$pthread_h_first" = "$define" -a "$pthread_h_done" = ""; then | |
90 | echo "#include <pthread.h>" >> try.c | |
91 | pthread_h_done=yes | |
92 | fi | |
959f3c4c JH |
93 | shift 2 |
94 | done | |
959f3c4c | 95 | cat >> try.c <<'EOCP' |
73484606 | 96 | #define _(args) args |
959f3c4c JH |
97 | EOCP |
98 | echo "$foo" >> try.c | |
99 | ?X: Just so we have something to compile. | |
100 | echo 'int no_real_function_has_this_name _((void)) { return 0; }' >> try.c | |
101 | $cc $optimize $ccflags -c try.c > /dev/null 2>&1 | |
102 | status=$? | |
2cb64bf6 | 103 | $rm_try |
959f3c4c JH |
104 | exit $status |
105 | EOSH | |
106 | chmod +x protochk | |
107 | $eunicefix protochk | |
108 |