1#!/bin/sh -
2#	$Id$
3#
4# Build the VxWorks files.
5
6msgc="/* DO NOT EDIT: automatically built by dist/s_vxworks. */"
7
8. RELEASE
9
10s=/tmp/__db_a
11t=/tmp/__db_b
12u=/tmp/__db_c
13vxfilelist=/tmp/__db_d
14vxsmallfiles=/tmp/__db_e
15
16trap 'rm -f $s $t $u $vxfilelist $vxsmallfiles ; exit 0' 0
17trap 'rm -f $s $t $u $vxfilelist $vxsmallfiles ; exit 1' 1 2 3 13 15
18
19# Build the VxWorks db.h.
20cat <<ENDOFSEDTEXT > $s
21/extern "C" {/{
22n
23n
24i\\
25\\
26/* Tornado 2 does not provide a standard C pre-processor #define. */\\
27#ifndef __vxworks\\
28#define	__vxworks\\
29#endif
30}
31/@inttypes_h_decl@/d
32/@stddef_h_decl@/d
33/@stdint_h_decl@/d
34/@unistd_h_decl@/d
35/@thread_h_decl@/d
36s/@u_int8_decl@/typedef unsigned char u_int8_t;/
37/@int16_decl@/d
38s/@u_int16_decl@/typedef unsigned short u_int16_t;/
39/@int32_decl@/d
40s/@u_int32_decl@/typedef unsigned int u_int32_t;/
41s/@int64_decl@//
42s/@u_int64_decl@/typedef unsigned long long u_int64_t;/
43/@u_char_decl@/d
44/@u_int_decl@/d
45/@u_long_decl@/d
46/@u_short_decl@/d
47s/@uintmax_t_decl@/typedef unsigned long uintmax_t;/
48s/@uintptr_t_decl@/typedef unsigned long uintptr_t;/
49/@FILE_t_decl@/d
50/@off_t_decl@/d
51/@pid_t_decl@/d
52/@size_t_decl@/d
53/@ssize_t_decl@/d
54/@time_t_decl@/d
55s/@db_seq_decl@/typedef int db_seq_t;/
56s/@db_threadid_t_decl@/typedef uintmax_t db_threadid_t;/
57s/@DB_VERSION_MAJOR@/$DB_VERSION_MAJOR/
58s/@DB_VERSION_MINOR@/$DB_VERSION_MINOR/
59s/@DB_VERSION_PATCH@/$DB_VERSION_PATCH/
60s/@DB_VERSION_STRING@/"$DB_VERSION_STRING"/
61s/@DB_VERSION_UNIQUE_NAME@//
62s/@DB_CONST@//
63s/@DB_PROTO1@/#undef __P/
64s/@DB_PROTO2@/#define	__P(protos)	protos/
65/@platform_header@/d
66/@platform_footer@/d
67ENDOFSEDTEXT
68(echo "$msgc" &&
69    sed -f $s ../dbinc/db.in &&
70    cat ../dbinc_auto/api_flags.in &&
71    cat ../dbinc_auto/ext_prot.in) > $t
72test `egrep '@.*@' $t` && {
73	egrep '@.*@' $t
74	echo 'Unexpanded autoconf variables found in VxWorks db.h.'
75	exit 1
76}
77f=../build_vxworks/db.h
78cmp $t $f > /dev/null 2>&1 ||
79    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
80
81# Build the VxWorks db_cxx.h.
82cat <<ENDOFSEDTEXT > $s
83s/@cxx_have_stdheaders@/#define	HAVE_CXX_STDHEADERS 1/
84ENDOFSEDTEXT
85(echo "$msgc" && sed -f $s ../dbinc/db_cxx.in) > $t
86test `egrep '@.*@' $t` && {
87	egrep '@.*@' $t
88	echo 'Unexpanded autoconf variables found in VxWorks db_cxx.h.'
89	exit 1
90}
91f=../build_vxworks/db_cxx.h
92cmp $t $f > /dev/null 2>&1 ||
93    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
94
95# Build the VxWorks db_int.h.
96cat <<ENDOFSEDTEXT > $s
97s/@PATH_SEPARATOR@/\/\\\\\\\\/
98s/@db_int_def@//
99/#ifdef.*HAVE_SYSTEM_INCLUDE_FILES/i\\
100#include "vxWorks.h"
101/#endif.*HAVE_SYSTEM_INCLUDE_FILES/a\\
102#include "clib_port.h"\\
103#include "db.h"
104ENDOFSEDTEXT
105(echo "$msgc" && sed -f $s ../dbinc/db_int.in) > $t
106test `egrep '@.*@' $t` && {
107	egrep '@.*@' $t
108	echo 'Unexpanded autoconf variables found in VxWorks db_int.h.'
109	exit 1
110}
111f=../build_vxworks/db_int.h
112cmp $t $f > /dev/null 2>&1 ||
113    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
114
115# Build the VxWorks db_config.h.
116# We don't fail, but we complain if the vx_config.in file isn't up-to-date.
117check_config()
118{
119	egrep '^#undef' config.hin | awk '{print $2}' | sort > $s
120	(egrep '#undef' $1 | awk '{print $3}'
121	 egrep '^#define' $1 | awk '{print $2}') | sort > $t
122	cmp $s $t > /dev/null || {
123		echo "config.hin and $1 differ"
124		echo "<<< config.hin >>> $1"
125		diff $s $t
126	}
127}
128check_config vx_config.in
129f=../build_vxworks/db_config.h
130(echo "$msgc" && sed "s/__EDIT_DB_VERSION__/$DB_VERSION/" vx_config.in) > $t
131cmp $t $f > /dev/null 2>&1 ||
132    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
133
134# Build the VxWorks db_config_small.h.
135f=../build_vxworks/db_config_small.h
136(echo "$msgc" &&
137    sed -e "s/__EDIT_DB_VERSION__/$DB_VERSION/" \
138	-e "s;^#define.*HAVE_CRYPTO.*1;/* #undef HAVE_CRYPTO */;" \
139	-e "s;^#define.*HAVE_HASH.*1;/* #undef HAVE_HASH */;" \
140	-e "s;^#define.*HAVE_QUEUE.*1;/* #undef HAVE_QUEUE */;" \
141	-e "s;^#define.*HAVE_REPLICATION.*1;/* #undef HAVE_REPLICATION */;" \
142	-e "s;^#define.*HAVE_STATISTICS.*1;/* #undef HAVE_STATISTICS */;" \
143	-e "s;^#define.*HAVE_VERIFY.*1;/* #undef HAVE_VERIFY */;" \
144    vx_config.in) > $t
145cmp $t $f > /dev/null 2>&1 ||
146    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
147
148# Build the VxWorks clib_port.h.
149cat <<ENDOFSEDTEXT > $s
150s/@INT64_FMT@/#define	INT64_FMT	"%lld"/
151s/@UINT64_FMT@/#define	UINT64_FMT	"%llu"/
152ENDOFSEDTEXT
153sed -f $s clib_port.in > $t
154test `egrep '@.*@' $t` && {
155	egrep '@.*@' $t
156	echo 'Unexpanded autoconf variables found in VxWorks clib_port.h.'
157	exit 1
158}
159f=../build_vxworks/clib_port.h
160cmp $t $f > /dev/null 2>&1 ||
161    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
162
163# Build a sed script that will change a "standard" DB utility into
164# VxWorks-compatible code.
165transform()
166{
167	# Build a sed script that will add argument parsing support and
168	# rename all of the functions to be private to this file.
169cat <<ENDOFSEDTEXT
170/^main(argc, argv)$/{
171i\\
172$1(args)\\
173\\	char *args;\\
174{\\
175\\	int argc;\\
176\\	char **argv;\\
177\\
178\\	__db_util_arg("$1", args, &argc, &argv);\\
179\\	return ($1_main(argc, argv) ? EXIT_FAILURE : EXIT_SUCCESS);\\
180}\\
181\\
182#include <stdio.h>\\
183#define	ERROR_RETURN	ERROR\\
184\\
185int\\
186$1_main(argc, argv)
187d
188}
189/^	while ((ch = getopt/i\\
190\\	__db_getopt_reset = 1;
191/^[	]*extern int optind;/s/;/, __db_getopt_reset;/
192ENDOFSEDTEXT
193
194	# Convert the ex_access sample into dbdemo for VxWorks.
195	echo 's/progname = "ex_access";/progname = "dbdemo";/'
196
197	# The example programs have to load db_int.h, not db.h -- else
198	# they won't have the right Berkeley DB prototypes for getopt
199	# and friends.
200	echo '/#include.*db.h/c\'
201	echo '#include <db_config.h>\'
202	echo '#include <db_int.h>'
203
204	# Replace all function names with VxWorks safe names.
205	# Function names are:
206	#	Tokens starting at the beginning of the line, immediately
207	#	followed by an opening parenthesis.
208	# Replace:
209	#	Matches preceded by a non-C-token character and immediately
210	#	followed by an opening parenthesis.
211	#	Matches preceded by a non-C-token character and immediately
212	#	followed by " __P".
213	#	Matches starting at the beginning of the line, immediately
214	#	followed by an opening parenthesis.
215	#
216	# Skip any line that starts with the name we're using as a prefix,
217	# it's a case we can't handle very well here, and it's been done by
218	# hand.
219	sed \
220	    -e "/^$1/d" \
221	    -e 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)(.*$/\1/p' -e d > $u
222	for k in `cat $u`; do
223cat <<ENDOFSEDTEXT
224		s/\([^a-zA-Z0-9_]\)\($k(\)/\1$1_\2/g
225		s/\([^a-zA-Z0-9_]\)\($k[	 ]__P\)/\1$1_\2/g
226		s/^\($k(\)/$1_\1/g
227ENDOFSEDTEXT
228	done
229}
230
231PROGRAM_LIST="\
232	db_archive
233	db_checkpoint
234	db_deadlock
235	db_dump
236	db_hotbackup
237	db_load
238	db_printlog
239	db_recover
240	db_stat
241	db_upgrade
242	db_verify
243	ex_access
244	test_micro"
245
246FILE_LIST="\
247	db_archive/db_archive.c
248	db_checkpoint/db_checkpoint.c
249	db_deadlock/db_deadlock.c
250	db_dump/db_dump.c
251	db_hotbackup/db_hotbackup.c
252	db_load/db_load.c
253	db_printlog/db_printlog.c
254	db_recover/db_recover.c
255	db_stat/db_stat.c
256	db_upgrade/db_upgrade.c
257	db_verify/db_verify.c
258	examples_c/ex_access.c
259	test_micro/source/b_curalloc.c
260	test_micro/source/b_curwalk.c
261	test_micro/source/b_del.c
262	test_micro/source/b_get.c
263	test_micro/source/b_inmem.c
264	test_micro/source/b_latch.c
265	test_micro/source/b_load.c
266	test_micro/source/b_open.c
267	test_micro/source/b_put.c
268	test_micro/source/b_recover.c
269	test_micro/source/b_txn.c
270	test_micro/source/b_txn_write.c
271	test_micro/source/b_uname.c
272	test_micro/source/b_util.c
273	test_micro/source/b_workload.c
274	test_micro/source/b_workload.h
275	test_micro/source/bench.h
276	test_micro/source/test_micro.c"
277
278# Build VxWorks versions of the files.
279for i in $FILE_LIST; do
280	# Lots of noise to transform random paths into VxWorks conventions.
281	case $i in
282	*ex_access*)
283		target=dbdemo/dbdemo.c
284		cat ../$i | transform dbdemo > $s
285		cat ../$i | sed -f $s > $t;;
286	test_micro*)
287		target=test_micro/`basename $i`
288		cat ../$i | transform `basename $i .c` > $s
289		cat ../$i | sed -f $s > $t;;
290	*)
291		target="$i"
292		cat ../$i | transform `basename $i .c` > $s
293		cat ../$i | sed -f $s > $t;;
294	esac
295
296	f=../build_vxworks/$target
297	cmp $t $f > /dev/null 2>&1 ||
298	    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
299done
300
301# Output the build lines for a single utility.
302#	$1 == application name
303util_one()
304{
305	egrep "app=$1" srcfiles.in |
306	awk '{print $1}' |
307	sed 's/ex_access/dbdemo/' > $u
308
309	# Build a list of source files.
310	for i in `cat $u`; do
311		if test "$1" = "ex_access" -o "$1" = `basename $i .c`; then
312			i=`basename $i`
313		else
314			i="\$(PRJ_DIR)/../../$i"
315		fi
316		o="<BEGIN> FILE_$i"
317
318		echo "${o}_dependDone"
319		echo "FALSE"
320		echo "<END>"
321		echo
322		echo "${o}_dependencies"
323		echo "<END>"
324		echo
325		echo "${o}_objects"
326		echo "`basename $i .c`.o"
327		echo "<END>"
328		echo
329		echo "${o}_tool"
330		echo "C/C++ compiler"
331		echo "<END>"
332		echo
333	done
334	echo "<BEGIN> PROJECT_FILES"
335	for i in `cat $u`; do
336		if test "$1" = "ex_access" -o "$1" = `basename $i .c`; then
337			i="`basename $i`"
338		else
339			i="../../$i"
340		fi
341		echo "\$(PRJ_DIR)/$i"
342	done |
343	sed -e '${' \
344	    -e 'p' \
345	    -e 'd' \
346	    -e '}' \
347	    -e 's/$/ \\/'
348	echo "<END>"
349	echo
350	echo "<BEGIN> userComments"
351	if test "$1" = "ex_access"; then
352		echo "dbdemo"
353	else
354		echo "$1"
355	fi
356	echo "<END>"
357}
358
359# Build VxWorks Tornado 2.0 project files for the utilities.
360for i in $PROGRAM_LIST; do
361	if [ $i = "ex_access" ]; then
362		target=dbdemo
363	else
364		target=$i
365	fi
366
367	(sed -e "s/__DB_APPLICATION_NAME__/$target/g" < vx_2.0/wpj.in
368	    util_one $i) > $t
369	f=../build_vxworks/$target/${target}20.wpj
370	cmp $t $f > /dev/null 2>&1 ||
371	    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
372
373	(sed -e "s/__DB_APPLICATION_NAME__/$target/g" < vx_2.2/wpj.in
374	    util_one $i) > $t
375	f=../build_vxworks/$target/${target}22.wpj
376	cmp $t $f > /dev/null 2>&1 ||
377	    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
378done
379
380# Build the list of "normal build" files VxWorks knows about.
381sed -e '/^$/d' -e '/^[	 #]/d' srcfiles.in |
382    egrep -w vx |
383    sed 's/[	 ].*//' > $vxfilelist
384
385# Build the list of "small build" files VxWorks knows about.
386sed -e '/^$/d' -e '/^[	 #]/d' srcfiles.in |
387    egrep -w vxsmall |
388    sed 's/[	 ].*//' > $vxsmallfiles
389
390# Build VxWorks Tornado 2.0 project files for the library itself.
391for v in 0 2 ; do
392	#
393	# Build regular project files
394	#
395	(cat vx_2.${v}/BerkeleyDB.wpj
396	for i in `cat $vxfilelist`; do
397		o="<BEGIN> FILE_\$(PRJ_DIR)/../$i"
398		echo "${o}_dependDone"
399		echo "TRUE"
400		echo "<END>"
401		echo
402		echo "${o}_dependencies"
403		echo "\$(PRJ_DIR)/db_config.h \\"
404		echo "	\$(PRJ_DIR)/db_int.h \\"
405		echo "	\$(PRJ_DIR)/db.h"
406		echo "<END>"
407		echo
408		echo "${o}_objects"
409		echo "`basename $i .c`.o"
410		echo "<END>"
411		echo
412		echo "${o}_tool"
413		echo "C/C++ compiler"
414		echo "<END>"
415		echo
416	done
417	echo "<BEGIN> PROJECT_FILES"
418	sed -e '$!s/$/ \\/' \
419	    -e 's/^/$(PRJ_DIR)\/..\//' \
420	    -e '1!s/^/	/' < $vxfilelist
421	echo "<END>"
422	echo
423	echo "<BEGIN> userComments"
424	echo "BerkeleyDB"
425	echo "<END>") > $t
426	#
427	# Build small lib project files
428	#
429	(cat vx_2.${v}/BerkeleyDBsmall.wpj
430	for i in `cat $vxsmallfiles`; do
431		o="<BEGIN> FILE_\$(PRJ_DIR)/../$i"
432		echo "${o}_dependDone"
433		echo "TRUE"
434		echo "<END>"
435		echo
436		echo "${o}_dependencies"
437		echo "\$(PRJ_DIR)/db_config.h \\"
438		echo "	\$(PRJ_DIR)/db_int.h \\"
439		echo "	\$(PRJ_DIR)/db.h"
440		echo "<END>"
441		echo
442		echo "${o}_objects"
443		echo "`basename $i .c`.o"
444		echo "<END>"
445		echo
446		echo "${o}_tool"
447		echo "C/C++ compiler"
448		echo "<END>"
449		echo
450	done
451	echo "<BEGIN> PROJECT_FILES"
452	sed -e '$!s/$/ \\/' \
453	    -e 's/^/$(PRJ_DIR)\/..\//' \
454	    -e '1!s/^/	/' < $vxsmallfiles
455	echo "<END>"
456	echo
457	echo "<BEGIN> userComments"
458	echo "BerkeleyDB"
459	echo "<END>") > $u
460	f=../build_vxworks/BerkeleyDB2${v}.wpj
461	cmp $t $f > /dev/null 2>&1 ||
462	    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
463	f=../build_vxworks/BerkeleyDB2${v}small.wpj
464	cmp $u $f > /dev/null 2>&1 ||
465	    (echo "Building $f" && rm -f $f && cp $u $f && chmod 444 $f)
466done
467
468# vx6 --
469#	Generate a VxWorks 6.X Makefile.
470#
471# $1: list of files
472vx6()
473{
474	# Build VxWorks 6x Makefile.
475	cat vx_6/Makefile.1
476	echo
477	sed -e 's/\.c$//p' -e d < $1 > $s
478	for i in `cat $s`; do
479		sed "s;__FILENAME__;$i;g" < vx_6/cfile
480	done
481	echo
482	sed -e 's/\.cpp$//p' -e d < $1 > $s
483	for i in `cat $s`; do
484		sed "s;__FILENAME__;$i;g" < vx_6/cxxfile
485	done
486	echo
487	sed -e 's/\.c.*//' < $1 > $s
488	/bin/echo -n "OBJECTS_bdbvxw ="
489	sep=" \\"
490	for i in `cat $s`; do
491		echo "$sep"
492		/bin/echo -n '	bdbvxw/$(MODE_DIR)/Objects/$(BDB_OBJECT_DIR)/'
493		/bin/echo -n "$i.o"
494	done
495	echo
496	echo
497	cat vx_6/Makefile.2
498	echo
499	/bin/echo -n "DEP_FILES :="
500	for i in `cat $s`; do
501		echo "$sep"
502		/bin/echo -n '	bdbvxw/$(MODE_DIR)/Objects/$(BDB_OBJECT_DIR)/'
503		/bin/echo -n "$i.d"
504	done
505	echo
506	echo
507	cat vx_6/Makefile.3
508}
509
510# Build the list of "normal build" files VxWorks 6x knows about -- it's
511# the standard Vx list plus some additions.
512sed -e '/^$/d' -e '/^[	 #]/d' srcfiles.in |
513    egrep -w vx6 |
514    sed 's/[	 ].*//' >> $vxfilelist
515vx6 $vxfilelist > $t
516f=../build_vxworks/Makefile.6x
517cmp $t $f > /dev/null 2>&1 ||
518    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
519
520# Build the list of "small build" files VxWorks 6x knows about -- it's
521# the standard vxsmall list.
522sed -e '/^$/d' -e '/^[	 #]/d' srcfiles.in |
523    egrep -w vxsmall |
524    sed 's/[	 ].*//' >> $vxfilelist
525vx6 $vxsmallfiles > $t
526f=../build_vxworks/Makefile.6x.small
527cmp $t $f > /dev/null 2>&1 ||
528    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
529