--- a/make/common/Execute.gmk Thu Feb 07 13:04:38 2019 +0100
+++ b/make/common/Execute.gmk Thu Feb 07 19:35:33 2019 +0100
@@ -42,10 +42,13 @@
#
# Remaining parameters are named arguments. These include:
# COMMAND : The command to execute
+# PRE_COMMAND :
# POST_COMMAND:
# OUTPUT_DIR : The directory that will contain the result from the command
+# SUPPORT_DIR :
# OUTPUT_FILE : Use this if the command results in a single output file.
# INFO : Message to display at LOG=info level when running command (optional).
+# WARN : Message to display at LOG=warn level when running command (optional).
# DEPS : Dependencies for the execution to take place
#
@@ -60,48 +63,104 @@
ifneq ($$($1_OUTPUT_DIR), )
$$(error Cannot specify both OUTPUT_DIR and OUTPUT_FILE in SetupExecute $1)
endif
+ # We need to know output dir since we will make sure it is created.
$1_OUTPUT_DIR := $$(patsubst %/,%, $$(dir $$($1_OUTPUT_FILE)))
- else ifeq ($$($1_OUTPUT_DIR), )
+ ifeq ($$($1_SUPPORT_DIR), )
+ # If support dir is not given, use base dir of output file.
+ $1_SUPPORT_DIR := $$($1_OUTPUT_DIR)
+ endif
+ else ifneq ($$($1_OUTPUT_DIR), )
+ ifeq ($$($1_SUPPORT_DIR), )
+ # If support dir is not given, use output dir.
+ $1_SUPPORT_DIR := $$($1_OUTPUT_DIR)
+ endif
+ else
$$(error OUTPUT_DIR or OUTPUT_FILE is required in SetupExecute $1)
endif
- $1_BASE := $$($1_OUTPUT_DIR)/_$1
- $1_MARKER := $$($1_BASE).marker
+ $1_BASE := $$($1_SUPPORT_DIR)/_$1
+ $1_PRE_MARKER := $$($1_BASE)_pre.marker
+ $1_EXEC_MARKER := $$($1_BASE)_exec.marker
+ $1_POST_MARKER := $$($1_BASE)_post.marker
ifeq ($$($1_OUTPUT_FILE), )
- $1_RESULT := $$($1_MARKER)
+ # No specified output file, use markers everywhere
+ $1_EXEC_RESULT := $$($1_EXEC_MARKER)
+ ifeq ($$($1_POST_COMMAND), )
+ $1_FINAL_RESULT := $$($1_EXEC_MARKER)
+ else
+ $1_FINAL_RESULT := $$($1_POST_MARKER)
+ endif
+
else
# If we have a single output file, we don't need a separate marker
- $1_RESULT := $$($1_OUTPUT_FILE)
+
+ ifeq ($$($1_POST_COMMAND), )
+ $1_EXEC_RESULT := $$($1_OUTPUT_FILE)
+ $1_FINAL_RESULT := $$($1_EXEC_RESULT)
+ else
+ $1_EXEC_RESULT := $$($1_EXEC_MARKER)
+ $1_FINAL_RESULT := $$($1_OUTPUT_FILE)
+ endif
+
endif
- ifeq ($$($1_INFO), )
+ ifeq ($$($1_INFO)$$($1_WARN), )
+ # If neither info nor warn is provided, add basic info text.
$1_INFO := Running commands for $1
endif
- $$($1_RESULT): $$($1_DEPS)
- $$(call LogInfo, $$($1_INFO))
- $$(call MakeDir, $$(@D))
- $$(call ExecuteWithLog, $$($1_BASE), \
+ ifneq ($$($1_PRE_COMMAND), )
+
+ $$($1_PRE_MARKER): $$($1_DEPS)
+ ifneq ($$($1_WARN), )
+ $$(call LogWarn, $$($1_WARN))
+ endif
+ ifneq ($$($1_INFO), )
+ $$(call LogInfo, $$($1_INFO))
+ endif
+ $$(call MakeDir, $$($1_SUPPORT_DIR) $$($1_OUTPUT_DIR))
+ $$(call ExecuteWithLog, $$($1_BASE)_pre, \
+ $$($1_PRE_COMMAND))
+ $$(TOUCH) $$@
+
+ $$($1_EXEC_RESULT): $$($1_PRE_MARKER)
+ $$(call ExecuteWithLog, $$($1_BASE)_exec, \
$$($1_COMMAND))
- ifeq ($$($1_RESULT), $$($1_MARKER))
+ ifeq ($$($1_EXEC_RESULT), $$($1_EXEC_MARKER))
$$(TOUCH) $$@
endif
- # Export all our generated targets in $1, and the final target in $1_TARGET.
- $1 := $$($1_RESULT)
- $1_TARGET := $$($1_RESULT)
+ $1 := $$($1_PRE_MARKER) $$($1_EXEC_RESULT)
+ else
+ $$($1_EXEC_RESULT): $$($1_DEPS)
+ ifneq ($$($1_WARN), )
+ $$(call LogWarn, $$($1_WARN))
+ endif
+ ifneq ($$($1_INFO), )
+ $$(call LogInfo, $$($1_INFO))
+ endif
+ $$(call MakeDir, $$($1_SUPPORT_DIR) $$($1_OUTPUT_DIR))
+ $$(call ExecuteWithLog, $$($1_BASE)_exec, \
+ $$($1_COMMAND))
+ ifeq ($$($1_EXEC_RESULT), $$($1_EXEC_MARKER))
+ $$(TOUCH) $$@
+ endif
+
+ $1 := $$($1_EXEC_RESULT)
+ endif
ifneq ($$($1_POST_COMMAND), )
- $1_POST_MARKER := $$($1_BASE)_post.marker
- $$($1_POST_MARKER): $$($1_MARKER)
- $$(call ExecuteWithLog, $$($1_BASE), \
+ $$($1_FINAL_RESULT): $$($1_EXEC_RESULT)
+ $$(call ExecuteWithLog, $$($1_BASE)_post, \
$$($1_POST_COMMAND))
$$(TOUCH) $$@
- $1 += $$($1_POST_MARKER)
- $1_TARGET := $$($1_POST_MARKER)
+ $1 += $$($1_FINAL_RESULT)
endif
+ # Export all our generated targets in $1, and the final target in $1_TARGET.
+ $1_TARGET := $$($1_FINAL_RESULT)
+
endef