1#!/bin/sh -
2#	$Id: s_vxworks,v 12.27 2008/03/20 03:53:54 mjc Exp $
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
223		echo "s/\([^a-zA-Z0-9_]\)\($k(\)/\1$1_\2/g"
224		echo "s/\([^a-zA-Z0-9_]\)\($k[	 ]__P\)/\1$1_\2/g"
225		echo "s/^\($k(\)/$1_\1/g"
226	done
227}
228
229PROGRAM_LIST="\
230	db_archive
231	db_checkpoint
232	db_deadlock
233	db_dump
234	db_hotbackup
235	db_load
236	db_printlog
237	db_recover
238	db_stat
239	db_upgrade
240	db_verify
241	ex_access
242	test_micro"
243
244FILE_LIST="\
245	db_archive/db_archive.c
246	db_checkpoint/db_checkpoint.c
247	db_deadlock/db_deadlock.c
248	db_dump/db_dump.c
249	db_hotbackup/db_hotbackup.c
250	db_load/db_load.c
251	db_printlog/db_printlog.c
252	db_recover/db_recover.c
253	db_stat/db_stat.c
254	db_upgrade/db_upgrade.c
255	db_verify/db_verify.c
256	examples_c/ex_access.c
257	test_micro/source/b_curalloc.c
258	test_micro/source/b_curwalk.c
259	test_micro/source/b_del.c
260	test_micro/source/b_get.c
261	test_micro/source/b_inmem.c
262	test_micro/source/b_load.c
263	test_micro/source/b_open.c
264	test_micro/source/b_put.c
265	test_micro/source/b_recover.c
266	test_micro/source/b_txn.c
267	test_micro/source/b_txn_write.c
268	test_micro/source/b_uname.c
269	test_micro/source/b_util.c
270	test_micro/source/b_workload.c
271	test_micro/source/b_workload.h
272	test_micro/source/bench.h
273	test_micro/source/test_micro.c"
274
275# Build VxWorks versions of the files.
276for i in $FILE_LIST; do
277	# Lots of noise to transform random paths into VxWorks conventions.
278	case $i in
279	*ex_access*)
280		target=dbdemo/dbdemo.c
281		cat ../$i | transform dbdemo > $s
282		cat ../$i | sed -f $s > $t;;
283	test_micro*)
284		target=test_micro/`basename $i`
285		cat ../$i | transform `basename $i .c` > $s
286		cat ../$i | sed -f $s > $t;;
287	*)
288		target="$i"
289		cat ../$i | transform `basename $i .c` > $s
290		cat ../$i | sed -f $s > $t;;
291	esac
292
293	f=../build_vxworks/$target
294	cmp $t $f > /dev/null 2>&1 ||
295	    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
296done
297
298# Output the build lines for a single utility.
299#	$1 == application name
300util_one()
301{
302	egrep "app=$1" srcfiles.in |
303	awk '{print $1}' |
304	sed 's/ex_access/dbdemo/' > $u
305
306	# Build a list of source files.
307	for i in `cat $u`; do
308		if test "$1" = "ex_access" -o "$1" = `basename $i .c`; then
309			i=`basename $i`
310		else
311			i="\$(PRJ_DIR)/../../$i"
312		fi
313		o="<BEGIN> FILE_$i"
314
315		echo "${o}_dependDone"
316		echo "FALSE"
317		echo "<END>"
318		echo
319		echo "${o}_dependencies"
320		echo "<END>"
321		echo
322		echo "${o}_objects"
323		echo "`basename $i .c`.o"
324		echo "<END>"
325		echo
326		echo "${o}_tool"
327		echo "C/C++ compiler"
328		echo "<END>"
329		echo
330	done
331	echo "<BEGIN> PROJECT_FILES"
332	for i in `cat $u`; do
333		if test "$1" = "ex_access" -o "$1" = `basename $i .c`; then
334			i="`basename $i`"
335		else
336			i="../../$i"
337		fi
338		echo "\$(PRJ_DIR)/$i"
339	done |
340	sed -e '${' \
341	    -e 'p' \
342	    -e 'd' \
343	    -e '}' \
344	    -e 's/$/ \\/'
345	echo "<END>"
346	echo
347	echo "<BEGIN> userComments"
348	if test "$1" = "ex_access"; then
349		echo "dbdemo"
350	else
351		echo "$1"
352	fi
353	echo "<END>"
354}
355
356# Build VxWorks Tornado 2.0 project files for the utilities.
357for i in $PROGRAM_LIST; do
358	if [ $i = "ex_access" ]; then
359		target=dbdemo
360	else
361		target=$i
362	fi
363
364	(sed -e "s/__DB_APPLICATION_NAME__/$target/g" < vx_2.0/wpj.in
365	    util_one $i) > $t
366	f=../build_vxworks/$target/${target}20.wpj
367	cmp $t $f > /dev/null 2>&1 ||
368	    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
369
370	(sed -e "s/__DB_APPLICATION_NAME__/$target/g" < vx_2.2/wpj.in
371	    util_one $i) > $t
372	f=../build_vxworks/$target/${target}22.wpj
373	cmp $t $f > /dev/null 2>&1 ||
374	    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
375done
376
377# Build the list of "normal build" files VxWorks knows about.
378sed -e '/^$/d' -e '/^[	 #]/d' srcfiles.in |
379    egrep -w vx |
380    sed 's/[	 ].*//' > $vxfilelist
381
382# Build the list of "small build" files VxWorks knows about.
383sed -e '/^$/d' -e '/^[	 #]/d' srcfiles.in |
384    egrep -w vxsmall |
385    sed 's/[	 ].*//' > $vxsmallfiles
386
387# Build VxWorks Tornado 2.0 project files for the library itself.
388for v in 0 2 ; do
389	#
390	# Build regular project files
391	#
392	(cat vx_2.${v}/BerkeleyDB.wpj
393	for i in `cat $vxfilelist`; do
394		o="<BEGIN> FILE_\$(PRJ_DIR)/../$i"
395		echo "${o}_dependDone"
396		echo "TRUE"
397		echo "<END>"
398		echo
399		echo "${o}_dependencies"
400		echo "\$(PRJ_DIR)/db_config.h \\"
401		echo "	\$(PRJ_DIR)/db_int.h \\"
402		echo "	\$(PRJ_DIR)/db.h"
403		echo "<END>"
404		echo
405		echo "${o}_objects"
406		echo "`basename $i .c`.o"
407		echo "<END>"
408		echo
409		echo "${o}_tool"
410		echo "C/C++ compiler"
411		echo "<END>"
412		echo
413	done
414	echo "<BEGIN> PROJECT_FILES"
415	sed -e '$!s/$/ \\/' \
416	    -e 's/^/$(PRJ_DIR)\/..\//' \
417	    -e '1!s/^/	/' < $vxfilelist
418	echo "<END>"
419	echo
420	echo "<BEGIN> userComments"
421	echo "BerkeleyDB"
422	echo "<END>") > $t
423	#
424	# Build small lib project files
425	#
426	(cat vx_2.${v}/BerkeleyDBsmall.wpj
427	for i in `cat $vxsmallfiles`; do
428		o="<BEGIN> FILE_\$(PRJ_DIR)/../$i"
429		echo "${o}_dependDone"
430		echo "TRUE"
431		echo "<END>"
432		echo
433		echo "${o}_dependencies"
434		echo "\$(PRJ_DIR)/db_config.h \\"
435		echo "	\$(PRJ_DIR)/db_int.h \\"
436		echo "	\$(PRJ_DIR)/db.h"
437		echo "<END>"
438		echo
439		echo "${o}_objects"
440		echo "`basename $i .c`.o"
441		echo "<END>"
442		echo
443		echo "${o}_tool"
444		echo "C/C++ compiler"
445		echo "<END>"
446		echo
447	done
448	echo "<BEGIN> PROJECT_FILES"
449	sed -e '$!s/$/ \\/' \
450	    -e 's/^/$(PRJ_DIR)\/..\//' \
451	    -e '1!s/^/	/' < $vxsmallfiles
452	echo "<END>"
453	echo
454	echo "<BEGIN> userComments"
455	echo "BerkeleyDB"
456	echo "<END>") > $u
457	f=../build_vxworks/BerkeleyDB2${v}.wpj
458	cmp $t $f > /dev/null 2>&1 ||
459	    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
460	f=../build_vxworks/BerkeleyDB2${v}small.wpj
461	cmp $u $f > /dev/null 2>&1 ||
462	    (echo "Building $f" && rm -f $f && cp $u $f && chmod 444 $f)
463done
464
465# vx6 --
466#	Generate a VxWorks 6.X Makefile.
467#
468# $1: list of files
469vx6()
470{
471	# Build VxWorks 6x Makefile.
472	cat vx_6/Makefile.1
473	echo
474	sed -e 's/\.c$//p' -e d < $1 > $s
475	for i in `cat $s`; do
476		sed "s;__FILENAME__;$i;g" < vx_6/cfile
477	done
478	echo
479	sed -e 's/\.cpp$//p' -e d < $1 > $s
480	for i in `cat $s`; do
481		sed "s;__FILENAME__;$i;g" < vx_6/cxxfile
482	done
483	echo
484	sed -e 's/\.c.*//' < $1 > $s
485	/bin/echo -n "OBJECTS_bdbvxw ="
486	sep=" \\"
487	for i in `cat $s`; do
488		echo "$sep"
489		/bin/echo -n '	bdbvxw/$(MODE_DIR)/Objects/$(BDB_OBJECT_DIR)/'
490		/bin/echo -n "$i.o"
491	done
492	echo
493	echo
494	cat vx_6/Makefile.2
495	echo
496	/bin/echo -n "DEP_FILES :="
497	for i in `cat $s`; do
498		echo "$sep"
499		/bin/echo -n '	bdbvxw/$(MODE_DIR)/Objects/$(BDB_OBJECT_DIR)/'
500		/bin/echo -n "$i.d"
501	done
502	echo
503	echo
504	cat vx_6/Makefile.3
505}
506
507# Build the list of "normal build" files VxWorks 6x knows about -- it's
508# the standard Vx list plus some additions.
509sed -e '/^$/d' -e '/^[	 #]/d' srcfiles.in |
510    egrep -w vx6 |
511    sed 's/[	 ].*//' >> $vxfilelist
512vx6 $vxfilelist > $t
513f=../build_vxworks/Makefile.6x
514cmp $t $f > /dev/null 2>&1 ||
515    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
516
517# Build the list of "small build" files VxWorks 6x knows about -- it's
518# the standard vxsmall list.
519sed -e '/^$/d' -e '/^[	 #]/d' srcfiles.in |
520    egrep -w vxsmall |
521    sed 's/[	 ].*//' >> $vxfilelist
522vx6 $vxsmallfiles > $t
523f=../build_vxworks/Makefile.6x.small
524cmp $t $f > /dev/null 2>&1 ||
525    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
526