Commit | Line | Data |
---|---|---|
959f3c4c JH |
1 | ?RCS: $Id: i_db.U,v 3.0.1.3 1995/07/25 14:10:22 ram Exp $ |
2 | ?RCS: | |
3 | ?RCS: Copyright (c) 1991-1993, Raphael Manfredi | |
0065f4af | 4 | ?RCS: |
65a32477 | 5 | ?RCS: You may redistribute only under the terms of the Artistic License, |
959f3c4c JH |
6 | ?RCS: as specified in the README file that comes with the distribution. |
7 | ?RCS: You may reuse parts of this distribution only within the terms of | |
65a32477 | 8 | ?RCS: that same Artistic License; a copy of which may be found at the root |
959f3c4c JH |
9 | ?RCS: of the source tree for dist 3.0. |
10 | ?RCS: | |
11 | ?RCS: Original Author: Andy Dougherty <doughera@lafcol.lafayette.edu> | |
12 | ?RCS: | |
13 | ?RCS: $Log: i_db.U,v $ | |
14 | ?RCS: Revision 3.0.1.3 1995/07/25 14:10:22 ram | |
15 | ?RCS: patch56: conditionally use const in test programs (ADO) | |
16 | ?RCS: | |
17 | ?RCS: Revision 3.0.1.2 1995/05/12 12:14:42 ram | |
18 | ?RCS: patch54: extended for more intimate DB probing (ADO) | |
19 | ?RCS: | |
20 | ?RCS: Revision 3.0.1.1 1994/08/29 16:21:50 ram | |
21 | ?RCS: patch32: created by ADO | |
22 | ?RCS: | |
7ab230d2 JH |
23 | ?MAKE:i_db db_hashtype db_prefixtype \ |
24 | db_version_major db_version_minor db_version_patch : \ | |
2cb64bf6 | 25 | Inhdr +cc +ccflags rm_try contains cat \ |
1273bb5e | 26 | Compile d_const libs sed run i_stdlib |
959f3c4c JH |
27 | ?MAKE: -pick add $@ %< |
28 | ?S:i_db: | |
29 | ?S: This variable conditionally defines the I_DB symbol, and indicates | |
30 | ?S: whether a C program may include Berkeley's DB include file <db.h>. | |
31 | ?S:. | |
32 | ?S:db_hashtype: | |
33 | ?S: This variable contains the type of the hash structure element | |
34 | ?S: in the <db.h> header file. In older versions of DB, it was | |
35 | ?S: int, while in newer ones it is u_int32_t. | |
36 | ?S:. | |
37 | ?S:db_prefixtype: | |
38 | ?S: This variable contains the type of the prefix structure element | |
39 | ?S: in the <db.h> header file. In older versions of DB, it was | |
40 | ?S: int, while in newer ones it is size_t. | |
41 | ?S:. | |
7ab230d2 JH |
42 | ?S:db_version_major: |
43 | ?S: This variable contains the major version number of | |
44 | ?S: Berkeley DB found in the <db.h> header file. | |
45 | ?S:. | |
46 | ?S:db_version_minor: | |
47 | ?S: This variable contains the minor version number of | |
48 | ?S: Berkeley DB found in the <db.h> header file. | |
49 | ?S: For DB version 1 this is always 0. | |
50 | ?S:. | |
51 | ?S:db_version_patch: | |
52 | ?S: This variable contains the patch version number of | |
53 | ?S: Berkeley DB found in the <db.h> header file. | |
54 | ?S: For DB version 1 this is always 0. | |
55 | ?S:. | |
959f3c4c JH |
56 | ?C:I_DB: |
57 | ?C: This symbol, if defined, indicates to the C program that it should | |
58 | ?C: include Berkeley's DB include file <db.h>. | |
59 | ?C:. | |
60 | ?C:DB_Prefix_t: | |
61 | ?C: This symbol contains the type of the prefix structure element | |
62 | ?C: in the <db.h> header file. In older versions of DB, it was | |
63 | ?C: int, while in newer ones it is u_int32_t. | |
64 | ?C:. | |
65 | ?C:DB_Hash_t: | |
66 | ?C: This symbol contains the type of the prefix structure element | |
67 | ?C: in the <db.h> header file. In older versions of DB, it was | |
68 | ?C: int, while in newer ones it is size_t. | |
69 | ?C:. | |
7ab230d2 JH |
70 | ?C:DB_VERSION_MAJOR_CFG: |
71 | ?C: This symbol, if defined, defines the major version number of | |
72 | ?C: Berkeley DB found in the <db.h> header when Perl was configured. | |
73 | ?C:. | |
74 | ?C:DB_VERSION_MINOR_CFG: | |
75 | ?C: This symbol, if defined, defines the minor version number of | |
76 | ?C: Berkeley DB found in the <db.h> header when Perl was configured. | |
77 | ?C: For DB version 1 this is always 0. | |
78 | ?C:. | |
79 | ?C:DB_VERSION_PATCH_CFG: | |
80 | ?C: This symbol, if defined, defines the patch version number of | |
81 | ?C: Berkeley DB found in the <db.h> header when Perl was configured. | |
82 | ?C: For DB version 1 this is always 0. | |
83 | ?C:. | |
959f3c4c JH |
84 | ?H:#$i_db I_DB /**/ |
85 | ?H:#define DB_Hash_t $db_hashtype /**/ | |
86 | ?H:#define DB_Prefix_t $db_prefixtype /**/ | |
7ab230d2 JH |
87 | ?H:#define DB_VERSION_MAJOR_CFG $db_version_major /**/ |
88 | ?H:#define DB_VERSION_MINOR_CFG $db_version_minor /**/ | |
89 | ?H:#define DB_VERSION_PATCH_CFG $db_version_patch /**/ | |
959f3c4c | 90 | ?H:. |
0065f4af | 91 | ?F:!try |
959f3c4c JH |
92 | ?LINT:change libs |
93 | : see if this is a db.h system | |
94 | set db.h i_db | |
95 | eval $inhdr | |
96 | ||
97 | case "$i_db" in | |
98 | $define) | |
99 | : Check db version. | |
100 | echo " " | |
101 | echo "Checking Berkeley DB version ..." >&4 | |
102 | $cat >try.c <<EOCP | |
103 | #$d_const HASCONST | |
104 | #ifndef HASCONST | |
105 | #define const | |
106 | #endif | |
107 | #include <sys/types.h> | |
108 | #include <stdio.h> | |
1273bb5e JH |
109 | #$i_stdlib I_STDLIB |
110 | #ifdef I_STDLIB | |
111 | #include <stdlib.h> | |
112 | #endif | |
959f3c4c | 113 | #include <db.h> |
7ab230d2 | 114 | int main(int argc, char *argv[]) |
959f3c4c JH |
115 | { |
116 | #ifdef DB_VERSION_MAJOR /* DB version >= 2 */ | |
117 | int Major, Minor, Patch ; | |
118 | unsigned long Version ; | |
119 | (void)db_version(&Major, &Minor, &Patch) ; | |
7ab230d2 JH |
120 | if (argc == 2) { |
121 | printf("%d %d %d %d %d %d\n", | |
122 | DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH, | |
123 | Major, Minor, Patch); | |
124 | exit(0); | |
125 | } | |
126 | printf("You have Berkeley DB Version 2 or greater.\n"); | |
959f3c4c JH |
127 | |
128 | printf("db.h is from Berkeley DB Version %d.%d.%d\n", | |
129 | DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH); | |
130 | printf("libdb is from Berkeley DB Version %d.%d.%d\n", | |
131 | Major, Minor, Patch) ; | |
132 | ||
133 | /* check that db.h & libdb are compatible */ | |
134 | if (DB_VERSION_MAJOR != Major || DB_VERSION_MINOR != Minor || DB_VERSION_PATCH != Patch) { | |
7ab230d2 | 135 | printf("db.h and libdb are incompatible.\n") ; |
2cb64bf6 | 136 | exit(3); |
959f3c4c JH |
137 | } |
138 | ||
7ab230d2 | 139 | printf("db.h and libdb are compatible.\n") ; |
959f3c4c JH |
140 | |
141 | Version = DB_VERSION_MAJOR * 1000000 + DB_VERSION_MINOR * 1000 | |
142 | + DB_VERSION_PATCH ; | |
143 | ||
144 | /* needs to be >= 2.3.4 */ | |
145 | if (Version < 2003004) { | |
146 | /* if (DB_VERSION_MAJOR == 2 && DB_VERSION_MINOR == 0 && DB_VERSION_PATCH < 5) { */ | |
7ab230d2 | 147 | printf("Perl needs Berkeley DB 2.3.4 or greater.\n") ; |
2cb64bf6 | 148 | exit(2); |
959f3c4c JH |
149 | } |
150 | ||
151 | exit(0); | |
152 | #else | |
153 | #if defined(_DB_H_) && defined(BTREEMAGIC) && defined(HASHMAGIC) | |
7ab230d2 JH |
154 | if (argc == 2) { |
155 | printf("1 0 0\n"); | |
156 | exit(0); | |
157 | } | |
158 | printf("You have Berkeley DB Version 1.\n"); | |
959f3c4c JH |
159 | exit(0); /* DB version < 2: the coast is clear. */ |
160 | #else | |
161 | exit(1); /* <db.h> not Berkeley DB? */ | |
162 | #endif | |
163 | #endif | |
164 | } | |
165 | EOCP | |
166 | set try | |
0f00356b | 167 | if eval $compile_ok && $run ./try; then |
959f3c4c | 168 | echo 'Looks OK.' >&4 |
0f00356b | 169 | set `$run ./try 1` |
7ab230d2 JH |
170 | db_version_major=$1 |
171 | db_version_minor=$2 | |
172 | db_version_patch=$3 | |
959f3c4c JH |
173 | else |
174 | echo "I can't use Berkeley DB with your <db.h>. I'll disable Berkeley DB." >&4 | |
175 | i_db=$undef | |
176 | case " $libs " in | |
177 | *"-ldb "*) | |
178 | : Remove db from list of libraries to use | |
179 | echo "Removing unusable -ldb from library list" >&4 | |
180 | set `echo X $libs | $sed -e 's/-ldb / /' -e 's/-ldb$//'` | |
181 | shift | |
182 | libs="$*" | |
183 | echo "libs = $libs" >&4 | |
184 | ;; | |
185 | esac | |
186 | fi | |
2cb64bf6 | 187 | $rm_try |
959f3c4c JH |
188 | ;; |
189 | esac | |
190 | ||
191 | @if DB_Hash_t | |
192 | case "$i_db" in | |
193 | define) | |
2cb64bf6 | 194 | : Check the return type needed for hash |
959f3c4c JH |
195 | echo " " |
196 | echo "Checking return type needed for hash for Berkeley DB ..." >&4 | |
197 | $cat >try.c <<EOCP | |
198 | #$d_const HASCONST | |
199 | #ifndef HASCONST | |
200 | #define const | |
201 | #endif | |
202 | #include <sys/types.h> | |
203 | #include <db.h> | |
204 | ||
205 | #ifndef DB_VERSION_MAJOR | |
16cf711a | 206 | u_int32_t hash_cb (const void* ptr, size_t size) |
959f3c4c JH |
207 | { |
208 | } | |
209 | HASHINFO info; | |
210 | int main() | |
211 | { | |
212 | info.hash = hash_cb; | |
213 | } | |
214 | #endif | |
215 | EOCP | |
216 | if $cc $ccflags -c try.c >try.out 2>&1 ; then | |
217 | if $contains warning try.out >>/dev/null 2>&1 ; then | |
218 | db_hashtype='int' | |
219 | else | |
220 | db_hashtype='u_int32_t' | |
221 | fi | |
222 | else | |
223 | : XXX Maybe we should just give up here. | |
224 | db_hashtype=u_int32_t | |
225 | $cat try.out >&4 | |
226 | echo "Help: I can't seem to compile the db test program." >&4 | |
227 | echo "Something's wrong, but I'll assume you use $db_hashtype." >&4 | |
228 | fi | |
2cb64bf6 | 229 | $rm_try |
959f3c4c JH |
230 | echo "Your version of Berkeley DB uses $db_hashtype for hash." |
231 | ;; | |
232 | *) db_hashtype=u_int32_t | |
233 | ;; | |
234 | esac | |
235 | @end | |
236 | @if DB_Prefix_t | |
237 | case "$i_db" in | |
238 | define) | |
2cb64bf6 | 239 | : Check the return type needed for prefix |
959f3c4c JH |
240 | echo " " |
241 | echo "Checking return type needed for prefix for Berkeley DB ..." >&4 | |
242 | cat >try.c <<EOCP | |
243 | #$d_const HASCONST | |
244 | #ifndef HASCONST | |
245 | #define const | |
246 | #endif | |
247 | #include <sys/types.h> | |
248 | #include <db.h> | |
249 | ||
250 | #ifndef DB_VERSION_MAJOR | |
16cf711a | 251 | size_t prefix_cb (const DBT *key1, const DBT *key2) |
959f3c4c JH |
252 | { |
253 | } | |
254 | BTREEINFO info; | |
255 | int main() | |
256 | { | |
257 | info.prefix = prefix_cb; | |
258 | } | |
259 | #endif | |
260 | EOCP | |
261 | if $cc $ccflags -c try.c >try.out 2>&1 ; then | |
262 | if $contains warning try.out >>/dev/null 2>&1 ; then | |
263 | db_prefixtype='int' | |
264 | else | |
265 | db_prefixtype='size_t' | |
266 | fi | |
267 | else | |
268 | db_prefixtype='size_t' | |
269 | : XXX Maybe we should just give up here. | |
270 | $cat try.out >&4 | |
271 | echo "Help: I can't seem to compile the db test program." >&4 | |
272 | echo "Something's wrong, but I'll assume you use $db_prefixtype." >&4 | |
273 | fi | |
2cb64bf6 | 274 | $rm_try |
959f3c4c JH |
275 | echo "Your version of Berkeley DB uses $db_prefixtype for prefix." |
276 | ;; | |
277 | *) db_prefixtype='size_t' | |
278 | ;; | |
279 | esac | |
959f3c4c | 280 | @end |
2cb64bf6 | 281 |