From 65d0ecdef757e28618d2c66702204b74486cf283 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 1 Jun 2015 10:09:43 +1000 Subject: [PATCH] build: fixed dependency on frame type and options this ensures "make sitl-heli" rebuilds after a "make sitl" Thanks to Michael Oborne for reporting this --- mk/board_avr.mk | 39 +-------------------------------------- mk/board_flymaple.mk | 39 +-------------------------------------- mk/board_native.mk | 42 +++--------------------------------------- mk/build_rules.mk | 38 ++++++++++++++++++++++++++++++++++++++ mk/sketch_sources.mk | 12 +++++++----- 5 files changed, 50 insertions(+), 120 deletions(-) create mode 100644 mk/build_rules.mk diff --git a/mk/board_avr.mk b/mk/board_avr.mk index 28d390af3e..505aa92bab 100644 --- a/mk/board_avr.mk +++ b/mk/board_avr.mk @@ -191,41 +191,4 @@ $(SKETCHEEP): $(SKETCHELF) $(RULEHDR) $(v)$(OBJCOPY) -O ihex -j.eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 $< $@ -# -# Build sketch objects -# -SKETCH_INCLUDES = $(SKETCHLIBINCLUDES) $(ARDUINOLIBINCLUDES) $(COREINCLUDES) - -$(BUILDROOT)/%.o: $(BUILDROOT)/%.cpp - $(RULEHDR) - $(v)$(CXX) $(CXXFLAGS) -c -o $@ $< -I$(SRCROOT) $(SKETCH_INCLUDES) - -$(BUILDROOT)/%.o: $(SRCROOT)/%.cpp - $(RULEHDR) - $(v)$(CXX) $(CXXFLAGS) -c -o $@ $< $(SKETCH_INCLUDES) - -$(BUILDROOT)/%.o: $(SRCROOT)/%.c - $(RULEHDR) - $(v)$(CC) $(CFLAGS) -c -o $@ $< $(SKETCH_INCLUDES) - -$(BUILDROOT)/%.o: $(SRCROOT)/%.S - $(RULEHDR) - $(v)$(AS) $(ASFLAGS) -c -o $@ $< $(SKETCH_INCLUDES) - -# -# Build library objects from sources in the sketchbook -# -SLIB_INCLUDES = -I$(dir $<)/utility $(SKETCHLIBINCLUDES) $(ARDUINOLIBINCLUDES) $(COREINCLUDES) - -$(BUILDROOT)/libraries/%.o: $(SKETCHBOOK)/libraries/%.cpp - $(RULEHDR) - $(v)$(CXX) $(CXXFLAGS) -c -o $@ $< $(SLIB_INCLUDES) - -$(BUILDROOT)/libraries/%.o: $(SKETCHBOOK)/libraries/%.c - $(RULEHDR) - $(v)$(CC) $(CFLAGS) -c -o $@ $< $(SLIB_INCLUDES) - -$(BUILDROOT)/libraries/%.o: $(SKETCHBOOK)/libraries/%.S - $(RULEHDR) - $(v)$(AS) $(ASFLAGS) -c -o $@ $< $(SLIB_INCLUDES) - +include $(MK_DIR)/build_rules.mk diff --git a/mk/board_flymaple.mk b/mk/board_flymaple.mk index 2f7d2057c0..749d2a1147 100644 --- a/mk/board_flymaple.mk +++ b/mk/board_flymaple.mk @@ -175,41 +175,4 @@ $(SKETCHEEP): $(SKETCHELF) $(RULEHDR) $(v)$(OBJCOPY) -O ihex -j.eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 $< $@ -# -# Build sketch objects -# -SKETCH_INCLUDES = $(SKETCHLIBINCLUDES) $(ARDUINOLIBINCLUDES) $(COREINCLUDES) - -$(BUILDROOT)/%.o: $(BUILDROOT)/%.cpp - $(RULEHDR) - $(v)$(CXX) $(CXXFLAGS) -c -o $@ $< -I$(SRCROOT) $(SKETCH_INCLUDES) - -$(BUILDROOT)/%.o: $(SRCROOT)/%.cpp - $(RULEHDR) - $(v)$(CXX) $(CXXFLAGS) -c -o $@ $< $(SKETCH_INCLUDES) - -$(BUILDROOT)/%.o: $(SRCROOT)/%.c - $(RULEHDR) - $(v)$(CC) $(CFLAGS) -c -o $@ $< $(SKETCH_INCLUDES) - -$(BUILDROOT)/%.o: $(SRCROOT)/%.S - $(RULEHDR) - $(v)$(AS) $(ASFLAGS) -c -o $@ $< $(SKETCH_INCLUDES) - -# -# Build library objects from sources in the sketchbook -# -SLIB_INCLUDES = -I$(dir $<)/utility $(SKETCHLIBINCLUDES) $(ARDUINOLIBINCLUDES) $(COREINCLUDES) - -$(BUILDROOT)/libraries/%.o: $(SKETCHBOOK)/libraries/%.cpp - $(RULEHDR) - $(v)$(CXX) $(CXXFLAGS) -c -o $@ $< $(SLIB_INCLUDES) - -$(BUILDROOT)/libraries/%.o: $(SKETCHBOOK)/libraries/%.c - $(RULEHDR) - $(v)$(CC) $(CFLAGS) -c -o $@ $< $(SLIB_INCLUDES) - -$(BUILDROOT)/libraries/%.o: $(SKETCHBOOK)/libraries/%.S - $(RULEHDR) - $(v)$(AS) $(ASFLAGS) -c -o $@ $< $(SLIB_INCLUDES) - +include $(MK_DIR)/build_rules.mk diff --git a/mk/board_native.mk b/mk/board_native.mk index 80abc863d0..ca8a4597fe 100644 --- a/mk/board_native.mk +++ b/mk/board_native.mk @@ -95,47 +95,11 @@ print-%: -include $(ALLDEPS) # Link the final object -$(SKETCHELF): $(SKETCHOBJS) $(LIBOBJS) +$(SKETCHELF): $(SKETCHOBJS) $(LIBOBJS) @echo "Building $(SKETCHELF)" $(RULEHDR) - $(v)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS) + $(v)$(LD) $(LDFLAGS) -o $@ $(SKETCHOBJS) $(LIBOBJS) $(LIBS) $(v)cp $(SKETCHELF) . @echo "Firmware is in $(BUILDELF)" -# -# Build sketch objects -# -SKETCH_INCLUDES = $(SKETCHLIBINCLUDES) - -$(BUILDROOT)/%.o: $(BUILDROOT)/%.cpp - $(RULEHDR) - $(v)$(CXX) $(CXXFLAGS) -c -o $@ $< -I$(SRCROOT) $(SKETCH_INCLUDES) - -$(BUILDROOT)/%.o: $(SRCROOT)/%.cpp - $(RULEHDR) - $(v)$(CXX) $(CXXFLAGS) -c -o $@ $< $(SKETCH_INCLUDES) - -$(BUILDROOT)/%.o: $(SRCROOT)/%.c - $(RULEHDR) - $(v)$(CC) $(CFLAGS) -c -o $@ $< $(SKETCH_INCLUDES) - -$(BUILDROOT)/%.o: $(SRCROOT)/%.S - $(RULEHDR) - $(v)$(AS) $(ASFLAGS) -c -o $@ $< $(SKETCH_INCLUDES) - -# -# Build library objects from sources in the sketchbook -# -SLIB_INCLUDES = -I$(dir $<)/utility $(SKETCHLIBINCLUDES) - -$(BUILDROOT)/libraries/%.o: $(SKETCHBOOK)/libraries/%.cpp - $(RULEHDR) - $(v)$(CXX) $(CXXFLAGS) -c -o $@ $< $(SLIB_INCLUDES) - -$(BUILDROOT)/libraries/%.o: $(SKETCHBOOK)/libraries/%.c - $(RULEHDR) - $(v)$(CC) $(CFLAGS) -c -o $@ $< $(SLIB_INCLUDES) - -$(BUILDROOT)/libraries/%.o: $(SKETCHBOOK)/libraries/%.S - $(RULEHDR) - $(v)$(AS) $(ASFLAGS) -c -o $@ $< $(SLIB_INCLUDES) +include $(MK_DIR)/build_rules.mk diff --git a/mk/build_rules.mk b/mk/build_rules.mk new file mode 100644 index 0000000000..58233f967d --- /dev/null +++ b/mk/build_rules.mk @@ -0,0 +1,38 @@ + +# +# Build sketch objects +# +SKETCH_INCLUDES = $(SKETCHLIBINCLUDES) + +$(BUILDROOT)/%.o: $(BUILDROOT)/%.cpp + $(RULEHDR) + $(v)$(CXX) $(CXXFLAGS) -c -o $@ $< -I$(SRCROOT) $(SKETCH_INCLUDES) + +$(BUILDROOT)/%.o: $(BUILDROOT)/make.flags $(SRCROOT)/%.cpp + $(RULEHDR) + $(v)$(CXX) $(CXXFLAGS) -c -o $@ $*.cpp $(SKETCH_INCLUDES) + +$(BUILDROOT)/%.o: $(SRCROOT)/%.c + $(RULEHDR) + $(v)$(CC) $(CFLAGS) -c -o $@ $< $(SKETCH_INCLUDES) + +$(BUILDROOT)/%.o: $(SRCROOT)/%.S + $(RULEHDR) + $(v)$(AS) $(ASFLAGS) -c -o $@ $< $(SKETCH_INCLUDES) + +# +# Build library objects from sources in the sketchbook +# +SLIB_INCLUDES = -I$(dir $<)/utility $(SKETCHLIBINCLUDES) + +$(BUILDROOT)/libraries/%.o: $(SKETCHBOOK)/libraries/%.cpp + $(RULEHDR) + $(v)$(CXX) $(CXXFLAGS) -c -o $@ $< $(SLIB_INCLUDES) + +$(BUILDROOT)/libraries/%.o: $(SKETCHBOOK)/libraries/%.c + $(RULEHDR) + $(v)$(CC) $(CFLAGS) -c -o $@ $< $(SLIB_INCLUDES) + +$(BUILDROOT)/libraries/%.o: $(SKETCHBOOK)/libraries/%.S + $(RULEHDR) + $(v)$(AS) $(ASFLAGS) -c -o $@ $< $(SLIB_INCLUDES) diff --git a/mk/sketch_sources.mk b/mk/sketch_sources.mk index 72a8328b61..f659f23bb5 100644 --- a/mk/sketch_sources.mk +++ b/mk/sketch_sources.mk @@ -77,12 +77,14 @@ else v = endif -.PHONY: $(BUILDROOT)/make.flags -$(BUILDROOT)/make.flags: - @mkdir -p $(BUILDROOT) - @echo "// BUILDROOT=$(BUILDROOT) HAL_BOARD=$(HAL_BOARD) HAL_BOARD_SUBTYPE=$(HAL_BOARD_SUBTYPE) TOOLCHAIN=$(TOOLCHAIN) EXTRAFLAGS=$(EXTRAFLAGS)" > $(BUILDROOT)/make.flags - @cat $(BUILDROOT)/make.flags +FORCE: +$(BUILDROOT)/make.flags: FORCE + @mkdir -p $(BUILDROOT) + @echo "// BUILDROOT=$(BUILDROOT) HAL_BOARD=$(HAL_BOARD) HAL_BOARD_SUBTYPE=$(HAL_BOARD_SUBTYPE) TOOLCHAIN=$(TOOLCHAIN) EXTRAFLAGS=$(EXTRAFLAGS)" > $(BUILDROOT)/make.flags.new + @cmp $(BUILDROOT)/make.flags $(BUILDROOT)/make.flags.new > /dev/null 2>&1 || mv $(BUILDROOT)/make.flags.new $(BUILDROOT)/make.flags + @rm -f $(BUILDROOT)/make.flags.new + @cat $(BUILDROOT)/make.flags ifeq (,$(MAKE_INC)) # Build the sketch.cpp file