build: simplify dependency generation

Modern GCC and Clang versions can generate .d files without needing the
complex sequence of sed scripts that we currently use.

Also adjust the .o rule so the .d file is regenerated if it gets
deleted.

Also make the .o depend on all of the Makefile fragments in
$(MAKEFILE_LIST) so that it is rebuilt if the Makefile is changed.

Change-Id: I44e186c0f34dabfa0cf35db1ffa66b84d9dae87d
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Daniel Verkamp 2015-11-09 16:40:44 -07:00
parent 8836b6f681
commit 9ea5194634
2 changed files with 10 additions and 16 deletions

View File

@ -55,14 +55,9 @@ $(UT_APP) : $(OBJS)
clean:
$(Q)rm -f $(UT_APP) $(OBJS) *.d
%.o: $(NVME_DIR)/%.c
%.o: $(NVME_DIR)/%.c %.d $(MAKEFILE_LIST)
@echo " CC $@"
$(Q)$(CC) $(CFLAGS) -c $< -o $@
$(Q)$(CC) -MM $(CFLAGS) $(NVME_DIR)/$*.c > $*.d
@mv -f $*.d $*.d.tmp
@sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d
@sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \
sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
@rm -f $*.d.tmp
$(Q)$(CC) $(DEPFLAGS) $(CFLAGS) -c $< -o $@
$(Q)mv -f $*.d.tmp $*.d
include $(SPDK_ROOT_DIR)/mk/spdk.deps.mk

View File

@ -88,15 +88,14 @@ CFLAGS += $(COMMON_CFLAGS) -Wno-pointer-sign -std=gnu99
MAKEFLAGS += --no-print-directory
%.o : %.c
DEPFLAGS = -MMD -MP -MF $*.d.tmp
%.o: %.c %.d $(MAKEFILE_LIST)
@echo " CC $@"
$(Q)$(CC) $(CFLAGS) -c $<
$(Q)$(CC) -MM $(CFLAGS) $*.c > $*.d
@mv -f $*.d $*.d.tmp
@sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d
@sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \
sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
@rm -f $*.d.tmp
$(Q)$(CC) $(DEPFLAGS) $(CFLAGS) -c $<
$(Q)mv -f $*.d.tmp $*.d
%.d: ;
DPDK_DIR ?= $(CONFIG_DPDK_DIR)
DPDK_INC_DIR ?= $(DPDK_DIR)/include