Merge pull request #976 from nathantsoi/feature/verboseable-makefile

option to set `V=1 make ...` for verbose make output
This commit is contained in:
Anders Höglund 2016-08-13 20:43:39 +02:00 committed by GitHub
commit 138c302e80
1 changed files with 61 additions and 47 deletions

108
Makefile
View File

@ -37,6 +37,20 @@ SERIAL_DEVICE ?= $(firstword $(wildcard /dev/ttyUSB*) no-port-found)
# Flash size (KB). Some low-end chips actually have more flash than advertised, use this to override. # Flash size (KB). Some low-end chips actually have more flash than advertised, use this to override.
FLASH_SIZE ?= FLASH_SIZE ?=
## Set verbosity level based on the V= parameter
## V=0 Low
## v=1 High
export AT := @
ifndef V
export V0 :=
export V1 := $(AT)
else ifeq ($(V), 0)
export V0 := $(AT)
export V1 := $(AT)
else ifeq ($(V), 1)
endif
############################################################################### ###############################################################################
# Things that need to be maintained as the source changes # Things that need to be maintained as the source changes
# #
@ -640,39 +654,39 @@ CLEAN_ARTIFACTS += $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
# It would be nice to compute these lists, but that seems to be just beyond make. # It would be nice to compute these lists, but that seems to be just beyond make.
$(TARGET_HEX): $(TARGET_ELF) $(TARGET_HEX): $(TARGET_ELF)
$(OBJCOPY) -O ihex --set-start 0x8000000 $< $@ $(V0) $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@
$(TARGET_BIN): $(TARGET_ELF) $(TARGET_BIN): $(TARGET_ELF)
$(OBJCOPY) -O binary $< $@ $(V0) $(OBJCOPY) -O binary $< $@
$(TARGET_ELF): $(TARGET_OBJS) $(TARGET_ELF): $(TARGET_OBJS)
@echo LD $(notdir $@) $(V1) echo LD $(notdir $@)
@$(CC) -o $@ $^ $(LDFLAGS) $(V1) $(CC) -o $@ $^ $(LDFLAGS)
$(SIZE) $(TARGET_ELF) $(V0) $(SIZE) $(TARGET_ELF)
# Compile # Compile
$(OBJECT_DIR)/$(TARGET)/%.o: %.c $(OBJECT_DIR)/$(TARGET)/%.o: %.c
@mkdir -p $(dir $@) $(V1) mkdir -p $(dir $@)
@echo %% $(notdir $<) $(V1) echo %% $(notdir $<)
@$(CC) -c -o $@ $(CFLAGS) $< $(V1) $(CC) -c -o $@ $(CFLAGS) $<
# Assemble # Assemble
$(OBJECT_DIR)/$(TARGET)/%.o: %.s $(OBJECT_DIR)/$(TARGET)/%.o: %.s
@mkdir -p $(dir $@) $(V1) mkdir -p $(dir $@)
@echo %% $(notdir $<) $(V1) echo %% $(notdir $<)
@$(CC) -c -o $@ $(ASFLAGS) $< $(V1) $(CC) -c -o $@ $(ASFLAGS) $<
$(OBJECT_DIR)/$(TARGET)/%.o: %.S $(OBJECT_DIR)/$(TARGET)/%.o: %.S
@mkdir -p $(dir $@) $(V1) mkdir -p $(dir $@)
@echo %% $(notdir $<) $(V1) echo %% $(notdir $<)
@$(CC) -c -o $@ $(ASFLAGS) $< $(V1) $(CC) -c -o $@ $(ASFLAGS) $<
## all : Build all valid targets ## all : Build all valid targets
all: $(VALID_TARGETS) all: $(VALID_TARGETS)
$(VALID_TARGETS): $(VALID_TARGETS):
echo "" && \ $(V0) echo "" && \
echo "Building $@" && \ echo "Building $@" && \
$(MAKE) binary hex TARGET=$@ && \ $(MAKE) binary hex TARGET=$@ && \
echo "Building $@ succeeded." echo "Building $@ succeeded."
@ -684,22 +698,22 @@ TARGETS_CLEAN = $(addsuffix _clean,$(VALID_TARGETS) )
## clean : clean up temporary / machine-generated files ## clean : clean up temporary / machine-generated files
clean: clean:
echo "Cleaning $(TARGET)" $(V0) echo "Cleaning $(TARGET)"
rm -f $(CLEAN_ARTIFACTS) $(V0) rm -f $(CLEAN_ARTIFACTS)
rm -rf $(OBJECT_DIR)/$(TARGET) $(V0) rm -rf $(OBJECT_DIR)/$(TARGET)
echo "Cleaning $(TARGET) succeeded." $(V0) echo "Cleaning $(TARGET) succeeded."
## clean_test : clean up temporary / machine-generated files (tests) ## clean_test : clean up temporary / machine-generated files (tests)
clean_test: clean_test:
cd src/test && $(MAKE) clean || true $(V0) cd src/test && $(MAKE) clean || true
## clean_<TARGET> : clean up one specific target ## clean_<TARGET> : clean up one specific target
$(CLEAN_TARGETS) : $(CLEAN_TARGETS) :
$(MAKE) -j TARGET=$(subst clean_,,$@) clean $(V0) $(MAKE) -j TARGET=$(subst clean_,,$@) clean
## <TARGET>_clean : clean up one specific target (alias for above) ## <TARGET>_clean : clean up one specific target (alias for above)
$(TARGETS_CLEAN) : $(TARGETS_CLEAN) :
$(MAKE) -j TARGET=$(subst _clean,,$@) clean $(V0) $(MAKE) -j TARGET=$(subst _clean,,$@) clean
## clean_all : clean all valid targets ## clean_all : clean all valid targets
clean_all:$(CLEAN_TARGETS) clean_all:$(CLEAN_TARGETS)
@ -709,62 +723,62 @@ all_clean:$(TARGETS_CLEAN)
flash_$(TARGET): $(TARGET_HEX) flash_$(TARGET): $(TARGET_HEX)
stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
echo -n 'R' >$(SERIAL_DEVICE) $(V0) echo -n 'R' >$(SERIAL_DEVICE)
stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE) $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
## flash : flash firmware (.hex) onto flight controller ## flash : flash firmware (.hex) onto flight controller
flash: flash_$(TARGET) flash: flash_$(TARGET)
st-flash_$(TARGET): $(TARGET_BIN) st-flash_$(TARGET): $(TARGET_BIN)
st-flash --reset write $< 0x08000000 $(V0) st-flash --reset write $< 0x08000000
## st-flash : flash firmware (.bin) onto flight controller ## st-flash : flash firmware (.bin) onto flight controller
st-flash: st-flash_$(TARGET) st-flash: st-flash_$(TARGET)
binary: binary:
$(MAKE) -j $(TARGET_BIN) $(V0) $(MAKE) -j $(TARGET_BIN)
hex: hex:
$(MAKE) -j $(TARGET_HEX) $(V0) $(MAKE) -j $(TARGET_HEX)
unbrick_$(TARGET): $(TARGET_HEX) unbrick_$(TARGET): $(TARGET_HEX)
stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE) $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
## unbrick : unbrick flight controller ## unbrick : unbrick flight controller
unbrick: unbrick_$(TARGET) unbrick: unbrick_$(TARGET)
## cppcheck : run static analysis on C source code ## cppcheck : run static analysis on C source code
cppcheck: $(CSOURCES) cppcheck: $(CSOURCES)
$(CPPCHECK) $(V0) $(CPPCHECK)
cppcheck-result.xml: $(CSOURCES) cppcheck-result.xml: $(CSOURCES)
$(CPPCHECK) --xml-version=2 2> cppcheck-result.xml $(V0) $(CPPCHECK) --xml-version=2 2> cppcheck-result.xml
## help : print this help message and exit ## help : print this help message and exit
help: Makefile help: Makefile
@echo "" $(V0) @echo ""
@echo "Makefile for the $(FORKNAME) firmware" $(V0) @echo "Makefile for the $(FORKNAME) firmware"
@echo "" $(V0) @echo ""
@echo "Usage:" $(V0) @echo "Usage:"
@echo " make [TARGET=<target>] [OPTIONS=\"<options>\"]" $(V0) @echo " make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
@echo "Or:" $(V0) @echo "Or:"
@echo " make <target> [OPTIONS=\"<options>\"]" $(V0) @echo " make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
@echo "" $(V0) @echo ""
@echo "Valid TARGET values are: $(VALID_TARGETS)" $(V0) @echo "Valid TARGET values are: $(VALID_TARGETS)"
@echo "" $(V0) @echo ""
@sed -n 's/^## //p' $< $(V0) @sed -n 's/^## //p' $<
## targets : print a list of all valid target platforms (for consumption by scripts) ## targets : print a list of all valid target platforms (for consumption by scripts)
targets: targets:
@echo "Valid targets: $(VALID_TARGETS)" $(V0) @echo "Valid targets: $(VALID_TARGETS)"
@echo "Target: $(TARGET)" $(V0) @echo "Target: $(TARGET)"
@echo "Base target: $(BASE_TARGET)" $(V0) @echo "Base target: $(BASE_TARGET)"
## test : run the cleanflight test suite ## test : run the cleanflight test suite
test: test:
cd src/test && $(MAKE) test || true $(V0) cd src/test && $(MAKE) test || true
# rebuild everything when makefile changes # rebuild everything when makefile changes
$(TARGET_OBJS) : Makefile $(TARGET_OBJS) : Makefile