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: | |
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 | |
10 | ?X: prototype. | |
11 | ?X: | |
12 | ?X: To use it, say something like: | |
13 | ?X: hdrs="$define sys/types.h | |
14 | ?X: $i_systime sys/time.h | |
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). | |
30 | ?X: Still, since QNX is a POSIX-ish system, just make your first | |
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 | |
35 | ?X: return types, however, is easier. Just give an ridiculuous | |
36 | ?X: return type, something like | |
37 | ?X: ./protochk 'extern int atof _((void));' $i_stdlib stdlib.h | |
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 | |
43 | ?X: like | |
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". | |
49 | ?X: | |
50 | ?X: Andy Dougherty Feb. 1998 | |
51 | ?MAKE:Protochk: cat rm startsh eunicefix +cc +optimize +ccflags \ | |
52 | prototype | |
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 |
959f3c4c | 57 | ?LINT: change cc optimize ccflags prototype define rm |
6f722ae2 JH |
58 | ?LINT: extern usethreads |
59 | ?LINT: extern i_pthread | |
60 | ?LINT: extern pthread_h_first | |
959f3c4c JH |
61 | : define a fucntion to check prototypes |
62 | $cat > protochk <<EOSH | |
63 | $startsh | |
64 | cc="$cc" | |
65 | optimize="$optimize" | |
66 | ccflags="$ccflags" | |
67 | prototype="$prototype" | |
68 | define="$define" | |
69 | rm=$rm | |
70 | EOSH | |
71 | ||
72 | $cat >> protochk <<'EOSH' | |
73 | ||
74 | $rm -f try.c | |
75 | foo="$1" | |
76 | shift | |
77 | while test $# -ge 2; do | |
78 | case "$1" in | |
79 | $define) echo "#include <$2>" >> try.c ;; | |
80 | literal) echo "$2" >> try.c ;; | |
81 | esac | |
6f722ae2 JH |
82 | # Extra magic for the benefit of systems that need pthread.h |
83 | # to be included early to correctly detect threadsafe functions. | |
84 | # Such functions must guarantee themselves, though, that the usethreads | |
85 | # and i_pthread have been defined, before calling protochk. | |
86 | if test "$usethreads" = "$define" -a "$i_pthread" = "$define" -a "$pthread_h_first" = "$define" -a "$pthread_h_done" = ""; then | |
87 | echo "#include <pthread.h>" >> try.c | |
88 | pthread_h_done=yes | |
89 | fi | |
959f3c4c JH |
90 | shift 2 |
91 | done | |
92 | test "$prototype" = "$define" && echo '#define CAN_PROTOTYPE' >> try.c | |
93 | cat >> try.c <<'EOCP' | |
94 | #ifdef CAN_PROTOTYPE | |
95 | #define _(args) args | |
96 | #else | |
97 | #define _(args) () | |
98 | #endif | |
99 | EOCP | |
100 | echo "$foo" >> try.c | |
101 | ?X: Just so we have something to compile. | |
102 | echo 'int no_real_function_has_this_name _((void)) { return 0; }' >> try.c | |
103 | $cc $optimize $ccflags -c try.c > /dev/null 2>&1 | |
104 | status=$? | |
105 | $rm -f try.[co] | |
106 | exit $status | |
107 | EOSH | |
108 | chmod +x protochk | |
109 | $eunicefix protochk | |
110 |