make/common/Execute.gmk
author ihse
Thu, 07 Feb 2019 13:04:38 +0100
branchihse-setupexecute-branch
changeset 57158 003703d03633
parent 57155 ba61956ea598
child 57159 0258a6f7d03f
permissions -rw-r--r--
Bug fixes. Now hotspot works.
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
57155
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    45
#   POST_COMMAND:
57139
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    46
#   OUTPUT_DIR  : The directory that will contain the result from the command
57155
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    47
#   OUTPUT_FILE : Use this if the command results in a single output file.
57139
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    48
#   INFO        : Message to display at LOG=info level when running command (optional).
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    49
#   DEPS        : Dependencies for the execution to take place
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
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    52
# 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
    53
SetupExecute = $(NamedParamsMacroTemplate)
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    54
define SetupExecuteBody
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    55
  ifeq ($$($1_COMMAND), )
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    56
    $$(error COMMAND is missing in SetupExecute $1)
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    57
  endif
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    58
57158
003703d03633 Bug fixes. Now hotspot works.
ihse
parents: 57155
diff changeset
    59
  ifneq ($$($1_OUTPUT_FILE), )
003703d03633 Bug fixes. Now hotspot works.
ihse
parents: 57155
diff changeset
    60
    ifneq ($$($1_OUTPUT_DIR), )
003703d03633 Bug fixes. Now hotspot works.
ihse
parents: 57155
diff changeset
    61
      $$(error Cannot specify both OUTPUT_DIR and OUTPUT_FILE in SetupExecute $1)
003703d03633 Bug fixes. Now hotspot works.
ihse
parents: 57155
diff changeset
    62
    endif
003703d03633 Bug fixes. Now hotspot works.
ihse
parents: 57155
diff changeset
    63
    $1_OUTPUT_DIR := $$(patsubst %/,%, $$(dir $$($1_OUTPUT_FILE)))
003703d03633 Bug fixes. Now hotspot works.
ihse
parents: 57155
diff changeset
    64
  else ifeq ($$($1_OUTPUT_DIR), )
003703d03633 Bug fixes. Now hotspot works.
ihse
parents: 57155
diff changeset
    65
    $$(error OUTPUT_DIR or OUTPUT_FILE is required in SetupExecute $1)
003703d03633 Bug fixes. Now hotspot works.
ihse
parents: 57155
diff changeset
    66
  endif
003703d03633 Bug fixes. Now hotspot works.
ihse
parents: 57155
diff changeset
    67
57155
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    68
  $1_BASE := $$($1_OUTPUT_DIR)/_$1
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    69
  $1_MARKER := $$($1_BASE).marker
57139
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    70
57158
003703d03633 Bug fixes. Now hotspot works.
ihse
parents: 57155
diff changeset
    71
  ifeq ($$($1_OUTPUT_FILE), )
57155
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    72
    $1_RESULT := $$($1_MARKER)
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    73
  else
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    74
    # If we have a single output file, we don't need a separate marker
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    75
    $1_RESULT := $$($1_OUTPUT_FILE)
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    76
  endif
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    77
57158
003703d03633 Bug fixes. Now hotspot works.
ihse
parents: 57155
diff changeset
    78
  ifeq ($$($1_INFO), )
003703d03633 Bug fixes. Now hotspot works.
ihse
parents: 57155
diff changeset
    79
    $1_INFO := Running commands for $1
003703d03633 Bug fixes. Now hotspot works.
ihse
parents: 57155
diff changeset
    80
  endif
003703d03633 Bug fixes. Now hotspot works.
ihse
parents: 57155
diff changeset
    81
57155
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    82
  $$($1_RESULT): $$($1_DEPS)
57139
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    83
	$$(call LogInfo, $$($1_INFO))
57155
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    84
	$$(call MakeDir, $$(@D))
57139
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    85
	$$(call ExecuteWithLog, $$($1_BASE), \
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
    86
	    $$($1_COMMAND))
57155
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    87
        ifeq ($$($1_RESULT), $$($1_MARKER))
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    88
	  $$(TOUCH) $$@
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    89
        endif
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    90
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    91
  # Export all our generated targets in $1, and the final target in $1_TARGET.
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    92
  $1 := $$($1_RESULT)
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    93
  $1_TARGET := $$($1_RESULT)
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    94
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    95
  ifneq ($$($1_POST_COMMAND), )
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    96
    $1_POST_MARKER := $$($1_BASE)_post.marker
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    97
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    98
    $$($1_POST_MARKER): $$($1_MARKER)
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
    99
	$$(call ExecuteWithLog, $$($1_BASE), \
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
   100
	    $$($1_POST_COMMAND))
57139
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
   101
	$$(TOUCH) $$@
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
   102
57155
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
   103
    $1 += $$($1_POST_MARKER)
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
   104
    $1_TARGET := $$($1_POST_MARKER)
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
   105
  endif
ba61956ea598 Convert some more to SetupExecute.
ihse
parents: 57139
diff changeset
   106
57139
94ff48d6eee4 Initial implementation and test case of SetupExecute.
ihse
parents:
diff changeset
   107
endef