From 191e408bb718639ea60d8ad48dce017fafaf729d Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Mon, 1 Mar 2010 16:27:58 -0500 Subject: [PATCH] auto-gen dependencies --- Makefile.include | 35 ++++++++++++++++++++++------------- config.mk | 2 +- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Makefile.include b/Makefile.include index 6dae2ebc8..e23947a37 100644 --- a/Makefile.include +++ b/Makefile.include @@ -30,20 +30,28 @@ export ARCH CPU VENDOR .SECONDARY: -#.depend: Makefile $(AOBJS:.o=.S) $(COBJS:.o=.c) -# $(CC) -M $(CFLAGS) $(AOBJS:.o=.S) $(COBJS:.o=.c) > $@ -#sinclude .depend + +### See http://make.paulandlesley.org/autodep.html#advanced +ifdef BOARD +-include ${addprefix $(OBJDIR)/,$(addsuffix .d,$(TARGETS))} +endif + +define FINALIZE_DEPENDENCY +cp $(@:.o=.d) $(@:.o=.$$$$); \ +sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ + -e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.$$$$) >> $(@:.o=.d); \ +rm -f $(@:.o=.$$$$) +endef + $(START): $(START:.o=.s) $(CC) $(AFLAGS) -c -o $@ $< $(ISR): $(ISR:.o=.c) - $(CC) $(CFLAGS) $(ARM_FLAGS) $< -c -o $@ + $(CC) $(CFLAGS) $(ARM_FLAGS) -MMD $< -c -o $@ + @$(FINALIZE_DEPENDENCY) -%_$(BOARD).elf: %.elf $(BOARDOBJS) - mv $< $@ - -%.elf: $(START) $(ISR) $(SRCOBJS) $(OBJDIR)/%.o $(BOARDOBJS) $(LINKERSCRIPT) $(LIBMC1322X)/libmc1322x.a +%_$(BOARD).elf: $(START) $(ISR) $(SRCOBJS) $(OBJDIR)/%.o $(BOARDOBJS) $(LINKERSCRIPT) $(LIBMC1322X)/libmc1322x.a $(CC) $(LDFLAGS) $(AOBJS) \ $(filter %.o %.a,$+) -o $@ @@ -62,22 +70,23 @@ $(ISR): $(ISR:.o=.c) $(OBJDIR)/%.s: %.S $(CPP) $(AFLAGS) -o $@ $< $(OBJDIR)/%.o: %.S - $(CC) $(AFLAGS) -c -o $@ $< + $(CC) $(AFLAGS) -MMD -c -o $@ $< + @$(FINALIZE_DEPENDENCY) $(OBJDIR)/%.o: %.c - $(CC) $(CFLAGS) $(THUMB_FLAGS) -c -o $@ $< - + $(CC) $(CFLAGS) $(THUMB_FLAGS) -MMD -c -o $@ $< + @$(FINALIZE_DEPENDENCY) clean: find $(MC1322X) \ \( -name 'core' -o -name '*.bak' -o -name '*~' \ -o -name '*.o' -o -name '*.a' -o -name '*.obj' -o -name '*.elf' -o -name '*.s' -o -name '*.map' \ - -o -name 'obj_*_board' -o -name '.depend' -o -name '*.bin' -o -name '*.dis' \) -print \ + -o -name 'obj_*_board' -o -name '.depend' -o -name '*.bin' -o -name '*.dis' -o -name '*.d' \) -print \ | xargs rm -rf rm -fr *.*~ find \ \( -name 'core' -o -name '*.bak' -o -name '*~' \ -o -name '*.o' -o -name '*.a' -o -name '*.obj' -o -name '*.elf' -o -name '*.s' -o -name '*.map' \ - -o -name 'obj_*_board' -o -name '.depend' -o -name '*.bin' -o -name '*.dis' \) -print \ + -o -name 'obj_*_board' -o -name '.depend' -o -name '*.bin' -o -name '*.dis' -o -name '*.d' \) -print \ | xargs rm -rf rm -fr *.*~ diff --git a/config.mk b/config.mk index b0f8aa261..c0e31618e 100644 --- a/config.mk +++ b/config.mk @@ -37,7 +37,7 @@ CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -Wcast-align -Wcast-align -Wextr AFLAGS_DEBUG := -Wa,-gstabs AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS) -LDFLAGS += -T $(LINKERSCRIPT) -nostartfiles -static -Wl,-Map=$*.map -export-dynamic +LDFLAGS += -T $(LINKERSCRIPT) -nostartfiles -static -Wl,-Map=$*_$(BOARD).map -export-dynamic #########################################################################