make/Main.gmk
author herrick
Thu, 25 Jul 2019 08:24:01 -0400
branchJDK-8200758-branch
changeset 57532 eb0bd96672f4
parent 55447 95794e32352e
child 57544 99d2dd7b84a8
permissions -rw-r--r--
Merge

#
# Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.  Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#

################################################################################
# This is the main makefile containing most actual top level targets. It needs
# to be called with a SPEC file defined.
################################################################################

# Declare default target
default:

ifeq ($(wildcard $(SPEC)),)
  $(error Main.gmk needs SPEC set to a proper spec.gmk)
endif

# Now load the spec
include $(SPEC)

include $(TOPDIR)/make/MainSupport.gmk

# Load the vital tools for all the makefiles.
include $(TOPDIR)/make/common/MakeBase.gmk
include $(TOPDIR)/make/common/Modules.gmk
include $(TOPDIR)/make/common/FindTests.gmk

# Declare ALL_TARGETS as an immediate variable. This variable is a list of all
# valid top level targets. It's used to declare them all as PHONY and to
# generate the -only targets.
ALL_TARGETS :=

# Hook to include the corresponding custom file, if present.
$(eval $(call IncludeCustomExtension, Main.gmk))

# All modules for the current target platform.
ALL_MODULES := $(call FindAllModules)

################################################################################
################################################################################
#
# Recipes for all targets. Only recipes, dependencies are declared later.
#
################################################################################

################################################################################
# Interim/build tools targets, compiling tools used during the build

buildtools-langtools:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f ToolsLangtools.gmk)

interim-langtools:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f CompileInterimLangtools.gmk)

interim-rmic:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f CompileInterimRmic.gmk)

interim-cldrconverter:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f CopyInterimCLDRConverter.gmk)

buildtools-jdk:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f CompileToolsJdk.gmk)

buildtools-modules:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f CompileModuleTools.gmk)

buildtools-hotspot:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f CompileToolsHotspot.gmk)

ALL_TARGETS += buildtools-langtools interim-langtools \
    interim-rmic interim-cldrconverter buildtools-jdk buildtools-modules \
    buildtools-hotspot

################################################################################
# Special targets for certain modules

generate-exported-symbols:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f BuildStatic.gmk)

ALL_TARGETS += generate-exported-symbols

################################################################################
# Gensrc targets, generating source before java compilation can be done
#
$(eval $(call DeclareRecipesForPhase, GENSRC, \
    TARGET_SUFFIX := gensrc-src, \
    FILE_PREFIX := Gensrc, \
    MAKE_SUBDIR := gensrc, \
    CHECK_MODULES := $(ALL_MODULES), \
))

$(foreach m, $(GENSRC_MODULES), $(eval $m-gensrc: $m-gensrc-src))

LANGTOOLS_GENSRC_TARGETS := $(filter $(addsuffix -%, $(LANGTOOLS_MODULES)), $(GENSRC_TARGETS))
INTERIM_LANGTOOLS_GENSRC_TARGETS := $(filter $(addsuffix -%, \
    $(INTERIM_LANGTOOLS_BASE_MODULES)), $(GENSRC_TARGETS))
HOTSPOT_GENSRC_TARGETS := $(filter $(addsuffix -%, $(HOTSPOT_MODULES)), $(GENSRC_TARGETS))
JDK_GENSRC_TARGETS := $(filter-out $(LANGTOOLS_GENSRC_TARGETS) \
    $(HOTSPOT_GENSRC_TARGETS), $(GENSRC_TARGETS))

GENSRC_MODULEINFO_MODULES := $(ALL_MODULES)
GENSRC_MODULEINFO_TARGETS := $(addsuffix -gensrc-moduleinfo, \
    $(GENSRC_MODULEINFO_MODULES))

GENSRC_MODULES := $(GENSRC_MODULEINFO_MODULES)
GENSRC_TARGETS += $(sort $(GENSRC_MODULEINFO_TARGETS) \
    $(addsuffix -gensrc, $(GENSRC_MODULES)))

define DeclareModuleInfoRecipe
  $1-gensrc-moduleinfo:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) \
	    -f GensrcModuleInfo.gmk MODULE=$1)

  $1-gensrc: $1-gensrc-moduleinfo
endef

$(foreach m, $(GENSRC_MODULEINFO_MODULES), $(eval $(call DeclareModuleInfoRecipe,$m)))

ALL_TARGETS += $(GENSRC_TARGETS)

################################################################################
# Generate data targets
$(eval $(call DeclareRecipesForPhase, GENDATA, \
    TARGET_SUFFIX := gendata, \
    FILE_PREFIX := Gendata, \
    MAKE_SUBDIR := gendata, \
    CHECK_MODULES := $(ALL_MODULES), \
    USE_WRAPPER := true))

ALL_TARGETS += $(GENDATA_TARGETS)

################################################################################
# Copy files targets
$(eval $(call DeclareRecipesForPhase, COPY, \
    TARGET_SUFFIX := copy, \
    FILE_PREFIX := Copy, \
    MAKE_SUBDIR := copy, \
    CHECK_MODULES := $(ALL_MODULES), \
    USE_WRAPPER := true, \
))

ALL_COPY_MODULES += $(COPY_MODULES)
ALL_COPY_TARGETS += $(COPY_TARGETS)

IMPORT_COPY_MODULES := $(call FindImportedModules)
IMPORT_COPY_TARGETS := $(addsuffix -copy, $(IMPORT_COPY_MODULES))
ALL_COPY_MODULES += $(IMPORT_COPY_MODULES)
ALL_COPY_TARGETS += $(IMPORT_COPY_TARGETS)

define DeclareImportCopyRecipe
  $1-copy:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) \
	    -f CopyImportModules.gmk MODULE=$1)
endef

$(foreach m, $(IMPORT_COPY_MODULES), $(eval $(call DeclareImportCopyRecipe,$m)))

ALL_TARGETS += $(ALL_COPY_TARGETS)

################################################################################
# Targets for compiling all java modules.
JAVA_MODULES := $(ALL_MODULES)
JAVA_TARGETS := $(addsuffix -java, $(JAVA_MODULES))

define DeclareCompileJavaRecipe
  $1-java:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) \
	    -f CompileJavaModules.gmk MODULE=$1)
endef

$(foreach m, $(JAVA_MODULES), $(eval $(call DeclareCompileJavaRecipe,$m)))

ALL_TARGETS += $(JAVA_TARGETS)

################################################################################
# Targets for running rmic.
$(eval $(call DeclareRecipesForPhase, RMIC, \
    TARGET_SUFFIX := rmic, \
    FILE_PREFIX := Rmic, \
    MAKE_SUBDIR := rmic, \
    CHECK_MODULES := $(ALL_MODULES)))

ALL_TARGETS += $(RMIC_TARGETS)

################################################################################
# Targets for compiling native libraries
$(eval $(call DeclareRecipesForPhase, LIBS, \
    TARGET_SUFFIX := libs, \
    FILE_PREFIX := Lib, \
    MAKE_SUBDIR := lib, \
    CHECK_MODULES := $(ALL_MODULES), \
    USE_WRAPPER := true))

ALL_TARGETS += $(LIBS_TARGETS)

################################################################################
# Targets for compiling native executables
$(eval $(call DeclareRecipesForPhase, LAUNCHER, \
    TARGET_SUFFIX := launchers, \
    FILE_PREFIX := Launcher, \
    MAKE_SUBDIR := launcher, \
    CHECK_MODULES := $(ALL_MODULES), \
    USE_WRAPPER := true))

ALL_TARGETS += $(LAUNCHER_TARGETS)

################################################################################
# Build hotspot target

HOTSPOT_VARIANT_TARGETS := $(addprefix hotspot-, $(JVM_VARIANTS))
HOTSPOT_VARIANT_GENSRC_TARGETS := $(addsuffix -gensrc, $(HOTSPOT_VARIANT_TARGETS))
HOTSPOT_VARIANT_LIBS_TARGETS := $(addsuffix -libs, $(HOTSPOT_VARIANT_TARGETS))

define DeclareHotspotGensrcRecipe
  hotspot-$1-gensrc:
	$$(call LogInfo, Building JVM variant '$1' with features '$(JVM_FEATURES_$1)')
	+($(CD) $(TOPDIR)/make/hotspot && $(MAKE) $(MAKE_ARGS) -f gensrc/GenerateSources.gmk \
	    JVM_VARIANT=$1)
endef

$(foreach v, $(JVM_VARIANTS), $(eval $(call DeclareHotspotGensrcRecipe,$v)))

define DeclareHotspotLibsRecipe
  hotspot-$1-libs:
	+($(CD) $(TOPDIR)/make/hotspot && $(MAKE) $(MAKE_ARGS) -f lib/CompileLibraries.gmk \
	    JVM_VARIANT=$1)
endef

$(foreach v, $(JVM_VARIANTS), $(eval $(call DeclareHotspotLibsRecipe,$v)))

hotspot-ide-project:
	+($(CD) $(TOPDIR)/make/hotspot && $(MAKE) $(MAKE_ARGS) -f ide/CreateVSProject.gmk)

ALL_TARGETS += $(HOTSPOT_VARIANT_TARGETS) $(HOTSPOT_VARIANT_GENSRC_TARGETS) \
    $(HOTSPOT_VARIANT_LIBS_TARGETS) hotspot-ide-project

################################################################################
# Generate libs and launcher targets for creating compile_commands.json fragments
define DeclareCompileCommandsRecipe
  $1-compile-commands:
	$$(call LogInfo, Generating compile_commands.json fragments for $1)
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Main.gmk $1-only \
	    GENERATE_COMPILE_COMMANDS_ONLY=true)

  COMPILE_COMMANDS_TARGETS_$2 += $1-compile-commands
endef

$(foreach t, $(HOTSPOT_VARIANT_LIBS_TARGETS), \
  $(eval $(call DeclareCompileCommandsRecipe,$t,HOTSPOT)) \
)

$(foreach t, $(LIBS_TARGETS) $(LAUNCHER_TARGETS), \
  $(eval $(call DeclareCompileCommandsRecipe,$t,JDK)) \
)

compile-commands compile-commands-hotspot:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f CompileCommands.gmk)

ALL_TARGETS += $(COMPILE_COMMANDS_TARGETS_HOTSPOT) $(COMPILE_COMMANDS_TARGETS_JDK)
ALL_TARGETS += compile-commands compile-commands-hotspot

################################################################################
# VS Code projects
vscode-project:
	+($(CD) $(TOPDIR)/make/vscode && $(MAKE) $(MAKE_ARGS) -f CreateVSCodeProject.gmk \
      VSCODE_INDEXER=cpptools)

vscode-project-clangd:
	+($(CD) $(TOPDIR)/make/vscode && $(MAKE) $(MAKE_ARGS) -f CreateVSCodeProject.gmk \
      VSCODE_INDEXER=clangd)

vscode-project-rtags:
	+($(CD) $(TOPDIR)/make/vscode && $(MAKE) $(MAKE_ARGS) -f CreateVSCodeProject.gmk \
      VSCODE_INDEXER=rtags)

vscode-project-ccls:
	+($(CD) $(TOPDIR)/make/vscode && $(MAKE) $(MAKE_ARGS) -f CreateVSCodeProject.gmk \
      VSCODE_INDEXER=ccls)

ALL_TARGETS += vscode-project vscode-project-clangd vscode-project-rtags \
  vscode-project-ccls

################################################################################
# Build demos targets

demos-jdk:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f CompileDemos.gmk)

test-image-demos-jdk:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f CompileDemos.gmk images)

ALL_TARGETS += demos-jdk test-image-demos-jdk

################################################################################
# Jigsaw specific data and analysis targets.

generate-summary:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f GenerateModuleSummary.gmk)

ALL_TARGETS += generate-summary

################################################################################
# Jmod targets

JMOD_MODULES := $(ALL_MODULES)
JMOD_TARGETS := $(addsuffix -jmod, $(JMOD_MODULES))

define DeclareJmodRecipe
  $1-jmod:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f CreateJmods.gmk \
	    MODULE=$1)
endef

$(foreach m, $(JMOD_MODULES), $(eval $(call DeclareJmodRecipe,$m)))

ALL_TARGETS += $(JMOD_TARGETS)

################################################################################
# Images targets

store-source-revision:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f SourceRevision.gmk store-source-revision)

create-source-revision-tracker:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f SourceRevision.gmk create-source-revision-tracker)

BOOTCYCLE_TARGET := product-images
bootcycle-images:
        ifneq ($(COMPILE_TYPE), cross)
	  $(call LogWarn, Boot cycle build step 2: Building a new JDK image using previously built image)
	  $(call MakeDir, $(OUTPUTDIR)/bootcycle-build)
	  +$(MAKE) $(MAKE_ARGS) -f $(TOPDIR)/make/Init.gmk PARALLEL_TARGETS=$(BOOTCYCLE_TARGET) \
	      LOG_PREFIX="[bootcycle] " JOBS= SPEC=$(dir $(SPEC))bootcycle-spec.gmk main
        else
	  $(call LogWarn, Boot cycle build disabled when cross compiling)
        endif

zip-security:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f ZipSecurity.gmk)

zip-source:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f ZipSource.gmk)

jrtfs-jar:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f JrtfsJar.gmk)

jdk-image:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Images.gmk jdk)

legacy-jre-image:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Images.gmk jre)

symbols-image:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Images.gmk symbols)

mac-jdk-bundle:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f MacBundles.gmk jdk-bundle)

mac-legacy-jre-bundle:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f MacBundles.gmk jre-bundle)

release-file:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f ReleaseFile.gmk)

exploded-image-optimize:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f ExplodedImageOptimize.gmk)

ifeq ($(JCOV_ENABLED), true)
  jcov-image:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Coverage.gmk jcov-image)
endif

ALL_TARGETS += store-source-revision create-source-revision-tracker bootcycle-images zip-security \
    zip-source jrtfs-jar jdk-image legacy-jre-image \
    symbols-image mac-jdk-bundle mac-legacy-jre-bundle \
    release-file exploded-image-optimize jcov-image

################################################################################
# Docs targets

# If building full docs, to complete docs-*-api we need both the javadoc and
# modulegraph targets.
docs-jdk-api-javadoc:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Docs.gmk docs-jdk-api-javadoc)

docs-jdk-api-modulegraph:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Docs.gmk docs-jdk-api-modulegraph)

docs-javase-api-javadoc:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Docs.gmk docs-javase-api-javadoc)

docs-javase-api-modulegraph:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Docs.gmk docs-javase-api-modulegraph)

docs-reference-api-javadoc:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Docs.gmk docs-reference-api-javadoc)

docs-reference-api-modulegraph:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Docs.gmk docs-reference-api-modulegraph)

docs-jdk-specs:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Docs.gmk docs-jdk-specs)

docs-jdk-index:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Docs.gmk docs-jdk-index)

docs-zip:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Docs.gmk docs-zip)

docs-specs-zip:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Docs.gmk docs-specs-zip)

update-build-docs:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f UpdateBuildDocs.gmk)

update-x11wrappers:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f UpdateX11Wrappers.gmk)

ALL_TARGETS += docs-jdk-api-javadoc docs-jdk-api-modulegraph \
    docs-javase-api-javadoc docs-javase-api-modulegraph \
    docs-reference-api-javadoc docs-reference-api-modulegraph docs-jdk-specs \
    docs-jdk-index docs-zip docs-specs-zip update-build-docs update-x11wrappers

################################################################################
# Cross compilation support

ifeq ($(CREATING_BUILDJDK), true)
  # This target is only called by the recursive call below.
  create-buildjdk-interim-image-helper: interim-image jdk.jlink-launchers \
      java.base-copy jdk.jdeps-launchers
endif

BUILDJDK_MODULES := $(sort $(foreach m, jdk.jlink $(INTERIM_IMAGE_MODULES), \
    $(call FindTransitiveDepsForModule, $m) $m))

create-buildjdk-interim-image:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Main.gmk \
	    $@-helper \
	    SPEC=$(dir $(SPEC))buildjdk-spec.gmk \
	    HOTSPOT_SPEC=$(dir $(SPEC))buildjdk-spec.gmk \
	    CREATING_BUILDJDK=true \
	    LOG_PREFIX="[buildjdk] " \
	    JAVA_MODULES="$(BUILDJDK_MODULES)" \
	)

ALL_TARGETS += create-buildjdk-copy create-buildjdk-interim-image

################################################################################
# The interim-image is a small jlinked image that is used to generate artifacts
# at build time for use when linking the real images.

INTERIM_JMOD_TARGETS := $(addsuffix -interim-jmod, $(INTERIM_IMAGE_MODULES))

define DeclareInterimJmodRecipe
  $1-interim-jmod:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f CreateJmods.gmk \
	    MODULE=$1 \
	    JMODS_DIR=$(INTERIM_JMODS_DIR) \
	    JMODS_SUPPORT_DIR=$(INTERIM_JMODS_DIR)/support \
	    INTERIM_JMOD=true \
	)
endef

$(foreach m, $(INTERIM_IMAGE_MODULES), $(eval $(call DeclareInterimJmodRecipe,$m)))

interim-image:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f InterimImage.gmk)

ifeq ($(ENABLE_GENERATE_CLASSLIST), true)
  generate-link-opt-data:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f GenerateLinkOptData.gmk)
endif

ALL_TARGETS += $(INTERIM_JMOD_TARGETS) interim-image generate-link-opt-data

################################################################################
# Generate test names for all JTReg test groups
#

define DeclareRunTestRecipe
  test-$1:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f RunTests.gmk \
	    TEST="$1")

  exploded-test-$1:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f RunTests.gmk \
	    TEST="$1" JDK_IMAGE_DIR=$(JDK_OUTPUTDIR))
endef

# ALL_NAMED_TESTS is defined in FindTests.gmk
$(foreach t, $(ALL_NAMED_TESTS), $(eval $(call DeclareRunTestRecipe,$t)))
ALL_TEST_TARGETS := $(addprefix test-, $(ALL_NAMED_TESTS))

# We only support the "exploded-test-gtest" shortcut
ALL_EXPLODED_TESTS := gtest
ALL_EXPLODED_TEST_TARGETS := $(addprefix exploded-test-, $(ALL_EXPLODED_TESTS))

ALL_TARGETS += $(ALL_TEST_TARGETS) $(ALL_EXPLODED_TEST_TARGETS)

################################################################################
# Build tests and microbenchmarks
#

prepare-test-image:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f TestImage.gmk prepare-test-image)

build-test-hotspot-jtreg-native:
	+($(CD) $(TOPDIR)/make/test && $(MAKE) $(MAKE_ARGS) -f JtregNativeHotspot.gmk \
	    build-test-hotspot-jtreg-native)

test-image-hotspot-jtreg-native:
	+($(CD) $(TOPDIR)/make/test && $(MAKE) $(MAKE_ARGS) -f JtregNativeHotspot.gmk \
	    test-image-hotspot-jtreg-native)

build-test-jdk-jtreg-native:
	+($(CD) $(TOPDIR)/make/test && $(MAKE) $(MAKE_ARGS) -f JtregNativeJdk.gmk \
	    build-test-jdk-jtreg-native)

test-image-jdk-jtreg-native:
	+($(CD) $(TOPDIR)/make/test && $(MAKE) $(MAKE_ARGS) -f JtregNativeJdk.gmk \
	    test-image-jdk-jtreg-native)

build-test-hotspot-jtreg-graal:
	+($(CD) $(TOPDIR)/make/test && $(MAKE) $(MAKE_ARGS) -f JtregGraalUnit.gmk \
	     build-test-hotspot-jtreg-graal)

test-image-hotspot-jtreg-graal:
	+($(CD) $(TOPDIR)/make/test && $(MAKE) $(MAKE_ARGS) -f JtregGraalUnit.gmk \
	     test-image-hotspot-jtreg-graal)

ifeq ($(BUILD_GTEST), true)
  test-image-hotspot-gtest:
	+($(CD) $(TOPDIR)/make/hotspot/test && $(MAKE) $(MAKE_ARGS) -f GtestImage.gmk)
endif

build-test-lib:
	+($(CD) $(TOPDIR)/make/test && $(MAKE) $(MAKE_ARGS) -f BuildTestLib.gmk)

ifeq ($(BUILD_FAILURE_HANDLER), true)
  # Builds the failure handler jtreg extension
  build-test-failure-handler:
	+($(CD) $(TOPDIR)/make/test && $(MAKE) $(MAKE_ARGS) \
	    -f BuildFailureHandler.gmk build)

  # Copies the failure handler jtreg extension into the test image
  test-image-failure-handler:
	+($(CD) $(TOPDIR)/make/test && $(MAKE) $(MAKE_ARGS) \
	     -f BuildFailureHandler.gmk images)
endif

build-microbenchmark:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f test/BuildMicrobenchmark.gmk)

ALL_TARGETS += prepare-test-image build-test-hotspot-jtreg-native \
    test-image-hotspot-jtreg-native build-test-jdk-jtreg-native \
    test-image-jdk-jtreg-native build-test-lib build-test-failure-handler \
    test-failure-handler test-image-failure-handler test-image-hotspot-gtest \
    test-image-hotspot-jtreg-graal build-test-hotspot-jtreg-graal \
    build-microbenchmark

################################################################################
# Run tests

test:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f RunTests.gmk \
	    TEST="$(TEST)")

exploded-test:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f RunTests.gmk \
	    TEST="$(TEST)" JDK_IMAGE_DIR=$(JDK_OUTPUTDIR))

jcov-test:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f RunTests.gmk \
	    TEST="$(TEST)" TEST_OPTS_JCOV=true)

ALL_TARGETS += test exploded-test jcov-test

################################################################################
# Bundles

product-bundles:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Bundles.gmk product-bundles)

legacy-bundles:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Bundles.gmk legacy-bundles)

test-bundles:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Bundles.gmk test-bundles)

docs-bundles:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Bundles.gmk docs-bundles)

ifeq ($(JCOV_ENABLED), true)
  jcov-bundles:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Bundles.gmk jcov-bundles)
endif

ALL_TARGETS += product-bundles legacy-bundles test-bundles docs-bundles jcov-bundles

################################################################################
# Install targets

install:
	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f Install.gmk)

ALL_TARGETS += install

################################################################################
#
# Dependency declarations between targets.
#
# These are declared in two groups. First all dependencies between targets that
# have recipes above as these dependencies may be disabled. Then the aggregator
# targets that do not have recipes of their own, which will never have their
# dependencies disabled.
#
################################################################################
# Targets with recipes above

# If running an *-only target, parallel execution and dependencies between
# recipe targets are disabled. This makes it possible to run a select set of
# recipe targets in order. It's the responsibility of the user to make sure
# all prerequisites are fulfilled.
ifneq ($(findstring -only, $(MAKECMDGOALS)), )
  .NOTPARALLEL:
else
  $(LANGTOOLS_GENSRC_TARGETS): buildtools-langtools

  interim-langtools: $(INTERIM_LANGTOOLS_GENSRC_TARGETS)

  buildtools-jdk: interim-langtools interim-cldrconverter

  buildtools-hotspot: interim-langtools

  buildtools-modules: exploded-image-base

  $(HOTSPOT_GENSRC_TARGETS): interim-langtools buildtools-hotspot

  $(JDK_GENSRC_TARGETS): interim-langtools buildtools-jdk

  $(GENSRC_MODULEINFO_TARGETS): buildtools-jdk

  $(GENDATA_TARGETS): interim-langtools buildtools-jdk

  interim-rmic: interim-langtools

  $(RMIC_TARGETS): interim-langtools interim-rmic

  $(JAVA_TARGETS): interim-langtools

  # Declare dependencies between hotspot-<variant>* targets
  $(foreach v, $(JVM_VARIANTS), \
      $(eval hotspot-$v-gensrc: java.base-copy) \
      $(eval hotspot-$v-libs: hotspot-$v-gensrc java.base-copy) \
  )

  hotspot-ide-project: hotspot exploded-image

  generate-exported-symbols: java.base-libs jdk.jdwp.agent-libs

  # If not already set, set the JVM variant target so that the JVM will be built.
  JVM_MAIN_LIB_TARGETS ?= hotspot-$(JVM_VARIANT_MAIN)-libs

  # Building one JVM variant is enough to start building the other libs
  $(LIBS_TARGETS): $(JVM_MAIN_LIB_TARGETS)

  $(LAUNCHER_TARGETS): java.base-libs

  ifeq ($(STATIC_BUILD), true)
    $(LAUNCHER_TARGETS): generate-exported-symbols
  endif

  # The demos are currently linking to libjvm and libjava, just like all other
  # jdk libs, even though they don't need to. To avoid warnings, make sure they
  # aren't built until after libjava and libjvm are available to link to.
  demos-jdk: java.base-libs exploded-image
  test-image-demos-jdk: demos-jdk

  # Declare dependency from <module>-java to <module>-gensrc
  $(foreach m, $(GENSRC_MODULES), $(eval $m-java: $m-gensrc))

  # Declare dependencies between java modules
  $(foreach m, $(JAVA_MODULES), \
      $(eval $m-java: $(addsuffix -java, $(filter $(JAVA_MODULES), \
      $(call FindDepsForModule,$m)))))

  # Declare dependencies between <module>-rmic to <module>-java
  $(foreach m, $(RMIC_MODULES), $(eval $m-rmic: $m-java))

  # Declare dependencies from <module>-lib to <module>-java
  # Skip modules that do not have java source.
  $(foreach m, $(filter $(JAVA_MODULES), $(LIBS_MODULES)), $(eval $m-libs: $m-java))

  # Declare dependencies from all other <module>-lib to java.base-lib
  $(foreach t, $(filter-out java.base-libs, $(LIBS_TARGETS)), \
      $(eval $t: java.base-libs))

  # jdk.accessibility depends on java.desktop
  jdk.accessibility-libs: java.desktop-libs

  # This dependency needs to be explicitly declared. jdk.jdi-gensrc generates a
  # header file used by jdk.jdwp.agent-libs. The jdk.jdwp.agent-gensrc is a
  # virtual target.
  jdk.jdwp.agent-libs: jdk.jdwp.agent-gensrc

  # The swing beans need to have java base properly generated to avoid errors
  # in javadoc. The X11 wrappers need the java.base include files to have been
  # copied and processed.
  java.desktop-gensrc-src: java.base-gensrc java.base-copy

  # The annotation processing for jdk.internal.vm.compiler
  # and jdk.internal.vm.compiler.management needs classes from the current JDK.
  jdk.internal.vm.compiler-gensrc-src: $(addsuffix -java, \
      $(call FindTransitiveDepsForModule, jdk.internal.vm.compiler))
  jdk.internal.vm.compiler.management-gensrc-src: $(addsuffix -java, \
      $(call FindTransitiveDepsForModule, jdk.internal.vm.compiler.management))

  # For these modules, the gensrc step is generating a module-info.java.extra
  # file to be processed by the gensrc-moduleinfo target.
  jdk.internal.vm.compiler-gensrc-moduleinfo: jdk.internal.vm.compiler-gensrc-src
  jdk.internal.vm.compiler.management-gensrc-moduleinfo: jdk.internal.vm.compiler.management-gensrc-src

  jdk.jdeps-gendata: java rmic

  # The ct.sym generation uses all the moduleinfos as input
  jdk.compiler-gendata: $(GENSRC_MODULEINFO_TARGETS)

  # Declare dependencies between jmod targets.
  # java.base jmod needs jrt-fs.jar and access to the other jmods to be built.
  # When creating the BUILDJDK, we don't need to add hashes to java.base, thus
  # we don't need to depend on all other jmods
  ifneq ($(CREATING_BUILDJDK), true)
    java.base-jmod: jrtfs-jar $(filter-out java.base-jmod, $(JMOD_TARGETS))
  endif

  # If not already set, set the JVM target so that the JVM will be built.
  JVM_MAIN_TARGETS ?= hotspot

  # Building java.base-jmod requires all of VM (ie hotspot) to be built.
  java.base-jmod: $(JVM_MAIN_TARGETS)

  # Declare dependencies from <module>-jmod to all other module targets
  $(foreach m, $(JAVA_MODULES), $(eval $m_JMOD_DEPS += $m-java))
  $(foreach m, $(GENDATA_MODULES), $(eval $m_JMOD_DEPS += $m-gendata))
  $(foreach m, $(RMIC_MODULES), $(eval $m_JMOD_DEPS += $m-rmic))
  $(foreach m, $(LIBS_MODULES), $(eval $m_JMOD_DEPS += $m-libs))
  $(foreach m, $(LAUNCHER_MODULES), $(eval $m_JMOD_DEPS += $m-launchers))
  $(foreach m, $(COPY_MODULES), $(eval $m_JMOD_DEPS += $m-copy))
  $(foreach m, $(ALL_MODULES), $(eval $m-jmod: $($(m)_JMOD_DEPS)))
  $(foreach m, $(INTERIM_IMAGE_MODULES), $(eval $m-interim-jmod: $($(m)_JMOD_DEPS)))

  # Setup the minimal set of generated native source dependencies for hotspot
  $(foreach v, $(JVM_VARIANTS), \
    $(eval hotspot-$v-libs-compile-commands: hotspot-$v-gensrc) \
    $(foreach m, $(filter java.desktop jdk.hotspot.agent, $(GENSRC_MODULES)), \
      $(eval hotspot-$v-libs-compile-commands: $m-gensrc)) \
  )

  # For the full JDK compile commands, create all possible generated sources
  $(foreach m, $(GENSRC_MODULES), $(eval $m-libs-compile-commands: $m-gensrc))
  $(foreach m, $(filter $(JAVA_MODULES), $(LIBS_MODULES)), $(eval $m-libs-compile-commands: $m-java))

  $(COMPILE_COMMANDS_TARGETS_HOTSPOT): clean-compile-commands
  $(COMPILE_COMMANDS_TARGETS_JDK): clean-compile-commands
  compile-commands-hotspot: $(COMPILE_COMMANDS_TARGETS_HOTSPOT)
  compile-commands: $(COMPILE_COMMANDS_TARGETS_HOTSPOT) $(COMPILE_COMMANDS_TARGETS_JDK)

  vscode-project: compile-commands
  vscode-project-clangd: compile-commands
  vscode-project-rtags: compile-commands
  vscode-project-ccls: compile-commands

  # Jmods cannot be created until we have the jmod tool ready to run. During
  # a normal build we run it from the exploded image, but when cross compiling
  # it's run from the buildjdk, which is either created at build time or user
  # supplied.
  ifeq ($(CREATE_BUILDJDK), true)
    ifneq ($(CREATING_BUILDJDK), true)
      # When cross compiling and buildjdk is to be created, simply depend on
      # creating the buildjdk.
      $(JMOD_TARGETS): create-buildjdk
      buildtools-modules: create-buildjdk
    else
      # While actually creating the buildjdk, we need to list the bare
      # minimum dependencies needed before running jmod, to avoid building
      # more than necessary. This includes:
      # * all java modules
      # * jdk.jlink-launchers
      # * copy jvm.cfg (done in java.base-copy)
      # * tzdb.dat (done in java.base-gendata)
      # Without all of these jimage, jlink and jmod won't start.
      $(JMOD_TARGETS) $(INTERIM_JMOD_TARGETS): java.base-libs java.base-copy \
          java.base-gendata jdk.jlink-launchers java
    endif
  else
    # The normal non cross compilation case uses needs to wait for the full
    # exploded-image to avoid a race with the optimize target.
    $(JMOD_TARGETS) $(INTERIM_JMOD_TARGETS): exploded-image
  endif

  # All modules include the main license files from java.base.
  $(JMOD_TARGETS): java.base-copy

  zip-security: java.base-java java.security.jgss-java java.security.jgss-libs \
      $(filter jdk.crypto%, $(JAVA_TARGETS))

  zip-source: gensrc rmic

  jrtfs-jar: interim-langtools

  build-microbenchmark: interim-langtools exploded-image

  ifeq ($(ENABLE_GENERATE_CLASSLIST), true)
    ifeq ($(CREATE_BUILDJDK), true)
      # If creating a buildjdk, the interim image needs to be based on that.
      generate-link-opt-data: create-buildjdk
    else ifeq ($(EXTERNAL_BUILDJDK), false)
      # If an external buildjdk has been provided, we skip generating an
      # interim-image and just use the external buildjdk for generating
      # classlist.
      generate-link-opt-data: interim-image
    endif
    generate-link-opt-data: buildtools-jdk

    # The generated classlist needs to go into java.base-jmod.
    java.base-jmod jdk.jlink-jmod jdk-image legacy-jre-image: generate-link-opt-data
  endif

  release-file: create-source-revision-tracker

  jdk-image: jmods zip-source demos release-file
  legacy-jre-image: jmods release-file
  symbols-image: $(LIBS_TARGETS) $(LAUNCHER_TARGETS)

  mac-jdk-bundle: jdk-image
  mac-legacy-jre-bundle: legacy-jre-image

  ifeq ($(JCOV_INPUT_JDK), )
    jcov-image: jdk-image
  endif

  # The optimize target can run as soon as the modules dir has been completely
  # populated (java, copy and gendata targets) and the basic libs and launchers
  # have been built.
  exploded-image-optimize: java copy gendata java.base-libs java.base-launchers \
      buildtools-modules

  bootcycle-images: jdk-image

  docs-jdk-api-javadoc: $(GENSRC_TARGETS) rmic

  docs-javase-api-javadoc: $(GENSRC_TARGETS) rmic

  docs-reference-api-javadoc: $(GENSRC_TARGETS) rmic

  docs-jdk-api-modulegraph: exploded-image buildtools-modules

  docs-javase-api-modulegraph: exploded-image buildtools-modules

  docs-reference-api-modulegraph: exploded-image buildtools-modules

  # If not already set, then set the JVM specific docs targets
  JVM_DOCS_TARGETS ?= hotspot-$(JVM_VARIANT_MAIN)-gensrc

  # The gensrc steps for hotspot and jdk.jdi create html spec files.
  docs-jdk-specs: buildtools-jdk $(JVM_DOCS_TARGETS) jdk.jdi-gensrc \
      docs-jdk-index

  docs-zip: docs-jdk

  docs-specs-zip: docs-jdk-specs

  # Tests
  test: jdk-image test-image

  exploded-test: exploded-image test-image

  jcov-test: jcov-image test-image

  test-make: clean-test-make compile-commands

  test-make-compile-commands: compile-commands

  # Declare dependency for all generated test targets
  $(foreach t, $(filter-out test-make%, $(ALL_TEST_TARGETS)), $(eval $t: jdk-image test-image))
  $(foreach t, $(ALL_EXPLODED_TEST_TARGETS), $(eval $t: exploded-image test-image))

  interim-image: $(INTERIM_JMOD_TARGETS)

  build-test-lib: exploded-image

  build-test-failure-handler: interim-langtools

  test-image-failure-handler: build-test-failure-handler

  build-test-hotspot-jtreg-native: buildtools-jdk \
      hotspot-$(JVM_VARIANT_MAIN)-libs

  build-test-jdk-jtreg-native: buildtools-jdk java.base-libs

  build-test-hotspot-jtreg-graal: exploded-image

  test-image-hotspot-jtreg-native: build-test-hotspot-jtreg-native

  test-image-jdk-jtreg-native: build-test-jdk-jtreg-native

  test-image-hotspot-jtreg-graal: build-test-hotspot-jtreg-graal

  test-image-hotspot-gtest: hotspot

  install: product-images

  product-bundles: product-images

  legacy-bundles: legacy-images

  test-bundles: test-image

  docs-bundles: docs-image

  jcov-bundles: jcov-image

  generate-summary: jmods buildtools-modules

  update-x11wrappers: java.base-copy buildtools-jdk

endif

################################################################################
# Virtual targets without recipes

# If not already set, set the JVM specific tools targets
JVM_TOOLS_TARGETS ?= buildtools-hotspot
buildtools: buildtools-langtools interim-langtools interim-rmic \
    buildtools-jdk $(JVM_TOOLS_TARGETS)

# Declare dependencies from hotspot-<variant> targets
$(foreach v, $(JVM_VARIANTS), \
  $(eval hotspot-$v: hotspot-$v-gensrc hotspot-$v-libs) \
)
hotspot: $(HOTSPOT_VARIANT_TARGETS)

# Create targets hotspot-libs and hotspot-gensrc.
$(foreach v, $(JVM_VARIANTS), \
  $(eval hotspot-libs: hotspot-$v-libs) \
  $(eval hotspot-gensrc: hotspot-$v-gensrc) \
)

gensrc: $(GENSRC_TARGETS)

gendata: $(GENDATA_TARGETS)

copy: $(ALL_COPY_TARGETS)

java: $(JAVA_TARGETS)

rmic: $(RMIC_TARGETS)

libs: $(LIBS_TARGETS)

launchers: $(LAUNCHER_TARGETS)

jmods: $(JMOD_TARGETS)

# Explicitly declare dependency for virtual target jdk.jdwp.agent-gensrc which
# is actually handled by jdk.jdi-gensrc
jdk.jdwp.agent-gensrc: jdk.jdi-gensrc

# Declare dependencies from <module> to all the individual targets specific
# to that module <module>-*, that are needed for the exploded image.
$(foreach m, $(GENSRC_MODULES), $(eval $m: $m-gensrc))
$(foreach m, $(JAVA_MODULES), $(eval $m: $m-java))
$(foreach m, $(GENDATA_MODULES), $(eval $m: $m-gendata))
$(foreach m, $(RMIC_MODULES), $(eval $m: $m-rmic))
$(foreach m, $(LIBS_MODULES), $(eval $m: $m-libs))
$(foreach m, $(LAUNCHER_MODULES), $(eval $m: $m-launchers))
$(foreach m, $(ALL_COPY_MODULES), $(eval $m: $m-copy))

# Building java.base includes building all of hotspot.
java.base: $(JVM_MAIN_TARGETS)

demos: demos-jdk

# The "exploded image" is a locally runnable JDK in $(OUTPUTDIR)/jdk.
exploded-image-base: $(ALL_MODULES)
exploded-image: exploded-image-base release-file
# When cross compiling, no need to optimize the exploded image since it won't
# be runnable on the host platform anyway.
ifneq ($(COMPILE_TYPE), cross)
  exploded-image: exploded-image-optimize
endif

create-buildjdk: create-buildjdk-interim-image

docs-jdk-api: docs-jdk-api-javadoc
docs-javase-api: docs-javase-api-javadoc
docs-reference-api: docs-reference-api-javadoc

# If we're building full docs, we must also generate the module graphs to
# get non-broken api documentation.
ifeq ($(ENABLE_FULL_DOCS), true)
  docs-jdk-api: docs-jdk-api-modulegraph
  docs-javase-api: docs-javase-api-modulegraph
  docs-reference-api: docs-reference-api-modulegraph
endif

docs-jdk: docs-jdk-api docs-jdk-specs docs-jdk-index
docs-javase: docs-javase-api
docs-reference: docs-reference-api

# alias for backwards compatibility
docs-javadoc: docs-jdk-api

mac-bundles: mac-jdk-bundle

# The $(OUTPUTDIR)/images directory contain the resulting deliverables,
# and in line with this, our targets for creating these are named *-image[s].

# This target builds the product images, e.g. the JDK image
# (and possibly other, more specific versions)
product-images: jdk-image symbols-image exploded-image

# This target builds the legacy images, e.g. the legacy JRE image
legacy-images: legacy-jre-image

# zip-security is actually a bundle, but for now it needs to be considered
# an image until this can be cleaned up properly.
product-images: zip-security

# The module summary cannot be run when:
# * Cross compiling and building a partial BUILDJDK for the build host
# * An external buildjdk has been supplied since it may not match the
#   module selection of the target jdk
ifneq ($(CREATE_BUILDJDK), true)
  ifeq ($(EXTERNAL_BUILDJDK), false)
    product-images: generate-summary
  endif
endif

ifeq ($(call isTargetOs, macosx), true)
  product-images: mac-jdk-bundle

  legacy-images: mac-legacy-jre-bundle
endif

# This target builds the documentation image
docs-image: docs-jdk

# If not already set, set the JVM specific targets to build the test image
JVM_TEST_IMAGE_TARGETS ?= test-image-hotspot-jtreg-native test-image-hotspot-gtest

ifeq ($(INCLUDE_GRAAL), true)
  JVM_TEST_IMAGE_TARGETS += test-image-hotspot-jtreg-graal
endif

# This target builds the test image
test-image: prepare-test-image \
    test-image-jdk-jtreg-native test-image-failure-handler \
    test-image-demos-jdk $(JVM_TEST_IMAGE_TARGETS)

ifneq ($(JMH_CORE_JAR), )
  test-image: build-microbenchmark
endif

################################################################################

# all-images builds all our deliverables as images.
all-images: product-images test-image docs-image

# all-bundles packages all our deliverables as tar.gz bundles.
all-bundles: product-bundles test-bundles docs-bundles

ALL_TARGETS += buildtools hotspot hotspot-libs hotspot-gensrc gensrc gendata \
    copy java rmic libs launchers jmods \
    jdk.jdwp.agent-gensrc $(ALL_MODULES) demos \
    exploded-image-base exploded-image \
    create-buildjdk docs-jdk-api docs-javase-api docs-reference-api docs-jdk \
    docs-javase docs-reference docs-javadoc mac-bundles product-images legacy-images \
    docs-image test-image all-images \
    all-bundles

################################################################################

# Traditional targets typically run by users.
# These can be considered aliases for the targets now named by a more
# "modern" naming scheme.
default: $(DEFAULT_MAKE_TARGET)
jdk: exploded-image
images: product-images
docs: docs-image
bundles: all-bundles
all: all-images

ALL_TARGETS += default jdk images docs bundles all

# Aliases used for running tests.

# Let "run-test" be an alias for "test"
$(foreach t, $(ALL_NAMED_TESTS), $(eval run-test-$t: test-$t))
RUN_TEST_TARGETS := $(addprefix run-test-, $(ALL_NAMED_TESTS))

run-test: test
exploded-run-test: exploded-test

# "make check" is a common idiom for running basic testing
check: test-tier1

# Keep some old names as aliases
test-hotspot-jtreg: test-hotspot_all
test-hotspot-jtreg-native: test-hotspot_native_sanity
test-hotspot-gtest: exploded-test-gtest
test-jdk-jtreg-native: test-jdk_native_sanity

ALL_TARGETS += $(RUN_TEST_TARGETS) run-test exploded-run-test check \
    test-hotspot-jtreg test-hotspot-jtreg-native test-hotspot-gtest \
    test-jdk-jtreg-native

################################################################################
################################################################################
#
# Clean targets
#
################################################################################
# Clean targets are automatically run serially by the Makefile calling this
# file.

CLEAN_DIRS += hotspot jdk bootcycle-build test buildtools support \
    images make-support test-make bundles buildjdk test-results test-support \
    support/images
CLEAN_DIR_TARGETS := $(addprefix clean-, $(CLEAN_DIRS))
CLEAN_SUPPORT_DIRS += demos
CLEAN_SUPPORT_DIR_TARGETS := $(addprefix clean-, $(CLEAN_SUPPORT_DIRS))
CLEAN_TESTS += hotspot-jtreg-native jdk-jtreg-native lib
CLEAN_TEST_TARGETS += $(addprefix clean-test-, $(CLEAN_TESTS))
CLEAN_PHASES := gensrc java native include
CLEAN_PHASE_TARGETS := $(addprefix clean-, $(CLEAN_PHASES))
CLEAN_MODULE_TARGETS := $(addprefix clean-, $(ALL_MODULES))
# Construct targets of the form clean-$module-$phase
CLEAN_MODULE_PHASE_TARGETS := $(addprefix clean-, $(foreach m, $(ALL_MODULES), \
    $(addprefix $m-, $(CLEAN_PHASES))))

# Remove everything, except the output from configure.
clean: $(CLEAN_DIR_TARGETS)
	($(CD) $(OUTPUTDIR) && $(RM) -r build*.log* compile_commands.json)
	$(ECHO) Cleaned all build artifacts.

clean-docs:
	$(call CleanDocs)

clean-compile-commands:
	$(call CleanMakeSupportDir,compile-commands)

$(CLEAN_DIR_TARGETS):
	$(call CleanDir,$(patsubst clean-%, %, $@))

$(CLEAN_SUPPORT_DIR_TARGETS):
	$(call CleanSupportDir,$(patsubst clean-%, %, $@))

$(CLEAN_TEST_TARGETS):
	$(call CleanTest,$(patsubst clean-test-%, %, $@))

$(CLEAN_PHASE_TARGETS):
	$(call Clean-$(patsubst clean-%,%, $@))

$(CLEAN_MODULE_TARGETS):
	$(call CleanModule,$(patsubst clean-%, %, $@))

$(CLEAN_MODULE_PHASE_TARGETS):
	$(call Clean-$(word 3, $(subst -,$(SPACE),$@)), \
	    $(word 2, $(subst -,$(SPACE),$@)))

# When removing the support dir, we must also remove jdk. Building classes has
# the side effect of generating native headers. The headers end up in support
# while classes and touch files end up in jdk.
clean-support: clean-jdk

clean-test: clean-test-results clean-test-support

# When cleaning images, also clean the support/images directory.
clean-images: clean-support/images

# Remove everything, including configure configuration. If the output
# directory was created by configure and now becomes empty, remove it as well.
dist-clean: clean
	($(CD) $(OUTPUTDIR) && \
	    $(RM) -r *spec.gmk $(CONFIGURESUPPORT_OUTPUTDIR) Makefile compare.sh ide \
	    configure.log* build.log*)
	$(if $(filter $(CONF_NAME),$(notdir $(OUTPUTDIR))), \
	  if test "x`$(LS) $(OUTPUTDIR)`" != x; then \
	    $(ECHO) "Warning: Not removing non-empty configuration directory for '$(CONF_NAME)'" ; \
	  else \
	    ($(CD) $(TOPDIR) && $(ECHO) "Removing configuration directory for '$(CONF_NAME)'" \
	        && $(RM) -r $(OUTPUTDIR)) \
	  fi \
	)
	$(ECHO) Cleaned everything, you will have to re-run configure.

ALL_TARGETS += clean clean-docs clean-compile-commands dist-clean $(CLEAN_DIR_TARGETS) \
    $(CLEAN_SUPPORT_DIR_TARGETS) $(CLEAN_TEST_TARGETS) $(CLEAN_PHASE_TARGETS) \
    $(CLEAN_MODULE_TARGETS) $(CLEAN_MODULE_PHASE_TARGETS)

################################################################################
# Declare *-only targets for each normal target
$(foreach t, $(ALL_TARGETS), $(eval $(t)-only: $(t)))

ALL_TARGETS += $(addsuffix -only, $(filter-out dist-clean clean%, $(ALL_TARGETS)))

################################################################################

# The following targets are intentionally not added to ALL_TARGETS since they
# are internal only, to support Init.gmk.

print-targets:
	  @$(ECHO) $(sort $(ALL_TARGETS))

print-modules:
	  @$(ECHO) $(sort $(ALL_MODULES))

print-tests:
	  @$(ECHO) $(sort $(ALL_NAMED_TESTS))

create-main-targets-include:
	  $(call LogInfo, Generating main target list)
	  @$(ECHO) ALL_MAIN_TARGETS := $(sort $(ALL_TARGETS)) > \
	      $(MAKESUPPORT_OUTPUTDIR)/main-targets.gmk

################################################################################
# Hook to include the corresponding custom file, if present.
$(eval $(call IncludeCustomExtension, Main-post.gmk))

.PHONY: $(ALL_TARGETS)

FRC: # Force target