1#!/bin/sh -
2#	$Id$
3#
4# Build Windows include files.
5
6msgc="/* DO NOT EDIT: automatically built by dist/s_windows. */"
7msgw="; DO NOT EDIT: automatically built by dist/s_windows."
8
9. RELEASE
10
11s=/tmp/__db_a$$
12t=/tmp/__db_b$$
13rm -f $s $t
14
15trap 'rm -f $s $t ; exit 1' 1 2 3 13 15
16
17# Build the Windows db.h
18cat <<ENDOFSEDTEXT > $s
19/@inttypes_h_decl@/d
20/@stdint_h_decl@/d
21s/@stddef_h_decl@/#include <stddef.h>/
22/@unistd_h_decl@/d
23/@thread_h_decl@/d
24s/@u_int8_decl@/typedef unsigned char u_int8_t;/
25s/@int16_decl@/typedef short int16_t;/
26s/@u_int16_decl@/typedef unsigned short u_int16_t;/
27s/@int32_decl@/typedef int int32_t;/
28s/@u_int32_decl@/typedef unsigned int u_int32_t;/
29s/@int64_decl@/typedef __int64 int64_t;/
30s/@u_int64_decl@/typedef unsigned __int64 u_int64_t;/
31s/@db_seq_decl@/typedef int64_t db_seq_t;/
32s/@db_threadid_t_decl@/typedef u_int32_t db_threadid_t;/
33s/@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}
39s/@u_short_decl@/typedef unsigned short u_short;/
40s/@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\\
51typedef int64_t ssize_t;\\
52#else\\
53typedef 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\\
61typedef u_int32_t uintmax_t;\\
62#else\\
63typedef u_int64_t uintmax_t;\\
64#endif
65	d
66}
67/@uintptr_t_decl@/{
68	i\\
69#ifdef _WIN64\\
70typedef u_int64_t uintptr_t;\\
71#else\\
72typedef 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\\
83typedef 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}
117s/@DB_VERSION_MAJOR@/$DB_VERSION_MAJOR/
118s/@DB_VERSION_MINOR@/$DB_VERSION_MINOR/
119s/@DB_VERSION_PATCH@/$DB_VERSION_PATCH/
120s/@DB_VERSION_STRING@/"$DB_VERSION_STRING"/
121s/@DB_VERSION_UNIQUE_NAME@//
122s/@DB_CONST@//
123s/@DB_PROTO1@/#undef __P/
124s/@DB_PROTO2@/#define	__P(protos)	protos/
125ENDOFSEDTEXT
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
135test `egrep '@.*@' $t` && {
136	egrep '@.*@' $t
137	echo 'Unexpanded autoconf variables found in Windows db.h.'
138	exit 1
139}
140f=../build_windows/db.h
141cmp $t $f > /dev/null 2>&1 ||
142    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
143f=../build_wince/db.h
144cmp $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.
148cat <<ENDOFSEDTEXT > $s
149s/@cxx_have_stdheaders@/#define	HAVE_CXX_STDHEADERS 1/
150ENDOFSEDTEXT
151(echo "$msgc" && sed -f $s ../dbinc/db_cxx.in) > $t
152test `egrep '@.*@' $t` && {
153	egrep '@.*@' $t
154	echo 'Unexpanded autoconf variables found in Windows db_cxx.h.'
155	exit 1
156}
157f=../build_windows/db_cxx.h
158cmp $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.
162cat <<ENDOFSEDTEXT > $s
163s/@PATH_SEPARATOR@/\\\\\\\\\/:/
164s/@db_int_def@//
165ENDOFSEDTEXT
166(echo "$msgc" && sed -f $s ../dbinc/db_int.in) > $t
167test `egrep '@.*@' $t` && {
168	egrep '@.*@' $t
169	echo 'Unexpanded autoconf variables found in Windows db_int.h.'
170	exit 1
171}
172f=../build_windows/db_int.h
173cmp $t $f > /dev/null 2>&1 ||
174    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
175f=../build_wince/db_int.h
176cmp $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.
181check_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}
192check_config win_config.in
193f=../build_windows/db_config.h
194(echo "$msgc" && sed "s/__EDIT_DB_VERSION__/$DB_VERSION/" win_config.in) > $t
195cmp $t $f > /dev/null 2>&1 ||
196    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
197check_config wince_config.in
198f=../build_wince/db_config.h
199(echo "$msgc" && sed "s/__EDIT_DB_VERSION__/$DB_VERSION/" wince_config.in) > $t
200cmp $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.
204f=../build_windows/libdb.rc
205cat <<ENDOFSEDTEXT > $s
206s/%MAJOR%/$DB_VERSION_MAJOR/
207s/%MINOR%/$DB_VERSION_MINOR/
208s/%PATCH%/$DB_VERSION_PATCH/
209ENDOFSEDTEXT
210sed -f $s ../build_windows/libdbrc.src > $t
211cmp $t $f > /dev/null 2>&1 ||
212    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
213f=../build_windows/libdb.def
214(echo $msgw &&
215 echo &&
216 echo EXPORTS;
217a=1
218for i in `sed -e '/^$/d' -e '/^#/d' win_exports.in`; do
219	echo "	$i	@$a"
220	a=`expr $a + 1`
221done) > $t
222cmp $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.
226cat <<ENDOFSEDTEXT > $s
227s/@INT64_FMT@/#define	INT64_FMT	"%I64d"/
228s/@UINT64_FMT@/#define	UINT64_FMT	"%I64u"/
229ENDOFSEDTEXT
230sed -f $s clib_port.in > $t
231test `egrep '@.*@' $t` && {
232	egrep '@.*@' $t
233	echo 'Unexpanded autoconf variables found in Windows clib_port.h.'
234	exit 1
235}
236f=../build_windows/clib_port.h
237cmp $t $f > /dev/null 2>&1 ||
238    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
239f=../build_wince/clib_port.h
240cmp $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.
244cat <<ENDOFSEDTEXT > $s
245s/@WSTRING_decl@/#define	HAVE_WSTRING	1/
246s/@TLS_decl@/#define	TLS_DECL_MODIFIER	__declspec(thread)/
247s/@TLS_defn@/#define	TLS_DEFN_MODIFIER	__declspec(thread)/
248ENDOFSEDTEXT
249sed -f $s ../stl/dbstl_common.in > $t
250f=../build_windows/dbstl_common.h
251cmp $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.
255f=../build_wince/errno.h
256cmp errno.h $f > /dev/null 2>&1 ||
257    (echo "Building $f" && rm -f $f && cp errno.h $f && chmod 444 $f)
258
259rm -f $s $t
260