author | ihse |
Fri, 01 Mar 2019 11:32:38 +0100 | |
branch | ihse-setupexecute-branch |
changeset 57228 | f802ad9cf3bc |
parent 57159 | 0258a6f7d03f |
child 58833 | ed9ef56bc7d5 |
permissions | -rw-r--r-- |
57139 | 1 |
# |
2 |
# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
|
3 |
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
# |
|
5 |
# This code is free software; you can redistribute it and/or modify it |
|
6 |
# under the terms of the GNU General Public License version 2 only, as |
|
7 |
# published by the Free Software Foundation. Oracle designates this |
|
8 |
# particular file as subject to the "Classpath" exception as provided |
|
9 |
# by Oracle in the LICENSE file that accompanied this code. |
|
10 |
# |
|
11 |
# This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
# version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
# accompanied this code). |
|
16 |
# |
|
17 |
# You should have received a copy of the GNU General Public License version |
|
18 |
# 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
# |
|
21 |
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
# or visit www.oracle.com if you need additional information or have any |
|
23 |
# questions. |
|
24 |
# |
|
25 |
||
26 |
ifeq (,$(_MAKEBASE_GMK)) |
|
27 |
$(error You must include MakeBase.gmk prior to including Execute.gmk) |
|
28 |
endif |
|
29 |
||
30 |
################################################################################ |
|
31 |
# |
|
32 |
# Code for handling the SetupExecute macro. |
|
33 |
# |
|
34 |
################################################################################ |
|
35 |
||
36 |
||
37 |
################################################################################ |
|
38 |
# Setup make rules for executing an arbitrary command. |
|
39 |
# |
|
40 |
# Parameter 1 is the name of the rule. This name is used as variable prefix, |
|
41 |
# and the targets generated are listed in a variable by that name. |
|
42 |
# |
|
43 |
# Remaining parameters are named arguments. These include: |
|
44 |
# COMMAND : The command to execute |
|
57159
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
45 |
# PRE_COMMAND : |
57155 | 46 |
# POST_COMMAND: |
57139 | 47 |
# OUTPUT_DIR : The directory that will contain the result from the command |
57159
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
48 |
# SUPPORT_DIR : |
57155 | 49 |
# OUTPUT_FILE : Use this if the command results in a single output file. |
57139 | 50 |
# INFO : Message to display at LOG=info level when running command (optional). |
57159
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
51 |
# WARN : Message to display at LOG=warn level when running command (optional). |
57139 | 52 |
# DEPS : Dependencies for the execution to take place |
53 |
# |
|
54 |
||
55 |
# Setup make rules for copying files, with an option to do more complex |
|
56 |
SetupExecute = $(NamedParamsMacroTemplate) |
|
57 |
define SetupExecuteBody |
|
58 |
ifeq ($$($1_COMMAND), ) |
|
59 |
$$(error COMMAND is missing in SetupExecute $1) |
|
60 |
endif |
|
61 |
||
57158 | 62 |
ifneq ($$($1_OUTPUT_FILE), ) |
63 |
ifneq ($$($1_OUTPUT_DIR), ) |
|
64 |
$$(error Cannot specify both OUTPUT_DIR and OUTPUT_FILE in SetupExecute $1) |
|
65 |
endif |
|
57159
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
66 |
# We need to know output dir since we will make sure it is created. |
57158 | 67 |
$1_OUTPUT_DIR := $$(patsubst %/,%, $$(dir $$($1_OUTPUT_FILE))) |
57159
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
68 |
ifeq ($$($1_SUPPORT_DIR), ) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
69 |
# If support dir is not given, use base dir of output file. |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
70 |
$1_SUPPORT_DIR := $$($1_OUTPUT_DIR) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
71 |
endif |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
72 |
else ifneq ($$($1_OUTPUT_DIR), ) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
73 |
ifeq ($$($1_SUPPORT_DIR), ) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
74 |
# If support dir is not given, use output dir. |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
75 |
$1_SUPPORT_DIR := $$($1_OUTPUT_DIR) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
76 |
endif |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
77 |
else |
57158 | 78 |
$$(error OUTPUT_DIR or OUTPUT_FILE is required in SetupExecute $1) |
79 |
endif |
|
80 |
||
57159
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
81 |
$1_BASE := $$($1_SUPPORT_DIR)/_$1 |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
82 |
$1_PRE_MARKER := $$($1_BASE)_pre.marker |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
83 |
$1_EXEC_MARKER := $$($1_BASE)_exec.marker |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
84 |
$1_POST_MARKER := $$($1_BASE)_post.marker |
57139 | 85 |
|
57158 | 86 |
ifeq ($$($1_OUTPUT_FILE), ) |
57159
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
87 |
# No specified output file, use markers everywhere |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
88 |
$1_EXEC_RESULT := $$($1_EXEC_MARKER) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
89 |
ifeq ($$($1_POST_COMMAND), ) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
90 |
$1_FINAL_RESULT := $$($1_EXEC_MARKER) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
91 |
else |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
92 |
$1_FINAL_RESULT := $$($1_POST_MARKER) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
93 |
endif |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
94 |
|
57155 | 95 |
else |
96 |
# If we have a single output file, we don't need a separate marker |
|
57159
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
97 |
|
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
98 |
ifeq ($$($1_POST_COMMAND), ) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
99 |
$1_EXEC_RESULT := $$($1_OUTPUT_FILE) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
100 |
$1_FINAL_RESULT := $$($1_EXEC_RESULT) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
101 |
else |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
102 |
$1_EXEC_RESULT := $$($1_EXEC_MARKER) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
103 |
$1_FINAL_RESULT := $$($1_OUTPUT_FILE) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
104 |
endif |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
105 |
|
57155 | 106 |
endif |
107 |
||
57159
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
108 |
ifeq ($$($1_INFO)$$($1_WARN), ) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
109 |
# If neither info nor warn is provided, add basic info text. |
57158 | 110 |
$1_INFO := Running commands for $1 |
111 |
endif |
|
112 |
||
57159
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
113 |
ifneq ($$($1_PRE_COMMAND), ) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
114 |
|
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
115 |
$$($1_PRE_MARKER): $$($1_DEPS) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
116 |
ifneq ($$($1_WARN), ) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
117 |
$$(call LogWarn, $$($1_WARN)) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
118 |
endif |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
119 |
ifneq ($$($1_INFO), ) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
120 |
$$(call LogInfo, $$($1_INFO)) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
121 |
endif |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
122 |
$$(call MakeDir, $$($1_SUPPORT_DIR) $$($1_OUTPUT_DIR)) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
123 |
$$(call ExecuteWithLog, $$($1_BASE)_pre, \ |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
124 |
$$($1_PRE_COMMAND)) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
125 |
$$(TOUCH) $$@ |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
126 |
|
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
127 |
$$($1_EXEC_RESULT): $$($1_PRE_MARKER) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
128 |
$$(call ExecuteWithLog, $$($1_BASE)_exec, \ |
57139 | 129 |
$$($1_COMMAND)) |
57159
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
130 |
ifeq ($$($1_EXEC_RESULT), $$($1_EXEC_MARKER)) |
57155 | 131 |
$$(TOUCH) $$@ |
132 |
endif |
|
133 |
||
57159
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
134 |
$1 := $$($1_PRE_MARKER) $$($1_EXEC_RESULT) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
135 |
else |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
136 |
$$($1_EXEC_RESULT): $$($1_DEPS) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
137 |
ifneq ($$($1_WARN), ) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
138 |
$$(call LogWarn, $$($1_WARN)) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
139 |
endif |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
140 |
ifneq ($$($1_INFO), ) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
141 |
$$(call LogInfo, $$($1_INFO)) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
142 |
endif |
57228 | 143 |
$$(call MakeDir, $$(call EncodeSpace, $$($1_SUPPORT_DIR)) $$(call EncodeSpace, $$($1_OUTPUT_DIR))) |
57159
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
144 |
$$(call ExecuteWithLog, $$($1_BASE)_exec, \ |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
145 |
$$($1_COMMAND)) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
146 |
ifeq ($$($1_EXEC_RESULT), $$($1_EXEC_MARKER)) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
147 |
$$(TOUCH) $$@ |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
148 |
endif |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
149 |
|
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
150 |
$1 := $$($1_EXEC_RESULT) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
151 |
endif |
57155 | 152 |
|
153 |
ifneq ($$($1_POST_COMMAND), ) |
|
154 |
||
57159
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
155 |
$$($1_FINAL_RESULT): $$($1_EXEC_RESULT) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
156 |
$$(call ExecuteWithLog, $$($1_BASE)_post, \ |
57155 | 157 |
$$($1_POST_COMMAND)) |
57139 | 158 |
$$(TOUCH) $$@ |
159 |
||
57159
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
160 |
$1 += $$($1_FINAL_RESULT) |
57155 | 161 |
endif |
162 |
||
57159
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
163 |
# Export all our generated targets in $1, and the final target in $1_TARGET. |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
164 |
$1_TARGET := $$($1_FINAL_RESULT) |
0258a6f7d03f
Adding SetupExecute to more places, and adding functionality.
ihse
parents:
57158
diff
changeset
|
165 |
|
57139 | 166 |
endef |