Add BSD license file
[platform/upstream/db4.git] / dist / s_brew
1 #!/bin/sh -
2 #       $Id$
3 #
4 # Build the BREW files.
5
6 msgc="/* DO NOT EDIT: automatically built by dist/s_brew. */"
7
8 . RELEASE
9
10 s=/tmp/__db_a
11 t=/tmp/__db_b
12
13 trap 'rm -f $s $t ; exit 0' 0
14 trap 'rm -f $s $t ; exit 1' 1 2 3 13 15
15
16 # Build the BREW db.h.
17 cat <<ENDOFSEDTEXT > $s
18 /@inttypes_h_decl@/d
19 /@stdint_h_decl@/d
20 s/@stddef_h_decl@/#include <stddef.h>/
21 /@unistd_h_decl@/d
22 /@thread_h_decl@/d
23 s/@u_int8_decl@/typedef unsigned char u_int8_t;/
24 s/@int16_decl@/typedef short int16_t;/
25 s/@u_int16_decl@/typedef unsigned short u_int16_t;/
26 s/@int32_decl@/typedef int int32_t;/
27 s/@u_int32_decl@/typedef unsigned int u_int32_t;/
28 /@int64_decl@/d
29 /@u_int64_decl@/d
30 s/@u_char_decl@/typedef unsigned char u_char;/
31 s/@u_int_decl@/typedef unsigned int u_int;/
32 s/@u_long_decl@/typedef unsigned long u_long;/
33 s/@u_short_decl@/typedef unsigned short u_short;/
34 s/@uintmax_t_decl@/typedef unsigned long uintmax_t;/
35 s/@uintptr_t_decl@/typedef unsigned long uintptr_t;/
36 s/@FILE_t_decl@/typedef IFile FILE;/
37 s/@off_t_decl@/typedef u_int32_t off_t;/
38 s/@pid_t_decl@/typedef int pid_t;/
39 s/@size_t_decl@/typedef unsigned int size_t;/
40 s/@ssize_t_decl@/typedef int ssize_t;/
41 s/@time_t_decl@/typedef long time_t;/
42 s/@db_seq_decl@/typedef int32_t db_seq_t;/
43 s/@db_threadid_t_decl@/typedef uintmax_t db_threadid_t;/
44 s/@DB_VERSION_MAJOR@/$DB_VERSION_MAJOR/
45 s/@DB_VERSION_MINOR@/$DB_VERSION_MINOR/
46 s/@DB_VERSION_PATCH@/$DB_VERSION_PATCH/
47 s/@DB_VERSION_STRING@/"$DB_VERSION_STRING"/
48 s/@DB_VERSION_UNIQUE_NAME@//
49 s/@DB_CONST@//
50 s/@DB_PROTO1@/#undef __P/
51 s/@DB_PROTO2@/#define   __P(protos)     protos/
52 /@platform_header@/d
53 /@platform_footer@/{
54         i\\
55 typedef struct {\\
56 \       AEEApplet a;                    /* AEEApplet must be listed first. */\\
57 \       void *db_global_values;\\
58 } BDBApp;\\
59 int brew_bdb_begin __P((void));\\
60 void 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
66 ENDOFSEDTEXT
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
71 test `egrep '@.*@' $t` && {
72         egrep '@.*@' $t
73         echo 'Unexpanded autoconf variables found in BREW db.h.'
74         exit 1
75 }
76 f=../build_brew/db.h
77 cmp $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.
81 cat <<ENDOFSEDTEXT > $s
82 s/@PATH_SEPARATOR@/\\\\\\\\\/:/
83 s/@db_int_def@//
84 /#endif.*HAVE_SYSTEM_INCLUDE_FILES/a\\
85 #include "brew_db.h"
86 ENDOFSEDTEXT
87 (echo "$msgc" && sed -f $s ../dbinc/db_int.in) > $t
88 test `egrep '@.*@' $t` && {
89         egrep '@.*@' $t
90         echo 'Unexpanded autoconf variables found in BREW db_int.h.'
91         exit 1
92 }
93 f=../build_brew/db_int.h
94 cmp $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.
99 check_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 }
110 check_config brew/brew_config.in
111 f=../build_brew/db_config.h
112 (echo "$msgc" &&
113     sed "s/__EDIT_DB_VERSION__/$DB_VERSION/" brew/brew_config.in) > $t
114 cmp $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
118 f=../build_brew/brew_db.h
119 i=brew/brew_db.in
120 cmp $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.
124 cat <<ENDOFSEDTEXT > $s
125 /@INT64_FMT@/d
126 /@UINT64_FMT@/d
127 ENDOFSEDTEXT
128 sed -f $s clib_port.in > $t
129 test `egrep '@.*@' $t` && {
130         egrep '@.*@' $t
131         echo 'Unexpanded autoconf variables found in BREW clib_port.h.'
132         exit 1
133 }
134 f=../build_brew/clib_port.h
135 cmp $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.
139 f=../build_brew/errno.h
140 cmp errno.h $f > /dev/null 2>&1 ||
141     (echo "Building $f" && rm -f $f && cp errno.h $f && chmod 444 $f)
142
143 exit 0