Add BSD license file
[platform/upstream/db4.git] / dist / s_include
1 #!/bin/sh -
2 #       $Id$
3 #
4 # Build the automatically generated function prototype files.
5
6 msgc="/* DO NOT EDIT: automatically built by dist/s_include. */"
7
8 . ./RELEASE
9
10 head()
11 {
12         defonly=0
13         while :
14                 do case "$1" in
15                 space)
16                         echo ""; shift;;
17                 defonly)
18                         defonly=1; shift;;
19                 *)
20                         name="$1"; break;;
21                 esac
22         done
23
24         echo "$msgc"
25         echo "#ifndef   $name"
26         echo "#define   $name"
27         echo ""
28         if [ $defonly -eq 0 ]; then
29                 echo "#if defined(__cplusplus)"
30                 echo "extern \"C\" {"
31                 echo "#endif"
32                 echo ""
33         fi
34 }
35
36 tail()
37 {
38         defonly=0
39         while :
40                 do case "$1" in
41                 defonly)
42                         defonly=1; shift;;
43                 *)
44                         name="$1"; break;;
45                 esac
46         done
47
48         echo ""
49         if [ $defonly -eq 0 ]; then
50                 echo "#if defined(__cplusplus)"
51                 echo "}"
52                 echo "#endif"
53         fi
54         echo "#endif /* !$name */"
55 }
56
57 # This script is run on a variety of systems.  To avoid spurious changes, fix
58 # some variables that affect sort order of ls(1).
59 unset LANG
60 export LANG
61 LC_ALL="C"
62 export LC_ALL
63
64 # We are building several files:
65 #       1 external #define file
66 #       1 external prototype file
67 #       1 internal #define file
68 #       N internal prototype files
69 e_dfile=/tmp/__db_c.$$
70 e_pfile=/tmp/__db_a.$$
71 i_dfile=/tmp/__db_d.$$
72 i_pfile=/tmp/__db_b.$$
73 trap 'rm -f $e_dfile $e_pfile $i_dfile $i_pfile; exit 0' 0 1 2 3 13 15
74
75 head defonly space _DB_EXT_DEF_IN_ > $e_dfile
76 head space _DB_EXT_PROT_IN_ > $e_pfile
77 head defonly _DB_INT_DEF_IN_ > $i_dfile
78
79 # Process the standard directories, creating per-directory prototype
80 # files and adding to the external prototype and #define files.
81 for i in db btree clib common crypto dbreg env fileops hash hmac \
82     lock log mp mutex os qam rep repmgr rpc_client rpc_server \
83     sequence tcl txn; do
84         head "_${i}_ext_h_" > $i_pfile
85
86         if [ $i = os ] ; then
87                 f=`ls ../$i/*.c \
88             ../os_brew/*.c ../os_qnx/*.c ../os_vxworks/*.c ../os_windows/*.c`
89         elif [ $i = rpc_server ] ; then
90                 f=`ls ../$i/c/*.c`
91         elif [ $i = crypto ] ; then
92                 f=`ls ../$i/*.c ../$i/*/*.c`
93         elif [ $i = env ] ; then
94                 f=`ls ../$i/*.c ../repmgr/repmgr_stub.c`
95         else
96                 f=`ls ../$i/*.c`
97         fi
98         awk -f gen_inc.awk \
99             -v db_version_unique_name=$DB_VERSION_UNIQUE_NAME \
100             -v e_dfile=$e_dfile \
101             -v e_pfile=$e_pfile \
102             -v i_dfile=$i_dfile \
103             -v i_pfile=$i_pfile $f
104
105         tail "_${i}_ext_h_" >> $i_pfile
106
107         f=../dbinc_auto/${i}_ext.h
108         cmp $i_pfile $f > /dev/null 2>&1 ||
109             (echo "Building $f" && rm -f $f && cp $i_pfile $f && chmod 444 $f)
110 done
111
112 # Process directories which only add to the external prototype and #define
113 # files.
114 for i in dbm hsearch; do
115         f=`ls ../$i/*.c`
116         awk -f gen_inc.awk \
117             -v db_version_unique_name=$DB_VERSION_UNIQUE_NAME \
118             -v e_dfile=$e_dfile \
119             -v e_pfile=$e_pfile \
120             -v i_dfile="" \
121             -v i_pfile="" $f
122 done
123
124 # There are a few global variables in DB -- add them to the external/internal
125 # #define files.
126 (echo "#define  __db_global_values __db_global_values@DB_VERSION_UNIQUE_NAME@";
127     echo "#define       __repmgr_guesstimated_max __repmgr_guesstimated_max@DB_VERSION_UNIQUE_NAME@") >> $i_dfile
128
129 # Wrap up the external #defines/prototypes, and internal #defines.
130 tail defonly _DB_EXT_DEF_IN_ >> $e_dfile
131 f=../dbinc_auto/ext_def.in
132 cmp $e_dfile $f > /dev/null 2>&1 ||
133     (echo "Building $f" && rm -f $f && cp $e_dfile $f && chmod 444 $f)
134
135 tail _DB_EXT_PROT_IN_ >> $e_pfile
136 f=../dbinc_auto/ext_prot.in
137 cmp $e_pfile $f > /dev/null 2>&1 ||
138     (echo "Building $f" && rm -f $f && cp $e_pfile $f && chmod 444 $f)
139
140 tail defonly _DB_INT_DEF_IN_ >> $i_dfile
141 f=../dbinc_auto/int_def.in
142 cmp $i_dfile $f > /dev/null 2>&1 ||
143     (echo "Building $f" && rm -f $f && cp $i_dfile $f && chmod 444 $f)
144
145 # DB185 compatibility support.
146 head space defonly _DB_EXT_185_DEF_IN_ > $e_dfile
147 head space _DB_EXT_185_PROT_IN_ > $e_pfile
148
149 f=`ls ../db185/*.c`
150 awk -f gen_inc.awk \
151     -v db_version_unique_name=$DB_VERSION_UNIQUE_NAME \
152     -v e_dfile=$e_dfile \
153     -v e_pfile=$e_pfile \
154     -v i_dfile="" \
155     -v i_pfile="" $f
156
157 tail defonly _DB_EXT_185_DEF_IN_ >> $e_dfile
158 f=../dbinc_auto/ext_185_def.in
159 cmp $e_dfile $f > /dev/null 2>&1 ||
160     (echo "Building $f" && rm -f $f && cp $e_dfile $f && chmod 444 $f)
161
162 tail _DB_EXT_185_PROT_IN_ >> $e_pfile
163 f=../dbinc_auto/ext_185_prot.in
164 cmp $e_pfile $f > /dev/null 2>&1 ||
165     (echo "Building $f" && rm -f $f && cp $e_pfile $f && chmod 444 $f)