[x264-devel] [Git][videolan/x264][master] 2 commits: msvsdepend: Allow using the script for .S sources too

Martin Storsjö (@mstorsjo) gitlab at videolan.org
Wed Mar 12 10:54:21 UTC 2025



Martin Storsjö pushed to branch master at VideoLAN / x264


Commits:
c80f8a28 by Martin Storsjö at 2025-03-04T11:15:49+02:00
msvsdepend: Allow using the script for .S sources too

Previously, MSVC would warn that the .S source is unrecognized,
and the script would only produce a depenency on the main source
file itself.

- - - - -
27d83708 by Martin Storsjö at 2025-03-11T22:22:24+02:00
Makefile: Generate dependency information implicitly while compiling

This updates the dependecy information on each successive recompile.

When building with MSVC, dependency information is generated with
a separate command just like before, but done together with
compiling each object file. (This is quite similar to how ffmpeg does
the same.)

This avoids the serial dependency generation step. In slow
environments (in particular if using MSVC) it could take a notable
amount of time; this can now all be done in parallel.

In one example, this reduces the time for a full build from clean
with MSVC (wrapped in wine) from 23 seconds down to 9 seconds,
thanks to parallelism. (For non-parallel builds, it doesn't make
much of a difference.)

- - - - -


4 changed files:

- .gitignore
- Makefile
- configure
- tools/msvsdepend.sh


Changes:

=====================================
.gitignore
=====================================
@@ -1,5 +1,6 @@
 *~
 *.a
+*.d
 *.diff
 *.orig
 *.rej


=====================================
Makefile
=====================================
@@ -311,39 +311,46 @@ example$(EXE): $(OBJEXAMPLE) $(LIBX264)
 $(OBJS) $(OBJSO): CFLAGS += $(CFLAGSSO)
 $(OBJCLI): CFLAGS += $(CFLAGSCLI)
 
-$(OBJS) $(OBJASM) $(OBJSO) $(OBJCLI) $(OBJCHK) $(OBJCHK_8) $(OBJCHK_10) $(OBJEXAMPLE): .depend
+ALLOBJS = $(OBJS) $(OBJASM) $(OBJSO) $(OBJCLI) $(OBJCHK) $(OBJCHK_8) $(OBJCHK_10) $(OBJEXAMPLE)
+$(ALLOBJS): $(GENERATED)
 
 %.o: %.c
-	$(CC) $(CFLAGS) -c $< $(CC_O)
+	$(DEPCMD)
+	$(CC) $(CFLAGS) -c $< $(CC_O) $(DEPFLAGS)
 
 %-8.o: %.c
-	$(CC) $(CFLAGS) -c $< $(CC_O) -DHIGH_BIT_DEPTH=0 -DBIT_DEPTH=8
+	$(DEPCMD)
+	$(CC) $(CFLAGS) -c $< $(CC_O) $(DEPFLAGS) -DHIGH_BIT_DEPTH=0 -DBIT_DEPTH=8
 
 %-10.o: %.c
-	$(CC) $(CFLAGS) -c $< $(CC_O) -DHIGH_BIT_DEPTH=1 -DBIT_DEPTH=10
+	$(DEPCMD)
+	$(CC) $(CFLAGS) -c $< $(CC_O) $(DEPFLAGS) -DHIGH_BIT_DEPTH=1 -DBIT_DEPTH=10
 
 %.o: %.asm common/x86/x86inc.asm common/x86/x86util.asm
-	$(AS) $(ASFLAGS) -o $@ $<
+	$(AS) $(ASFLAGS) -o $@ $< -MD $(@:.o=.d)
 	-@ $(if $(STRIP), $(STRIP) -x $@) # delete local/anonymous symbols, so they don't show up in oprofile
 
 %-8.o: %.asm common/x86/x86inc.asm common/x86/x86util.asm
-	$(AS) $(ASFLAGS) -o $@ $< -DBIT_DEPTH=8 -Dprivate_prefix=x264_8
+	$(AS) $(ASFLAGS) -o $@ $< -MD $(@:.o=.d) -DBIT_DEPTH=8 -Dprivate_prefix=x264_8
 	-@ $(if $(STRIP), $(STRIP) -x $@)
 
 %-10.o: %.asm common/x86/x86inc.asm common/x86/x86util.asm
-	$(AS) $(ASFLAGS) -o $@ $< -DBIT_DEPTH=10 -Dprivate_prefix=x264_10
+	$(AS) $(ASFLAGS) -o $@ $< -MD $(@:.o=.d) -DBIT_DEPTH=10 -Dprivate_prefix=x264_10
 	-@ $(if $(STRIP), $(STRIP) -x $@)
 
 %.o: %.S
-	$(AS) $(ASFLAGS) -o $@ $<
+	$(DEPCMD)
+	$(AS) $(ASFLAGS) -o $@ $< $(DEPFLAGS)
 	-@ $(if $(STRIP), $(STRIP) -x $@) # delete local/anonymous symbols, so they don't show up in oprofile
 
 %-8.o: %.S
-	$(AS) $(ASFLAGS) -o $@ $< -DHIGH_BIT_DEPTH=0 -DBIT_DEPTH=8
+	$(DEPCMD)
+	$(AS) $(ASFLAGS) -o $@ $< $(DEPFLAGS) -DHIGH_BIT_DEPTH=0 -DBIT_DEPTH=8
 	-@ $(if $(STRIP), $(STRIP) -x $@)
 
 %-10.o: %.S
-	$(AS) $(ASFLAGS) -o $@ $< -DHIGH_BIT_DEPTH=1 -DBIT_DEPTH=10
+	$(DEPCMD)
+	$(AS) $(ASFLAGS) -o $@ $< $(DEPFLAGS) -DHIGH_BIT_DEPTH=1 -DBIT_DEPTH=10
 	-@ $(if $(STRIP), $(STRIP) -x $@)
 
 %.dll.o: %.rc x264.h
@@ -352,34 +359,19 @@ $(OBJS) $(OBJASM) $(OBJSO) $(OBJCLI) $(OBJCHK) $(OBJCHK_8) $(OBJCHK_10) $(OBJEXA
 %.o: %.rc x264.h x264res.manifest
 	$(RC) $(RCFLAGS)$@ $<
 
-.depend: config.mak $(GENERATED)
-	@rm -f .depend
-	@echo 'dependency file generation...'
-ifeq ($(COMPILER),CL)
-	@$(foreach SRC, $(addprefix $(SRCPATH)/, $(SRCS) $(SRCCLI) $(SRCSO) $(SRCEXAMPLE)), $(SRCPATH)/tools/msvsdepend.sh "$(CC)" "$(CFLAGS)" "$(SRC)" "$(SRC:$(SRCPATH)/%.c=%.o)" 1>> .depend;)
-ifneq ($(findstring HAVE_BITDEPTH8 1, $(CONFIG)),)
-	@$(foreach SRC, $(addprefix $(SRCPATH)/, $(SRCS_X) $(SRCS_8) $(SRCCLI_X) $(SRCCHK_X)), $(SRCPATH)/tools/msvsdepend.sh "$(CC)" "$(CFLAGS)" "$(SRC)" "$(SRC:$(SRCPATH)/%.c=%-8.o)" 1>> .depend;)
-endif
-ifneq ($(findstring HAVE_BITDEPTH10 1, $(CONFIG)),)
-	@$(foreach SRC, $(addprefix $(SRCPATH)/, $(SRCS_X) $(SRCCLI_X) $(SRCCHK_X)), $(SRCPATH)/tools/msvsdepend.sh "$(CC)" "$(CFLAGS)" "$(SRC)" "$(SRC:$(SRCPATH)/%.c=%-10.o)" 1>> .depend;)
-endif
-else
-	@$(foreach SRC, $(addprefix $(SRCPATH)/, $(SRCS) $(SRCCLI) $(SRCSO) $(SRCEXAMPLE)), $(CC) $(CFLAGS) $(SRC) $(DEPMT) $(SRC:$(SRCPATH)/%.c=%.o) $(DEPMM) 1>> .depend;)
-ifneq ($(findstring HAVE_BITDEPTH8 1, $(CONFIG)),)
-	@$(foreach SRC, $(addprefix $(SRCPATH)/, $(SRCS_X) $(SRCS_8) $(SRCCLI_X) $(SRCCHK_X)), $(CC) $(CFLAGS) $(SRC) $(DEPMT) $(SRC:$(SRCPATH)/%.c=%-8.o) $(DEPMM) 1>> .depend;)
-endif
-ifneq ($(findstring HAVE_BITDEPTH10 1, $(CONFIG)),)
-	@$(foreach SRC, $(addprefix $(SRCPATH)/, $(SRCS_X) $(SRCCLI_X) $(SRCCHK_X)), $(CC) $(CFLAGS) $(SRC) $(DEPMT) $(SRC:$(SRCPATH)/%.c=%-10.o) $(DEPMM) 1>> .depend;)
-endif
-endif
-
 config.mak:
 	./configure
 
-depend: .depend
-ifneq ($(wildcard .depend),)
-include .depend
-endif
+# This is kept as a no-op
+depend:
+	@echo "make depend" is handled implicitly now
+
+-include $(wildcard $(ALLOBJS:.o=.d))
+
+# Dummy rule to avoid failing, if the dependency files specify dependencies on
+# a removed .h file.
+%.h:
+	@:
 
 OBJPROF = $(OBJS) $(OBJSO) $(OBJCLI)
 # These should cover most of the important codepaths
@@ -412,11 +404,12 @@ endif
 endif
 
 clean:
-	rm -f $(OBJS) $(OBJASM) $(OBJCLI) $(OBJSO) $(GENERATED) .depend TAGS
+	rm -f $(OBJS) $(OBJASM) $(OBJCLI) $(OBJSO) $(GENERATED) TAGS
 	rm -f $(SONAME) *.a *.lib *.exp *.pdb x264$(EXE) x264_lookahead.clbin
 	rm -f checkasm8$(EXE) checkasm10$(EXE) $(OBJCHK) $(OBJCHK_8) $(OBJCHK_10)
 	rm -f example$(EXE) $(OBJEXAMPLE)
 	rm -f $(OBJPROF:%.o=%.gcda) $(OBJPROF:%.o=%.gcno) *.dyn pgopti.dpi pgopti.dpi.lock *.pgd *.pgc
+	rm -f $(ALLOBJS:%.o=%.d)
 
 distclean: clean
 	rm -f config.mak x264_config.h config.h config.log x264.pc x264.def


=====================================
configure
=====================================
@@ -1496,9 +1496,9 @@ else
     CLI_LIBX264='$(LIBX264)'
 fi
 
-DEPMM="${QPRE}MM"
-DEPMT="${QPRE}MT"
 if [ $compiler_style = MS ]; then
+    DEPFLAGS=""
+    DEPCMD='@$(SRCPATH)/tools/msvsdepend.sh "$(CC)" "$(CFLAGS)" "$<" "$@" > $(@:.o=.d)'
     AR="lib.exe -nologo -out:"
     LD="link.exe -out:"
     if [ $compiler = ICL ]; then
@@ -1522,7 +1522,8 @@ if [ $compiler_style = MS ]; then
         CFLAGS="-DNDEBUG $CFLAGS"
     fi
 else # gcc/icc
-    DEPMM="$DEPMM -g0"
+    DEPFLAGS="${QPRE}MMD ${QPRE}MF"' $(@:.o=.d)'
+    DEPCMD=""
     AR="$AR rc "
     LD="$CC -o "
     LIBX264=libx264.a
@@ -1575,8 +1576,8 @@ CFLAGSSO=$CFLAGSSO
 CFLAGSCLI=$CFLAGSCLI
 COMPILER=$compiler
 COMPILER_STYLE=$compiler_style
-DEPMM=$DEPMM
-DEPMT=$DEPMT
+DEPCMD=$DEPCMD
+DEPFLAGS=$DEPFLAGS
 LD=$LD
 LDFLAGS=$LDFLAGS
 LDFLAGSCLI=$LDFLAGSCLI


=====================================
tools/msvsdepend.sh
=====================================
@@ -8,11 +8,22 @@ set -f
 [ -n "$1" ] && [ -n "$3" ] && [ -n "$4" ] || exit 1
 
 # Add flags to only perform syntax checking and output a list of included files
+# For sources that aren't C, run preprocessing to NUL instead.
+
+case "$3" in
+*.c)
+    opts="-W0 -Zs"
+    ;;
+*)
+    opts="-P -FiNUL"
+    ;;
+esac
+
 # 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 |
+deps="$($1 $2 -nologo -showIncludes $opts "$3" 2>&1 |
         grep '^Note: including file:' |
         sed 's/^Note: including file:[[:space:]]*\(.*\)$/\1/; s/\\/\//g' |
         sed '/\/[Pp]rogram [Ff]iles/d')



View it on GitLab: https://code.videolan.org/videolan/x264/-/compare/373697b467f7cd0af88f1e9e32d4f10540df4687...27d8370847d79665de06bbf8f043ce9a3a4a3da1

-- 
View it on GitLab: https://code.videolan.org/videolan/x264/-/compare/373697b467f7cd0af88f1e9e32d4f10540df4687...27d8370847d79665de06bbf8f043ce9a3a4a3da1
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the x264-devel mailing list