From ffde764adaa56cf00296857c8fd4a821b6b2e506 Mon Sep 17 00:00:00 2001 From: Julien Ridoux Date: Fri, 14 Mar 2014 10:42:35 +1100 Subject: [PATCH] Add phony target to run pre-build hook script Fix #176 --- Arduino.mk | 15 +++++++++++++-- Common.mk | 8 ++++++++ HISTORY.md | 1 + arduino-mk-vars.md | 19 +++++++++++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Arduino.mk b/Arduino.mk index 508c7ab..84d8af5 100644 --- a/Arduino.mk +++ b/Arduino.mk @@ -465,6 +465,13 @@ else $(call show_config_variable,USER_LIB_PATH,[USER]) endif +ifndef PRE_BUILD_HOOK + PRE_BUILD_HOOK = pre-build-hook.sh + $(call show_config_variable,PRE_BUILD_HOOK,[DEFAULT]) +else + $(call show_config_variable,PRE_BUILD_HOOK,[USER]) +endif + ######################################################################## # boards.txt parsing @@ -1106,9 +1113,12 @@ all: $(TARGET_EEP) $(TARGET_HEX) # prerequisite" (e.g., put "| $(OBJDIR)" at the end of the prerequisite # list) to prevent remaking the target when any file in the directory # changes. -$(OBJDIR): +$(OBJDIR): pre-build $(MKDIR) $(OBJDIR) +pre-build: + $(call runscript_if_exists,$(PRE_BUILD_HOOK)) + $(TARGET_ELF): $(LOCAL_OBJS) $(CORE_LIB) $(OTHER_OBJS) $(CC) $(LDFLAGS) -o $@ $(LOCAL_OBJS) $(CORE_LIB) $(OTHER_OBJS) -lc -lm @@ -1118,6 +1128,7 @@ $(CORE_LIB): $(CORE_OBJS) $(LIB_OBJS) $(USER_LIB_OBJS) error_on_caterina: $(ERROR_ON_CATERINA) + # Use submake so we can guarantee the reset happens # before the upload, even with make -j upload: $(TARGET_HEX) verify_size @@ -1244,7 +1255,7 @@ 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 + generate_assembly verify_size burn_bootloader help pre-build # added - in the beginning, so that we don't get an error if the file is not present -include $(DEPS) diff --git a/Common.mk b/Common.mk index a94c37f..9aa36b8 100644 --- a/Common.mk +++ b/Common.mk @@ -4,6 +4,14 @@ # (directory and optional filename) exists dir_if_exists = $(if $(wildcard $(1)$(2)),$(1)) +# Run a shell script if it exists. Stops make on error. +runscript_if_exists = \ + $(if $(wildcard $(1)), \ + $(if $(findstring 0, \ + $(lastword $(shell $(abspath $(wildcard $(1))); echo $$?))), \ + $(info Info: $(1) success), \ + $(error ERROR: $(1) failed))) + # For message printing: pad the right side of the first argument with spaces to # the number of bytes indicated by the second argument. space_pad_to = $(shell echo $(1) " " | head -c$(2)) diff --git a/HISTORY.md b/HISTORY.md index a70ac82..a911d65 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -14,6 +14,7 @@ I tried to give credit whenever possible. If I have missed anyone, kindly add it - Tweak: *Beautify* `arduino-mk-vars.md` with code blocks. (https://github.com/tinyladi) - Fix: AVR tools paths for chipKIT in Linux. (https://github.com/peplin) - Fix: Consider usb or usb:... to be a valid ISP_PORT (https://github.com/geoffholden) +- Add: Add phony target to run pre-build hook script (https://github.com/jrid) ### 1.3.1 (2014-02-04) - Fix: BUNDLED_AVR_TOOLS_DIR is now set properly when using only arduino-core and not the whole arduino package. (https://github.com/sej7278) diff --git a/arduino-mk-vars.md b/arduino-mk-vars.md index f8eb9a8..51e32ae 100644 --- a/arduino-mk-vars.md +++ b/arduino-mk-vars.md @@ -776,6 +776,25 @@ MONITOR_CMD = minicom ---- +### PRE_BUILD_HOOK + +**Description:** + +Path to shell script to be executed before build. Could be used to automatically +bump revision number for example. + +Defaults to `pre-build-hook.sh` + +**Example:** + +```Makefile +PRE_BUILD_HOOK = ~/bin/bump-revision.sh +``` + +**Requirement:** *Optional* + +---- + ## Avrdude setting variables ### AVRDUDE