OSDN Git Service

Merge branch 'master' of github.com:jca02266/lha
[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=
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 '
19 # `interrupt' is the reserved word for cproto.
20
21 SOURCES='append.c bitio.c crcio.c dhuf.c extract.c header.c
22         huf.c indicator.c larc.c lhadd.c lharc.c lhext.c
23         lhlist.c maketbl.c maketree.c patmatch.c
24         shuf.c slide.c util.c
25         pm2.c pm2tree.c pm2hist.c
26 '
27
28 test -f prototypes.h && mv -f prototypes.h prototypes.h.bak
29
30 # below makes cproto regard `RETSIGTYPE' as the variable type.
31 cat <<END >prototypes.h
32 typedef void RETSIGTYPE;
33 END
34
35 exec 5>&1 > prototypes.h.tmp
36
37 cat <<END
38 /* This file was generated by cproto. */
39
40 END
41
42 cproto $CPROTO_FLAGS $CPPFLAGS $SOURCES |
43         sed -e '/^int main /d' -e 's/dummy__/interrupt/'
44
45 cat <<END
46
47 /* util.c */
48 #if !HAVE_MEMMOVE
49 void *memmove(void *dst, const void *src, size_t cnt);
50 #endif
51 #if !HAVE_STRDUP
52 char *strdup(const char *buf);
53 #endif
54 #if !HAVE_MEMSET
55 char *memset(char *s, int c, size_t n);
56 #endif
57 #if !HAVE_STRCASECMP
58 int strcasecmp(const char *p1, const char *p2);
59 #endif
60 #if defined HAVE_DECL_BASENAME && !HAVE_DECL_BASENAME
61 char *basename(char *s);
62 #endif
63
64 /* vsnprintf.c */
65 #if !HAVE_VSNPRINTF
66 int vsnprintf(char *str, size_t n, const char *fmt, va_list ap);
67 int snprintf(char *str, size_t n, char const *fmt, ...);
68 #endif
69 END
70
71 exec 1>&5
72 if test -f prototypes.h.bak && cmp -s prototypes.h.tmp prototypes.h.bak; then
73   mv -f prototypes.h.bak prototypes.h
74 else
75   mv -f prototypes.h.tmp prototypes.h
76 fi