diff --git a/libraries/AP_Common/Arduino.mk b/libraries/AP_Common/Arduino.mk index 59bddff8cf..db89ffb837 100644 --- a/libraries/AP_Common/Arduino.mk +++ b/libraries/AP_Common/Arduino.mk @@ -146,15 +146,16 @@ endif # DEFINES = -DF_CPU=$(F_CPU) -DARDUINO=$(ARDUINO_VERS) OPTFLAGS = -Os +DEPFLAGS = -MD -MT $@ # XXX warning options TBD CXXOPTS = -mcall-prologues -ffunction-sections -fdata-sections -fno-exceptions COPTS = -mcall-prologues -ffunction-sections -fdata-sections ASOPTS = -assembler-with-cpp -CXXFLAGS = -g -mmcu=$(MCU) $(DEFINES) $(OPTFLAGS) $(CXXOPTS) -CFLAGS = -g -mmcu=$(MCU) $(DEFINES) $(OPTFLAGS) $(COPTS) -ASFLAGS = -g -mmcu=$(MCU) $(DEFINES) $(ASOPTS) +CXXFLAGS = -g -mmcu=$(MCU) $(DEFINES) $(OPTFLAGS) $(DEPFLAGS) $(CXXOPTS) +CFLAGS = -g -mmcu=$(MCU) $(DEFINES) $(OPTFLAGS) $(DEPFLAGS) $(COPTS) +ASFLAGS = -g -mmcu=$(MCU) $(DEFINES) $(DEPFLAGS) $(ASOPTS) LDFLAGS = -g -mmcu=$(MCU) $(OPTFLAGS) -Wl,--gc-sections LIBS = -lm @@ -291,6 +292,12 @@ SKETCHEEP = $(BUILDROOT)/$(SKETCH).eep # The core library CORELIB = $(BUILDROOT)/$(HARDWARE)/core.a +# All of the objects that may be built +ALLOBJS = $(SKETCHOBJS) $(LIBOBJS) $(CORELIBOBJS) + +# All of the dependency files that may be generated +ALLDEPS = $(ALLOBJS:%.o=%.d) + ################################################################################ # Targets # @@ -306,6 +313,9 @@ clean: # Rules # +# fetch dependency info from a previous build if any of it exists +-include $(ALLDEPS) + # common header for rules, prints what is being built define RULEHDR @echo %% $(subst $(BUILDROOT)/,,$@) @@ -327,10 +337,6 @@ $(SKETCHEEP): $(SKETCHELF) $(RULEHDR) $(v)$(OBJCOPY) -O ihex -j.eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 $< $@ -# Make the buildroot -$(BUILDROOT): - @mkdir -p $(BUILDROOT) - # # Build sketch objects # @@ -425,7 +431,7 @@ $(CORELIB): $(CORELIBOBJS) # In addition, we add #line directives wherever the originating file changes # to help backtrack from compiler messages and in the debugger. # -$(SKETCHCPP): $(SKETCHCPP_SRC) $(BUILDROOT) +$(SKETCHCPP): $(SKETCHCPP_SRC) $(RULEHDR) $(v)$(AWK) -v mode=header '$(SKETCH_SPLITTER)' $(SKETCHCPP_SRC) > $@ $(v)echo "#line 1 \"autogenerated\"" >> $@