OSDN Git Service

*** empty log message ***
[lha/lha.git] / src / cproto.sh
1 #!/bin/sh
2 #
3 # generate function prototypes `prototype.h'.
4 #
5
6 trap "rm -f prototypes.h.tmp prototypes.h.bak" 0 1 2 3 15
7
8 CPROTO_FLAGS='-m -d'
9 CPPFLAGS='-DSTDC_HEADERS=1
10         -DHAVE_STRDUP=1
11         -DHAVE_MEMSET=1
12         -DHAVE_MEMMOVE=1
13         -DHAVE_STRCASECMP=1
14         -DHAVE_BASENAME=1
15         -DMULTIBYTE_FILENAME=1
16         -Dinterrupt=dummy__
17         -DNEED_INCREMENTAL_INDICATOR=1
18         -D__builtin_va_list=int
19         -D__extension__=
20 '
21 # `interrupt' is the reserved word for cproto.
22
23 SOURCES='append.c bitio.c crcio.c dhuf.c extract.c header.c
24         huf.c larc.c lhadd.c lharc.c lhext.c
25         lhlist.c maketbl.c maketree.c patmatch.c
26         shuf.c slide.c util.c
27 '
28
29 test -f prototypes.h && mv -f prototypes.h prototypes.h.bak
30
31 # below makes cproto regard `RETSIGTYPE' as the variable type.
32 cat <<END >prototypes.h
33 typedef void RETSIGTYPE;
34 END
35
36 exec 5>&1 > prototypes.h.tmp
37
38 cat <<END
39 /* This file was generated by cproto. */
40 #if PROTOTYPES /* defined in config.h */
41 #define P_(s) s
42 #else
43 #define P_(s) ()
44 #endif
45
46 END
47
48 cproto $CPROTO_FLAGS $CPPFLAGS $SOURCES |
49         sed -e '/^int main /d' -e 's/dummy__/interrupt/'
50
51 cat <<END
52
53 /* util.c */
54 #if !HAVE_MEMMOVE
55 void *memmove P_((void *dst, const void *src, size_t cnt));
56 #endif
57 #if !HAVE_STRDUP
58 char *strdup P_((const char *buf));
59 #endif
60 #if !HAVE_MEMSET
61 char *memset P_((char *s, int c, size_t n));
62 #endif
63 #if !HAVE_STRCASECMP
64 int strcasecmp P_((const char *p1, const char *p2));
65 #endif
66 #if !HAVE_BASENAME
67 char *basename P_((char *s));
68 #endif
69
70 /* vsnprintf.c */
71 #if !HAVE_VSNPRINTF
72 int vsnprintf P_((char *str, size_t n, const char *fmt, va_list ap));
73 int snprintf P_((char *str, size_t n, char const *fmt, ...));
74 #endif
75
76 #undef P_
77 END
78
79 exec 1>&5
80 if test -f prototypes.h.bak && cmp -s prototypes.h.tmp prototypes.h.bak; then
81   mv -f prototypes.h.bak prototypes.h
82 else
83   mv -f prototypes.h.tmp prototypes.h
84 fi