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
|
57155
|
45 |
# POST_COMMAND:
|
57139
|
46 |
# OUTPUT_DIR : The directory that will contain the result from the command
|
57155
|
47 |
# OUTPUT_FILE : Use this if the command results in a single output file.
|
57139
|
48 |
# INFO : Message to display at LOG=info level when running command (optional).
|
|
49 |
# DEPS : Dependencies for the execution to take place
|
|
50 |
#
|
|
51 |
|
|
52 |
# Setup make rules for copying files, with an option to do more complex
|
|
53 |
SetupExecute = $(NamedParamsMacroTemplate)
|
|
54 |
define SetupExecuteBody
|
|
55 |
ifeq ($$($1_COMMAND), )
|
|
56 |
$$(error COMMAND is missing in SetupExecute $1)
|
|
57 |
endif
|
|
58 |
|
57158
|
59 |
ifneq ($$($1_OUTPUT_FILE), )
|
|
60 |
ifneq ($$($1_OUTPUT_DIR), )
|
|
61 |
$$(error Cannot specify both OUTPUT_DIR and OUTPUT_FILE in SetupExecute $1)
|
|
62 |
endif
|
|
63 |
$1_OUTPUT_DIR := $$(patsubst %/,%, $$(dir $$($1_OUTPUT_FILE)))
|
|
64 |
else ifeq ($$($1_OUTPUT_DIR), )
|
|
65 |
$$(error OUTPUT_DIR or OUTPUT_FILE is required in SetupExecute $1)
|
|
66 |
endif
|
|
67 |
|
57155
|
68 |
$1_BASE := $$($1_OUTPUT_DIR)/_$1
|
|
69 |
$1_MARKER := $$($1_BASE).marker
|
57139
|
70 |
|
57158
|
71 |
ifeq ($$($1_OUTPUT_FILE), )
|
57155
|
72 |
$1_RESULT := $$($1_MARKER)
|
|
73 |
else
|
|
74 |
# If we have a single output file, we don't need a separate marker
|
|
75 |
$1_RESULT := $$($1_OUTPUT_FILE)
|
|
76 |
endif
|
|
77 |
|
57158
|
78 |
ifeq ($$($1_INFO), )
|
|
79 |
$1_INFO := Running commands for $1
|
|
80 |
endif
|
|
81 |
|
57155
|
82 |
$$($1_RESULT): $$($1_DEPS)
|
57139
|
83 |
$$(call LogInfo, $$($1_INFO))
|
57155
|
84 |
$$(call MakeDir, $$(@D))
|
57139
|
85 |
$$(call ExecuteWithLog, $$($1_BASE), \
|
|
86 |
$$($1_COMMAND))
|
57155
|
87 |
ifeq ($$($1_RESULT), $$($1_MARKER))
|
|
88 |
$$(TOUCH) $$@
|
|
89 |
endif
|
|
90 |
|
|
91 |
# Export all our generated targets in $1, and the final target in $1_TARGET.
|
|
92 |
$1 := $$($1_RESULT)
|
|
93 |
$1_TARGET := $$($1_RESULT)
|
|
94 |
|
|
95 |
ifneq ($$($1_POST_COMMAND), )
|
|
96 |
$1_POST_MARKER := $$($1_BASE)_post.marker
|
|
97 |
|
|
98 |
$$($1_POST_MARKER): $$($1_MARKER)
|
|
99 |
$$(call ExecuteWithLog, $$($1_BASE), \
|
|
100 |
$$($1_POST_COMMAND))
|
57139
|
101 |
$$(TOUCH) $$@
|
|
102 |
|
57155
|
103 |
$1 += $$($1_POST_MARKER)
|
|
104 |
$1_TARGET := $$($1_POST_MARKER)
|
|
105 |
endif
|
|
106 |
|
57139
|
107 |
endef
|