make/common/Execute.gmk
author ihse
Fri, 01 Feb 2019 12:29:52 +0100
branchihse-setupexecute-branch
changeset 57139 94ff48d6eee4
child 57155 ba61956ea598
permissions -rw-r--r--
Initial implementation and test case of SetupExecute.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57139
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
     1
#
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
     2
# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
     3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
     4
#
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
     5
# This code is free software; you can redistribute it and/or modify it
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
     6
# under the terms of the GNU General Public License version 2 only, as
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
     7
# published by the Free Software Foundation.  Oracle designates this
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
     8
# particular file as subject to the "Classpath" exception as provided
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
     9
# by Oracle in the LICENSE file that accompanied this code.
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    10
#
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    11
# This code is distributed in the hope that it will be useful, but WITHOUT
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    13
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    14
# version 2 for more details (a copy is included in the LICENSE file that
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    15
# accompanied this code).
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    16
#
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    17
# You should have received a copy of the GNU General Public License version
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    18
# 2 along with this work; if not, write to the Free Software Foundation,
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    19
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    20
#
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    21
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    22
# or visit www.oracle.com if you need additional information or have any
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    23
# questions.
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    24
#
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    25
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    26
ifeq (,$(_MAKEBASE_GMK))
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    27
  $(error You must include MakeBase.gmk prior to including Execute.gmk)
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    28
endif
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    29
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    30
################################################################################
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    31
#
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    32
# Code for handling the SetupExecute macro.
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    33
#
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    34
################################################################################
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    35
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    36
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    37
################################################################################
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    38
# Setup make rules for executing an arbitrary command.
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    39
#
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    40
# Parameter 1 is the name of the rule. This name is used as variable prefix,
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    41
# and the targets generated are listed in a variable by that name.
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    42
#
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    43
# Remaining parameters are named arguments. These include:
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    44
#   COMMAND     : The command to execute
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    45
#   OUTPUT_DIR  : The directory that will contain the result from the command
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    46
#   (OUTPUT_FILE : Use this if the command results in a single output file. (N/A))
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    47
#   INFO        : Message to display at LOG=info level when running command (optional).
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    48
#   DEPS        : Dependencies for the execution to take place
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    49
#
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    50
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    51
# Setup make rules for copying files, with an option to do more complex
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    52
SetupExecute = $(NamedParamsMacroTemplate)
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    53
define SetupExecuteBody
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    54
  ifeq ($$($1_COMMAND), )
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    55
    $$(error COMMAND is missing in SetupExecute $1)
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    56
  endif
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    57
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    58
  ifeq ($$($1_OUTPUT_DIR), )
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    59
    $$(error OUTPUT_DIR is missing in SetupExecute $1)
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    60
  endif
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    61
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    62
  ifeq ($$($1_INFO), )
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    63
    $1_INFO := Running commands for $1
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    64
  endif
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    65
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    66
  $1_BASE := $$($1_OUTPUT_DIR)/_$1
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    67
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    68
  $1_MARKER := $$($1_BASE).marker
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    69
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    70
  $$($1_MARKER): $$($1_DEPS)
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    71
	$$(call LogInfo, $$($1_INFO))
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    72
	$$(call MakeDir, $$($1_OUTPUT_DIR))
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    73
	$$(call ExecuteWithLog, $$($1_BASE), \
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    74
	    $$($1_COMMAND))
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    75
	$$(TOUCH) $$@
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    76
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    77
  # Export our generated targets in $1, and also $1_TARGET for clarity.
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    78
  $1 := $$($1_MARKER)
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    79
  $1_TARGET := $$($1)
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    80
endef