#!/bin/sh -
#	$Id: s_win32,v 1.2 2004/03/30 01:21:34 jtownsen Exp $
#
# Build Windows/32 include files.

msgc="/* DO NOT EDIT: automatically built by dist/s_win32. */"
msgw="; DO NOT EDIT: automatically built by dist/s_win32."

. RELEASE

s=/tmp/__db_a$$
t=/tmp/__db_b$$
rm -f $s $t

trap 'rm -f $s $t ; exit 1' 1 2 3 13 15

# Build the Win32 automatically generated files.
f=../build_win32/db.h
cat <<ENDOFSEDTEXT > $s
/@inttypes_decl@/d
s/@u_int8_decl@/typedef unsigned char u_int8_t;/
s/@int16_decl@/typedef short int16_t;/
s/@u_int16_decl@/typedef unsigned short u_int16_t;/
s/@int32_decl@/typedef int int32_t;/
s/@u_int32_decl@/typedef unsigned int u_int32_t;/
/@u_char_decl@/{
	i\\
#if !defined(_WINSOCKAPI_)
	s/@u_char_decl@/typedef unsigned char u_char;/
}
s/@u_short_decl@/typedef unsigned short u_short;/
s/@u_int_decl@/typedef unsigned int u_int;/
/@u_long_decl@/{
	s/@u_long_decl@/typedef unsigned long u_long;/
	a\\
#endif
}
/@ssize_t_decl@/{
	i\\
#if defined(_WIN64)\\
typedef __int64 ssize_t;\\
#else\\
typedef int ssize_t;\\
#endif
	d
}
s/@DB_VERSION_MAJOR@/$DB_VERSION_MAJOR/
s/@DB_VERSION_MINOR@/$DB_VERSION_MINOR/
s/@DB_VERSION_PATCH@/$DB_VERSION_PATCH/
s/@DB_VERSION_STRING@/"$DB_VERSION_STRING"/
s/@DB_VERSION_UNIQUE_NAME@//
s/@DB_CONST@//
s/@DB_PROTO1@/#undef __P/
s/@DB_PROTO2@/#define	__P(protos)	protos/
ENDOFSEDTEXT
(echo "$msgc" &&
    sed -f $s ../dbinc/db.in &&
    cat ../dbinc_auto/rpc_defs.in &&
    cat ../dbinc_auto/ext_prot.in) > $t
cmp $t $f > /dev/null 2>&1 ||
    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)

f=../build_win32/db_cxx.h
cat <<ENDOFSEDTEXT > $s
s/@cxx_have_stdheaders@/#define	HAVE_CXX_STDHEADERS 1/
ENDOFSEDTEXT
(echo "$msgc" && sed -f $s ../dbinc/db_cxx.in) > $t
cmp $t $f > /dev/null 2>&1 ||
    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)

f=../build_win32/db_int.h
cat <<ENDOFSEDTEXT > $s
s/@PATH_SEPARATOR@/\\\\\\\\\/:/
s/@db_align_t_decl@/typedef unsigned long db_align_t;/
s/@db_alignp_t_decl@/typedef unsigned long db_alignp_t;/
s/@db_int_def@//
ENDOFSEDTEXT
(echo "$msgc" && sed -f $s ../dbinc/db_int.in) > $t
cmp $t $f > /dev/null 2>&1 ||
    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)

f=../build_win32/db_config.h
(echo "$msgc" && sed "s/__EDIT_DB_VERSION__/$DB_VERSION/" win_config.in) > $t
cmp $t $f > /dev/null 2>&1 ||
    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)

f=../build_win32/libdb.rc
cat <<ENDOFSEDTEXT > $s
s/%MAJOR%/$DB_VERSION_MAJOR/
s/%MINOR%/$DB_VERSION_MINOR/
s/%PATCH%/$DB_VERSION_PATCH/
ENDOFSEDTEXT
sed -f $s ../build_win32/libdbrc.src > $t
cmp $t $f > /dev/null 2>&1 ||
    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)

f=../build_win32/libdb.def
(echo $msgw &&
 echo &&
 echo \
 "DESCRIPTION	'Berkeley DB $DB_VERSION_MAJOR.$DB_VERSION_MINOR Library'" &&
 echo &&
 echo EXPORTS;
a=1
for i in `sed -e '/^$/d' -e '/^#/d' win_exports.in`; do
	echo "	$i	@$a"
	a=`expr $a + 1`
done) > $t
cmp $t $f > /dev/null 2>&1 ||
    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)

f=../build_win32/win_db.h
i=win_db.in
cmp $i $f > /dev/null 2>&1 ||
    (echo "Building $f" && rm -f $f && cp $i $f && chmod 444 $f)

rm -f $s $t
