[x264-devel] cygwin: Enable MSVS support

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


x264 | branch: master | Henrik Gramner <henrik at gramner.com> | Sat Aug  8 22:26:38 2015 +0200| [e7b4b863dc2555ed835569c400d3a30f7ddc15ff] | committer: Anton Mitrofanov

cygwin: Enable MSVS support

`cl -showIncludes` creates absolute Windows paths for some files, attempt
to convert those to Unix paths.

Use relative paths for dependencies located in or below the working directory
in order to mimic the behavior of gcc and to make the paths more readable.

Make the dependency generation script a bit more robust in general.

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

 configure           |    4 +---
 tools/msvsdepend.sh |   63 +++++++++++++++++++++++++++++++++++----------------
 2 files changed, 44 insertions(+), 23 deletions(-)

diff --git a/configure b/configure
index 486b1a9..70aa07f 100755
--- a/configure
+++ b/configure
@@ -527,8 +527,6 @@ if [[ $host_os = mingw* || $host_os = cygwin* ]]; then
         fi
     elif [[ "$cc_base" = cl || "$cc_base" = cl[\ .]* ]]; then
         # Standard Microsoft Visual Studio
-        # Dependency creation includes absolute windows paths, Cygwin's make does not support Windows paths.
-        [[ $host_os = cygwin* ]] && die "Microsoft Visual Studio support requires MSYS"
         compiler=CL
         compiler_style=MS
         CFLAGS="$CFLAGS -nologo -DHAVE_STRING_H -I\$(SRCPATH)/extras"
@@ -591,7 +589,7 @@ case $host_os in
         ;;
     cygwin*)
         EXE=".exe"
-        if cc_check "" -mno-cygwin; then
+        if [ $compiler_style = GNU ] && cc_check "" -mno-cygwin; then
             CFLAGS="$CFLAGS -mno-cygwin"
             LDFLAGS="$LDFLAGS -mno-cygwin"
         fi
diff --git a/tools/msvsdepend.sh b/tools/msvsdepend.sh
index 4d054eb..568f611 100755
--- a/tools/msvsdepend.sh
+++ b/tools/msvsdepend.sh
@@ -1,21 +1,44 @@
 #!/bin/sh
-# There's a lot of things going on here
-# expected arguments are $(CC) $(CFLAGS) $(SRC) $(OBJ)
-# 1) start the dependency line with the object argument
-# 2) need to add -Zs -showIncludes to the flags to have the compiler output list of include files without compilation
-# 3) look for notes in the output that start with "Note: including file:"
-# 4) retain only the filepath from the notes
-# 5) convert \ foldername separators to /
-# 6) escape spaces in the filepath
-# 7) remove system includes (hack: check for "/Program Files" string in filepath)
-# 8) sort and remove duplicate filepath entries
-# 9) convert newlines to spaces to collapse the dependencies into the one dependency line
-# 10) print a newline character, to properly separate dependency lines
-echo -n "$4: "
-$1 $2 $3 -Zs -showIncludes 2>&1 |
-    grep '^Note: including file:' |
-    sed 's/^Note: including file:[[:space:]]*\(.*\)$/\1/; s/\\/\//g; s/ /\\ /g' |
-    sed '/\/[Pp]rogram\\ [Ff]iles/d' |
-    sort | uniq |
-    tr -s '\n\r' ' '
-echo ''
+
+# Output a Makefile rule describing the dependencies of a given source file.
+# Expected arguments are $(CC) $(CFLAGS) $(SRC) $(OBJ)
+
+set -f
+
+[ -n "$1" ] && [ -n "$3" ] && [ -n "$4" ] || exit 1
+
+# Add flags to only perform syntax checking and output a list of included files
+# Discard all output other than included files
+# Convert '\' directory separators to '/'
+# Remove system includes (hack: check for "/Program Files" string in path)
+# Add the source file itself as a dependency
+deps="$($1 $2 -nologo -showIncludes -W0 -Zs "$3" 2>&1 |
+        grep '^Note: including file:' |
+        sed 's/^Note: including file:[[:space:]]*\(.*\)$/\1/; s/\\/\//g' |
+        sed '/\/[Pp]rogram [Ff]iles/d')
+$3"
+
+# Convert Windows paths to Unix paths if possible
+if command -v cygpath >/dev/null 2>&1 ; then
+    IFS='
+'
+    deps="$(cygpath -u -- $deps)"
+fi
+
+# Escape characters as required to create valid Makefile file names
+escape() {
+    sed 's/ /\\ /g; s/#/\\#/g; s/\$/\$\$/g'
+}
+
+# Remove prefixes that are equal to the working directory
+# Sort and remove duplicate entries
+# Escape and collapse the dependencies into one line
+deps="$(printf '%s' "$deps" |
+        sed "s/^$(pwd | sed 's/\//\\\//g')\///; s/^\.\///" |
+        sort | uniq |
+        escape | tr -s '\n\r' ' ' | sed 's/^ *\(.*\) $/\1/')"
+
+# Escape the target file name as well
+target="$(printf '%s' "$4" | escape)"
+
+printf '%s: %s\n' "$target" "$deps"



More information about the x264-devel mailing list