1 ?RCS: $Id: Protochk.U,v $
3 ?RCS: Copyright (c) 1998 Andy Dougherty
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.
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
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"
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."
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 :-).
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.
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>
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
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".
50 ?X: Andy Dougherty Feb. 1998
51 ?MAKE:Protochk: cat rm startsh eunicefix +cc +optimize +ccflags \
53 ?MAKE: -pick add $@ %<
55 ?X: Comfort metalint. All these are actually used in the protochk script.
57 ?LINT: change cc optimize ccflags prototype define rm
58 : define a fucntion to check prototypes
59 $cat > protochk <<EOSH
64 prototype="$prototype"
69 $cat >> protochk <<'EOSH'
74 while test $# -ge 2; do
76 $define) echo "#include <$2>" >> try.c ;;
77 literal) echo "$2" >> try.c ;;
81 test "$prototype" = "$define" && echo '#define CAN_PROTOTYPE' >> try.c
90 ?X: Just so we have something to compile.
91 echo 'int no_real_function_has_this_name _((void)) { return 0; }' >> try.c
92 $cc $optimize $ccflags -c try.c > /dev/null 2>&1