Add BSD license file
[platform/upstream/db4.git] / dist / s_brew_posix
1 #!/bin/sh -
2 #       $Id$
3 #
4 # Build the BREW files on a POSIX system.
5
6 s=/tmp/__db_a
7 t=/tmp/__db_b
8
9 trap 'rm -f $s $t ; exit 0' 0
10 trap 'rm -f $s $t ; exit 1' 1 2 3 13 15
11
12 # Temporary directory to build in.
13 test -d ../build_brew_x || mkdir ../build_brew_x
14
15 # Copy in db_config.h.
16 #
17 # We do have system include files in the POSIX build.
18 f=../build_brew_x/db_config.h
19 cat <<ENDOFSEDTEXT > $s
20 /HAVE_SYSTEM_INCLUDE_FILES/{
21         a\\
22 #define HAVE_SYSTEM_INCLUDE_FILES 1
23 }
24 ENDOFSEDTEXT
25 sed -f $s < ../build_brew/db_config.h > $t
26 cmp $t $f > /dev/null 2>&1 ||
27     (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
28
29 # Copy in db.h.
30 f=../build_brew_x/db.h
31 sed -e '/typedef.*[      ]FILE;/s/.*/#define IFile FILE/' \
32     -e '/typedef.*[      ]off_t;/d' \
33     -e '/typedef.*[      ]time_t;/d' \
34     -e '/typedef.*[      ]uintptr_t;/d' \
35     -e '/#include.<AEEFile.h>/d' \
36     < ../build_brew/db.h > $t
37
38 cmp $t $f > /dev/null 2>&1 ||
39     (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
40
41 # Copy in brew_db.h
42 f=../build_brew_x/brew_db.h
43 cmp brew/brew_posix.h $f > /dev/null 2>&1 ||
44     (echo "Building $f" && rm -f $f && cp brew/brew_posix.h $f && chmod 444 $f)
45
46 # Copy in clib_port.h
47 #
48 # Delete all references to isalpha, isdigit, isprint, isspace.
49 f=../build_brew_x/clib_port.h
50 sed -e '/HAVE_ISALPHA/,/#endif/d' \
51     -e '/HAVE_ISDIGIT/,/#endif/d' \
52     -e '/HAVE_ISPRINT/,/#endif/d' \
53     -e '/HAVE_ISSPACE/,/#endif/d' < ../build_brew/clib_port.h > $t
54 cmp $t $f > /dev/null 2>&1 ||
55     (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
56
57 # Copy in remaining files.
58 for i in db_int.h errno.h; do
59         f=../build_brew_x/$i
60         cmp ../build_brew/$i $f > /dev/null 2>&1 ||
61             (echo "Building $f" &&
62             rm -f $f && cp ../build_brew/$i $f && chmod 444 $f)
63 done
64
65 # Build a Makefile for testing on a POSIX system.
66 # $1 is srcfiles keyword
67 # $2 is Makefile name
68 build_make()
69 {
70         f=../build_brew_x/$2
71
72         (cat brew/brew_make.in &&
73             echo &&
74             echo '###################################################' &&
75             echo '# EVERYTHING BELOW THIS LINE IS GENERATED BY s_brew' &&
76             echo '##################################################' &&
77             echo 'OBJS=\' &&
78             grep -w $1 srcfiles.in |
79             awk '{print $1}' |
80             sed -e '/isalpha/d' \
81                 -e '/isdigit/d' \
82                 -e '/isprint/d' \
83                 -e '/isspace/d' \
84                 -e 's/.*\//     /' \
85                 -e 's/\.c$/.o/' \
86                 -e '$!s/$/\\/' &&
87             echo &&
88             grep -w $1 srcfiles.in |
89             awk '{print $1}' |
90             sed -e '/isalpha/d' \
91                 -e '/isdigit/d' \
92                 -e '/isprint/d' \
93                 -e '/isspace/d' \
94                 -e 's/\.c$//' \
95                 -e 's/.*/&.o: ..\/&.c/' \
96                 -e 's/^[^\/]*\///' &&
97             echo &&
98             echo 'libdb.a: $(OBJS)' &&
99             echo '      ar cr $@ $(OBJS)') > $t
100
101         cmp $t $f > /dev/null 2>&1 ||
102             (echo "Building $f" && rm -f $f && cp $t $f && chmod 444 $f)
103 }
104
105 build_make brew Makefile
106
107 exit 0