?RCS: $Id: i_db.U,v 3.0.1.3 1995/07/25 14:10:22 ram Exp $
?RCS:
?RCS: Copyright (c) 1991-1993, Raphael Manfredi
?RCS:
?RCS: You may redistribute only under the terms of the Artistic License,
?RCS: as specified in the README file that comes with the distribution.
?RCS: You may reuse parts of this distribution only within the terms of
?RCS: that same Artistic License; a copy of which may be found at the root
?RCS: of the source tree for dist 3.0.
?RCS:
?RCS: Original Author: Andy Dougherty <doughera@lafcol.lafayette.edu>
?RCS:
?RCS: $Log: i_db.U,v $
?RCS: Revision 3.0.1.3  1995/07/25  14:10:22  ram
?RCS: patch56: conditionally use const in test programs (ADO)
?RCS:
?RCS: Revision 3.0.1.2  1995/05/12  12:14:42  ram
?RCS: patch54: extended for more intimate DB probing (ADO)
?RCS:
?RCS: Revision 3.0.1.1  1994/08/29  16:21:50  ram
?RCS: patch32: created by ADO
?RCS:
?MAKE:i_db db_hashtype db_prefixtype \
	db_version_major db_version_minor db_version_patch : \
	Inhdr +cc +ccflags rm_try compiler_warning cat \
	Compile libs sed run i_stdlib
?MAKE:	-pick add $@ %<
?S:i_db:
?S:	This variable conditionally defines the I_DB symbol, and indicates
?S:	whether a C program may include Berkeley's DB include file <db.h>.
?S:.
?S:db_hashtype:
?S:	This variable contains the type of the hash structure element
?S:	in the <db.h> header file.  In older versions of DB, it was
?S:	int, while in newer ones it is u_int32_t.
?S:.
?S:db_prefixtype:
?S:	This variable contains the type of the prefix structure element
?S:	in the <db.h> header file.  In older versions of DB, it was
?S:	int, while in newer ones it is size_t.
?S:.
?S:db_version_major:
?S:	This variable contains the major version number of
?S:	Berkeley DB found in the <db.h> header file.
?S:.
?S:db_version_minor:
?S:	This variable contains the minor version number of
?S:	Berkeley DB found in the <db.h> header file.
?S:	For DB version 1 this is always 0.
?S:.
?S:db_version_patch:
?S:	This variable contains the patch version number of
?S:	Berkeley DB found in the <db.h> header file.
?S:	For DB version 1 this is always 0.
?S:.
?C:I_DB:
?C:	This symbol, if defined, indicates to the C program that it should
?C:	include Berkeley's DB include file <db.h>.
?C:.
?C:DB_Prefix_t:
?C:	This symbol contains the type of the prefix structure element
?C:	in the <db.h> header file.  In older versions of DB, it was
?C:	int, while in newer ones it is u_int32_t.
?C:.
?C:DB_Hash_t:
?C:	This symbol contains the type of the prefix structure element
?C:	in the <db.h> header file.  In older versions of DB, it was
?C:	int, while in newer ones it is size_t.
?C:.
?C:DB_VERSION_MAJOR_CFG:
?C:	This symbol, if defined, defines the major version number of
?C:	Berkeley DB found in the <db.h> header when Perl was configured.
?C:.
?C:DB_VERSION_MINOR_CFG:
?C:	This symbol, if defined, defines the minor version number of
?C:	Berkeley DB found in the <db.h> header when Perl was configured.
?C:	For DB version 1 this is always 0.
?C:.
?C:DB_VERSION_PATCH_CFG:
?C:	This symbol, if defined, defines the patch version number of
?C:	Berkeley DB found in the <db.h> header when Perl was configured.
?C:	For DB version 1 this is always 0.
?C:.
?H:#$i_db I_DB		/**/
?H:#define DB_Hash_t	$db_hashtype		/**/
?H:#define DB_Prefix_t	$db_prefixtype		/**/
?H:#define DB_VERSION_MAJOR_CFG	$db_version_major	/**/
?H:#define DB_VERSION_MINOR_CFG	$db_version_minor	/**/
?H:#define DB_VERSION_PATCH_CFG	$db_version_patch	/**/
?H:.
?F:!try
?LINT:change libs
: see if this is a db.h system
set db.h i_db
eval $inhdr

case "$i_db" in
$define)
	: Check db version.
	echo " "
	echo "Checking Berkeley DB version ..." >&4
	$cat >try.c <<EOCP
#include <sys/types.h>
#include <stdio.h>
#$i_stdlib I_STDLIB
#ifdef I_STDLIB
#include <stdlib.h>
#endif
#include <db.h>
int main(int argc, char *argv[])
{
#ifdef DB_VERSION_MAJOR	/* DB version >= 2 */
    int Major, Minor, Patch ;
    unsigned long Version ;
    (void)db_version(&Major, &Minor, &Patch) ;
    if (argc == 2) {
        printf("%d %d %d %d %d %d\n",
               DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH,
               Major, Minor, Patch);
        exit(0);
    }
    printf("You have Berkeley DB Version 2 or greater.\n");

    printf("db.h is from Berkeley DB Version %d.%d.%d\n",
		DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH);
    printf("libdb is from Berkeley DB Version %d.%d.%d\n",
		Major, Minor, Patch) ;

    /* check that db.h & libdb are compatible */
    if (DB_VERSION_MAJOR != Major || DB_VERSION_MINOR != Minor || DB_VERSION_PATCH != Patch) {
	printf("db.h and libdb are incompatible.\n") ;
        exit(3);
    }

    printf("db.h and libdb are compatible.\n") ;

    Version = DB_VERSION_MAJOR * 1000000 + DB_VERSION_MINOR * 1000
		+ DB_VERSION_PATCH ;

    /* needs to be >= 2.3.4 */
    if (Version < 2003004) {
    /* if (DB_VERSION_MAJOR == 2 && DB_VERSION_MINOR == 0 && DB_VERSION_PATCH < 5) { */
	printf("Perl needs Berkeley DB 2.3.4 or greater.\n") ;
        exit(2);
    }

    exit(0);
#else
#if defined(_DB_H_) && defined(BTREEMAGIC) && defined(HASHMAGIC)
    if (argc == 2) {
        printf("1 0 0\n");
        exit(0);
    }
    printf("You have Berkeley DB Version 1.\n");
    exit(0);	/* DB version < 2: the coast is clear. */
#else
    exit(1);	/* <db.h> not Berkeley DB? */
#endif
#endif
}
EOCP
	set try
	if eval $compile_ok && $run ./try; then
		echo 'Looks OK.' >&4
		set `$run ./try 1`
		db_version_major=$1
		db_version_minor=$2
		db_version_patch=$3
	else
		echo "I can't use Berkeley DB with your <db.h>.  I'll disable Berkeley DB." >&4
		i_db=$undef
		case " $libs " in
		*"-ldb "*)
			: Remove db from list of libraries to use
			echo "Removing unusable -ldb from library list" >&4
			set `echo X $libs | $sed -e 's/-ldb / /' -e 's/-ldb$//'`
			shift
			libs="$*"
			echo "libs = $libs" >&4
			;;
		esac
	fi
	$rm_try
	;;
esac

@if DB_Hash_t
case "$i_db" in
define)
	: Check the return type needed for hash
	echo " "
	echo "Checking return type needed for hash for Berkeley DB ..." >&4
	$cat >try.c <<EOCP
#include <sys/types.h>
#include <db.h>

#ifndef DB_VERSION_MAJOR
u_int32_t hash_cb (const void* ptr, size_t size)
{
	return 0;
}
HASHINFO info;
int main()
{
	info.hash = hash_cb;
}
#endif
EOCP
	if $cc $ccflags -c try.c >try.out 2>&1 ; then
		if $compiler_warning try.out >>/dev/null 2>&1 ; then
			db_hashtype='int'
		else
			db_hashtype='u_int32_t'
		fi
	else
		: XXX Maybe we should just give up here.
		db_hashtype=u_int32_t
		$cat try.out >&4
		echo "Help:  I can't seem to compile the db test program." >&4
		echo "Something's wrong, but I'll assume you use $db_hashtype." >&4
	fi
	$rm_try
	echo "Your version of Berkeley DB uses $db_hashtype for hash."
	;;
*)	db_hashtype=u_int32_t
	;;
esac
@end
@if DB_Prefix_t
case "$i_db" in
define)
	: Check the return type needed for prefix
	echo " "
	echo "Checking return type needed for prefix for Berkeley DB ..." >&4
	cat >try.c <<EOCP
#include <sys/types.h>
#include <db.h>

#ifndef DB_VERSION_MAJOR
size_t prefix_cb (const DBT *key1, const DBT *key2)
{
	return 0;
}
BTREEINFO info;
int main()
{
	info.prefix = prefix_cb;
}
#endif
EOCP
	if $cc $ccflags -c try.c  >try.out 2>&1 ; then
		if $compiler_warning try.out >>/dev/null 2>&1 ; then
			db_prefixtype='int'
		else
			db_prefixtype='size_t'
		fi
	else
		db_prefixtype='size_t'
		: XXX Maybe we should just give up here.
		$cat try.out >&4
		echo "Help:  I can't seem to compile the db test program." >&4
		echo "Something's wrong, but I'll assume you use $db_prefixtype." >&4
	fi
	$rm_try
	echo "Your version of Berkeley DB uses $db_prefixtype for prefix."
	;;
*)	db_prefixtype='size_t'
	;;
esac
@end

