1#!/bin/sh -
2#	$Id: s_brew,v 12.7 2008/01/17 13:59:11 bostic Exp $
3#
4# Build the BREW files.
5
6msgc="/* DO NOT EDIT: automatically built by dist/s_brew. */"
7
8. RELEASE
9
10s=/tmp/__db_a
11t=/tmp/__db_b
12
13trap 'rm -f $s $t ; exit 0' 0
14trap 'rm -f $s $t ; exit 1' 1 2 3 13 15
15
16# Build the BREW db.h.
17cat <<ENDOFSEDTEXT > $s
18/@inttypes_h_decl@/d
19/@stdint_h_decl@/d
20s/@stddef_h_decl@/#include <stddef.h>/
21/@unistd_h_decl@/d
22/@thread_h_decl@/d
23s/@u_int8_decl@/typedef unsigned char u_int8_t;/
24s/@int16_decl@/typedef short int16_t;/
25s/@u_int16_decl@/typedef unsigned short u_int16_t;/
26s/@int32_decl@/typedef int int32_t;/
27s/@u_int32_decl@/typedef unsigned int u_int32_t;/
28/@int64_decl@/d
29/@u_int64_decl@/d
30s/@u_char_decl@/typedef unsigned char u_char;/
31s/@u_int_decl@/typedef unsigned int u_int;/
32s/@u_long_decl@/typedef unsigned long u_long;/
33s/@u_short_decl@/typedef unsigned short u_short;/
34s/@uintmax_t_decl@/typedef unsigned long uintmax_t;/
35s/@uintptr_t_decl@/typedef unsigned long uintptr_t;/
36s/@FILE_t_decl@/typedef IFile FILE;/
37s/@off_t_decl@/typedef u_int32_t off_t;/
38s/@pid_t_decl@/typedef int pid_t;/
39s/@size_t_decl@/typedef unsigned int size_t;/
40s/@ssize_t_decl@/typedef int ssize_t;/
41s/@time_t_decl@/typedef long time_t;/
42s/@db_seq_decl@/typedef int32_t db_seq_t;/
43s/@db_threadid_t_decl@/typedef uintmax_t db_threadid_t;/
44s/@DB_VERSION_MAJOR@/$DB_VERSION_MAJOR/
45s/@DB_VERSION_MINOR@/$DB_VERSION_MINOR/
46s/@DB_VERSION_PATCH@/$DB_VERSION_PATCH/
47s/@DB_VERSION_STRING@/"$DB_VERSION_STRING"/
48s/@DB_VERSION_UNIQUE_NAME@//
49s/@DB_CONST@//
50s/@DB_PROTO1@/#undef __P/
51s/@DB_PROTO2@/#define	__P(protos)	protos/
52/@platform_header@/d
53/@platform_footer@/{
54	i\\
55typedef struct {\\
56\	AEEApplet a;			/* AEEApplet must be listed first. */\\
57\	void *db_global_values;\\
58} BDBApp;\\
59int brew_bdb_begin __P((void));\\
60void brew_bdb_end __P((void));
61	d
62}
63/^#ifndef.__NO_SYSTEM_INCLUDES/i\\
64#include <AEEFile.h>
65/^#ifndef.__NO_SYSTEM_INCLUDES/,/^#endif/d
66ENDOFSEDTEXT
67(echo "$msgc" &&
68    sed -f $s ../dbinc/db.in &&
69    cat ../dbinc_auto/api_flags.in &&
70    cat ../dbinc_auto/ext_prot.in) > $t
71test `egrep '@.*@' $t` && {
72	egrep '@.*@' $t
73	echo 'Unexpanded autoconf variables found in BREW db.h.'
74	exit 1
75}
76f=../build_brew/db.h
77cmp $t $f > /dev/null 2>&1 ||
78    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
79
80# Build the BREW db_int.h.
81cat <<ENDOFSEDTEXT > $s
82s/@PATH_SEPARATOR@/\\\\\\\\\/:/
83s/@db_int_def@//
84/#endif.*HAVE_SYSTEM_INCLUDE_FILES/a\\
85#include "brew_db.h"
86ENDOFSEDTEXT
87(echo "$msgc" && sed -f $s ../dbinc/db_int.in) > $t
88test `egrep '@.*@' $t` && {
89	egrep '@.*@' $t
90	echo 'Unexpanded autoconf variables found in BREW db_int.h.'
91	exit 1
92}
93f=../build_brew/db_int.h
94cmp $t $f > /dev/null 2>&1 ||
95    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
96
97# Build the BREW db_config.h
98# We don't fail, but we complain if the brew_config.in file isn't up-to-date.
99check_config()
100{
101	egrep '^#undef' config.hin | awk '{print $2}' | sort > $s
102	(egrep '#undef' $1 | awk '{print $3}'
103	 egrep '^#define' $1 | awk '{print $2}') | sort > $t
104	cmp $s $t > /dev/null || {
105		echo "config.hin and $1 differ"
106		echo "<<< config.hin >>> $1"
107		diff $s $t
108	}
109}
110check_config brew/brew_config.in
111f=../build_brew/db_config.h
112(echo "$msgc" &&
113    sed "s/__EDIT_DB_VERSION__/$DB_VERSION/" brew/brew_config.in) > $t
114cmp $t $f > /dev/null 2>&1 ||
115    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
116
117# Build BREW's brew_db.h
118f=../build_brew/brew_db.h
119i=brew/brew_db.in
120cmp $i $f > /dev/null 2>&1 ||
121    (echo "Building $f" && rm -f $f && cp $i $f && chmod 444 $f)
122
123# Build the BREW clib_port.h.
124cat <<ENDOFSEDTEXT > $s
125/@INT64_FMT@/d
126/@UINT64_FMT@/d
127ENDOFSEDTEXT
128sed -f $s clib_port.in > $t
129test `egrep '@.*@' $t` && {
130	egrep '@.*@' $t
131	echo 'Unexpanded autoconf variables found in BREW clib_port.h.'
132	exit 1
133}
134f=../build_brew/clib_port.h
135cmp $t $f > /dev/null 2>&1 ||
136    (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
137
138# Copy in errno.h.
139f=../build_brew/errno.h
140cmp errno.h $f > /dev/null 2>&1 ||
141    (echo "Building $f" && rm -f $f && cp errno.h $f && chmod 444 $f)
142
143exit 0
144