@@ -45,6 +45,9 @@ ifeq ($(INCLUDE), true)
45
45
# e.g. a simple sed replacement on the input file. If the operations are
46
46
# unrelated to the main COMMAND, this is not a suitable solution.
47
47
#
48
+ # Before execution, the current working directory is changed to SUPPORT_DIR.
49
+ # This can be overridden with WORKING_DIR.
50
+ #
48
51
# If your command outputs a variety of files, or if it's really a single file
49
52
# but you don't really care about the output from the perspective, you can just
50
53
# supply an OUTPUT_DIR. You are supposed to make sure the command creates files
@@ -75,6 +78,7 @@ ifeq ($(INCLUDE), true)
75
78
# OUTPUT_DIR : The directory that will contain the result from the command
76
79
# OUTPUT_FILE : Use this if the command results in a single output file
77
80
# SUPPORT_DIR : Where to store generated support files
81
+ # WORKING_DIR : Directory to cd to before executing the command
78
82
# INFO : Message to display at LOG=info level when running command (optional)
79
83
# WARN : Message to display at LOG=warn level when running command (optional)
80
84
# DEPS : Dependencies for the execution to take place
@@ -133,6 +137,10 @@ define SetupExecuteBody
133
137
134
138
endif
135
139
140
+ ifeq ($$($1_WORKING_DIR), )
141
+ $1_WORKING_DIR := $$($1_SUPPORT_DIR)
142
+ endif
143
+
136
144
ifeq ($$($1_INFO)$$($1_WARN), )
137
145
# If neither info nor warn is provided, add basic info text.
138
146
$1_INFO := Running commands for $1
@@ -147,14 +155,14 @@ define SetupExecuteBody
147
155
ifneq ($$($1_INFO), )
148
156
$$(call LogInfo, $$($1_INFO))
149
157
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) ))
151
159
$$(call ExecuteWithLog, $$($1_BASE)_pre, \
152
- $$($1_PRE_COMMAND))
160
+ cd $$($1_WORKING_DIR) && $$($1_PRE_COMMAND))
153
161
$$(TOUCH) $$@
154
162
155
163
$$($1_EXEC_RESULT): $$($1_PRE_MARKER)
156
164
$$(call ExecuteWithLog, $$($1_BASE)_exec, \
157
- $$($1_COMMAND))
165
+ cd $$($1_WORKING_DIR) && $$($1_COMMAND))
158
166
ifeq ($$($1_EXEC_RESULT), $$($1_EXEC_MARKER))
159
167
$$(TOUCH) $$@
160
168
endif
@@ -168,9 +176,9 @@ define SetupExecuteBody
168
176
ifneq ($$($1_INFO), )
169
177
$$(call LogInfo, $$($1_INFO))
170
178
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)))
172
180
$$(call ExecuteWithLog, $$($1_BASE)_exec, \
173
- $$($1_COMMAND))
181
+ cd $$($1_WORKING_DIR) && $$($1_COMMAND))
174
182
ifeq ($$($1_EXEC_RESULT), $$($1_EXEC_MARKER))
175
183
$$(TOUCH) $$@
176
184
endif
@@ -182,7 +190,7 @@ define SetupExecuteBody
182
190
183
191
$$($1_FINAL_RESULT): $$($1_EXEC_RESULT)
184
192
$$(call ExecuteWithLog, $$($1_BASE)_post, \
185
- $$($1_POST_COMMAND))
193
+ cd $$($1_WORKING_DIR) && $$($1_POST_COMMAND))
186
194
$$(TOUCH) $$@
187
195
188
196
$1 += $$($1_FINAL_RESULT)
0 commit comments