This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Populate metaconfig branch.
[metaconfig.git] / U / protos / Protochk.U
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.
56 ?T:foo status
57 ?LINT: change cc optimize ccflags prototype define rm
58 : define a fucntion to check prototypes
59 $cat > protochk <<EOSH
60 $startsh
61 cc="$cc"
62 optimize="$optimize"
63 ccflags="$ccflags"
64 prototype="$prototype"
65 define="$define"
66 rm=$rm
67 EOSH
68
69 $cat >> protochk <<'EOSH'
70
71 $rm -f try.c
72 foo="$1"
73 shift
74 while test $# -ge 2; do
75         case "$1" in
76                 $define) echo "#include <$2>" >> try.c ;;
77                 literal) echo "$2" >> try.c ;;
78         esac
79     shift 2
80 done
81 test "$prototype" = "$define"  && echo '#define CAN_PROTOTYPE' >> try.c
82 cat >> try.c <<'EOCP'
83 #ifdef CAN_PROTOTYPE
84 #define _(args) args
85 #else
86 #define _(args) ()
87 #endif
88 EOCP
89 echo "$foo" >> 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
93 status=$?
94 $rm -f try.[co]
95 exit $status
96 EOSH
97 chmod +x protochk
98 $eunicefix protochk
99