[RFA/gdb-9-branch] Abort configure immediately if building GDB in tree

Message ID 20200105073000.1012-1-brobecker@adacore.com
State New
Headers show
Series
  • [RFA/gdb-9-branch] Abort configure immediately if building GDB in tree
Related show

Commit Message

Joel Brobecker Jan. 5, 2020, 7:30 a.m.
Hello,

Following the discussions on the gdb@ mailing-list regarding
the fact that GDB 9 is not buildable when configured in tree,
I propose the following patch for the gdb-9-branch. Ideally,
I would have liked to propose it for both master and gdb-9-branch,
but I think toplevel configure is supposed to be coordinated
between GCC and ourselves. Looking at this patch, I don't think
it's necessary, since we hope to lift that limitation at some
point.

---------------------------------------------------------------------------

The move of gnulib to the toplevel directory is causing the GDB build
to break if configured in tree. We hope to lift that limitation at
some point but, in the meantime, this commit allows us to abort
the initial configure right away with a clear error message should
the user attempt to build in tree.

ChangeLog:

        * configure.ac: Abort the build with an error if trying to build
        GDB in tree.
        * configure: Regenerate.

Tested by running the configure script with no argument, --enable-gdb,
and --disable-gdb; from both the toplevel source directory as well
as from other directories.

OK to push to gdb-9-branch?

Thanks,
-- 
Joel

---
 configure    | 9 +++++++++
 configure.ac | 9 +++++++++
 2 files changed, 18 insertions(+)

-- 
2.17.1

Comments

Simon Marchi Jan. 6, 2020, 3:06 a.m. | #1
On 2020-01-05 2:30 a.m., Joel Brobecker wrote:
> Hello,

> 

> Following the discussions on the gdb@ mailing-list regarding

> the fact that GDB 9 is not buildable when configured in tree,

> I propose the following patch for the gdb-9-branch. Ideally,

> I would have liked to propose it for both master and gdb-9-branch,

> but I think toplevel configure is supposed to be coordinated

> between GCC and ourselves. Looking at this patch, I don't think

> it's necessary, since we hope to lift that limitation at some

> point.

> 

> ---------------------------------------------------------------------------

> 

> The move of gnulib to the toplevel directory is causing the GDB build

> to break if configured in tree. We hope to lift that limitation at

> some point but, in the meantime, this commit allows us to abort

> the initial configure right away with a clear error message should

> the user attempt to build in tree.

> 

> ChangeLog:

> 

>         * configure.ac: Abort the build with an error if trying to build

>         GDB in tree.

>         * configure: Regenerate.

> 

> Tested by running the configure script with no argument, --enable-gdb,

> and --disable-gdb; from both the toplevel source directory as well

> as from other directories.

> 

> OK to push to gdb-9-branch?

> 

> Thanks,

> -- 

> Joel

> 

> ---

>  configure    | 9 +++++++++

>  configure.ac | 9 +++++++++

>  2 files changed, 18 insertions(+)

> 

> diff --git a/configure b/configure

> index 6a9719f6091..6273a6a4055 100755

> --- a/configure

> +++ b/configure

> @@ -2279,6 +2279,15 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu

>  

>  

>  

> +if test x"${enable_gdb}" != x"no"; then

> +  # For this branch, we do not support building GDB in-tree.

> +  # Try to detect whether we are in this situation or not by

> +  # searching for a couple of known files in the source directory.

> +  if test -f gnulib/update-gnulib.sh -a -f gdb/ChangeLog; then

> +    as_fn_error $? "GDB must be configured and built in a directory separate from its sources" "$LINENO" 5

> +  fi

> +fi

> +

>  progname=$0

>  # if PWD already has a value, it is probably wrong.

>  if test -n "$PWD" ; then PWD=`${PWDCMD-pwd}`; fi

> diff --git a/configure.ac b/configure.ac

> index 7433badc217..25b3392da9a 100644

> --- a/configure.ac

> +++ b/configure.ac

> @@ -33,6 +33,15 @@ m4_include([config/isl.m4])

>  AC_INIT(move-if-change)

>  AC_DISABLE_OPTION_CHECKING

>  

> +if test x"${enable_gdb}" != x"no"; then

> +  # For this branch, we do not support building GDB in-tree.

> +  # Try to detect whether we are in this situation or not by

> +  # searching for a couple of known files in the source directory.

> +  if test -f gnulib/update-gnulib.sh -a -f gdb/ChangeLog; then

> +    AC_MSG_ERROR([GDB must be configured and built in a directory separate from its sources])


Finish the message with a period?

Some people who only know the "./configure && make && make install" recipe
might not know how (or that it's even possible) to configure and build in a
separate directory, so they'll be stuck there.  I think it would be helpful
to give an example of how to do that, like:

    GDB must be configured and built in a directory separate from its sources.

    To do so, create a dedicated directory for your GDB build and invoke the configure
    script from that directory:

      $ mkdir my-gdb-build
      $ cd my-gdb-build
      $ ../path/to/gdb-x.y.z/configure [configure args]
      $ make

Otherwise, that looks good to me.  I'm starting to look at Tom's patchset to move gdbsupport
to the top-level, and I agree that it would be a bit dangerous to finish the work that late
in the cycle, so I'm fine if we prohibit building in the source directory for that release.
It will just look strange that it's the case only for one specific release, but it's not really
a big deal.

Simon
Sergio Durigan Junior Jan. 30, 2020, 9:06 p.m. | #2
On Friday, January 17 2020, Joel Brobecker wrote:

>> > Attached is a revised patch. I chose to use the same sequence as

>> > the one in gdb/README, just for consistency.

>> 

>> LGTM, thanks!

>

> Thanks Simon (and thanks Tom also). Now pushed!


Hey, Joel!

I just found out that this commit broke the snapshot generation for the
gdb-9-branch.  It's pretty easy to reproduce the problem locally:

  $ ./src-release.sh -x gdb
  ==> Cleaning sources.
  ==> Making gdb-9.0.90.20200130/
  ==> configure --target=i386-pc-linux-gnu  --disable-binutils --disable-gas --disable-gold --disable-gprof --disable-ld  --enable-gdb --enable-libctf --enable-libdecnumber --enable-readline --enable-sim
  configure: error: GDB must be configured and built in a directory separate from its sources.
  ...

I'm wondering what to do here.  I think I found a hacky and ugly
solution here, but I'm trying to see if there's a better approach.
Meanwhile, I thought I'd report this problem in case you already have a
better idea.

Cheers,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/
Eli Zaretskii Jan. 31, 2020, 7:34 a.m. | #3
> From: Sergio Durigan Junior <sergiodj@redhat.com>

> Cc: Simon Marchi <simark@simark.ca>,  gdb-patches@sourceware.org,  Tom Tromey <tom@tromey.com>

> Date: Thu, 30 Jan 2020 16:06:18 -0500

> 

>   $ ./src-release.sh -x gdb

>   ==> Cleaning sources.

>   ==> Making gdb-9.0.90.20200130/

>   ==> configure --target=i386-pc-linux-gnu  --disable-binutils --disable-gas --disable-gold --disable-gprof --disable-ld  --enable-gdb --enable-libctf --enable-libdecnumber --enable-readline --enable-sim

>   configure: error: GDB must be configured and built in a directory separate from its sources.

>   ...

> 

> I'm wondering what to do here.  I think I found a hacky and ugly

> solution here, but I'm trying to see if there's a better approach.


A special command-line switch to 'configure', to be used by
src-release.sh?
Sergio Durigan Junior Jan. 31, 2020, 6:37 p.m. | #4
On Friday, January 31 2020, Eli Zaretskii wrote:

>> From: Sergio Durigan Junior <sergiodj@redhat.com>

>> Cc: Simon Marchi <simark@simark.ca>,  gdb-patches@sourceware.org,  Tom Tromey <tom@tromey.com>

>> Date: Thu, 30 Jan 2020 16:06:18 -0500

>> 

>>   $ ./src-release.sh -x gdb

>>   ==> Cleaning sources.

>>   ==> Making gdb-9.0.90.20200130/

>>   ==> configure --target=i386-pc-linux-gnu --disable-binutils

>> --disable-gas --disable-gold --disable-gprof --disable-ld

>> --enable-gdb --enable-libctf --enable-libdecnumber --enable-readline

>> --enable-sim

>>   configure: error: GDB must be configured and built in a directory separate from its sources.

>>   ...

>> 

>> I'm wondering what to do here.  I think I found a hacky and ugly

>> solution here, but I'm trying to see if there's a better approach.

>

> A special command-line switch to 'configure', to be used by

> src-release.sh?


A quick attempt here didn't really work.  The script is able to finish
the build and create a tarball, but for some reason the gdb directory is
not configured/built.

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/
Sergio Durigan Junior Jan. 31, 2020, 9:39 p.m. | #5
On Friday, January 31 2020, I wrote:

> On Friday, January 31 2020, Eli Zaretskii wrote:

>

>>> From: Sergio Durigan Junior <sergiodj@redhat.com>

>>> Cc: Simon Marchi <simark@simark.ca>,  gdb-patches@sourceware.org,  Tom Tromey <tom@tromey.com>

>>> Date: Thu, 30 Jan 2020 16:06:18 -0500

>>> 

>>>   $ ./src-release.sh -x gdb

>>>   ==> Cleaning sources.

>>>   ==> Making gdb-9.0.90.20200130/

>>>   ==> configure --target=i386-pc-linux-gnu --disable-binutils

>>> --disable-gas --disable-gold --disable-gprof --disable-ld

>>> --enable-gdb --enable-libctf --enable-libdecnumber --enable-readline

>>> --enable-sim

>>>   configure: error: GDB must be configured and built in a directory separate from its sources.

>>>   ...

>>> 

>>> I'm wondering what to do here.  I think I found a hacky and ugly

>>> solution here, but I'm trying to see if there's a better approach.

>>

>> A special command-line switch to 'configure', to be used by

>> src-release.sh?

>

> A quick attempt here didn't really work.  The script is able to finish

> the build and create a tarball, but for some reason the gdb directory is

> not configured/built.


OK, I think I have something that works.  When 'configure' is invoked
with '--enable-src-release-build', a tarball is generated and, as far as
I have checked, contains the correct snapshot.

WDYT?

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

diff --git a/ChangeLog b/ChangeLog
index 0bfe989885..de13206e2e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2020-01-31  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+	* configure.ac: Don't abort the build if trying to build GDB in tree
+	_and_ invoking with '--enable-src-release-build'.
+	* configure: Regenerate.
+	* src-release.sh (do_proto_toplev): Invoke 'configure' using
+	'--enable-src-release-build'.
+
 2020-01-17  Joel Brobecker  <brobecker@adacore.com>
 
 	* configure.ac: Abort the build with an error if trying to build
diff --git a/configure b/configure
index 7168a4e90e..276f33fee3 100755
--- a/configure
+++ b/configure
@@ -2279,7 +2279,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 
 
-if test x"${enable_gdb}" != x"no"; then
+if test x"${enable_gdb}" != x"no" -a x"${enable_src_release_build}" != x"yes"; then
   # For this branch, we do not support building GDB in-tree.
   # Try to detect whether we are in this situation or not by
   # searching for a couple of known files in the source directory.
diff --git a/configure.ac b/configure.ac
index e5ca1eaa57..cd0867dd76 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,7 +33,7 @@ m4_include([config/isl.m4])
 AC_INIT(move-if-change)
 AC_DISABLE_OPTION_CHECKING
 
-if test x"${enable_gdb}" != x"no"; then
+if test x"${enable_gdb}" != x"no" -a x"${enable_src_release_build}" != x"yes"; then
   # For this branch, we do not support building GDB in-tree.
   # Try to detect whether we are in this situation or not by
   # searching for a couple of known files in the source directory.
diff --git a/src-release.sh b/src-release.sh
index 275f0f24b5..68e824c749 100755
--- a/src-release.sh
+++ b/src-release.sh
@@ -99,8 +99,8 @@ do_proto_toplev()
 	    *) disables="$disables --disable-$dir" ;;
 	esac
     done
-    echo "==> configure --target=i386-pc-linux-gnu $disables $enables"
-    ./configure --target=i386-pc-linux-gnu $disables $enables
+    echo "==> configure --target=i386-pc-linux-gnu --enable-src-release-build=yes $disables $enables"
+    ./configure --target=i386-pc-linux-gnu --enable-src-release-build=yes $disables $enables
     $MAKE configure-host configure-target \
 	ALL_GCC="" ALL_GCC_C="" ALL_GCC_CXX="" \
 	CC_FOR_TARGET="$CC" CXX_FOR_TARGET="$CXX"
Eli Zaretskii Feb. 1, 2020, 7:23 a.m. | #6
> From: Sergio Durigan Junior <sergiodj@redhat.com>

> Cc: brobecker@adacore.com,  simark@simark.ca,  gdb-patches@sourceware.org,  tom@tromey.com

> Date: Fri, 31 Jan 2020 16:39:49 -0500

> 

> OK, I think I have something that works.  When 'configure' is invoked

> with '--enable-src-release-build', a tarball is generated and, as far as

> I have checked, contains the correct snapshot.

> 

> WDYT?


It certainly looks like something I had in mind, but since I know very
little about sourceware configury, I hope others will chime in.

Thanks.
Joel Brobecker Feb. 1, 2020, 10:19 a.m. | #7
> >>> I'm wondering what to do here.  I think I found a hacky and ugly

> >>> solution here, but I'm trying to see if there's a better approach.

> >>

> >> A special command-line switch to 'configure', to be used by

> >> src-release.sh?

> >

> > A quick attempt here didn't really work.  The script is able to finish

> > the build and create a tarball, but for some reason the gdb directory is

> > not configured/built.

> 

> OK, I think I have something that works.  When 'configure' is invoked

> with '--enable-src-release-build', a tarball is generated and, as far as

> I have checked, contains the correct snapshot.

> 

> WDYT?


Thanks! I didn't realize that this would impact source packaging
like that.

Let's go with your patch. I'm about to start working on the release,
so I'll apply it for you.

Thanks again,

> diff --git a/ChangeLog b/ChangeLog

> index 0bfe989885..de13206e2e 100644

> --- a/ChangeLog

> +++ b/ChangeLog

> @@ -1,3 +1,11 @@

> +2020-01-31  Sergio Durigan Junior  <sergiodj@redhat.com>

> +

> +	* configure.ac: Don't abort the build if trying to build GDB in tree

> +	_and_ invoking with '--enable-src-release-build'.

> +	* configure: Regenerate.

> +	* src-release.sh (do_proto_toplev): Invoke 'configure' using

> +	'--enable-src-release-build'.

> +

>  2020-01-17  Joel Brobecker  <brobecker@adacore.com>

>  

>  	* configure.ac: Abort the build with an error if trying to build

> diff --git a/configure b/configure

> index 7168a4e90e..276f33fee3 100755

> --- a/configure

> +++ b/configure

> @@ -2279,7 +2279,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu

>  

>  

>  

> -if test x"${enable_gdb}" != x"no"; then

> +if test x"${enable_gdb}" != x"no" -a x"${enable_src_release_build}" != x"yes"; then

>    # For this branch, we do not support building GDB in-tree.

>    # Try to detect whether we are in this situation or not by

>    # searching for a couple of known files in the source directory.

> diff --git a/configure.ac b/configure.ac

> index e5ca1eaa57..cd0867dd76 100644

> --- a/configure.ac

> +++ b/configure.ac

> @@ -33,7 +33,7 @@ m4_include([config/isl.m4])

>  AC_INIT(move-if-change)

>  AC_DISABLE_OPTION_CHECKING

>  

> -if test x"${enable_gdb}" != x"no"; then

> +if test x"${enable_gdb}" != x"no" -a x"${enable_src_release_build}" != x"yes"; then

>    # For this branch, we do not support building GDB in-tree.

>    # Try to detect whether we are in this situation or not by

>    # searching for a couple of known files in the source directory.

> diff --git a/src-release.sh b/src-release.sh

> index 275f0f24b5..68e824c749 100755

> --- a/src-release.sh

> +++ b/src-release.sh

> @@ -99,8 +99,8 @@ do_proto_toplev()

>  	    *) disables="$disables --disable-$dir" ;;

>  	esac

>      done

> -    echo "==> configure --target=i386-pc-linux-gnu $disables $enables"

> -    ./configure --target=i386-pc-linux-gnu $disables $enables

> +    echo "==> configure --target=i386-pc-linux-gnu --enable-src-release-build=yes $disables $enables"

> +    ./configure --target=i386-pc-linux-gnu --enable-src-release-build=yes $disables $enables

>      $MAKE configure-host configure-target \

>  	ALL_GCC="" ALL_GCC_C="" ALL_GCC_CXX="" \

>  	CC_FOR_TARGET="$CC" CXX_FOR_TARGET="$CXX"


-- 
Joel
Joel Brobecker Feb. 1, 2020, 10:26 a.m. | #8
> > >>> I'm wondering what to do here.  I think I found a hacky and ugly

> > >>> solution here, but I'm trying to see if there's a better approach.

> > >>

> > >> A special command-line switch to 'configure', to be used by

> > >> src-release.sh?

> > >

> > > A quick attempt here didn't really work.  The script is able to finish

> > > the build and create a tarball, but for some reason the gdb directory is

> > > not configured/built.

> > 

> > OK, I think I have something that works.  When 'configure' is invoked

> > with '--enable-src-release-build', a tarball is generated and, as far as

> > I have checked, contains the correct snapshot.

> > 

> > WDYT?

> 

> Thanks! I didn't realize that this would impact source packaging

> like that.

> 

> Let's go with your patch. I'm about to start working on the release,

> so I'll apply it for you.


Or not. Jonah just reported another blocking issue :-(, so I won't
be creating this release this weekend.

So the "good" news is that you can push the patch yourself!

-- 
Joel
Sergio Durigan Junior Feb. 1, 2020, 8:37 p.m. | #9
On Saturday, February 01 2020, Joel Brobecker wrote:

>> > >>> I'm wondering what to do here.  I think I found a hacky and ugly

>> > >>> solution here, but I'm trying to see if there's a better approach.

>> > >>

>> > >> A special command-line switch to 'configure', to be used by

>> > >> src-release.sh?

>> > >

>> > > A quick attempt here didn't really work.  The script is able to finish

>> > > the build and create a tarball, but for some reason the gdb directory is

>> > > not configured/built.

>> > 

>> > OK, I think I have something that works.  When 'configure' is invoked

>> > with '--enable-src-release-build', a tarball is generated and, as far as

>> > I have checked, contains the correct snapshot.

>> > 

>> > WDYT?

>> 

>> Thanks! I didn't realize that this would impact source packaging

>> like that.

>> 

>> Let's go with your patch. I'm about to start working on the release,

>> so I'll apply it for you.

>

> Or not. Jonah just reported another blocking issue :-(, so I won't

> be creating this release this weekend.

>

> So the "good" news is that you can push the patch yourself!


Thanks for the quick review, Joel :-).

Below is what I pushed.

Cheers,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

From 1aa93c3a9b9a216703aaf882b3af541f3bc3042a Mon Sep 17 00:00:00 2001
From: Sergio Durigan Junior <sergiodj@redhat.com>

Date: Sat, 1 Feb 2020 15:33:31 -0500
Subject: [PATCH] Implement '--enable-src-release-build' option and make
 src-release.sh use it

The generation of snapshots has been broken since we've disable
in-tree builds for GDB.  Given that src-release.sh performs a build
before creating the release tarball, and that this build is performed
in-tree, the solution we found is to implement a new top-level
configure flag called '--enable-src-release-build' which disables the
in-tree build restriction, and then make src-release.sh use it.

ChangeLog:
2020-02-01  Sergio Durigan Junior  <sergiodj@redhat.com>
	    Eli Zaretskii  <eliz@gnu.org>

	* configure.ac: Don't abort the build if trying to build GDB in tree
	_and_ invoking with '--enable-src-release-build'.
	* configure: Regenerate.
	* src-release.sh (do_proto_toplev): Invoke 'configure' using

Change-Id: Ic6dd55accd9a03e62fe498f7fd704fb67f44bfa9
---
 ChangeLog      | 8 ++++++++
 configure      | 2 +-
 configure.ac   | 2 +-
 src-release.sh | 4 ++--
 4 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0bfe989885..211451345e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2020-02-01  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+	* configure.ac: Don't abort the build if trying to build GDB in tree
+	_and_ invoking with '--enable-src-release-build'.
+	* configure: Regenerate.
+	* src-release.sh (do_proto_toplev): Invoke 'configure' using
+	'--enable-src-release-build'.
+
 2020-01-17  Joel Brobecker  <brobecker@adacore.com>
 
 	* configure.ac: Abort the build with an error if trying to build
diff --git a/configure b/configure
index 7168a4e90e..276f33fee3 100755
--- a/configure
+++ b/configure
@@ -2279,7 +2279,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 
 
-if test x"${enable_gdb}" != x"no"; then
+if test x"${enable_gdb}" != x"no" -a x"${enable_src_release_build}" != x"yes"; then
   # For this branch, we do not support building GDB in-tree.
   # Try to detect whether we are in this situation or not by
   # searching for a couple of known files in the source directory.
diff --git a/configure.ac b/configure.ac
index e5ca1eaa57..cd0867dd76 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,7 +33,7 @@ m4_include([config/isl.m4])
 AC_INIT(move-if-change)
 AC_DISABLE_OPTION_CHECKING
 
-if test x"${enable_gdb}" != x"no"; then
+if test x"${enable_gdb}" != x"no" -a x"${enable_src_release_build}" != x"yes"; then
   # For this branch, we do not support building GDB in-tree.
   # Try to detect whether we are in this situation or not by
   # searching for a couple of known files in the source directory.
diff --git a/src-release.sh b/src-release.sh
index 275f0f24b5..68e824c749 100755
--- a/src-release.sh
+++ b/src-release.sh
@@ -99,8 +99,8 @@ do_proto_toplev()
 	    *) disables="$disables --disable-$dir" ;;
 	esac
     done
-    echo "==> configure --target=i386-pc-linux-gnu $disables $enables"
-    ./configure --target=i386-pc-linux-gnu $disables $enables
+    echo "==> configure --target=i386-pc-linux-gnu --enable-src-release-build=yes $disables $enables"
+    ./configure --target=i386-pc-linux-gnu --enable-src-release-build=yes $disables $enables
     $MAKE configure-host configure-target \
 	ALL_GCC="" ALL_GCC_C="" ALL_GCC_CXX="" \
 	CC_FOR_TARGET="$CC" CXX_FOR_TARGET="$CXX"
-- 
2.21.0

Patch

diff --git a/configure b/configure
index 6a9719f6091..6273a6a4055 100755
--- a/configure
+++ b/configure
@@ -2279,6 +2279,15 @@  ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 
 
+if test x"${enable_gdb}" != x"no"; then
+  # For this branch, we do not support building GDB in-tree.
+  # Try to detect whether we are in this situation or not by
+  # searching for a couple of known files in the source directory.
+  if test -f gnulib/update-gnulib.sh -a -f gdb/ChangeLog; then
+    as_fn_error $? "GDB must be configured and built in a directory separate from its sources" "$LINENO" 5
+  fi
+fi
+
 progname=$0
 # if PWD already has a value, it is probably wrong.
 if test -n "$PWD" ; then PWD=`${PWDCMD-pwd}`; fi
diff --git a/configure.ac b/configure.ac
index 7433badc217..25b3392da9a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,6 +33,15 @@  m4_include([config/isl.m4])
 AC_INIT(move-if-change)
 AC_DISABLE_OPTION_CHECKING
 
+if test x"${enable_gdb}" != x"no"; then
+  # For this branch, we do not support building GDB in-tree.
+  # Try to detect whether we are in this situation or not by
+  # searching for a couple of known files in the source directory.
+  if test -f gnulib/update-gnulib.sh -a -f gdb/ChangeLog; then
+    AC_MSG_ERROR([GDB must be configured and built in a directory separate from its sources])
+  fi
+fi
+
 progname=$0
 # if PWD already has a value, it is probably wrong.
 if test -n "$PWD" ; then PWD=`${PWDCMD-pwd}`; fi