diff --git a/configure b/configure
index bd2de34..fba948a 100755
--- a/configure
+++ b/configure
@@ -3993,6 +3993,9 @@ for opt do
         --libfuzzer=*)
             libfuzzer_path="$optval"
         ;;
+        --debug)
+            enable debug_configure
+        ;;
         *)
             optname="${opt%%=*}"
             optname="${optname#--}"
@@ -6152,8 +6155,13 @@ fi
 
 enabled  zlib && { check_pkg_config zlib zlib "zlib.h" zlibVersion ||
                    check_lib zlib   zlib.h      zlibVersion    -lz; }
-enabled bzlib && check_lib bzlib bzlib.h BZ2_bzlibVersion    -lbz2
-enabled  lzma && check_lib lzma   lzma.h lzma_version_number -llzma
+if enabled debug_configure; then
+    enabled bzlib && check_lib bzlib bzlib.h BZ2_bzlibVersion    -lbz2d
+    enabled  lzma && check_lib lzma   lzma.h lzma_version_number -llzmad
+else
+    enabled bzlib && check_lib bzlib bzlib.h BZ2_bzlibVersion    -lbz2
+    enabled  lzma && check_lib lzma   lzma.h lzma_version_number -llzma
+fi
 
 # On some systems dynamic loading requires no extra linker flags
 check_lib libdl dlfcn.h "dlopen dlsym" || check_lib libdl dlfcn.h "dlopen dlsym" -ldl
