PR #23669 opened by Kacper Michajłow (kasper93)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23669
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23669.patch


From 4f54cd0e3132c8a80c0033afd1f0f3b0d4e1e564 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <[email protected]>
Date: Wed, 1 Jul 2026 04:17:12 +0200
Subject: [PATCH 1/2] compat/windows/mscl: add wrapper script for cl.exe that
 produces dep file
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This compiler wrapper script parses -showIncludes output and converts
that into GNU dep file. This is a port of _DEPCMD inlined in the
configure.

Signed-off-by: Kacper Michajłow <[email protected]>
---
 compat/windows/mscl | 56 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100755 compat/windows/mscl

diff --git a/compat/windows/mscl b/compat/windows/mscl
new file mode 100755
index 0000000000..b7e7e99e8d
--- /dev/null
+++ b/compat/windows/mscl
@@ -0,0 +1,56 @@
+#!/bin/sh
+#
+# msvc compiler wrapper, used as: mscl <compiler> <arguments...>
+#
+# cl.exe cannot write a GNU styl dependency file directly. This wrapper script
+# parses the -showIncludes output and converts it to .d file and outputs this a
+# a byproduct of compile.
+
+for arg; do
+    case $arg in
+        -showIncludes|/showIncludes) deps=1; break ;;
+    esac
+done
+
+[ "$deps" ] || exec "$@"
+
+obj=
+src=
+for arg; do
+    case $arg in
+        -Fo*) obj=${arg#-Fo} ;;
+        /Fo*) obj=${arg#/Fo} ;;
+        *.c|*.cc|*.cpp|*.cxx|*.m|*.mm|*.s|*.S|*.asm) src=${arg##*/} ;;
+    esac
+done
+
+output=$("$@" 2>&1)
+status=$?
+
+printf '%s\n' "$output" | awk -v src="$src" '
+    { sub(/\r$/, "") }
+    /including/ { next }
+    $0 == src   { next }
+    NF          { print }
+'
+
+if [ -n "$obj" ]; then
+    {
+        printf '%s:' "$obj"
+        printf '%s\n' "$output" | awk '/including/ {
+                sub(/\r$/, ""); sub(/^.*file: */, "")
+                if (index($0, " ") == 0) print
+            }' |
+        if command -v wslpath >/dev/null 2>&1; then
+            xargs -r -d '\n' -n1 wslpath -u
+        else
+            sed 's/\\/\//g'
+        fi |
+        while IFS= read -r path; do
+            printf ' %s' "$path"
+        done
+        printf '\n'
+    } > "${obj%.o}.d"
+fi
+
+exit "$status"
-- 
2.52.0


From 5b68bfa6a6cea28843e2c8171e551b66aa396c3b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <[email protected]>
Date: Wed, 1 Jul 2026 04:19:36 +0200
Subject: [PATCH 2/2] configure: wrap MSVC with script that output make dep
 file

Currently when MSVC is used, compilation of single .c file invokes
compiler twice. One for creating .d file and another to produce .o file.
This is wasteful, there is not need to invoke compiler twice, even
though one is preprocessing only, it still takes time.

Fix that by using wrapper script that can parse -showIncludes directly
and can be used as main compiler driver.
---
 configure | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/configure b/configure
index 70e31c563d..35fad7a943 100755
--- a/configure
+++ b/configure
@@ -5454,15 +5454,7 @@ probe_cc(){
         else
             _ident=$($_cc --version 2>/dev/null | head -n1 | tr -d '\r')
         fi
-        if [ -x "$(command -v wslpath)" ]; then
-            _DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $< 2>&1 | awk 
'\''/including/ { sub(/^.*file: */, ""); if (!match($$0, / /)) { print $$0 } 
}'\'' | xargs -r -d\\n -n1 wslpath -u | awk '\''BEGIN { printf "%s:", "$@" }; { 
sub(/\r/,""); printf " %s", $$0 }; END { print "" }'\'' > $(@:.o=.d)'
-
-        else
-            _DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $< 2>&1 | awk 
'\''/including/ { sub(/^.*file: */, ""); gsub(/\\/, "/"); if (!match($$0, / /)) 
print "$@:", $$0 }'\'' > $(@:.o=.d)'
-        fi
-        _DEPFLAGS='$(CPPFLAGS) -showIncludes -Zs'
-        _DEPCCFLAGS='$(CFLAGS)'
-        _DEPCXXFLAGS='$(CXXFLAGS)'
+        _depflags='-showIncludes'
         _cflags_speed="-O2"
         _cflags_size="-O1"
         if $_cc -nologo- 2>&1 | grep -q Linker; then
@@ -8623,6 +8615,12 @@ echo "config:$arch:$subarch:$cpu:$target_os:$(esc 
$cc_ident):$(esc $FFMPEG_CONFI
 enabled stripping || striptype="nostrip"
 enabled stripping || ASMSTRIPFLAGS=""
 
+mscl="$source_path/compat/windows/mscl"
+test "$cc_type"     = msvc && cc="$mscl $cc"
+test "$cc_type"     = msvc && cxx="$mscl $cxx"
+test "$as_type"     = msvc && as="$mscl $as"
+test "$hostcc_type" = msvc && host_cc="$mscl $host_cc"
+
 config_files="$TMPH ffbuild/config.mak doc/config.texi"
 
 cat > ffbuild/config.mak <<EOF
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to