Skip to content

Commit

Permalink
Support building rpm without Berkeley DB, simplify the configuration
Browse files Browse the repository at this point in the history
Replace the --with-external-db switch with the following simple logic:
if internal copy of BDB is detected, use it, otherwise look for an
external one. By default BDB is still required, but it's now possible
to build without it by using --disable-bdb argument to configure.
If no database is built in, we'll segfault for now, to be dealt with
in coming commits.

This is a rather historical moment, BTW.
  • Loading branch information
pmatilai committed Feb 1, 2019
1 parent 815a362 commit e1d3811
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 62 deletions.
6 changes: 3 additions & 3 deletions INSTALL
Expand Up @@ -67,12 +67,12 @@ distinct advantages and disadvantages:
hand, major BDB upgrades can be disruptive, especially if
the on-disk format changes somehow.

To use this method, simply pass in --with-external-db to ./configure
script. If the system BDB is installed outside compiler + linker default
This method is the default if no "db" link exists in the top directory.
If the system BDB is installed outside compiler + linker default
paths, you can use CPPFLAGS and LDFLAGS to tell configure where to look,
for example:

$ ./configure --with-external-db CPPFLAGS=-I/usr/include/db45
$ ./configure CPPFLAGS=-I/usr/include/db45

Minimal instructions for building BDB are
cd build_unix
Expand Down
2 changes: 1 addition & 1 deletion Makefile.am
Expand Up @@ -2,7 +2,7 @@

ACLOCAL_AMFLAGS = -I m4

DISTCHECK_CONFIGURE_FLAGS = --with-external-db --enable-python
DISTCHECK_CONFIGURE_FLAGS = --enable-python

include $(top_srcdir)/rpm.am
AM_CFLAGS = @RPMCFLAGS@
Expand Down
93 changes: 36 additions & 57 deletions configure.ac
Expand Up @@ -498,63 +498,47 @@ AM_CONDITIONAL(LIBDW,[test "$WITH_LIBDW" = yes])
AM_CONDITIONAL(HAVE_LIBDW_STRTAB,[test "$HAVE_LIBDW_STRTAB" = yes])

#=================
# Process --with/without-external-db
AC_ARG_WITH(external_db, [AS_HELP_STRING([--with-external-db],[build against an external Berkeley db])],
[case "$with_external_db" in
yes|no) ;;
*) AC_MSG_ERROR([invalid argument to --with-external-db]) ;;
esac],
[with_external_db=maybe])

case "$with_external_db" in
yes )
AC_CHECK_HEADERS([db.h],[
AC_PREPROC_IFELSE([
AC_LANG_SOURCE([
#include <db.h>
#if ((DB_VERSION_MAJOR < 4) || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 5))
#error Berkeley DB too old
#endif
])
],[ WITH_DB_LIB=-ldb ],
[ AC_MSG_ERROR([Berkeley DB version >= 4.5 required])
])
],[
AC_MSG_ERROR([missing required header db.h])
])
;;
no|maybe )
# Try internal database first, then fall back to external
# unless --without-external-db (no) was explicitly given.
# Check for BDB support
AC_ARG_ENABLE([bdb],
[AS_HELP_STRING([--enable-bdb=@<:@yes/no/auto@:>@],
[build with Berkeley DB rpm database format support (default=yes)])],
[enable_bdb="$enableval"],
[enable_bdb=yes])

AS_IF([test "x$enable_bdb" != "xno"], [
if [ test -x db/dist/configure ]; then
with_external_db=no
have_bdb="internal"
else
case "$with_external_db" in
maybe)
AC_CHECK_HEADERS([db.h],[
AC_PREPROC_IFELSE([
AC_LANG_SOURCE([
#include <db.h>
#if ((DB_VERSION_MAJOR < 4) || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 5))
#error Berkeley DB too old
#endif
])
],[ WITH_DB_LIB=-ldb ],
[ AC_MSG_ERROR([Berkeley DB version >= 4.5 required])
have_bdb="no"
AC_CHECK_HEADERS([db.h],[
AC_PREPROC_IFELSE([
AC_LANG_SOURCE([
#include <db.h>
#if ((DB_VERSION_MAJOR < 4) || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 5))
#error Berkeley DB too old
#endif
])
],[
AC_MSG_ERROR([missing required header db.h])
])
;;
no)
AC_MSG_ERROR([internal Berkeley DB directory not present, see INSTALL])
;;
esac
],[ have_bdb="yes" ])
])
fi
;;
esac
AC_MSG_CHECKING(for Berkeley DB >= 4.5)
AC_MSG_RESULT($have_bdb)
AS_IF([test "x$enable_bdb" = "xyes"], [
if test "x$have_bdb" = "xno"; then
AC_MSG_ERROR([--enable-bdb specified, but not available])
fi
AC_DEFINE([WITH_BDB], [1], [Define if BDB is available])
WITH_DB_LIB=-ldb
AC_SUBST([WITH_DB_LIB])
])
])

AM_CONDITIONAL([BDB], [test "x$have_bdb" != "xno"])
AM_CONDITIONAL([WITH_INTERNAL_DB],[test "x$have_bdb" = "xinternal"])
if test "x$have_bdb" = "xinternal"; then
AC_CONFIG_SUBDIRS(db3)
fi

AC_SUBST([WITH_DB_LIB])

#=================
# Process --enable-ndb
Expand Down Expand Up @@ -1052,11 +1036,6 @@ AC_SUBST(RPMCONFIGDIR)

AC_SUBST(OBJDUMP)

if test "$with_external_db" = no; then
AC_CONFIG_SUBDIRS(db3)
fi

AM_CONDITIONAL([WITH_INTERNAL_DB],[test "$with_external_db" = no])
AM_CONDITIONAL([DOXYGEN],[test "$DOXYGEN" != no])
AM_CONDITIONAL([HACKINGDOCS],[test "$with_hackingdocs" = yes])

Expand Down
5 changes: 4 additions & 1 deletion lib/Makefile.am
Expand Up @@ -24,7 +24,7 @@ EXTRA_PROGRAMS =

usrlib_LTLIBRARIES = librpm.la
librpm_la_SOURCES = \
backend/db3.c backend/dbi.c backend/dbi.h \
backend/dbi.c backend/dbi.h \
backend/dbiset.c backend/dbiset.h \
headerutil.c header.c headerfmt.c header_internal.h \
rpmdb.c rpmdb_internal.h \
Expand Down Expand Up @@ -59,11 +59,14 @@ librpm_la_LIBADD += @LUA_LIBS@
librpm_la_SOURCES += rpmliblua.c rpmliblua.h
endif

if BDB
if WITH_INTERNAL_DB
librpm_la_SOURCES += backend/db3.c
librpm_la_LIBADD += $(libdb_la)
else
librpm_la_LIBADD += @WITH_DB_LIB@
endif
endif

if NDB
librpm_la_SOURCES += \
Expand Down
4 changes: 4 additions & 0 deletions lib/backend/dbi.c
Expand Up @@ -49,13 +49,15 @@ dbDetectBackend(rpmdb rdb)
rdb->db_ops = &ndb_dbops;
} else
#endif
#if defined(WITH_BDB)
{
rdb->db_ops = &db3_dbops;
if (*db_backend == '\0') {
free(db_backend);
db_backend = xstrdup("bdb");
}
}
#endif

#if defined(WITH_LMDB)
path = rstrscat(NULL, dbhome, "/data.mdb", NULL);
Expand All @@ -75,12 +77,14 @@ dbDetectBackend(rpmdb rdb)
free(path);
#endif

#if defined(WITH_BDB)
path = rstrscat(NULL, dbhome, "/Packages", NULL);
if (access(path, F_OK) == 0 && rdb->db_ops != &db3_dbops) {
rdb->db_ops = &db3_dbops;
rpmlog(RPMLOG_WARNING, _("Found BDB Packages database while attempting %s backend: using bdb backend.\n"), db_backend);
}
free(path);
#endif

if (db_backend)
free(db_backend);
Expand Down
2 changes: 2 additions & 0 deletions lib/backend/dbi.h
Expand Up @@ -262,8 +262,10 @@ struct rpmdbOps_s {
const void * (*idxdbKey)(dbiIndex dbi, dbiCursor dbc, unsigned int *keylen);
};

#if defined(WITH_BDB)
RPM_GNUC_INTERNAL
extern struct rpmdbOps_s db3_dbops;
#endif

#ifdef ENABLE_NDB
RPM_GNUC_INTERNAL
Expand Down

0 comments on commit e1d3811

Please sign in to comment.