Automatically track per-file dependencies

This is enabled for platforms/compilers that support the -MMD
option, which creates a dependency file named out.d when compiling
to a file named out.o, only including local, not system headers.

The additional -MP option adds phony targets for all included
headers, to avoid having make error out due to "no rule to make
target foo.h" if a header is renamed/removed.

This makes sure that all the right files are rebuilt if a header
is changed, avoiding the need for a full rebuild if only a few
files are affected.
This commit is contained in:
Martin Storsjö 2014-01-23 15:16:29 +02:00
parent 977768ac88
commit a164436d98
5 changed files with 9 additions and 4 deletions

3
.gitignore vendored
View File

@ -2,6 +2,9 @@
*.o *.o
*.ko *.ko
# Dependency files
*.d
# Libraries # Libraries
*.lib *.lib
*.a *.a

View File

@ -94,7 +94,7 @@ CODEC_UNITTEST_DEPS = $(LIBPREFIX)gtest.$(LIBSUFFIX) $(LIBPREFIX)decoder.$(LIBSU
all: libraries binaries all: libraries binaries
clean: clean:
rm -f $(OBJS) $(LIBRARIES) $(BINARIES) rm -f $(OBJS) $(OBJS:.o=.d) $(LIBRARIES) $(BINARIES)
gtest-bootstrap: gtest-bootstrap:
svn co https://googletest.googlecode.com/svn/trunk/ gtest svn co https://googletest.googlecode.com/svn/trunk/ gtest
@ -119,3 +119,5 @@ ifeq ($(HAVE_GTEST),Yes)
include build/gtest-targets.mk include build/gtest-targets.mk
include test/targets.mk include test/targets.mk
endif endif
-include $(OBJS:.o=.d)

View File

@ -1,6 +1,6 @@
ASM = nasm ASM = nasm
CFLAGS += -Wno-deprecated-declarations -Werror -fPIC -DMACOS -DMT_ENABLED CFLAGS += -Wno-deprecated-declarations -Werror -fPIC -DMACOS -DMT_ENABLED -MMD -MP
LDFLAGS += -lpthread LDFLAGS += -lpthread
ASMFLAGS += --prefix _ -DNOPREFIX ASMFLAGS += --prefix _ -DNOPREFIX
ifeq ($(ENABLE64BIT), Yes) ifeq ($(ENABLE64BIT), Yes)

View File

@ -1,5 +1,5 @@
ASM = nasm ASM = nasm
CFLAGS += -Werror -fPIC -DLINUX -DMT_ENABLED CFLAGS += -Werror -fPIC -DLINUX -DMT_ENABLED -MMD -MP
LDFLAGS += -lpthread LDFLAGS += -lpthread
ASMFLAGS += -DNOPREFIX ASMFLAGS += -DNOPREFIX
ifeq ($(ENABLE64BIT), Yes) ifeq ($(ENABLE64BIT), Yes)

View File

@ -1,5 +1,5 @@
ASM = nasm ASM = nasm
CFLAGS += -DMT_ENABLED CFLAGS += -DMT_ENABLED -MMD -MP
LDFLAGS += LDFLAGS +=
ifeq ($(ENABLE64BIT), Yes) ifeq ($(ENABLE64BIT), Yes)
ASMFLAGS += -f win64 ASMFLAGS += -f win64