auto-gen dependencies

This commit is contained in:
Mariano Alvira 2010-03-01 16:27:58 -05:00
parent de4080c359
commit 191e408bb7
2 changed files with 23 additions and 14 deletions

View file

@ -30,20 +30,28 @@ export ARCH CPU VENDOR
.SECONDARY: .SECONDARY:
#.depend: Makefile $(AOBJS:.o=.S) $(COBJS:.o=.c)
# $(CC) -M $(CFLAGS) $(AOBJS:.o=.S) $(COBJS:.o=.c) > $@ ### See http://make.paulandlesley.org/autodep.html#advanced
#sinclude .depend 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) $(START): $(START:.o=.s)
$(CC) $(AFLAGS) -c -o $@ $< $(CC) $(AFLAGS) -c -o $@ $<
$(ISR): $(ISR:.o=.c) $(ISR): $(ISR:.o=.c)
$(CC) $(CFLAGS) $(ARM_FLAGS) $< -c -o $@ $(CC) $(CFLAGS) $(ARM_FLAGS) -MMD $< -c -o $@
@$(FINALIZE_DEPENDENCY)
%_$(BOARD).elf: %.elf $(BOARDOBJS) %_$(BOARD).elf: $(START) $(ISR) $(SRCOBJS) $(OBJDIR)/%.o $(BOARDOBJS) $(LINKERSCRIPT) $(LIBMC1322X)/libmc1322x.a
mv $< $@
%.elf: $(START) $(ISR) $(SRCOBJS) $(OBJDIR)/%.o $(BOARDOBJS) $(LINKERSCRIPT) $(LIBMC1322X)/libmc1322x.a
$(CC) $(LDFLAGS) $(AOBJS) \ $(CC) $(LDFLAGS) $(AOBJS) \
$(filter %.o %.a,$+) -o $@ $(filter %.o %.a,$+) -o $@
@ -62,22 +70,23 @@ $(ISR): $(ISR:.o=.c)
$(OBJDIR)/%.s: %.S $(OBJDIR)/%.s: %.S
$(CPP) $(AFLAGS) -o $@ $< $(CPP) $(AFLAGS) -o $@ $<
$(OBJDIR)/%.o: %.S $(OBJDIR)/%.o: %.S
$(CC) $(AFLAGS) -c -o $@ $< $(CC) $(AFLAGS) -MMD -c -o $@ $<
@$(FINALIZE_DEPENDENCY)
$(OBJDIR)/%.o: %.c $(OBJDIR)/%.o: %.c
$(CC) $(CFLAGS) $(THUMB_FLAGS) -c -o $@ $< $(CC) $(CFLAGS) $(THUMB_FLAGS) -MMD -c -o $@ $<
@$(FINALIZE_DEPENDENCY)
clean: clean:
find $(MC1322X) \ find $(MC1322X) \
\( -name 'core' -o -name '*.bak' -o -name '*~' \ \( -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 '*.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 | xargs rm -rf
rm -fr *.*~ rm -fr *.*~
find \ find \
\( -name 'core' -o -name '*.bak' -o -name '*~' \ \( -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 '*.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 | xargs rm -rf
rm -fr *.*~ rm -fr *.*~

View file

@ -37,7 +37,7 @@ CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -Wcast-align -Wcast-align -Wextr
AFLAGS_DEBUG := -Wa,-gstabs AFLAGS_DEBUG := -Wa,-gstabs
AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS) 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
######################################################################### #########################################################################