This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Even better use64bitall logic.
[metaconfig.git] / U / perl / i_db.U
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
4 ?RCS: 
5 ?RCS: You may redistribute only under the terms of the Artistic Licence,
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
8 ?RCS: that same Artistic Licence; a copy of which may be found at the root
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:
23 ?MAKE:i_db db_hashtype db_prefixtype: Inhdr +cc +ccflags rm contains cat \
24                 Compile d_const libs sed
25 ?MAKE:  -pick add $@ %<
26 ?S:i_db:
27 ?S:     This variable conditionally defines the I_DB symbol, and indicates
28 ?S:     whether a C program may include Berkeley's DB include file <db.h>.
29 ?S:.
30 ?S:db_hashtype:
31 ?S:     This variable contains the type of the hash structure element
32 ?S:     in the <db.h> header file.  In older versions of DB, it was
33 ?S:     int, while in newer ones it is u_int32_t.
34 ?S:.
35 ?S:db_prefixtype:
36 ?S:     This variable contains the type of the prefix structure element
37 ?S:     in the <db.h> header file.  In older versions of DB, it was
38 ?S:     int, while in newer ones it is size_t.
39 ?S:.
40 ?C:I_DB:
41 ?C:     This symbol, if defined, indicates to the C program that it should
42 ?C:     include Berkeley's DB include file <db.h>.
43 ?C:.
44 ?C:DB_Prefix_t:
45 ?C:     This symbol contains the type of the prefix structure element
46 ?C:     in the <db.h> header file.  In older versions of DB, it was
47 ?C:     int, while in newer ones it is u_int32_t.
48 ?C:.
49 ?C:DB_Hash_t:
50 ?C:     This symbol contains the type of the prefix structure element
51 ?C:     in the <db.h> header file.  In older versions of DB, it was
52 ?C:     int, while in newer ones it is size_t.
53 ?C:.
54 ?H:#$i_db I_DB          /**/
55 ?H:#define DB_Hash_t    $db_hashtype            /**/
56 ?H:#define DB_Prefix_t  $db_prefixtype          /**/
57 ?H:.
58 ?LINT:set i_db
59 ?LINT:change libs
60 : see if this is a db.h system
61 set db.h i_db
62 eval $inhdr
63
64 case "$i_db" in
65 $define)
66         : Check db version.
67         echo " "
68         echo "Checking Berkeley DB version ..." >&4
69         $cat >try.c <<EOCP
70 #$d_const HASCONST
71 #ifndef HASCONST
72 #define const
73 #endif
74 #include <sys/types.h>
75 #include <stdio.h>
76 #include <db.h>
77 int main()
78 {
79 #ifdef DB_VERSION_MAJOR /* DB version >= 2 */
80     int Major, Minor, Patch ;
81     unsigned long Version ;
82     (void)db_version(&Major, &Minor, &Patch) ;
83     printf("You have Berkeley DB Version 2 or greater\n");
84
85     printf("db.h is from Berkeley DB Version %d.%d.%d\n",
86                 DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH);
87     printf("libdb is from Berkeley DB Version %d.%d.%d\n",
88                 Major, Minor, Patch) ;
89
90     /* check that db.h & libdb are compatible */
91     if (DB_VERSION_MAJOR != Major || DB_VERSION_MINOR != Minor || DB_VERSION_PATCH != Patch) {
92         printf("db.h and libdb are incompatible\n") ;
93         exit(3);        
94     }
95
96     printf("db.h and libdb are compatible\n") ;
97
98     Version = DB_VERSION_MAJOR * 1000000 + DB_VERSION_MINOR * 1000
99                 + DB_VERSION_PATCH ;
100
101     /* needs to be >= 2.3.4 */
102     if (Version < 2003004) {
103     /* if (DB_VERSION_MAJOR == 2 && DB_VERSION_MINOR == 0 && DB_VERSION_PATCH < 5) { */
104         printf("but Perl needs Berkeley DB 2.3.4 or greater\n") ;
105         exit(2);        
106     }
107
108     exit(0);
109 #else
110 #if defined(_DB_H_) && defined(BTREEMAGIC) && defined(HASHMAGIC)
111     printf("You have Berkeley DB Version 1\n");
112     exit(0);    /* DB version < 2: the coast is clear. */
113 #else
114     exit(1);    /* <db.h> not Berkeley DB? */
115 #endif
116 #endif
117 }
118 EOCP
119         set try
120         if eval $compile_ok && ./try; then
121                 echo 'Looks OK.' >&4
122         else
123                 echo "I can't use Berkeley DB with your <db.h>.  I'll disable Berkeley DB." >&4
124                 i_db=$undef
125                 case " $libs " in
126                 *"-ldb "*)
127                         : Remove db from list of libraries to use
128                         echo "Removing unusable -ldb from library list" >&4
129                         set `echo X $libs | $sed -e 's/-ldb / /' -e 's/-ldb$//'`
130                         shift
131                         libs="$*"
132                         echo "libs = $libs" >&4
133                         ;;
134                 esac
135         fi
136         $rm -f try.*
137         ;;
138 esac
139
140 @if DB_Hash_t
141 case "$i_db" in
142 define)
143         : Check the return type needed for hash 
144         echo " "
145         echo "Checking return type needed for hash for Berkeley DB ..." >&4
146         $cat >try.c <<EOCP
147 #$d_const HASCONST
148 #ifndef HASCONST
149 #define const
150 #endif
151 #include <sys/types.h>
152 #include <db.h>
153
154 #ifndef DB_VERSION_MAJOR
155 u_int32_t hash_cb (ptr, size)
156 const void *ptr;
157 size_t size;
158 {
159 }
160 HASHINFO info;
161 int main()
162 {
163         info.hash = hash_cb;
164 }
165 #endif
166 EOCP
167         if $cc $ccflags -c try.c >try.out 2>&1 ; then
168                 if $contains warning try.out >>/dev/null 2>&1 ; then
169                         db_hashtype='int'
170                 else
171                         db_hashtype='u_int32_t'
172                 fi
173         else
174                 : XXX Maybe we should just give up here.
175                 db_hashtype=u_int32_t
176                 $cat try.out >&4
177                 echo "Help:  I can't seem to compile the db test program." >&4
178                 echo "Something's wrong, but I'll assume you use $db_hashtype." >&4
179         fi
180         $rm -f try.*
181         echo "Your version of Berkeley DB uses $db_hashtype for hash."
182         ;;
183 *)      db_hashtype=u_int32_t
184         ;;
185 esac
186 @end
187 @if DB_Prefix_t
188 case "$i_db" in
189 define)
190         : Check the return type needed for prefix 
191         echo " "
192         echo "Checking return type needed for prefix for Berkeley DB ..." >&4
193         cat >try.c <<EOCP
194 #$d_const HASCONST
195 #ifndef HASCONST
196 #define const
197 #endif
198 #include <sys/types.h>
199 #include <db.h>
200
201 #ifndef DB_VERSION_MAJOR
202 size_t prefix_cb (key1, key2)
203 const DBT *key1;
204 const DBT *key2;
205 {
206 }
207 BTREEINFO info;
208 int main()
209 {
210         info.prefix = prefix_cb;
211 }
212 #endif
213 EOCP
214         if $cc $ccflags -c try.c  >try.out 2>&1 ; then
215                 if $contains warning try.out >>/dev/null 2>&1 ; then
216                         db_prefixtype='int'
217                 else
218                         db_prefixtype='size_t'
219                 fi
220         else
221                 db_prefixtype='size_t'
222                 : XXX Maybe we should just give up here.
223                 $cat try.out >&4
224                 echo "Help:  I can't seem to compile the db test program." >&4
225                 echo "Something's wrong, but I'll assume you use $db_prefixtype." >&4
226         fi
227         $rm -f try.*
228         echo "Your version of Berkeley DB uses $db_prefixtype for prefix."
229         ;;
230 *)      db_prefixtype='size_t'
231         ;;
232 esac
233
234 @end