--- configure
+++ configure
@@ -18627,6 +18627,7 @@
 done
 
 
+if test "$enable_pcregrep_libz" = "yes"; then
 # Check for the availability of libz (aka zlib)
 
 for ac_header in zlib.h
@@ -18680,8 +18681,10 @@
 if test "x$ac_cv_lib_z_gzopen" = xyes; 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:
@@ -18743,6 +18746,7 @@
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
 LIBS="$OLD_LIBS"
+fi
 
 # Check for the availabiity of libreadline
 
