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


From 16155851cfdb60f2dd22ef57c9b3ea9ef81f8956 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <[email protected]>
Date: Mon, 21 Sep 2026 13:46:28 +0200
Subject: [PATCH 1/2] compat/windows/mscl: keep dependency paths outside the
 build directory absolute
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Only paths below the current directory are written relative now, which
is valid in every view of the same directory. Everything else stays
absolute, in forward slash form.

Signed-off-by: Kacper Michajłow <[email protected]>
---
 compat/windows/mscl.c | 85 +++++++++++++++----------------------------
 1 file changed, 30 insertions(+), 55 deletions(-)

diff --git a/compat/windows/mscl.c b/compat/windows/mscl.c
index cc1ee7a15e..8f30abfcb2 100644
--- a/compat/windows/mscl.c
+++ b/compat/windows/mscl.c
@@ -24,11 +24,11 @@
  * include records from the compiler's stdout into a .d file, written next to
  * the object file as a byproduct of compilation.
  *
- * Dependency paths are rewritten relative to the current directory, which
- * keeps the .d files independent of how the environment maps Windows drives
- * (MSYS, Cygwin and WSL all differ). Paths on a different drive or share are
- * kept absolute, in forward slash form. Spaces, '#' and '$' are escaped the
- * same way gcc escapes them in -MD output.
+ * Dependency paths below the current directory are written relative to it,
+ * which keeps the .d files independent of how the environment maps Windows
+ * drives (MSYS, Cygwin and WSL all differ). Everything else stays absolute,
+ * in forward slash form. Spaces, '#' and '$' are escaped the same way gcc
+ * escapes them in -MD output.
  *
  * On a POSIX host driving a Windows compiler (cl.exe through WSL interop, for
  * example) the records carry Windows paths. Each distinct drive or share root
@@ -195,60 +195,17 @@ static int chr_eq(char a, char b)
 #endif
 }
 
-/* Length of the root that "../" cannot climb out of, "//server/share" for
- * UNC paths and "X:" for drive letter paths, 0 otherwise. Forward slashes 
only. */
-static size_t root_len(const char *p)
-{
-    size_t i = 0;
-
-    if (p[0] == '/' && p[1] == '/') {
-        for (i = 2; p[i] && p[i] != '/'; i++)
-            ;
-        if (p[i])
-            for (i++; p[i] && p[i] != '/'; i++)
-                ;
-    } else if (isalpha(p[0]) && p[1] == ':') {
-        i = 2;
-    }
-    return i;
-}
-
+/* Relative form of a path below the current directory, NULL for any other. */
 static char *make_relative(const char *path)
 {
-    size_t i, tail = 0, updirs = 0, root = root_len(path);
-    int found = 0;
-    const char *rest;
-    char *out, *q;
+    size_t i;
 
-    /* longest common prefix ending on a component boundary */
-    for (i = 0;; i++) {
-        int pb = !path[i] || path[i] == '/';
-        int cb = !cwd[i]  || cwd[i]  == '/';
-        if (pb && cb) {
-            tail  = i;
-            found = 1;
-        }
-        if (!path[i] || !cwd[i] || !chr_eq(path[i], cwd[i]))
-            break;
-    }
-    /* nothing to name, or a different drive or share */
-    if (!found || !path[tail] || tail < root || root_len(cwd) != root)
+    for (i = 0; cwd[i]; i++)
+        if (!path[i] || !chr_eq(path[i], cwd[i]))
+            return NULL;
+    if (path[i] != '/' || !path[i + 1])
         return NULL;
-
-    if (cwd[tail])
-        for (i = tail + 1;; i++) {
-            if (!cwd[i] || cwd[i] == '/')
-                updirs++;
-            if (!cwd[i])
-                break;
-        }
-
-    rest = path + tail + 1;
-    out  = q = xrealloc(NULL, 3 * updirs + strlen(rest) + 1);
-    for (i = 0; i < updirs; i++, q += 3)
-        memcpy(q, "../", 3);
-    strcpy(q, rest);
-    return out;
+    return xstrdup(path + i + 1);
 }
 
 static void add_dep(char *path)
@@ -269,6 +226,24 @@ static const char *unmapped;
 
 #ifndef _WIN32
 
+/* Length of the root that "../" cannot climb out of, "//server/share" for
+ * UNC paths and "X:" for drive letter paths, 0 otherwise. */
+static size_t root_len(const char *p)
+{
+    size_t i = 0;
+
+    if (p[0] == '/' && p[1] == '/') {
+        for (i = 2; p[i] && p[i] != '/'; i++)
+            ;
+        if (p[i])
+            for (i++; p[i] && p[i] != '/'; i++)
+                ;
+    } else if (isalpha(p[0]) && p[1] == ':') {
+        i = 2;
+    }
+    return i;
+}
+
 static struct {
     char *root;
     char *host;
-- 
2.52.0


From c287a34a521e5fffa6ac1229dab79eb0728c67c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <[email protected]>
Date: Mon, 21 Sep 2026 13:58:18 +0200
Subject: [PATCH 2/2] Reapply "Makefile: output MSVC dependency files as a
 byproduct of compilation"
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit fddc59cf34b303a269493aaf7ec7c80e390f25f5.

Signed-off-by: Kacper Michajłow <[email protected]>
---
 Makefile                | 13 +++++++++++++
 configure               | 10 +---------
 ffbuild/common.mak      | 19 ++++++++++---------
 libswscale/x86/Makefile |  2 +-
 tools/Makefile          | 16 ++++++++--------
 5 files changed, 33 insertions(+), 27 deletions(-)

diff --git a/Makefile b/Makefile
index 1fe6549ba8..b8ecf5be42 100644
--- a/Makefile
+++ b/Makefile
@@ -47,6 +47,19 @@ SKIPHEADERS = compat/w32pthreads.h
 # first so "all" becomes default target
 all: all-yes
 
+# cl.exe cannot write make dependency files directly, the mscl helper
+# converts its -showIncludes output into .d files.
+MSCL := $(if $(filter -showIncludes,$(CC_DEPFLAGS) $(CXX_DEPFLAGS) 
$(OBJCC_DEPFLAGS) $(AS_DEPFLAGS) $(HOSTCC_DEPFLAGS)),ffbuild/mscl$(HOSTEXESUF))
+ifneq ($(MSCL),)
+MSCLCC := $(HOSTCC)
+$(foreach V,CC CXX OBJCC HOSTCC AS,\
+    $(if $(filter -showIncludes,$($(V)_DEPFLAGS)),$(eval $(V) := $(MSCL) 
$($(V)))))
+HOSTPROGS += ffbuild/mscl
+
+ffbuild/mscl.o: $(SRC_PATH)/compat/windows/mscl.c
+       $(MSCLCC) $(HOSTCCFLAGS) $(HOSTCC_C) $(HOSTCC_O) $<
+endif
+
 include $(SRC_PATH)/tools/Makefile
 include $(SRC_PATH)/ffbuild/common.mak
 
diff --git a/configure b/configure
index 6901344317..035d4d090a 100755
--- a/configure
+++ b/configure
@@ -5388,15 +5388,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
diff --git a/ffbuild/common.mak b/ffbuild/common.mak
index 1f6c5a7522..d03764df7d 100644
--- a/ffbuild/common.mak
+++ b/ffbuild/common.mak
@@ -22,7 +22,7 @@ INSTALL_FILES = $(INSTALL) $(1) $(2) "$(3)"
 ifndef V
 Q      = @
 ECHO   = printf "$(1)\t%s\n" $(2)
-BRIEF  = CC CXX OBJCC HOSTCC HOSTLD AS X86ASM AR LD LDXX STRIP CP WINDRES 
GLSLC NVCC BIN2C METALCC METALLIB
+BRIEF  = CC CXX OBJCC HOSTCC HOSTLD AS X86ASM AR LD LDXX STRIP CP WINDRES 
GLSLC NVCC BIN2C METALCC METALLIB MSCLCC
 SILENT = DEPCC DEPCXX DEPHOSTCC DEPAS DEPX86ASM RANLIB RM
 
 MSG    = $@
@@ -82,22 +82,22 @@ COMPILE_LASX = $(call COMPILE,CC,LASXFLAGS)
 %_lasx.o: %_lasx.c
        $(COMPILE_LASX)
 
-%.o: %.c
+%.o: %.c | $(MSCL)
        $(COMPILE_C)
 
-%.o: %.cpp
+%.o: %.cpp | $(MSCL)
        $(COMPILE_CXX)
 
-%.o: %.m
+%.o: %.m | $(MSCL)
        $(COMPILE_M)
 
-%.s: %.c
+%.s: %.c | $(MSCL)
        $(CC) $(CCFLAGS) -S -o $@ $<
 
-%.o: %.S
+%.o: %.S | $(MSCL)
        $(COMPILE_S)
 
-%_host.o: %.c
+%_host.o: %.c | $(MSCL)
        $(COMPILE_HOSTC)
 
 %.o: %.asm
@@ -107,7 +107,7 @@ COMPILE_LASX = $(call COMPILE,CC,LASXFLAGS)
 %.o: %.rc
        $(WINDRES) $(IFLAGS) $(foreach ARG,$(CC_DEPFLAGS),--preprocessor-arg 
"$(ARG)") -o $@ $<
 
-%.i: %.c
+%.i: %.c | $(MSCL)
        $(CC) $(CCFLAGS) $(CC_E) $<
 
 %.h.c:
@@ -243,7 +243,8 @@ checkheaders: $(HOBJS)
 .SECONDARY:   $(HOBJS:.o=.c) $(SPVOBJS:.o=.c) $(SPVOBJS:.o=.gz) $(SPVOBJS:.o=) 
$(PTXOBJS:.o=.c) $(PTXOBJS:.o=.gz) $(PTXOBJS:.o=)
 alltools: $(TOOLS)
 
-$(HOSTOBJS): %.o: %.c
+# ffbuild/mscl.o is excluded as it has its own bootstrap rule in Makefile
+$(filter-out ffbuild/mscl.o,$(HOSTOBJS)): %.o: %.c | $(MSCL)
        $(COMPILE_HOSTC)
 
 $(HOSTPROGS): %$(HOSTEXESUF): %.o
diff --git a/libswscale/x86/Makefile b/libswscale/x86/Makefile
index 4467fd877d..5fae34a832 100644
--- a/libswscale/x86/Makefile
+++ b/libswscale/x86/Makefile
@@ -31,6 +31,6 @@ $(SUBDIR)x86/ops_common.o: $(SUBDIR)x86/uops_macros.gen.asm
 $(SUBDIR)x86/ops_int.o: $(SUBDIR)x86/uops_macros.gen.asm
 $(SUBDIR)x86/ops_float.o: $(SUBDIR)x86/uops_macros.gen.asm
 $(SUBDIR)x86/uops_macros.gen.asm: $(SRC_PATH)/libswscale/x86/uops_macros.asm.h 
\
-                                  $(SRC_PATH)/libswscale/uops_macros.h
+                                  $(SRC_PATH)/libswscale/uops_macros.h | 
$(MSCL)
        $(HOSTCC) $(HOSTCC_E) $(HOSTCPPFLAGS) $<
 endif
diff --git a/tools/Makefile b/tools/Makefile
index 7ae6e3cb75..9ed3251ff9 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -2,28 +2,28 @@ TOOLS = enc_recon_frame_test enum_options qt-faststart 
scale_slice_test trasher
 TOOLS-$(CONFIG_LIBMYSOFA) += sofa2wavs
 TOOLS-$(CONFIG_ZLIB) += cws2fws
 
-tools/target_dec_%_fuzzer.o: tools/target_dec_fuzzer.c
+tools/target_dec_%_fuzzer.o: tools/target_dec_fuzzer.c | $(MSCL)
        $(COMPILE_C) -DFFMPEG_DECODER=$*
 
-tools/target_enc_%_fuzzer.o: tools/target_enc_fuzzer.c
+tools/target_enc_%_fuzzer.o: tools/target_enc_fuzzer.c | $(MSCL)
        $(COMPILE_C) -DFFMPEG_ENCODER=$*
 
-tools/target_bsf_%_fuzzer.o: tools/target_bsf_fuzzer.c
+tools/target_bsf_%_fuzzer.o: tools/target_bsf_fuzzer.c | $(MSCL)
        $(COMPILE_C) -DFFMPEG_BSF=$*
 
-tools/target_dem_%_fuzzer.o: tools/target_dem_fuzzer.c
+tools/target_dem_%_fuzzer.o: tools/target_dem_fuzzer.c | $(MSCL)
        $(COMPILE_C) -DFFMPEG_DEMUXER=$* -DIO_FLAT=0
 
-tools/target_dem_fuzzer.o: tools/target_dem_fuzzer.c
+tools/target_dem_fuzzer.o: tools/target_dem_fuzzer.c | $(MSCL)
        $(COMPILE_C) -DIO_FLAT=1
 
-tools/target_io_dem_fuzzer.o: tools/target_dem_fuzzer.c
+tools/target_io_dem_fuzzer.o: tools/target_dem_fuzzer.c | $(MSCL)
        $(COMPILE_C) -DIO_FLAT=0
 
-tools/target_sws_fuzzer.o: tools/target_sws_fuzzer.c
+tools/target_sws_fuzzer.o: tools/target_sws_fuzzer.c | $(MSCL)
        $(COMPILE_C)
 
-tools/target_swr_fuzzer.o: tools/target_swr_fuzzer.c
+tools/target_swr_fuzzer.o: tools/target_swr_fuzzer.c | $(MSCL)
        $(COMPILE_C)
 
 tools/enc_recon_frame_test$(EXESUF): tools/decode_simple.o
-- 
2.52.0

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

Reply via email to