From c84fd58ce4033f8e557bf0cc86a4199978925469 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Wed, 26 Sep 2012 23:35:52 -0400 Subject: [PATCH] Makefile: Add automatic dependency generation --- .gitignore | 1 + Makefile | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 7220ed4..a05b5bb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ aedrix-kernel.elf aedrix-kernel.img *.o *.swp +*.d diff --git a/Makefile b/Makefile index ec118d1..215bc89 100644 --- a/Makefile +++ b/Makefile @@ -50,21 +50,27 @@ aedrix-kernel.img: aedrix-kernel.elf %.o: %.c @echo ' CC $@' - $(V)$(CC) $(KCFLAGS) -c -o $@ $< + $(V)$(CC) $(KCFLAGS) -MD -c -o $@ $< + @# Automatic dependency generation fixups (http://mad-scientist.net/make/autodep.html) + @cp $*.d $(*D)/.$(*F).d; \ + sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ + -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $(*D)/.$(*F).d; \ + rm -f $*.d -# Assembly files without preprocessor directives -%.o: %.s - @echo ' AS $@' - $(V)$(AS) -o $@ $< - -# Assembly files with preprocessor directives %.o: %.S @echo ' AS $@' - $(V)$(AS) -o $@ $< + $(V)$(CC) $(KCFLAGS) -MD -c -o $@ $< + @# Automatic dependency generation fixups (http://mad-scientist.net/make/autodep.html) + @cp $*.d $(*D)/.$(*F).d; \ + sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ + -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $(*D)/.$(*F).d; \ + rm -f $*.d clean: @echo ' CLEAN *.o' $(V)rm -f $(KOBJS) + @echo ' CLEAN .*.d' + $(V)rm -f $(DEPENDENCY_FILES) @echo ' CLEAN aedrix-kernel.elf' $(V)rm -f aedrix-kernel.elf @echo ' CLEAN aedrix-kernel.objdump' @@ -76,3 +82,6 @@ boot: aedrix-kernel.img $(V)qemu-system-arm -m 1024 -M vexpress-a9 -kernel aedrix-kernel.img -serial stdio boot-gdb: aedrix-kernel.img $(V)qemu-system-arm -m 1024 -M vexpress-a9 -kernel aedrix-kernel.img -serial stdio -S -s + +DEPENDENCY_FILES = $(foreach file,$(KOBJS), $(dir $(file)).$(notdir $(basename $(file))).d) +-include $(DEPENDENCY_FILES)