[x264-devel] Use a relative $SRCPATH for out-of-tree builds

Henrik Gramner git at videolan.org
Wed Aug 19 21:16:14 CEST 2015


x264 | branch: master | Henrik Gramner <henrik at gramner.com> | Wed Aug 12 22:23:31 2015 +0200| [7edaf4b966aaee098ff301436f8d2b33a6fe5983] | committer: Anton Mitrofanov

Use a relative $SRCPATH for out-of-tree builds

Fixes out-of-tree MSVS builds on Cygwin.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=7edaf4b966aaee098ff301436f8d2b33a6fe5983
---

 configure |   19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 70aa07f..e96973a 100755
--- a/configure
+++ b/configure
@@ -305,9 +305,22 @@ configure_system_override() {
 
 rm -f x264_config.h config.h config.mak config.log x264.pc x264.def conftest*
 
-SRCPATH="$(cd $(dirname $0); pwd)"
-[ "$SRCPATH" = "$(pwd)" ] && SRCPATH=.
-[ -n "$(echo $SRCPATH | grep ' ')" ] && die "Out of tree builds are impossible with whitespace in source path."
+# Construct a path to the specified directory relative to the working directory
+relative_path() {
+    local base="${PWD%/}"
+    local path="$(cd "$1" >/dev/null; printf '%s/.' "${PWD%/}")"
+    local up=''
+
+    while [[ $path != "$base/"* ]]; do
+        base="${base%/*}"
+        up="../$up"
+    done
+
+    dirname "$up${path#"$base/"}"
+}
+
+SRCPATH="$(relative_path "$(dirname "$0")")"
+echo "$SRCPATH" | grep -q ' ' && die "Out of tree builds are impossible with whitespace in source path."
 [ -e "$SRCPATH/config.h" -o -e "$SRCPATH/x264_config.h" ] && die "Out of tree builds are impossible with config.h/x264_config.h in source dir."
 
 prefix='/usr/local'



More information about the x264-devel mailing list