#!/bin/sh -
#	@(#)distrib	10.11 (Sleepycat) 8/12/97

# Build autoconf structure.
echo "Running autoheader"
autoheader 2>&1 | sed '/warning: AC_TRY_RUN called without default/d'
chmod 444 config.h.in
echo "Running autoconf"
autoconf 2>&1 | sed '/warning: AC_TRY_RUN called without default/d'
chmod 555 configure config.guess config.sub install-sh

msg="/* Do not edit: automatically built by dist/distrib. */"

# Build the automatically generated logging/recovery files.
for i in db btree hash log txn; do
	echo "Building $i logging/recovery files"
	sh ./db_gen.sh ../$i/$i.src ../$i/
done

# Build the automatically generated function prototype files.
for i in db btree clib common hash lock log mp mutex os txn; do
	f=../include/${i}_ext.h
	echo "Building $f"
	(echo "$msg" && sed -n "s/^ \* PUBLIC: \(.*\)/\1/p" ../$i/*.c) > $f
	chmod 444 $f
done

f=../build.win32/db.h
echo "Building $f"
(echo "$msg" && sed \
    -e 's/@u_int8_decl@/typedef unsigned char u_int8_t;/' \
    -e 's/@int16_decl@/typedef short int16_t;/' \
    -e 's/@u_int16_decl@/typedef unsigned short u_int16_t;/' \
    -e 's/@int32_decl@/typedef int int32_t;/' \
    -e 's/@u_int32_decl@/typedef unsigned int u_int32_t;/' \
    -e '/@u_char_decl@/{' \
    -e		'i\' \
    -e		'#if defined(_WIN32) || !defined(_WINSOCKAPI_)' \
    -e		's/@u_char_decl@/typedef unsigned char u_char;/' \
    -e '}' \
    -e 's/@u_short_decl@/typedef unsigned short u_short;/' \
    -e 's/@u_int_decl@/typedef unsigned int u_int;/' \
    -e '/@u_long_decl@/{' \
    -e		's/@u_long_decl@/typedef unsigned long u_long;/' \
    -e	 	'a\' \
    -e		'#endif' \
    -e '}' \
    -e 's/@enable_dbm@/0/' \
    -e 's/@enable_hsearch@/0/' \
    < ../include/db.h.src) > $f
chmod 444 $f

f=../build.win32/db_int.h
echo "Building $f"
(echo "$msg" && sed \
    -e 's/\(PATH_SEPARATOR[^"]*"\)\/"/\1\\\\\/"/' \
    -e 's/@spin_line1@/typedef unsigned int tsl_t;/' \
    -e '/@spin_line2@/d' \
    -e '/@spin_line3@/d' \
    -e 's/@mutex_align@/sizeof(unsigned int)/' \
    < ../include/db_int.h.src) > $f
chmod 444 $f

f=../build.macos/db.h
echo "Building $f"
(echo "$msg" && sed \
    -e 's/@u_int8_decl@/typedef unsigned char u_int8_t;/' \
    -e 's/@int16_decl@/typedef short int16_t;/' \
    -e 's/@u_int16_decl@/typedef unsigned short u_int16_t;/' \
    -e 's/@int32_decl@/typedef int int32_t;/' \
    -e 's/@u_int32_decl@/typedef unsigned int u_int32_t;/' \
    -e '/@u_char_decl@/d' \
    -e '/@u_short_decl@/d' \
    -e '/@u_int_decl@/d' \
    -e '/@u_long_decl@/d' \
    -e 's/@enable_dbm@/0/' \
    -e 's/@enable_hsearch@/0/' \
    < ../include/db.h.src) > $f
chmod 444 $f

f=../build.macos/db_int.h
echo "Building $f"
(echo "$msg" && sed \
    -e 's/^#include."db.h".*/#include "::build.macintosh:db.h"/' \
    -e 's/\(PATH_SEPARATOR[^"]*"\)\/"/\1:"/' \
    -e 's/@spin_line1@/typedef unsigned char tsl_t;/' \
    -e '/@spin_line2@/d' \
    -e 's/@mutex_align@/sizeof(unsigned char)/' \
    < ../include/db_int.h.src) > $f
chmod 444 $f

shmsg="# Do not edit: automatically built by configure and dist/distrib."
f=../build.win32/.dbtestrc
(echo "$shmsg" && \
 cat ../test/test.tcl) > $f
chmod 444 $f

f=../test/include.tcl.src
echo "Building $f"
rm -f $f
(echo "$shmsg" && \
 echo 'global dict'			&& \
 echo 'global testdir'			&& \
 echo ''				&& \
 echo 'set CMP @db_cv_path_cmp@'	&& \
 echo 'set CP @db_cv_path_cp@'	&& \
 echo 'set DIFF @db_cv_path_diff@'	&& \
 echo 'set KILL @db_cv_path_kill@'	&& \
 echo 'set LS @db_cv_path_ls@'	&& \
 echo 'set MKDIR @db_cv_path_mkdir@'	&& \
 echo 'set MV @db_cv_path_mv@'	&& \
 echo 'set RM @db_cv_path_rm@'	&& \
 echo 'set SED @db_cv_path_sed@'	&& \
 echo 'set SLEEP @db_cv_path_sleep@'	&& \
 echo 'set SORT @db_cv_path_sort@'	&& \
 echo ''				&& \
 echo 'set DB_LOCK_GET 0'		&& \
 echo 'set DB_LOCK_PUT 1'		&& \
 echo 'set DB_LOCK_PUT_ALL 2'		&& \
 echo 'set DB_LOCK_PUT_OBJ 3'		&& \
 echo 'set DB_LOCK_NG 0'		&& \
 echo 'set DB_LOCK_READ 1'		&& \
 echo 'set DB_LOCK_WRITE 2'		&& \
 echo 'set DB_LOCK_IREAD 3'		&& \
 echo 'set DB_LOCK_IWRITE 4'		&& \
 echo 'set DB_LOCK_IWR 5'		&& \
 grep '#define.DB_' ../include/db.h.src | sed -e '/"/d' -e 's/[()]//g' | \
     awk '{ print "set " $2 " " $3}') > $f
chmod 444 $f

# Build tags files.
echo "Building tags file"
f=tags
rm -f $f
ctags -d -w \
	../include/*.src ../include/*.h ../btree/*.[ch] ../clib/*.[ch] \
	../common/*.[ch] ../db/*.[ch] ../db185/*.[ch] ../dbm/*.[ch] \
	../hash/*.[ch] ../hsearch/*.[ch] ../lock/*.[ch] ../log/*.[ch] \
	../mp/*.[ch] ../mutex/*.[ch] ../os/*.[ch] ../test/*.[ch] ../txn/*.[ch]
chmod 444 $f
