@@ -45,6 +45,9 @@ ifeq ($(INCLUDE), true)
4545# e.g. a simple sed replacement on the input file. If the operations are
4646# unrelated to the main COMMAND, this is not a suitable solution.
4747#
48+ # Before execution, the current working directory is changed to SUPPORT_DIR.
49+ # This can be overridden with WORKING_DIR.
50+ #
4851# If your command outputs a variety of files, or if it's really a single file
4952# but you don't really care about the output from the perspective, you can just
5053# supply an OUTPUT_DIR. You are supposed to make sure the command creates files
@@ -75,6 +78,7 @@ ifeq ($(INCLUDE), true)
7578# OUTPUT_DIR : The directory that will contain the result from the command
7679# OUTPUT_FILE : Use this if the command results in a single output file
7780# SUPPORT_DIR : Where to store generated support files
81+ # WORKING_DIR : Directory to cd to before executing the command
7882# INFO : Message to display at LOG=info level when running command (optional)
7983# WARN : Message to display at LOG=warn level when running command (optional)
8084# DEPS : Dependencies for the execution to take place
@@ -133,6 +137,10 @@ define SetupExecuteBody
133137
134138 endif
135139
140+ ifeq ($$($1_WORKING_DIR), )
141+ $1_WORKING_DIR := $$($1_SUPPORT_DIR)
142+ endif
143+
136144 ifeq ($$($1_INFO)$$($1_WARN), )
137145 # If neither info nor warn is provided, add basic info text.
138146 $1_INFO := Running commands for $1
@@ -147,14 +155,14 @@ define SetupExecuteBody
147155 ifneq ($$($1_INFO), )
148156 $$(call LogInfo, $$($1_INFO))
149157 endif
150- $$(call MakeDir, $$($ 1_SUPPORT_DIR) $$($ 1_OUTPUT_DIR))
158+ $$(call MakeDir, $$(call EncodeSpace, $$($1_WORKING_DIR)) $$(call EncodeSpace, $$($ 1_SUPPORT_DIR)) $$(call EncodeSpace, $$($ 1_OUTPUT_DIR) ))
151159 $$(call ExecuteWithLog, $$($1_BASE)_pre, \
152- $$($1_PRE_COMMAND))
160+ cd $$($1_WORKING_DIR) && $$($1_PRE_COMMAND))
153161 $$(TOUCH) $$@
154162
155163 $$($1_EXEC_RESULT): $$($1_PRE_MARKER)
156164 $$(call ExecuteWithLog, $$($1_BASE)_exec, \
157- $$($1_COMMAND))
165+ cd $$($1_WORKING_DIR) && $$($1_COMMAND))
158166 ifeq ($$($1_EXEC_RESULT), $$($1_EXEC_MARKER))
159167 $$(TOUCH) $$@
160168 endif
@@ -168,9 +176,9 @@ define SetupExecuteBody
168176 ifneq ($$($1_INFO), )
169177 $$(call LogInfo, $$($1_INFO))
170178 endif
171- $$(call MakeDir, $$(call EncodeSpace, $$($1_SUPPORT_DIR)) $$(call EncodeSpace, $$($1_OUTPUT_DIR)))
179+ $$(call MakeDir, $$(call EncodeSpace, $$($1_WORKING_DIR)) $$(call EncodeSpace, $$($ 1_SUPPORT_DIR)) $$(call EncodeSpace, $$($1_OUTPUT_DIR)))
172180 $$(call ExecuteWithLog, $$($1_BASE)_exec, \
173- $$($1_COMMAND))
181+ cd $$($1_WORKING_DIR) && $$($1_COMMAND))
174182 ifeq ($$($1_EXEC_RESULT), $$($1_EXEC_MARKER))
175183 $$(TOUCH) $$@
176184 endif
@@ -182,7 +190,7 @@ define SetupExecuteBody
182190
183191 $$($1_FINAL_RESULT): $$($1_EXEC_RESULT)
184192 $$(call ExecuteWithLog, $$($1_BASE)_post, \
185- $$($1_POST_COMMAND))
193+ cd $$($1_WORKING_DIR) && $$($1_POST_COMMAND))
186194 $$(TOUCH) $$@
187195
188196 $1 += $$($1_FINAL_RESULT)
0 commit comments