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 \ |
43ee3b36 | 52 | prototype 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 |
2cb64bf6 | 57 | ?LINT: change cc optimize ccflags prototype 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" | |
68 | prototype="$prototype" | |
69 | define="$define" | |
95a2bb51 | 70 | rm_try="$rm_try" |
43ee3b36 JH |
71 | usethreads=$usethreads |
72 | i_pthread=$i_pthread | |
73 | pthread_h_first=$pthread_h_first | |
959f3c4c JH |
74 | EOSH |
75 | ||
76 | $cat >> protochk <<'EOSH' | |
77 | ||
2cb64bf6 | 78 | $rm_try |
959f3c4c JH |
79 | foo="$1" |
80 | shift | |
81 | while test $# -ge 2; do | |
82 | case "$1" in | |
83 | $define) echo "#include <$2>" >> try.c ;; | |
84 | literal) echo "$2" >> try.c ;; | |
85 | esac | |
6f722ae2 JH |
86 | # Extra magic for the benefit of systems that need pthread.h |
87 | # to be included early to correctly detect threadsafe functions. | |
88 | # Such functions must guarantee themselves, though, that the usethreads | |
89 | # and i_pthread have been defined, before calling protochk. | |
90 | if test "$usethreads" = "$define" -a "$i_pthread" = "$define" -a "$pthread_h_first" = "$define" -a "$pthread_h_done" = ""; then | |
91 | echo "#include <pthread.h>" >> try.c | |
92 | pthread_h_done=yes | |
93 | fi | |
959f3c4c JH |
94 | shift 2 |
95 | done | |
96 | test "$prototype" = "$define" && echo '#define CAN_PROTOTYPE' >> try.c | |
97 | cat >> try.c <<'EOCP' | |
98 | #ifdef CAN_PROTOTYPE | |
99 | #define _(args) args | |
100 | #else | |
101 | #define _(args) () | |
102 | #endif | |
103 | EOCP | |
104 | echo "$foo" >> try.c | |
105 | ?X: Just so we have something to compile. | |
106 | echo 'int no_real_function_has_this_name _((void)) { return 0; }' >> try.c | |
107 | $cc $optimize $ccflags -c try.c > /dev/null 2>&1 | |
108 | status=$? | |
2cb64bf6 | 109 | $rm_try |
959f3c4c JH |
110 | exit $status |
111 | EOSH | |
112 | chmod +x protochk | |
113 | $eunicefix protochk | |
114 |