qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] configure: make source tree build more robust


From: Michael S. Tsirkin
Subject: [Qemu-devel] [PATCH] configure: make source tree build more robust
Date: Mon, 28 Apr 2014 15:21:15 +0300

When source directory can be arrived at by two paths,
configure might misdetect an out of tree build.
The simplest way to trigger the problem is running
configure using a full path. E.g. (<firstpath> refers to qemu source
tree):
    ln -s <firstpath> <secondpath>
    cd <firstpath>
    <secondpath>/configure

A more practical way is when make runs configure automatically:

1. cd <firstpath>/; ./configure
    SRC_PATH=<firstpath>/ is written into config_host.mak
2. cd <secondpath>/; touch configure; make
    make now runs <firstpath>/configure, so configure
    assumes it's an out of tree build

When this happens configure overwrites parts of
the current tree with symlinks.

Make the test more robust: create a canary file under
the build tree, then look for it in the source tree.
If there - we know it's a source build!

Signed-off-by: Michael S. Tsirkin <address@hidden>
---
 configure | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index b08afc3..4a59cb7 100755
--- a/configure
+++ b/configure
@@ -404,6 +404,22 @@ fi
 # make source path absolute
 source_path=`cd "$source_path"; pwd`
 
+# running configure in the source tree? create a temporary file
+# under pwd, check for it in source tree. Use .o suffix so that
+# make clean will blow it away if
+canary_path=`pwd`
+canary_fullpath=`mktemp "$canary_path/canary.XXXXXXXXXX.o"`
+if test -z "$canary_fullpath"; then
+    error_exit "Current directory $canary_path/ does not appear to be 
writeable"
+fi
+canary_basename=`basename "$canary_fullpath"`
+if test -e "$source_path/$canary_basename"; then
+    pwd_is_source_path="y"
+else
+    pwd_is_source_path="n"
+fi
+rm -f -- "$canary_fullpath"
+
 check_define() {
 cat > $TMPC <<EOF
 #if !defined($1)
@@ -2940,7 +2956,7 @@ EOF
     fdt=yes
     dtc_internal="yes"
     mkdir -p dtc
-    if [ "$source_path" != `pwd` ] ; then
+    if [ "$pwd_is_source_path" != "y" ] ; then
        symlink "$source_path/dtc/Makefile" "dtc/Makefile"
        symlink "$source_path/dtc/scripts" "dtc/scripts"
     fi
@@ -5178,7 +5194,7 @@ do
 done
 mkdir -p $DIRS
 for f in $FILES ; do
-    if [ -e "$source_path/$f" ] && [ "$source_path" != `pwd` ]; then
+    if [ -e "$source_path/$f" ] && [ "$pwd_is_source_path" != "y" ]; then
         symlink "$source_path/$f" "$f"
     fi
 done
-- 
MST



reply via email to

[Prev in Thread] Current Thread [Next in Thread]