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.)
This commit is contained in:
Martin Storsjö
2025-03-03 21:44:27 +02:00
parent c80f8a2815
commit 27d8370847
3 changed files with 36 additions and 41 deletions
+1
View File
@@ -1,5 +1,6 @@
*~ *~
*.a *.a
*.d
*.diff *.diff
*.orig *.orig
*.rej *.rej
+29 -36
View File
@@ -311,39 +311,46 @@ example$(EXE): $(OBJEXAMPLE) $(LIBX264)
$(OBJS) $(OBJSO): CFLAGS += $(CFLAGSSO) $(OBJS) $(OBJSO): CFLAGS += $(CFLAGSSO)
$(OBJCLI): CFLAGS += $(CFLAGSCLI) $(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 %.o: %.c
$(CC) $(CFLAGS) -c $< $(CC_O) $(DEPCMD)
$(CC) $(CFLAGS) -c $< $(CC_O) $(DEPFLAGS)
%-8.o: %.c %-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 %-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 %.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 -@ $(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 %-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 $@) -@ $(if $(STRIP), $(STRIP) -x $@)
%-10.o: %.asm common/x86/x86inc.asm common/x86/x86util.asm %-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 $@) -@ $(if $(STRIP), $(STRIP) -x $@)
%.o: %.S %.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 -@ $(if $(STRIP), $(STRIP) -x $@) # delete local/anonymous symbols, so they don't show up in oprofile
%-8.o: %.S %-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 $@) -@ $(if $(STRIP), $(STRIP) -x $@)
%-10.o: %.S %-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 $@) -@ $(if $(STRIP), $(STRIP) -x $@)
%.dll.o: %.rc x264.h %.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 %.o: %.rc x264.h x264res.manifest
$(RC) $(RCFLAGS)$@ $< $(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: config.mak:
./configure ./configure
depend: .depend # This is kept as a no-op
ifneq ($(wildcard .depend),) depend:
include .depend @echo "make depend" is handled implicitly now
endif
-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) OBJPROF = $(OBJS) $(OBJSO) $(OBJCLI)
# These should cover most of the important codepaths # These should cover most of the important codepaths
@@ -412,11 +404,12 @@ endif
endif endif
clean: 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 $(SONAME) *.a *.lib *.exp *.pdb x264$(EXE) x264_lookahead.clbin
rm -f checkasm8$(EXE) checkasm10$(EXE) $(OBJCHK) $(OBJCHK_8) $(OBJCHK_10) rm -f checkasm8$(EXE) checkasm10$(EXE) $(OBJCHK) $(OBJCHK_8) $(OBJCHK_10)
rm -f example$(EXE) $(OBJEXAMPLE) rm -f example$(EXE) $(OBJEXAMPLE)
rm -f $(OBJPROF:%.o=%.gcda) $(OBJPROF:%.o=%.gcno) *.dyn pgopti.dpi pgopti.dpi.lock *.pgd *.pgc rm -f $(OBJPROF:%.o=%.gcda) $(OBJPROF:%.o=%.gcno) *.dyn pgopti.dpi pgopti.dpi.lock *.pgd *.pgc
rm -f $(ALLOBJS:%.o=%.d)
distclean: clean distclean: clean
rm -f config.mak x264_config.h config.h config.log x264.pc x264.def rm -f config.mak x264_config.h config.h config.log x264.pc x264.def
Vendored
+6 -5
View File
@@ -1496,9 +1496,9 @@ else
CLI_LIBX264='$(LIBX264)' CLI_LIBX264='$(LIBX264)'
fi fi
DEPMM="${QPRE}MM"
DEPMT="${QPRE}MT"
if [ $compiler_style = MS ]; then if [ $compiler_style = MS ]; then
DEPFLAGS=""
DEPCMD='@$(SRCPATH)/tools/msvsdepend.sh "$(CC)" "$(CFLAGS)" "$<" "$@" > $(@:.o=.d)'
AR="lib.exe -nologo -out:" AR="lib.exe -nologo -out:"
LD="link.exe -out:" LD="link.exe -out:"
if [ $compiler = ICL ]; then if [ $compiler = ICL ]; then
@@ -1522,7 +1522,8 @@ if [ $compiler_style = MS ]; then
CFLAGS="-DNDEBUG $CFLAGS" CFLAGS="-DNDEBUG $CFLAGS"
fi fi
else # gcc/icc else # gcc/icc
DEPMM="$DEPMM -g0" DEPFLAGS="${QPRE}MMD ${QPRE}MF"' $(@:.o=.d)'
DEPCMD=""
AR="$AR rc " AR="$AR rc "
LD="$CC -o " LD="$CC -o "
LIBX264=libx264.a LIBX264=libx264.a
@@ -1575,8 +1576,8 @@ CFLAGSSO=$CFLAGSSO
CFLAGSCLI=$CFLAGSCLI CFLAGSCLI=$CFLAGSCLI
COMPILER=$compiler COMPILER=$compiler
COMPILER_STYLE=$compiler_style COMPILER_STYLE=$compiler_style
DEPMM=$DEPMM DEPCMD=$DEPCMD
DEPMT=$DEPMT DEPFLAGS=$DEPFLAGS
LD=$LD LD=$LD
LDFLAGS=$LDFLAGS LDFLAGS=$LDFLAGS
LDFLAGSCLI=$LDFLAGSCLI LDFLAGSCLI=$LDFLAGSCLI