]> git.sesse.net Git - x264/commitdiff
Use a relative $SRCPATH for out-of-tree builds
authorHenrik Gramner <henrik@gramner.com>
Wed, 12 Aug 2015 20:23:31 +0000 (22:23 +0200)
committerAnton Mitrofanov <BugMaster@narod.ru>
Tue, 18 Aug 2015 22:00:26 +0000 (01:00 +0300)
Fixes out-of-tree MSVS builds on Cygwin.

configure

index 70aa07f212690bfb7b9119784b35d9dc7fb065d0..e96973a5011ac1face9643cf2b94957eed70963e 100755 (executable)
--- 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'