diff --git a/config/programs.m4 b/config/programs.m4
index 5fa03c3..f43db4d 100644
--- a/config/programs.m4
+++ b/config/programs.m4
@@ -34,12 +34,23 @@ if test "$BISON"; then
 fi
 
 if test -z "$BISON"; then
-  AC_MSG_WARN([
+  if test "$cross_compiling" != "yes"; then
+    PGAC_TEST_GENERATED_FILES
+  fi
+  if test x"$generated_missing" = x"yes"; then
+    AC_MSG_ERROR([
+*** Without Bison you will not be able to build PostgreSQL from Git nor
+*** change any of the parser definition files.  You can obtain Bison from
+*** a GNU mirror site. You can also download the official distribution of
+*** PostgreSQL which contains the Bison output pre-generated.])
+  else
+    AC_MSG_WARN([
 *** Without Bison you will not be able to build PostgreSQL from Git nor
 *** change any of the parser definition files.  You can obtain Bison from
 *** a GNU mirror site.  (If you are using the official distribution of
 *** PostgreSQL then you do not need to worry about this, because the Bison
 *** output is pre-generated.)])
+  fi
 fi
 # We don't need AC_SUBST(BISON) because AC_PATH_PROG did it
 AC_SUBST(BISONFLAGS)
@@ -96,13 +107,23 @@ fi
 ])[]dnl AC_CACHE_CHECK
 
 if test x"$pgac_cv_path_flex" = x"no"; then
-  AC_MSG_WARN([
+  if test "$cross_compiling" != "yes"; then
+    PGAC_TEST_GENERATED_FILES
+  fi
+  if test x"$generated_missing" = x"yes"; then
+    AC_MSG_ERROR([
+*** Without Flex you will not be able to build PostgreSQL from Git nor
+*** change any of the scanner definition files.  You can obtain Flex from
+*** a GNU mirror site. You can also download the official distribution of
+*** PostgreSQL which contains the Flex output pre-generated.])
+  else
+    AC_MSG_WARN([
 *** Without Flex you will not be able to build PostgreSQL from Git nor
 *** change any of the scanner definition files.  You can obtain Flex from
 *** a GNU mirror site.  (If you are using the official distribution of
-*** PostgreSQL then you do not need to worry about this because the Flex
+*** PostgreSQL then you do not need to worry about this, because the Flex
 *** output is pre-generated.)])
-
+  fi
   FLEX=
 else
   FLEX=$pgac_cv_path_flex
@@ -116,6 +137,32 @@ AC_SUBST(FLEXFLAGS)
 
 
 
+# PGAC_TEST_GENERATED_FILES
+# -------------------------
+# Test for the existence of the required generated files in case we don't
+# find a working installation of flex/bison on the system. If the source tree
+# is from an official distribution the files are pre-generated and we can
+# proceed even without flex/bison.
+
+AC_DEFUN([PGAC_TEST_GENERATED_FILES],
+[
+  AC_CHECK_FILES([
+    src/backend/parser/gram.c
+    src/backend/parser/gram.h
+    src/backend/parser/scan.c
+    src/pl/plpgsql/src/pl_gram.c
+    src/pl/plpgsql/src/pl_gram.h
+    src/pl/plpgsql/src/plerrcodes.h
+    src/interfaces/ecpg/preproc/preproc.y
+    src/interfaces/ecpg/preproc/preproc.c
+    src/interfaces/ecpg/preproc/preproc.h
+    src/interfaces/ecpg/preproc/pgc.c
+  ],,generated_missing="yes")
+  AC_MSG_RESULT($generated_missing)
+]) # PGAC_TEST_GENERATED_FILES
+
+
+
 # PGAC_LDAP_SAFE
 # --------------
 # PostgreSQL sometimes loads libldap_r and plain libldap into the same
