qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH] build: support disjoint build directory


From: Blue Swirl
Subject: [Qemu-devel] [PATCH] build: support disjoint build directory
Date: Sat, 9 Feb 2013 18:59:59 +0000

Support building in any directory, not just in-tree build.

Use VPATH for non-Forth files.

Forth compiler does not support explicit paths, so drop source path
prefixes added by XML and rely on directories passed with -I flag.

Signed-off-by: Blue Swirl <address@hidden>
---
 .gitignore                 |    1 +
 Makefile                   |    3 +-
 Makefile.target            |    5 +++-
 config/scripts/switch-arch |   47 +++++++++++++++++++++++++------------------
 config/xml/dictionary.xsl  |    3 +-
 config/xml/object.xsl      |    1 -
 6 files changed, 35 insertions(+), 25 deletions(-)

diff --git a/.gitignore b/.gitignore
index e6b5c59..38e6dd8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
 obj-*
 .stgit-*
+config-host.mak
diff --git a/Makefile b/Makefile
index 74e462c..3526b75 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,4 @@
-ODIRS=$(wildcard obj-*)
-TARGETS=$(subst obj-,,$(ODIRS))
+include config-host.mak
 
 all: requirements info build
 
diff --git a/Makefile.target b/Makefile.target
index 934b95a..913fb13 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -6,7 +6,6 @@
 include config.mak
 
 ODIR := .
-SRCDIR := ..
 HOSTCC := gcc
 
 HOSTCFLAGS+= -O2 -g -DFCOMPILER -DBOOTSTRAP $(CROSSCFLAGS)
@@ -38,6 +37,10 @@ AS_FLAGS+= -g
 
 quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
 
+VPATH_SUFFIXES = %.c %.h %.S %.fs
+set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath 
$(PATTERN) $1)))
+$(call set-vpath, $(SRCDIR))
+
 #
 # pre rules
 #
diff --git a/config/scripts/switch-arch b/config/scripts/switch-arch
index a9c911b..b91af7c 100755
--- a/config/scripts/switch-arch
+++ b/config/scripts/switch-arch
@@ -117,21 +117,18 @@ config_set_boolean()
     echo "<option name=\"$option\" type=\"boolean\" value=\"true\" />"
 }
 
-if ! test -f utils/dist/debian/rules; then
-       echo "switch-arch must be run from the top-level source directory" >&2
-       exit 1
-fi
 
-# This is needed because viewvc messes with the permissions of executables:
-chmod 755 utils/dist/debian/rules
-chmod 755 config/scripts/switch-arch
-chmod 755 config/scripts/reldir
+SRCDIR=`dirname "$0"`/../..
+BUILDDIR=`pwd`
+
+# make source path absolute
+SRCDIR=`cd "$SRCDIR"; pwd`
 
 if test "x$HOSTARCH" = "x"; then
     archname
 fi
 
-VERSION=`head VERSION`
+VERSION=`head $SRCDIR/VERSION`
 
 echo "Configuring OpenBIOS on $HOSTARCH for $*"
 
@@ -156,8 +153,8 @@ done
 arch_list=""
 for target in $target_list; do
     arch=`echo $target | sed s/.*-//g`
-    if ! test -f config/examples/${arch}_config.xml; then
-        echo "Cannot find config/examples/${arch}_config.xml" >&2
+    if ! test -f $SRCDIR/config/examples/${arch}_config.xml; then
+        echo "Cannot find $SRCDIR/config/examples/${arch}_config.xml" >&2
         exit 1
     fi
     if ! echo $arch_list | grep -q "$arch"; then
@@ -269,7 +266,8 @@ for ARCH in $arch_list; do
         cross="yes"
     fi
     crosscflags $HOSTARCH $ARCH
-    OBJDIR=obj-$ARCH
+    OBJDIR=$BUILDDIR/obj-$ARCH
+    ODIRS="$ODIRS $OBJDIR"
 
     printf "Initializing build tree $OBJDIR..."
     rm -rf "$OBJDIR"
@@ -294,9 +292,9 @@ for ARCH in $arch_list; do
     mkdir -p $OBJDIR/host/include
     mkdir -p $OBJDIR/host/kernel
     mkdir -p $OBJDIR/forth
-    ln -s ../../../include/arch/$BASEARCH $OBJDIR/target/include/asm
+    ln -s  $SRCDIR/include/arch/$BASEARCH $OBJDIR/target/include/asm
     #compile the host binary with target settings instead
-    #ln -s ../../../include/arch/$HOSTARCH $OBJDIR/host/include/asm
+    #ln -s $SRCDIR/include/arch/$HOSTARCH $OBJDIR/host/include/asm
     if [ "$mol" = "yes" ]; then
         printf "\nUsing MOL path $MOLPATH...\n"
         mkdir -p $OBJDIR/target/arch/ppc/mol
@@ -324,11 +322,9 @@ for ARCH in $arch_list; do
     fi
     echo "ok."
 
-    cd $OBJDIR
-    SRCDIR=..
-    ODIR=.
+    ODIR=$OBJDIR
 
-    printf "Creating target Makefile..."
+    printf "Creating target config.mak..."
     echo "ARCH=$ARCH" > $ODIR/config.mak
     if [ "$cross" = "yes" ]; then
         echo "TARGET=$TARGET" >> $ODIR/config.mak
@@ -338,7 +334,10 @@ for ARCH in $arch_list; do
     echo "HOSTARCH?=$HOSTARCH" >> $ODIR/config.mak
     echo "CROSSCFLAGS=$CROSSCFLAGS" >> $ODIR/config.mak
     echo "VERSION=\"$VERSION\"" >> $ODIR/config.mak
+    echo "SRCDIR=$SRCDIR" >> $ODIR/config.mak
+    echo "ok."
 
+    printf "Creating target rules.mak..."
     ln -s $SRCDIR/config/xml/rules.xml $ODIR/rules.xml
     echo "<?xml version=\"1.0\"?><config>" > $ODIR/config.xml
     # Generic
@@ -381,8 +380,9 @@ for ARCH in $arch_list; do
     fi
     cat $SRCDIR/config/examples/${ARCH}_config.xml >> $ODIR/config.xml
 
+    cd $ODIR
     echo "</config>" >> $ODIR/config.xml
-    ln -s ../Makefile.target $ODIR/Makefile
+    ln -s $SRCDIR/Makefile.target $ODIR/Makefile
     xsltproc $SRCDIR/config/xml/xinclude.xsl $SRCDIR/build.xml > 
$ODIR/build-full.xml
     xsltproc $SRCDIR/config/xml/makefile.xsl $ODIR/build-full.xml > 
$ODIR/rules.mak
     echo "ok."
@@ -392,5 +392,12 @@ for ARCH in $arch_list; do
     xsltproc $SRCDIR/config/xml/config-forth.xsl $ODIR/config.xml > 
$ODIR/forth/config.fs
     echo "ok."
 
-    cd $SRCDIR
+    cd $BUILDDIR
 done
+
+if [ "$SRCDIR" != "$BUILDDIR" ]; then
+    ln -s $SRCDIR/Makefile $BUILDDIR
+fi
+
+echo "ODIRS=$ODIRS" >> $BUILDDIR/config-host.mak
+echo "TARGETS=$arch_list" >> $BUILDDIR/config-host.mak
diff --git a/config/xml/dictionary.xsl b/config/xml/dictionary.xsl
index 52d836a..664df0f 100644
--- a/config/xml/dictionary.xsl
+++ b/config/xml/dictionary.xsl
@@ -56,7 +56,6 @@
       <xsl:value-of select="$dictname"/><xsl:text>-DICTIONARY:=$(</xsl:text>
       <xsl:value-of select="$dictname"/><xsl:text>-DICTIONARY) </xsl:text>
 
-      <xsl:text>$(SRCDIR)/</xsl:text>
       <xsl:value-of select="$path"/>
       <xsl:value-of select="@source"/>
       <xsl:text>&#10;</xsl:text>
@@ -122,6 +121,8 @@
       </xsl:if>
      </xsl:for-each>
 
+     <!-- needed to locate files with full path -->
+     <xsl:text> -I$(SRCDIR)</xsl:text>
      <!-- needed to include config and build date -->
      <xsl:text> -I$(ODIR)/forth</xsl:text>
      
diff --git a/config/xml/object.xsl b/config/xml/object.xsl
index 7af54ab..cf521f5 100644
--- a/config/xml/object.xsl
+++ b/config/xml/object.xsl
@@ -52,7 +52,6 @@
     <xsl:text>.o: </xsl:text>
  
     <!-- path of source file -->
-    <xsl:text>$(SRCDIR)/</xsl:text>
     <xsl:value-of select="$path"/>
     <xsl:value-of select="@source"/>
 
-- 
1.7.2.5




reply via email to

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