summaryrefslogtreecommitdiff
path: root/dist/s_vxworks
blob: 66a9adb4067a56d9e46a6ab9e76b08b440038c36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
#!/bin/sh -
#	$Id$
#
# Build the VxWorks files.

msgc="/* DO NOT EDIT: automatically built by dist/s_vxworks. */"

. ./RELEASE

s=/tmp/__db_a
t=/tmp/__db_b
u=/tmp/__db_c
vxfilelist=/tmp/__db_d
vxsmallfiles=/tmp/__db_e

trap 'rm -f $s $t $u $vxfilelist $vxsmallfiles ; exit 0' 0
trap 'rm -f $s $t $u $vxfilelist $vxsmallfiles ; exit 1' 1 2 3 13 15

# Build the VxWorks db.h.
cat <<ENDOFSEDTEXT > $s
/extern "C" {/{
n
n
i\\
\\
#ifndef __vxworks\\
#define	__vxworks\\
#endif
}
/@inttypes_h_decl@/d
/@stddef_h_decl@/d
/@stdint_h_decl@/d
/@unistd_h_decl@/d
s/@thread_h_decl@/#include <pthread.h>/
s/@u_int8_decl@/typedef unsigned char u_int8_t;/
/@int16_decl@/d
s/@u_int16_decl@/typedef unsigned short u_int16_t;/
/@int32_decl@/d
s/@u_int32_decl@/typedef unsigned int u_int32_t;/
s/@int64_decl@//
s/@u_int64_decl@/typedef unsigned long long u_int64_t;/
/@u_char_decl@/d
/@u_int_decl@/d
/@u_long_decl@/d
/@u_short_decl@/d
s/@uintmax_t_decl@/typedef unsigned long uintmax_t;/
/@uintptr_t_decl@/d
/@FILE_t_decl@/d
/@off_t_decl@/d
s/@db_off_t_decl@/typedef int64_t db_off_t;/
/@pid_t_decl@/d
/@size_t_decl@/d
/@ssize_t_decl@/d
/@time_t_decl@/d
s/@db_seq_decl@/typedef int64_t db_seq_t;/
s/@db_threadid_t_decl@/typedef uintmax_t db_threadid_t;/
s/@DB_VERSION_FAMILY@/$DB_VERSION_FAMILY/
s/@DB_VERSION_RELEASE@/$DB_VERSION_RELEASE/
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_FULL_STRING@/"$DB_VERSION_FULL_STRING"/
s/@DB_VERSION_UNIQUE_NAME@//
s/@DB_CONST@//
s/@DB_PROTO1@/#undef __P/
s/@DB_PROTO2@/#define	__P(protos)	protos/
/@platform_header@/d
/@platform_footer@/d
ENDOFSEDTEXT
(echo "$msgc" &&
    sed -f $s ../src/dbinc/db.in &&
    cat ../src/dbinc_auto/api_flags.in &&
    cat ../src/dbinc_auto/ext_prot.in) > $t
test `egrep '@.*@' $t` && {
	egrep '@.*@' $t
	echo 'Unexpanded autoconf variables found in VxWorks db.h.'
	exit 1
}
f=../build_vxworks/db.h
cmp $t $f > /dev/null 2>&1 ||
    (echo "Building $f" && rm -f $f && cp $t $f)

# Build the VxWorks db_cxx.h.
cat <<ENDOFSEDTEXT > $s
s/@cxx_have_stdheaders@/#define	HAVE_CXX_STDHEADERS 1/
ENDOFSEDTEXT
(echo "$msgc" && sed -f $s ../src/dbinc/db_cxx.in) > $t
test `egrep '@.*@' $t` && {
	egrep '@.*@' $t
	echo 'Unexpanded autoconf variables found in VxWorks db_cxx.h.'
	exit 1
}
f=../build_vxworks/db_cxx.h
cmp $t $f > /dev/null 2>&1 ||
    (echo "Building $f" && rm -f $f && cp $t $f)

# Build the VxWorks db_int.h.
cat <<ENDOFSEDTEXT > $s
s/@DB_STRUCT_ALIGN8@//
s/@PATH_SEPARATOR@/\/\\\\\\\\/
s/@db_int_def@//
/#ifdef.*HAVE_SYSTEM_INCLUDE_FILES/i\\
#include "vxWorks.h"
/#endif.*HAVE_SYSTEM_INCLUDE_FILES/a\\
#include "clib_port.h"\\
#include "db.h"
ENDOFSEDTEXT
(echo "$msgc" && sed -f $s ../src/dbinc/db_int.in) > $t
test `egrep '@.*@' $t` && {
	egrep '@.*@' $t
	echo 'Unexpanded autoconf variables found in VxWorks db_int.h.'
	exit 1
}
f=../build_vxworks/db_int.h
cmp $t $f > /dev/null 2>&1 ||
    (echo "Building $f" && rm -f $f && cp $t $f)

# Build the VxWorks db_config.h.
# We don't fail, but we complain if the vx_config.in file isn't up-to-date.
check_config()
{
	egrep '^#undef' config.hin | awk '{print $2}' | sort > $s
	(egrep '#undef' $1 | awk '{print $3}'
	 egrep '^#define' $1 | awk '{print $2}') | sort > $t
	cmp $s $t > /dev/null || {
		echo "config.hin and $1 differ"
		echo "<<< config.hin >>> $1"
		diff $s $t
	}
}
check_config vx_config.in
f=../build_vxworks/db_config.h
(echo "$msgc" && sed "s/__EDIT_DB_VERSION__/$DB_VERSION/" vx_config.in) > $t
cmp $t $f > /dev/null 2>&1 ||
    (echo "Building $f" && rm -f $f && cp $t $f)

# Build the VxWorks db_config_small.h.
f=../build_vxworks/db_config_small.h
(echo "$msgc" &&
    sed -e "s/__EDIT_DB_VERSION__/$DB_VERSION/" \
	-e "s;^#define.*HAVE_CRYPTO.*1;/* #undef HAVE_CRYPTO */;" \
	-e "s;^#define.*HAVE_HASH.*1;/* #undef HAVE_HASH */;" \
	-e "s;^#define.*HAVE_QUEUE.*1;/* #undef HAVE_QUEUE */;" \
	-e "s;^#define.*HAVE_REPLICATION.*1;/* #undef HAVE_REPLICATION */;" \
	-e "s;^#define.*HAVE_STATISTICS.*1;/* #undef HAVE_STATISTICS */;" \
	-e "s;^#define.*HAVE_VERIFY.*1;/* #undef HAVE_VERIFY */;" \
    vx_config.in) > $t
cmp $t $f > /dev/null 2>&1 ||
    (echo "Building $f" && rm -f $f && cp $t $f)

# Build the VxWorks clib_port.h.
cat <<ENDOFSEDTEXT > $s
s/@INT64_FMT@/#define	INT64_FMT	"%lld"/
s/@UINT64_FMT@/#define	UINT64_FMT	"%llu"/
ENDOFSEDTEXT
sed -f $s clib_port.in > $t
test `egrep '@.*@' $t` && {
	egrep '@.*@' $t
	echo 'Unexpanded autoconf variables found in VxWorks clib_port.h.'
	exit 1
}
f=../build_vxworks/clib_port.h
cmp $t $f > /dev/null 2>&1 ||
    (echo "Building $f" && rm -f $f && cp $t $f)

# Build a sed script that will change a "standard" DB utility into
# VxWorks-compatible code.
transform()
{
	# Build a sed script that will add argument parsing support and
	# rename all of the functions to be private to this file.
cat <<ENDOFSEDTEXT
/^main(argc, argv)$/{
i\\
$1(args)\\
\\	char *args;\\
{\\
\\	int argc;\\
\\	char **argv;\\
\\
\\	__db_util_arg("$1", args, &argc, &argv);\\
\\	return ($1_main(argc, argv) ? EXIT_FAILURE : EXIT_SUCCESS);\\
}\\
\\
#include <stdio.h>\\
#define	ERROR_RETURN	ERROR\\
\\
int\\
$1_main(argc, argv)
d
}
/^	while ((ch = getopt/i\\
\\	__db_getopt_reset = 1;
/^[	]*extern int optind;/s/;/, __db_getopt_reset;/
ENDOFSEDTEXT

	# Convert the ex_access sample into dbdemo for VxWorks.
	echo 's/progname = "ex_access";/progname = "dbdemo";/'

	# The example programs have to load db_int.h, not db.h -- else
	# they won't have the right Berkeley DB prototypes for getopt
	# and friends.
	echo '/#include.*db.h/c\'
	echo '#include <db_config.h>\'
	echo '#include <db_int.h>'

	# Replace all function names with VxWorks safe names.
	# Function names are:
	#	Tokens starting at the beginning of the line, immediately
	#	followed by an opening parenthesis.
	# Replace:
	#	Matches preceded by a non-C-token character and immediately
	#	followed by an opening parenthesis.
	#	Matches preceded by a non-C-token character and immediately
	#	followed by " __P".
	#	Matches starting at the beginning of the line, immediately
	#	followed by an opening parenthesis.
	#	Matches tokens starting with a space and ending in a comma
	#	(i.e. ' token,')  to cover cases where token is used in a
	#	procedure call.  Sequence could occur in a comment line.
	#
	# Skip any line that starts with the name we're using as a prefix,
	# it's a case we can't handle very well here, and it's been done by
	# hand.
	sed \
	    -e "/^$1/d" \
	    -e 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)(.*$/\1/p' -e d > $u
	for k in `cat $u`; do
cat <<ENDOFSEDTEXT
		s/\([^a-zA-Z0-9_]\)\($k(\)/\1$1_\2/g
		s/\([^a-zA-Z0-9_]\)\($k[	 ]__P\)/\1$1_\2/g
		s/^\($k(\)/$1_\1/g
		s/\([ ]\)\($k,\)/\1$1_\2/g
ENDOFSEDTEXT
	done
}

PROGRAM_LIST="\
	db_archive
	db_checkpoint
	db_deadlock
	db_dump
	db_hotbackup
	db_load
	db_log_verify
	db_printlog
	db_recover
	db_stat
	db_tuner
	db_upgrade
	db_verify
	ex_access
	test_micro"

FILE_LIST="\
	util/db_archive.c
	util/db_checkpoint.c
	util/db_deadlock.c
	util/db_dump.c
	util/db_hotbackup.c
	util/db_load.c
	util/db_printlog.c
	util/db_recover.c
	util/db_stat.c
	util/db_tuner.c
	util/db_upgrade.c
	util/db_verify.c
	util/db_log_verify.c
	examples/c/ex_access.c
	test/micro/source/b_curalloc.c
	test/micro/source/b_curwalk.c
	test/micro/source/b_del.c
	test/micro/source/b_get.c
	test/micro/source/b_inmem.c
	test/micro/source/b_latch.c
	test/micro/source/b_load.c
	test/micro/source/b_open.c
	test/micro/source/b_put.c
	test/micro/source/b_recover.c
	test/micro/source/b_txn.c
	test/micro/source/b_txn_write.c
	test/micro/source/b_uname.c
	test/micro/source/b_util.c
	test/micro/source/b_workload.c
	test/micro/source/b_workload.h
	test/micro/source/bench.h
	test/micro/source/test_micro.c"

# Build VxWorks versions of the files.
for i in $FILE_LIST; do
	# Lots of noise to transform random paths into VxWorks conventions.
	case $i in
	*ex_access*)
		target=dbdemo/dbdemo.c
		cat ../$i | transform dbdemo > $s
		cat ../$i | sed -f $s > $t;;
	test\/micro*)
		target=test/micro/`basename $i`
		cat ../$i | transform `basename $i .c` > $s
		cat ../$i | sed -f $s > $t;;
	*)
		target="$i"
		cat ../$i | transform `basename $i .c` > $s
		cat ../$i | sed -f $s > $t;;
	esac

	f=../build_vxworks/$target
	cmp $t $f > /dev/null 2>&1 ||
	    (echo "Building $f" && rm -f $f && cp $t $f)
done

# Output the build lines for a single utility.
#	$1 == application name
util_one()
{
	egrep "app=$1" srcfiles.in |
	awk '{print $1}' |
	sed 's/ex_access/dbdemo/' > $u

	# Build a list of source files.
	for i in `cat $u`; do
		if test "$1" = "ex_access" -o "$1" = `basename $i .c`; then
			i=`basename $i`
		else
			i="\$(PRJ_DIR)/../../$i"
		fi
		o="<BEGIN> FILE_$i"

		echo "${o}_dependDone"
		echo "FALSE"
		echo "<END>"
		echo
		echo "${o}_dependencies"
		echo "<END>"
		echo
		echo "${o}_objects"
		echo "`basename $i .c`.o"
		echo "<END>"
		echo
		echo "${o}_tool"
		echo "C/C++ compiler"
		echo "<END>"
		echo
	done
	echo "<BEGIN> PROJECT_FILES"
	for i in `cat $u`; do
		if test "$1" = "ex_access" -o "$1" = `basename $i .c`; then
			i="`basename $i`"
		else
			i="../../$i"
		fi
		echo "\$(PRJ_DIR)/$i"
	done |
	sed -e '${' \
	    -e 'p' \
	    -e 'd' \
	    -e '}' \
	    -e 's/$/ \\/'
	echo "<END>"
	echo
	echo "<BEGIN> userComments"
	if test "$1" = "ex_access"; then
		echo "dbdemo"
	else
		echo "$1"
	fi
	echo "<END>"
}

# vx6 --
#	Generate a VxWorks 6.X Makefile.
#
# $1: list of files
vx6()
{
	# Build VxWorks 6x Makefile.
	cat vx_6/Makefile.1
	echo
	sed -e 's/\.c$//p' -e d < $1 > $s
	for i in `cat $s`; do
		sed "s;__FILENAME__;$i;g" < vx_6/cfile
	done
	echo
	sed -e 's/\.cpp$//p' -e d < $1 > $s
	for i in `cat $s`; do
		sed "s;__FILENAME__;$i;g" < vx_6/cxxfile
	done
	echo
	sed -e 's/\.c.*//' < $1 > $s
	/bin/echo -n "OBJECTS_bdbvxw ="
	sep=" \\"
	for i in `cat $s`; do
		echo "$sep"
		/bin/echo -n '	bdbvxw/$(MODE_DIR)/Objects/$(BDB_OBJECT_DIR)/'
		/bin/echo -n "$i.o"
	done
	echo
	echo
	cat vx_6/Makefile.2
	echo
	/bin/echo -n "DEP_FILES :="
	for i in `cat $s`; do
		echo "$sep"
		/bin/echo -n '	bdbvxw/$(MODE_DIR)/Objects/$(BDB_OBJECT_DIR)/'
		/bin/echo -n "$i.d"
	done
	echo
	echo
	cat vx_6/Makefile.3
}

# Build the list of "normal build" files VxWorks 6x knows about -- it's
# the standard Vx list plus some additions.
sed -e '/^$/d' -e '/^[	 #]/d' srcfiles.in |
    egrep -w vx |
    sed 's/[	 ].*//' > $vxfilelist
sed -e '/^$/d' -e '/^[	 #]/d' srcfiles.in |
    egrep -w vx6 |
    sed 's/[	 ].*//' >> $vxfilelist
vx6 $vxfilelist > $t
f=../build_vxworks/Makefile.6x
cmp $t $f > /dev/null 2>&1 ||
    (echo "Building $f" && rm -f $f && cp $t $f)

# Build the list of "small build" files VxWorks 6x knows about -- it's
# the standard vxsmall list.
sed -e '/^$/d' -e '/^[	 #]/d' srcfiles.in |
    egrep -w vxsmall |
    sed 's/[	 ].*//' >> $vxsmallfiles
vx6 $vxsmallfiles > $t
f=../build_vxworks/Makefile.6x.small
cmp $t $f > /dev/null 2>&1 ||
    (echo "Building $f" && rm -f $f && cp $t $f)