diff mbox

Remove visible dependency files

Message ID 20150529142017.GA32617@rmk-PC.arm.linux.org.uk (mailing list archive)
State New, archived
Headers show

Commit Message

Russell King May 29, 2015, 2:20 p.m. UTC
After building, there is a lot of clutter from the dependency system.
Let's clean this up by using dir/.file.d style dependencies, similar
to those used in the Linux kernel.

In order to support this, rearrange the dependency generation to
create the dependency files as we build rather than as a separate
step, and have make clean remove them.

Signed-off-by: Russell King <rmk@arm.linux.org.uk>
---
 Makefile | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)
diff mbox

Patch

diff --git a/Makefile b/Makefile
index 4bd86ee..c07fd8e 100644
--- a/Makefile
+++ b/Makefile
@@ -288,7 +288,13 @@  LIBS	+= -lpthread
 LIBS	+= -lutil
 
 
-DEPS	:= $(patsubst %.o,%.d,$(OBJS))
+comma = ,
+
+# The dependency file for the current target
+depfile = $(subst $(comma),_,$(dir $@).$(notdir $@).d)
+
+DEPS	:= $(foreach obj,$(OBJS),\
+		$(subst $(comma),_,$(dir $(obj)).$(notdir $(obj)).d))
 
 DEFINES	+= -D_FILE_OFFSET_BITS=64
 DEFINES	+= -D_GNU_SOURCE
@@ -327,6 +333,10 @@  all: arch_support_check $(PROGRAM) $(PROGRAM_ALIAS) $(GUEST_INIT)
 arch_support_check:
 	$(UNSUPP_ERR)
 
+# CFLAGS used when building objects
+# This is intentionally not assigned using :=
+c_flags	= -Wp,-MD,$(depfile) $(CFLAGS)
+
 # When building -static all objects are built with appropriate flags, which
 # may differ between static & dynamic .o.  The objects are separated into
 # .o and .static.o.  See the %.o: %.c rules below.
@@ -336,11 +346,11 @@  arch_support_check:
 STATIC_OBJS = $(patsubst %.o,%.static.o,$(OBJS) $(OBJS_STATOPT))
 GUEST_OBJS = guest/guest_init.o
 
-$(PROGRAM)-static:  $(DEPS) $(STATIC_OBJS) $(OTHEROBJS) $(GUEST_INIT)
+$(PROGRAM)-static:  $(STATIC_OBJS) $(OTHEROBJS) $(GUEST_INIT)
 	$(E) "  LINK    " $@
 	$(Q) $(CC) -static $(CFLAGS) $(STATIC_OBJS) $(OTHEROBJS) $(GUEST_OBJS) $(LIBS) $(LIBS_STATOPT) -o $@
 
-$(PROGRAM): $(DEPS) $(OBJS) $(OBJS_DYNOPT) $(OTHEROBJS) $(GUEST_INIT)
+$(PROGRAM): $(OBJS) $(OBJS_DYNOPT) $(OTHEROBJS) $(GUEST_INIT)
 	$(E) "  LINK    " $@
 	$(Q) $(CC) $(CFLAGS) $(OBJS) $(OBJS_DYNOPT) $(OTHEROBJS) $(GUEST_OBJS) $(LIBS) $(LIBS_DYNOPT) -o $@
 
@@ -353,19 +363,11 @@  $(GUEST_INIT): guest/init.c
 	$(Q) $(CC) -static guest/init.c -o $@
 	$(Q) $(LD) $(LDFLAGS) -r -b binary -o guest/guest_init.o $(GUEST_INIT)
 
-$(DEPS):
-
-util/rbtree.d: util/rbtree.c
-	$(Q) $(CC) -M -MT util/rbtree.o $(CFLAGS) $< -o $@
-
-%.d: %.c
-	$(Q) $(CC) -M -MT $(patsubst %.d,%.o,$@) $(CFLAGS) $< -o $@
-
 %.s: %.c
 	$(Q) $(CC) -o $@ -S $(CFLAGS) -fverbose-asm $<
 
 # The header file common-cmds.h is needed for compilation of builtin-help.c.
-builtin-help.d: $(KVM_INCLUDE)/common-cmds.h
+builtin-help.o: $(KVM_INCLUDE)/common-cmds.h
 
 $(OBJS):
 
@@ -375,7 +377,7 @@  ifeq ($(C),1)
 	$(Q) $(CHECK) -c $(CFLAGS) $< -o $@
 endif
 	$(E) "  CC      " $@
-	$(Q) $(CC) -c $(CFLAGS) $< -o $@
+	$(Q) $(CC) -c $(c_flags) $< -o $@
 
 %.static.o: %.c
 ifeq ($(C),1)
@@ -383,7 +385,7 @@  ifeq ($(C),1)
 	$(Q) $(CHECK) -c $(CFLAGS) $(CFLAGS_STATOPT) $< -o $@
 endif
 	$(E) "  CC      " $@
-	$(Q) $(CC) -c $(CFLAGS) $(CFLAGS_STATOPT)  $< -o $@
+	$(Q) $(CC) -c $(c_flags) $(CFLAGS_STATOPT)  $< -o $@
 
 %.o: %.c
 ifeq ($(C),1)
@@ -391,7 +393,7 @@  ifeq ($(C),1)
 	$(Q) $(CHECK) -c $(CFLAGS) $(CFLAGS_DYNOPT) $< -o $@
 endif
 	$(E) "  CC      " $@
-	$(Q) $(CC) -c $(CFLAGS) $(CFLAGS_DYNOPT) $< -o $@
+	$(Q) $(CC) -c $(c_flags) $(CFLAGS_DYNOPT) $< -o $@
 
 
 $(KVM_INCLUDE)/common-cmds.h: util/generate-cmdlist.sh command-list.txt