From ad06484063972abdf3f426412af9aa101bea26a8 Mon Sep 17 00:00:00 2001
From: pbrook <pbrook@c046a42c-6fe2-441c-8c8c-71466251a162>
Date: Sun, 16 Apr 2006 12:41:07 +0000
Subject: [PATCH] Fix out of tree builds.

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1814 c046a42c-6fe2-441c-8c8c-71466251a162
---
 Makefile        | 21 +++++++++++----------
 Makefile.target |  2 +-
 configure       | 18 ++++++++++++------
 3 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/Makefile b/Makefile
index 59a549a5c0b..a8fd496ebef 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
--include config-host.mak
+include config-host.mak
 
-CFLAGS=-Wall -O2 -g -fno-strict-aliasing 
+CFLAGS=-Wall -O2 -g -fno-strict-aliasing -I.
 ifdef CONFIG_DARWIN
 CFLAGS+= -mdynamic-no-pic
 endif
@@ -47,18 +47,19 @@ install: all
 	mkdir -p "$(DESTDIR)$(bindir)"
 	install -m 755 -s $(TOOLS) "$(DESTDIR)$(bindir)"
 	mkdir -p "$(DESTDIR)$(datadir)"
-	install -m 644 pc-bios/bios.bin pc-bios/vgabios.bin \
-                       pc-bios/vgabios-cirrus.bin \
-                       pc-bios/ppc_rom.bin pc-bios/video.x \
-                       pc-bios/proll.elf \
-                       pc-bios/linux_boot.bin "$(DESTDIR)$(datadir)"
+	for x in bios.bin vgabios.bin vgabios-cirrus.bin ppc_rom.bin \
+			video.x proll.elf linux_boot.bin; do \
+		install -m 644 $(SRC_PATH)/pc-bios/$$x "$(DESTDIR)$(datadir)"; \
+	done
 	mkdir -p "$(DESTDIR)$(docdir)"
 	install -m 644 qemu-doc.html  qemu-tech.html "$(DESTDIR)$(docdir)"
 ifndef CONFIG_WIN32
 	mkdir -p "$(DESTDIR)$(mandir)/man1"
 	install qemu.1 qemu-img.1 "$(DESTDIR)$(mandir)/man1"
 	mkdir -p "$(DESTDIR)$(datadir)/keymaps"
-	install -m 644 $(addprefix keymaps/,$(KEYMAPS)) "$(DESTDIR)$(datadir)/keymaps"
+	for x in $(KEYMAPS); do \
+		install -m 644 $(SRC_PATH)/keymaps/$$x "$(DESTDIR)$(datadir)/keymaps"; \
+	done
 endif
 	for d in $(TARGET_DIRS); do \
 	$(MAKE) -C $$d $@ || exit 1 ; \
@@ -81,11 +82,11 @@ cscope:
 	texi2html -monolithic -number $<
 
 qemu.1: qemu-doc.texi
-	./texi2pod.pl $< qemu.pod
+	$(SRC_PATH)/texi2pod.pl $< qemu.pod
 	pod2man --section=1 --center=" " --release=" " qemu.pod > $@
 
 qemu-img.1: qemu-img.texi
-	./texi2pod.pl $< qemu-img.pod
+	$(SRC_PATH)/texi2pod.pl $< qemu-img.pod
 	pod2man --section=1 --center=" " --release=" " qemu-img.pod > $@
 
 FILE=qemu-$(shell cat VERSION)
diff --git a/Makefile.target b/Makefile.target
index 755fba1e73f..abe19c0a641 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -12,7 +12,7 @@ TARGET_BASE_ARCH:=sparc
 endif
 TARGET_PATH=$(SRC_PATH)/target-$(TARGET_BASE_ARCH)
 VPATH=$(SRC_PATH):$(TARGET_PATH):$(SRC_PATH)/hw:$(SRC_PATH)/audio
-DEFINES=-I. -I$(TARGET_PATH) -I$(SRC_PATH)
+DEFINES=-I. -I.. -I$(TARGET_PATH) -I$(SRC_PATH)
 ifdef CONFIG_USER_ONLY
 VPATH+=:$(SRC_PATH)/linux-user
 DEFINES+=-I$(SRC_PATH)/linux-user -I$(SRC_PATH)/linux-user/$(TARGET_ARCH)
diff --git a/configure b/configure
index ff504b2b3a0..8331e4f25d1 100755
--- a/configure
+++ b/configure
@@ -139,14 +139,16 @@ if [ "$bsd" = "yes" ] ; then
 fi
 
 # find source path
-# XXX: we assume an absolute path is given when launching configure,
-# except in './configure' case.
-source_path=${0%configure}
-source_path=${source_path%/}
-source_path_used="yes"
-if test -z "$source_path" -o "$source_path" = "." ; then
+source_path=`dirname "$0"`
+if [ -z "$source_path" ]; then
     source_path=`pwd`
+else
+    source_path=`cd "$source_path"; pwd`
+fi
+if test "$source_path" = `pwd` ; then
     source_path_used="no"
+else
+    source_path_used="yes"
 fi
 
 for opt do
@@ -158,6 +160,7 @@ for opt do
   --interp-prefix=*) interp_prefix=`echo $opt | cut -d '=' -f 2`
   ;;
   --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
+  source_path_used="yes"
   ;;
   --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
   ;;
@@ -615,6 +618,9 @@ head $source_path/VERSION >> $config_h
 echo "\"" >> $config_h
 
 echo "SRC_PATH=$source_path" >> $config_mak
+if [ "$source_path_used" = "yes" ]; then
+  echo "VPATH=$source_path" >> $config_mak
+fi
 echo "TARGET_DIRS=$target_list" >> $config_mak
 
 # XXX: suppress that
-- 
GitLab