diff --git a/Makefile-SIM b/Makefile-SIM index 80ecfd6..89c1711 100644 --- a/Makefile-SIM +++ b/Makefile-SIM @@ -42,9 +42,6 @@ SOURCES = $(wildcard *.c) SIM_SOURCES = $(subst $(SIM_PATH)/,,$(wildcard $(SIM_PATH)/*.c)) SOURCES := $(filter-out $(subst _sim.c,.c,$(SIM_SOURCES)),$(SOURCES)) $(SIM_SOURCES) -HEADERS = config.h serial.h dda.h timer.h clock.h temp.h sermsg.h -HEADERS += dda_queue.h debug.h sersendf.h heater.h analog.h delay.h -HEADERS += simulator.h OBJ = $(patsubst %.c,$(BUILDDIR)/%.sim.o,$(SOURCES)) CFLAGS = -g -Wall -Wstrict-prototypes -Wno-format -Os $(DEFS) -std=gnu99 @@ -58,9 +55,10 @@ CFLAGS += -D__AVR_ATmega1280__ include Makefile-common -$(BUILDDIR)/%.sim.o: %.c $(HEADERS) +$(BUILDDIR)/%.sim.o: %.c | $(BUILDDIR) @echo " CC $@" - @cc -c $(CFLAGS) -o $@ $< + @cc -c $(CFLAGS) -MMD -o $@ $< + @$(call CCPOST) $(TARGET): $(OBJ) @echo " LINK $@" diff --git a/Makefile-common b/Makefile-common index b287d6b..298b265 100644 --- a/Makefile-common +++ b/Makefile-common @@ -32,8 +32,6 @@ ############################################################################## BUILDDIR = build -DEPEND = $(BUILDDIR)/depend - CFLAGS += -save-temps=obj CC = $(TOOLCHAIN)gcc @@ -63,20 +61,27 @@ functionsbysize: $(OBJ) @$(OBJDUMP) -h $^ | grep '\.text\.' | perl -ne '/\.text\.(\S+)\s+([0-9a-f]+)/ && printf "%u\t%s\n", eval("0x$$2"), $$1;' | sort -n $(BUILDDIR): - mkdir $(BUILDDIR) - -$(DEPEND): $(SOURCES) - @echo " DEP $@" - @rm -f $(DEPEND) - @mkdir -p $(@D) - @$(CC) $(CFLAGS) -MM $^ > $@ + mkdir -p $(BUILDDIR) # pull in dependency info --include $(DEPEND) +-include $(OBJ:%.o=%.P) -$(BUILDDIR)/%.o: %.c config.h $(MAKEFILE_LIST) +# Everything depends on makefiles, excluding auto-built makefiles +$(OBJ): $(filter-out %.P,$(MAKEFILE_LIST)) + +# Auto-depends extension +df = $(@:.o=) +define CCPOST + cp $(df).d $(df).P; \ + sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ + -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \ + rm -f $(df).d +endef + +$(BUILDDIR)/%.o: %.c | $(BUILDDIR) @echo " CC $@" - @$(CC) -c $(CFLAGS) -Wa,-adhlns=$(@:.o=.al) -o $@ $< + @$(CC) -c $(CFLAGS) -MMD -Wa,-adhlns=$(@:.o=.al) -o $@ $< + @$(call CCPOST) $(BUILDDIR)/%.elf: $(OBJ) @echo " LINK $@"