--- configure
+++ configure
@@ -14594,6 +14594,7 @@
 rm -f core conftest.err conftest.$ac_objext conftest.beam \
     conftest$ac_exeext conftest.$ac_ext
 
+if test "$enable_pcregrep_libz" = "yes"; then
 # Check for the availability of libz (aka zlib)
 
        for ac_header in zlib.h
@@ -14645,8 +14646,10 @@
 then :
   HAVE_LIBZ=1
 fi
+fi
 
 
+if test "$enable_pcregrep_libbz2" = "yes"; then
 # Check for the availability of libbz2. Originally we just used AC_CHECK_LIB,
 # as for libz. However, this had the following problem, diagnosed and fixed by
 # a user:
@@ -14707,6 +14710,7 @@
 rm -f core conftest.err conftest.$ac_objext conftest.beam \
     conftest$ac_exeext conftest.$ac_ext
 LIBS="$OLD_LIBS"
+fi
 
 # Check for the availabiity of libreadline
 
