Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arduino.mk: added PRE_UPLOAD_HOOK macro to specify script to run befo… #585

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions Arduino.mk
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,13 @@ else
$(call show_config_variable,PRE_BUILD_HOOK,[USER])
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

Expand Down Expand Up @@ -1441,7 +1448,7 @@ $(OBJDIR)/%.lss: $(OBJDIR)/%.elf $(COMMON_DEPS)

$(OBJDIR)/%.sym: $(OBJDIR)/%.elf $(COMMON_DEPS)
@$(MKDIR) $(dir $@)
$(NM) --size-sort --demangle --reverse-sort --line-numbers $< > $@
$(NM) $(AVR_SIZE_OPTS) --size-sort --demangle --reverse-sort --line-numbers $< > $@

########################################################################
# Ctags
Expand Down Expand Up @@ -1621,7 +1628,7 @@ error_on_caterina:

# Use submake so we can guarantee the reset happens
# 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)
# do reset toggle at 1200 BAUD to enter bootloader if using avrdude or bossa
ifeq ($(strip $(UPLOAD_TOOL)), avrdude)
Expand All @@ -1635,6 +1642,9 @@ else
$(MAKE) do_upload
endif

pre-upload:
$(call runscript_if_exists,$(PRE_UPLOAD_HOOK))

raw_upload: $(TARGET_HEX) verify_size
ifeq ($(findstring sam, $(strip $(ARCHITECTURE))), sam)
$(MAKE) do_sam_upload
Expand Down Expand Up @@ -1827,7 +1837,8 @@ help:

.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 \
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
-include $(DEPS)
17 changes: 17 additions & 0 deletions arduino-mk-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,23 @@ PRE_BUILD_HOOK = $(HOME)/bin/bump-revision.sh

**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
Expand Down