Index: subversion/libsvn_fs_base/fs.c
===================================================================
--- subversion/libsvn_fs_base/fs.c	(revision 31974)
+++ subversion/libsvn_fs_base/fs.c	(working copy)
@@ -917,11 +917,9 @@ svn_fs_base__clean_logs(const char *live_path,
 }
 
 
-/* ### There -must- be a more elegant way to do a compile-time check
-       for BDB 4.2 or later.  We're doing this because apparently
-       env->get_flags() and DB->get_pagesize() don't exist in earlier
-       versions of BDB.  */
-#ifdef DB_LOG_AUTOREMOVE
+/* env->get_flags() and DB->get_pagesize() don't exist prior to
+   Berkeley DB 4.2. */
+#if DB_VERSION_MINOR >= 2
 
 /* Open the BDB environment at PATH and compare its configuration
    flags with FLAGS.  If every flag in FLAGS is set in the
@@ -933,16 +931,28 @@ check_env_flags(svn_boolean_t *match,
                 apr_pool_t *pool)
 {
   bdb_env_baton_t *bdb;
+#if DB_VERSION_MINOR >= 7
+  int flag_state;
+#else
   u_int32_t envflags;
+#endif
 
   SVN_ERR(svn_fs_bdb__open(&bdb, path,
                            SVN_BDB_STANDARD_ENV_FLAGS,
                            0666, pool));
+#if DB_VERSION_MINOR >= 7
+  SVN_BDB_ERR(bdb, bdb->env->log_get_config(bdb->env, flags, &flag_state));
+#else
+  SVN_BDB_ERR(bdb, bdb->env->get_flags(bdb->env, &envflags));
+#endif
 
-  SVN_BDB_ERR(bdb, bdb->env->get_flags(bdb->env, &envflags));
   SVN_ERR(svn_fs_bdb__close(bdb));
 
+#if DB_VERSION_MINOR >= 7
+  if (flag_state == 0)
+#else
   if (flags & envflags)
+#endif
     *match = TRUE;
   else
     *match = FALSE;
@@ -977,7 +987,7 @@ get_db_pagesize(u_int32_t *pagesize,
 
   return svn_fs_bdb__close(bdb);
 }
-#endif /* DB_LOG_AUTOREMOVE */
+#endif /* DB_VERSION_MINOR >= 2 */
 
 
 /* Copy FILENAME from SRC_DIR to DST_DIR in byte increments of size
@@ -1084,15 +1094,19 @@ base_hotcopy(const char *src_path,
           (&format, svn_path_join(src_path, FORMAT_FILE, pool), pool));
   SVN_ERR(check_format(format));
 
-  /* If using DB 4.2 or later, note whether the DB_LOG_AUTOREMOVE
+  /* If using Berkeley DB 4.2 or later, note whether the DB_LOG_AUTO_REMOVE
      feature is on.  If it is, we have a potential race condition:
      another process might delete a logfile while we're in the middle
      of copying all the logfiles.  (This is not a huge deal; at worst,
      the hotcopy fails with a file-not-found error.) */
-#ifdef DB_LOG_AUTOREMOVE
-  SVN_ERR(check_env_flags(&log_autoremove, DB_LOG_AUTOREMOVE,
+  SVN_ERR(check_env_flags(&log_autoremove,
+#if DB_VERSION_MINOR >= 7
+                          DB_LOG_AUTO_REMOVE,
+ /* DB_LOG_AUTO_REMOVE was named DB_LOG_AUTOREMOVE before Berkeley DB 4.7. */
+#elif DB_VERSION_MINOR >= 2
+                          DB_LOG_AUTOREMOVE,
+#endif
                           src_path, pool));
-#endif
 
   /* Copy the DB_CONFIG file. */
   SVN_ERR(svn_io_dir_file_copy(src_path, dest_path, "DB_CONFIG", pool));
@@ -1100,7 +1114,7 @@ base_hotcopy(const char *src_path,
   /* In order to copy the database files safely and atomically, we
      must copy them in chunks which are multiples of the page-size
      used by BDB.  See sleepycat docs for details, or svn issue #1818. */
-#ifdef DB_LOG_AUTOREMOVE
+#if DB_VERSION_MINOR >= 2
   SVN_ERR(get_db_pagesize(&pagesize, src_path, pool));
   if (pagesize < SVN__STREAM_CHUNK_SIZE)
     {
Index: build/generator/gen_win.py
===================================================================
--- build/generator/gen_win.py	(revision 31974)
+++ build/generator/gen_win.py	(working copy)
@@ -142,7 +142,7 @@ class GeneratorBase(gen_base.GeneratorBase):
 
   def _find_bdb(self):
     "Find the Berkeley DB library and version"
-    for ver in ("46", "45", "44", "43", "42", "41", "40"):
+    for ver in ("47", "46", "45", "44", "43", "42", "41", "40"):
       lib = "libdb" + ver
       path = os.path.join(self.bdb_path, "lib")
       if os.path.exists(os.path.join(path, lib + ".lib")):

