configure: error out as early as possible on build = source directory

Message ID 13f29dc9-4069-6ca5-d7bd-79246defe2bd@owlfolio.org
State New
Headers
Series configure: error out as early as possible on build = source directory |

Checks

Context Check Description
dj/TryBot-apply_patch fail Patch failed to apply to master at the time it was sent
dj/TryBot-32bit fail Patch series failed to apply
redhat-pt-bot/TryBot-still_applies warning Patch no longer applies to master

Commit Message

Zack Weinberg March 22, 2023, 4:17 p.m. UTC
  Related to the discussion at 
<https://sourceware.org/pipermail/libc-alpha/2023-March/146542.html>, if 
someone makes the mistake of running configure in the source directory 
(i.e. attempting to set up to build within the source tree, which we 
don't support) configure should error out as quickly as possible, rather 
than making this hypothetical someone sit through a bunch of compiler 
checks first.

(Ideally we would validate _everything_ about the way configure has been 
invoked before doing any other work, but the other places where we have 
an AC_MSG_ERROR as a response to something about the invocation look 
significantly harder to change.)

Completely untested as I don't have convenient access to a machine with 
autoconf 2.69 at the moment.

zw

  AC_PROG_CC
@@ -80,10 +88,6 @@ LDFLAGS="$old_LDFLAGS"
  AC_LANG_POP([C++])])
  AS_IF([test $libc_cv_cxx_link_ok != yes], [CXX=])

-if test "`cd $srcdir; pwd -P`" = "`pwd -P`"; then
-  AC_MSG_ERROR([you must configure in a separate build directory])
-fi
-
  # This will get text that should go into config.make.
  config_vars=

--
2.34.1
  

Patch

diff --git a/configure.ac b/configure.ac
index 011844a3d4..afaedfb056 100644
--- a/configure.ac
+++ b/configure.ac
@@ -43,6 +43,14 @@  AC_DEFUN([_AC_PROG_CC_C89], [[$1]])
  dnl This is here so we can set $subdirs directly based on configure 
fragments.
  AC_CONFIG_SUBDIRS()

+# Validate the build directory as early as possible, so that someone
+# who's made the mistake of casually typing "./configure" in the source
+# directory doesn't have to wait for autoconf to probe a bunch of stuff
+# before it gets around to telling them they made a mistake.
+AS_IF(["`cd $srcdir && pwd -P`" = "`pwd -P`"],
+  [AC_MSG_ERROR([you must configure in a separate build directory])
+])
+
  AC_CANONICAL_HOST