Arduino.mk: added PRE_UPLOAD_HOOK macro to specify script to run before uploading code,

added AVR_SIZE_OPTS when using $(NM) to dump symbols,
[taret upload]: added prerequestive pre-upload in order to execute the PRE_UPLOAD_HOOK script,
[added target pre-upload] to execute PRE_UPLOAD_HOOK script,
[.PHONY]: added target pre-upload,
arduino-mk-vars.md: added description for PRE_UPLOAD_HOOK
This commit is contained in:
Evangelos Rokas 2018-10-12 01:08:55 +03:00
parent 5a0c80bf0c
commit e0a4355287
2 changed files with 31 additions and 3 deletions

View file

@ -623,6 +623,13 @@ else
$(call show_config_variable,PRE_BUILD_HOOK,[USER]) $(call show_config_variable,PRE_BUILD_HOOK,[USER])
endif endif
ifndef PRE_UPLOAD_HOOK
PRE_UPLOAD_HOOK = pre-upload-hook.sh
$(call show_config_variable,PRE_UPLOAD_HOOK,[DEFAULT])
else
$(call show_config_variable,PRE_UPLOAD_HOOK,[USER])
endif
######################################################################## ########################################################################
# boards.txt parsing # boards.txt parsing
@ -1441,7 +1448,7 @@ $(OBJDIR)/%.lss: $(OBJDIR)/%.elf $(COMMON_DEPS)
$(OBJDIR)/%.sym: $(OBJDIR)/%.elf $(COMMON_DEPS) $(OBJDIR)/%.sym: $(OBJDIR)/%.elf $(COMMON_DEPS)
@$(MKDIR) $(dir $@) @$(MKDIR) $(dir $@)
$(NM) --size-sort --demangle --reverse-sort --line-numbers $< > $@ $(NM) $(AVR_SIZE_OPTS) --size-sort --demangle --reverse-sort --line-numbers $< > $@
######################################################################## ########################################################################
# Ctags # Ctags
@ -1621,7 +1628,7 @@ error_on_caterina:
# Use submake so we can guarantee the reset happens # Use submake so we can guarantee the reset happens
# before the upload, even with make -j # before the upload, even with make -j
upload: $(TARGET_HEX) verify_size upload: $(TARGET_HEX) pre-upload verify_size
ifeq ($(findstring sam, $(strip $(ARCHITECTURE))), sam) ifeq ($(findstring sam, $(strip $(ARCHITECTURE))), sam)
# do reset toggle at 1200 BAUD to enter bootloader if using avrdude or bossa # do reset toggle at 1200 BAUD to enter bootloader if using avrdude or bossa
ifeq ($(strip $(UPLOAD_TOOL)), avrdude) ifeq ($(strip $(UPLOAD_TOOL)), avrdude)
@ -1635,6 +1642,9 @@ else
$(MAKE) do_upload $(MAKE) do_upload
endif endif
pre-upload:
$(call runscript_if_exists,$(PRE_UPLOAD_HOOK))
raw_upload: $(TARGET_HEX) verify_size raw_upload: $(TARGET_HEX) verify_size
ifeq ($(findstring sam, $(strip $(ARCHITECTURE))), sam) ifeq ($(findstring sam, $(strip $(ARCHITECTURE))), sam)
$(MAKE) do_sam_upload $(MAKE) do_sam_upload
@ -1827,7 +1837,8 @@ help:
.PHONY: all upload raw_upload raw_eeprom error_on_caterina reset reset_stty ispload \ .PHONY: all upload raw_upload raw_eeprom error_on_caterina reset reset_stty ispload \
clean depends size show_boards monitor disasm symbol_sizes generated_assembly \ clean depends size show_boards monitor disasm symbol_sizes generated_assembly \
generate_assembly verify_size burn_bootloader help pre-build tags debug debug_init generate_assembly verify_size burn_bootloader help pre-build tags debug debug_init \
pre-upload
# added - in the beginning, so that we don't get an error if the file is not present # added - in the beginning, so that we don't get an error if the file is not present
-include $(DEPS) -include $(DEPS)

View file

@ -1239,6 +1239,23 @@ PRE_BUILD_HOOK = $(HOME)/bin/bump-revision.sh
**Requirement:** *Optional* **Requirement:** *Optional*
### PRE_UPLOAD_HOOK
**Description:**
Path to shell script to be executed before uploading. Could be used to automatically
last minute modification just before uploading code to chip.
Defaults to `pre-upload-hook.sh`
**Example:**
```Makefile
PRE_UPLOAD_HOOK = $(HOME)/bin/upload-revision.sh
```
**Requirement:** *Optional*
---- ----
## Avrdude setting variables ## Avrdude setting variables