From a164436d9801ac13f604e788adba9b59b611b56d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 23 Jan 2014 15:16:29 +0200 Subject: [PATCH] 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. --- .gitignore | 3 +++ Makefile | 4 +++- build/platform-darwin.mk | 2 +- build/platform-linux.mk | 2 +- build/platform-mingw_nt.mk | 2 +- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 445e27ae..5bf8a9e6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,9 @@ *.o *.ko +# Dependency files +*.d + # Libraries *.lib *.a diff --git a/Makefile b/Makefile index 690fa322..f59005b9 100644 --- a/Makefile +++ b/Makefile @@ -94,7 +94,7 @@ CODEC_UNITTEST_DEPS = $(LIBPREFIX)gtest.$(LIBSUFFIX) $(LIBPREFIX)decoder.$(LIBSU all: libraries binaries clean: - rm -f $(OBJS) $(LIBRARIES) $(BINARIES) + rm -f $(OBJS) $(OBJS:.o=.d) $(LIBRARIES) $(BINARIES) gtest-bootstrap: svn co https://googletest.googlecode.com/svn/trunk/ gtest @@ -119,3 +119,5 @@ ifeq ($(HAVE_GTEST),Yes) include build/gtest-targets.mk include test/targets.mk endif + +-include $(OBJS:.o=.d) diff --git a/build/platform-darwin.mk b/build/platform-darwin.mk index d5ae8d2c..01eda0a1 100644 --- a/build/platform-darwin.mk +++ b/build/platform-darwin.mk @@ -1,6 +1,6 @@ ASM = nasm -CFLAGS += -Wno-deprecated-declarations -Werror -fPIC -DMACOS -DMT_ENABLED +CFLAGS += -Wno-deprecated-declarations -Werror -fPIC -DMACOS -DMT_ENABLED -MMD -MP LDFLAGS += -lpthread ASMFLAGS += --prefix _ -DNOPREFIX ifeq ($(ENABLE64BIT), Yes) diff --git a/build/platform-linux.mk b/build/platform-linux.mk index 32c88ff8..8cc35678 100644 --- a/build/platform-linux.mk +++ b/build/platform-linux.mk @@ -1,5 +1,5 @@ ASM = nasm -CFLAGS += -Werror -fPIC -DLINUX -DMT_ENABLED +CFLAGS += -Werror -fPIC -DLINUX -DMT_ENABLED -MMD -MP LDFLAGS += -lpthread ASMFLAGS += -DNOPREFIX ifeq ($(ENABLE64BIT), Yes) diff --git a/build/platform-mingw_nt.mk b/build/platform-mingw_nt.mk index 78f11940..367a42d8 100644 --- a/build/platform-mingw_nt.mk +++ b/build/platform-mingw_nt.mk @@ -1,5 +1,5 @@ ASM = nasm -CFLAGS += -DMT_ENABLED +CFLAGS += -DMT_ENABLED -MMD -MP LDFLAGS += ifeq ($(ENABLE64BIT), Yes) ASMFLAGS += -f win64