Add BSD license file
[platform/upstream/db4.git] / dist / s_windows
1 #!/bin/sh -
2 #       $Id$
3 #
4 # Build Windows include files.
5
6 msgc="/* DO NOT EDIT: automatically built by dist/s_windows. */"
7 msgw="; DO NOT EDIT: automatically built by dist/s_windows."
8
9 . RELEASE
10
11 s=/tmp/__db_a$$
12 t=/tmp/__db_b$$
13 rm -f $s $t
14
15 trap 'rm -f $s $t ; exit 1' 1 2 3 13 15
16
17 # Build the Windows db.h
18 cat <<ENDOFSEDTEXT > $s
19 /@inttypes_h_decl@/d
20 /@stdint_h_decl@/d
21 s/@stddef_h_decl@/#include <stddef.h>/
22 /@unistd_h_decl@/d
23 /@thread_h_decl@/d
24 s/@u_int8_decl@/typedef unsigned char u_int8_t;/
25 s/@int16_decl@/typedef short int16_t;/
26 s/@u_int16_decl@/typedef unsigned short u_int16_t;/
27 s/@int32_decl@/typedef int int32_t;/
28 s/@u_int32_decl@/typedef unsigned int u_int32_t;/
29 s/@int64_decl@/typedef __int64 int64_t;/
30 s/@u_int64_decl@/typedef unsigned __int64 u_int64_t;/
31 s/@db_seq_decl@/typedef int64_t db_seq_t;/
32 s/@db_threadid_t_decl@/typedef u_int32_t db_threadid_t;/
33 s/@pid_t_decl@/typedef int pid_t;/
34 /@u_char_decl@/{
35         i\\
36 #ifndef _WINSOCKAPI_
37         s/@u_char_decl@/typedef unsigned char u_char;/
38 }
39 s/@u_short_decl@/typedef unsigned short u_short;/
40 s/@u_int_decl@/typedef unsigned int u_int;/
41 /@u_long_decl@/{
42         s/@u_long_decl@/typedef unsigned long u_long;/
43         a\\
44 #endif
45 }
46 /@FILE_t_decl@/d
47 /@size_t_decl@/d
48 /@ssize_t_decl@/{
49         i\\
50 #ifdef _WIN64\\
51 typedef int64_t ssize_t;\\
52 #else\\
53 typedef int32_t ssize_t;\\
54 #endif
55         d
56 }
57 /@time_t_decl@/d
58 /@uintmax_t_decl@/{
59         i\\
60 #if defined(_MSC_VER) && _MSC_VER < 1300\\
61 typedef u_int32_t uintmax_t;\\
62 #else\\
63 typedef u_int64_t uintmax_t;\\
64 #endif
65         d
66 }
67 /@uintptr_t_decl@/{
68         i\\
69 #ifdef _WIN64\\
70 typedef u_int64_t uintptr_t;\\
71 #else\\
72 typedef u_int32_t uintptr_t;\\
73 #endif
74         d
75 }
76 /@off_t_decl@/{
77         i\\
78 /*\\
79 \ * Windows defines off_t to long (i.e., 32 bits).  We need to pass 64-bit\\
80 \ * file offsets, so we declare our own.\\
81 \ */\\
82 #define off_t   __db_off_t\\
83 typedef int64_t off_t;
84         d
85 }
86 /@platform_header@/{
87         i\\
88 /*\\
89 \ * Turn off inappropriate compiler warnings\\
90 \ */\\
91 #ifdef _MSC_VER\\
92 /*\\
93 \ * This warning is explicitly disabled in Visual C++ by default.\\
94 \ * It is necessary to explicitly enable the /Wall flag to generate this\\
95 \ * warning.\\
96 \ * Since this is a shared include file it should compile without warnings\\
97 \ * at the highest warning level, so third party applications can use\\
98 \ * higher warning levels cleanly.\\
99 \ *\\
100 \ * 4820: 'bytes' bytes padding added after member 'member'\\
101 \ *       The type and order of elements caused the compiler to\\
102 \ *       add padding to the end of a struct.\\
103 \ */\\
104 #pragma warning(push)\\
105 #pragma warning(disable: 4820)\\
106 #endif /* _MSC_VER */
107         d
108 }
109 /@platform_footer@/{
110         i\\
111 /* Restore default compiler warnings */\\
112 #ifdef _MSC_VER\\
113 #pragma warning(pop)\\
114 #endif
115         d
116 }
117 s/@DB_VERSION_MAJOR@/$DB_VERSION_MAJOR/
118 s/@DB_VERSION_MINOR@/$DB_VERSION_MINOR/
119 s/@DB_VERSION_PATCH@/$DB_VERSION_PATCH/
120 s/@DB_VERSION_STRING@/"$DB_VERSION_STRING"/
121 s/@DB_VERSION_UNIQUE_NAME@//
122 s/@DB_CONST@//
123 s/@DB_PROTO1@/#undef __P/
124 s/@DB_PROTO2@/#define   __P(protos)     protos/
125 ENDOFSEDTEXT
126 # The db.h, db_int.h files are identical between Windows and WinCE.
127 # This may change in the future, for now have the script copy
128 # the headers into the build_wince directory.
129 # WinCE does not support the C++ API, so don't need to copy db_cxx.h
130
131 (echo "$msgc" &&
132     sed -f $s ../dbinc/db.in &&
133     cat ../dbinc_auto/api_flags.in &&
134     cat ../dbinc_auto/ext_prot.in) > $t
135 test `egrep '@.*@' $t` && {
136         egrep '@.*@' $t
137         echo 'Unexpanded autoconf variables found in Windows db.h.'
138         exit 1
139 }
140 f=../build_windows/db.h
141 cmp $t $f > /dev/null 2>&1 ||
142     (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
143 f=../build_wince/db.h
144 cmp $t $f > /dev/null 2>&1 ||
145     (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
146
147 # Build the Windows db_cxx.h.
148 cat <<ENDOFSEDTEXT > $s
149 s/@cxx_have_stdheaders@/#define HAVE_CXX_STDHEADERS 1/
150 ENDOFSEDTEXT
151 (echo "$msgc" && sed -f $s ../dbinc/db_cxx.in) > $t
152 test `egrep '@.*@' $t` && {
153         egrep '@.*@' $t
154         echo 'Unexpanded autoconf variables found in Windows db_cxx.h.'
155         exit 1
156 }
157 f=../build_windows/db_cxx.h
158 cmp $t $f > /dev/null 2>&1 ||
159     (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
160
161 # Build the Windows db_int.h.
162 cat <<ENDOFSEDTEXT > $s
163 s/@PATH_SEPARATOR@/\\\\\\\\\/:/
164 s/@db_int_def@//
165 ENDOFSEDTEXT
166 (echo "$msgc" && sed -f $s ../dbinc/db_int.in) > $t
167 test `egrep '@.*@' $t` && {
168         egrep '@.*@' $t
169         echo 'Unexpanded autoconf variables found in Windows db_int.h.'
170         exit 1
171 }
172 f=../build_windows/db_int.h
173 cmp $t $f > /dev/null 2>&1 ||
174     (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
175 f=../build_wince/db_int.h
176 cmp $t $f > /dev/null 2>&1 ||
177     (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
178
179 # Build the Windows and WinCE db_config.h.
180 # We don't fail, but we complain if the win_config.in file isn't up-to-date.
181 check_config()
182 {
183         egrep '^#undef' config.hin | awk '{print $2}' | sort > $s
184         (egrep '#undef' $1 | awk '{print $3}'
185          egrep '^#define' $1 | awk '{print $2}') | sed '/__STDC__/d' | sort > $t
186         cmp $s $t > /dev/null || {
187                 echo "config.hin and $1 differ"
188                 echo "<<< config.hin >>> $1"
189                 diff $s $t
190         }
191 }
192 check_config win_config.in
193 f=../build_windows/db_config.h
194 (echo "$msgc" && sed "s/__EDIT_DB_VERSION__/$DB_VERSION/" win_config.in) > $t
195 cmp $t $f > /dev/null 2>&1 ||
196     (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
197 check_config wince_config.in
198 f=../build_wince/db_config.h
199 (echo "$msgc" && sed "s/__EDIT_DB_VERSION__/$DB_VERSION/" wince_config.in) > $t
200 cmp $t $f > /dev/null 2>&1 ||
201     (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
202
203 # Build the Windows libdb.rc and libdb.def.
204 f=../build_windows/libdb.rc
205 cat <<ENDOFSEDTEXT > $s
206 s/%MAJOR%/$DB_VERSION_MAJOR/
207 s/%MINOR%/$DB_VERSION_MINOR/
208 s/%PATCH%/$DB_VERSION_PATCH/
209 ENDOFSEDTEXT
210 sed -f $s ../build_windows/libdbrc.src > $t
211 cmp $t $f > /dev/null 2>&1 ||
212     (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
213 f=../build_windows/libdb.def
214 (echo $msgw &&
215  echo &&
216  echo EXPORTS;
217 a=1
218 for i in `sed -e '/^$/d' -e '/^#/d' win_exports.in`; do
219         echo "  $i      @$a"
220         a=`expr $a + 1`
221 done) > $t
222 cmp $t $f > /dev/null 2>&1 ||
223     (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
224
225 # Build the Windows clib_port.h.
226 cat <<ENDOFSEDTEXT > $s
227 s/@INT64_FMT@/#define   INT64_FMT       "%I64d"/
228 s/@UINT64_FMT@/#define  UINT64_FMT      "%I64u"/
229 ENDOFSEDTEXT
230 sed -f $s clib_port.in > $t
231 test `egrep '@.*@' $t` && {
232         egrep '@.*@' $t
233         echo 'Unexpanded autoconf variables found in Windows clib_port.h.'
234         exit 1
235 }
236 f=../build_windows/clib_port.h
237 cmp $t $f > /dev/null 2>&1 ||
238     (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
239 f=../build_wince/clib_port.h
240 cmp $t $f > /dev/null 2>&1 ||
241     (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
242
243 # Build the Windows dbstl_common.h.
244 cat <<ENDOFSEDTEXT > $s
245 s/@WSTRING_decl@/#define        HAVE_WSTRING    1/
246 s/@TLS_decl@/#define    TLS_DECL_MODIFIER       __declspec(thread)/
247 s/@TLS_defn@/#define    TLS_DEFN_MODIFIER       __declspec(thread)/
248 ENDOFSEDTEXT
249 sed -f $s ../stl/dbstl_common.in > $t
250 f=../build_windows/dbstl_common.h
251 cmp $t $f > /dev/null 2>&1 ||
252     (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
253
254 # Copy in errno.h.
255 f=../build_wince/errno.h
256 cmp errno.h $f > /dev/null 2>&1 ||
257     (echo "Building $f" && rm -f $f && cp errno.h $f && chmod 444 $f)
258
259 rm -f $s $t