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