MainSupport.gmk revision 2262:7dcf453eacae
1# 2# Copyright (c) 2011, 2015, 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################################################################################ 27# This file contains helper functions for Main.gmk. 28################################################################################ 29 30ifndef _MAINSUPPORT_GMK 31_MAINSUPPORT_GMK := 1 32 33# Run the tests specified by $1, with PRODUCT_HOME specified by $2 34# JT_JAVA is picked up by the jtreg launcher and used to run Jtreg itself. 35define RunTests 36 ($(CD) $(SRC_ROOT)/test && $(MAKE) $(MAKE_ARGS) -j1 -k MAKEFLAGS= \ 37 JT_HOME=$(JT_HOME) PRODUCT_HOME=$(strip $2) \ 38 TEST_IMAGE_DIR=$(TEST_IMAGE_DIR) \ 39 ALT_OUTPUTDIR=$(OUTPUT_ROOT) TEST_JOBS=$(TEST_JOBS) \ 40 JT_JAVA=$(BOOT_JDK) \ 41 JOBS=$(JOBS) $1) || true 42endef 43 44# Cleans the dir given as $1 45define CleanDir 46 @$(PRINTF) "Cleaning $(strip $1) build artifacts ..." 47 @$(PRINTF) "\n" $(LOG_DEBUG) 48 ($(CD) $(OUTPUT_ROOT) && $(RM) -r $1) 49 @$(PRINTF) " done\n" 50endef 51 52define CleanSupportDir 53 @$(PRINTF) "Cleaning $(strip $1) build artifacts ..." 54 @$(PRINTF) "\n" $(LOG_DEBUG) 55 $(RM) -r $(SUPPORT_OUTPUTDIR)/$(strip $1) 56 @$(PRINTF) " done\n" 57endef 58 59define CleanTest 60 @$(PRINTF) "Cleaning test $(strip $1) ..." 61 @$(PRINTF) "\n" $(LOG_DEBUG) 62 $(RM) -r $(SUPPORT_OUTPUTDIR)/test/$(strip $(subst -,/,$1)) 63 # Remove as much of the test directory structure as is empty 64 $(RMDIR) -p $(dir $(SUPPORT_OUTPUTDIR)/test/$(strip $(subst -,/,$1))) 2> /dev/null || true 65 @$(PRINTF) " done\n" 66endef 67 68define Clean-gensrc 69 @$(PRINTF) "Cleaning gensrc $(if $1,for $(strip $1) )..." 70 @$(PRINTF) "\n" $(LOG_DEBUG) 71 $(RM) -r $(SUPPORT_OUTPUTDIR)/gensrc/$(strip $1) 72 @$(PRINTF) " done\n" 73endef 74 75define Clean-java 76 @$(PRINTF) "Cleaning java $(if $1,for $(strip $1) )..." 77 @$(PRINTF) "\n" $(LOG_DEBUG) 78 $(RM) -r $(JDK_OUTPUTDIR)/modules/$(strip $1) 79 $(RM) -r $(SUPPORT_OUTPUTDIR)/special_classes/$(strip $1) 80 $(PRINTF) " done\n" 81 $(PRINTF) "Cleaning headers $(if $1,for $(strip $1)) ..." 82 $(RM) -r $(SUPPORT_OUTPUTDIR)/headers/$(strip $1) 83 @$(PRINTF) " done\n" 84endef 85 86define Clean-native 87 @$(PRINTF) "Cleaning native $(if $1,for $(strip $1) )..." 88 @$(PRINTF) "\n" $(LOG_DEBUG) 89 $(RM) -r $(SUPPORT_OUTPUTDIR)/native/$(strip $1) 90 $(RM) -r $(SUPPORT_OUTPUTDIR)/modules_libs/$(strip $1) 91 $(RM) -r $(SUPPORT_OUTPUTDIR)/modules_libs-stripped/$(strip $1) 92 $(RM) -r $(SUPPORT_OUTPUTDIR)/modules_cmds/$(strip $1) 93 $(RM) -r $(SUPPORT_OUTPUTDIR)/modules_cmds-stripped/$(strip $1) 94 @$(PRINTF) " done\n" 95endef 96 97define Clean-include 98 @$(PRINTF) "Cleaning include $(if $1,for $(strip $1) )..." 99 @$(PRINTF) "\n" $(LOG_DEBUG) 100 $(RM) -r $(SUPPORT_OUTPUTDIR)/modules_include/$(strip $1) 101 @$(PRINTF) " done\n" 102endef 103 104define Clean-docs 105 @$(PRINTF) "Cleaning docs ..." 106 @$(PRINTF) "\n" $(LOG_DEBUG) 107 $(RM) -r $(SUPPORT_OUTPUTDIR)/docs 108 $(RM) -r $(IMAGES_OUTPUTDIR)/docs 109 $(RM) $(OUTPUT_ROOT)/bundles/jdk-*-docs.zip 110 @$(PRINTF) " done\n" 111endef 112 113define CleanModule 114 $(call Clean-gensrc, $1) 115 $(call Clean-java, $1) 116 $(call Clean-native, $1) 117 $(call Clean-include, $1) 118endef 119 120 121################################################################################ 122 123MAKE_TOPDIR_LIST := $(JDK_TOPDIR) $(CORBA_TOPDIR) $(LANGTOOLS_TOPDIR) \ 124 $(HOTSPOT_TOPDIR) 125MAKE_MAKEDIR_LIST := make 126 127# Helper macro for DeclareRecipesForPhase 128# Declare a recipe for calling the module and phase specific makefile. 129# If there are multiple makefiles to call, create a rule for each topdir 130# that contains a makefile with the target $module-$suffix-$repodir, 131# (i.e: java.base-gensrc-jdk) 132# Normally there is only one makefile, and the target will just be 133# $module-$suffix 134# Param 1: Name of list to add targets to 135# Param 2: Module name 136# Param 3: Topdir 137define DeclareRecipeForModuleMakefile 138 ifeq ($$($1_MULTIPLE_MAKEFILES), true) 139 $2-$$($1_TARGET_SUFFIX): $2-$$($1_TARGET_SUFFIX)-$$(notdir $3) 140 141 $2-$$($1_TARGET_SUFFIX)-$$(notdir $3): 142 else 143 $2-$$($1_TARGET_SUFFIX): 144 endif 145 ifeq ($$($1_USE_WRAPPER), true) 146 +($(CD) $(SRC_ROOT)/make && $(MAKE) $(MAKE_ARGS) \ 147 -f ModuleWrapper.gmk \ 148 $$(addprefix -I, $$(wildcard $$(addprefix $3/, $(MAKE_MAKEDIR_LIST)) \ 149 $$(addsuffix /$$($1_MAKE_SUBDIR), $$(addprefix $3/, $(MAKE_MAKEDIR_LIST))))) \ 150 MODULE=$2 MAKEFILE_PREFIX=$$($1_FILE_PREFIX)) 151 else 152 +($(CD) $$(dir $$(firstword $$(wildcard $$(patsubst %, \ 153 $3/%/$$($1_MAKE_SUBDIR)/$$($1_FILE_PREFIX)-$2.gmk, $(MAKE_MAKEDIR_LIST))))) \ 154 && $(MAKE) $(MAKE_ARGS) \ 155 -f $$($1_FILE_PREFIX)-$2.gmk \ 156 $$(addprefix -I, $$(wildcard $$(addprefix $3/, $(MAKE_MAKEDIR_LIST)) \ 157 $$(addsuffix /$$($1_MAKE_SUBDIR), $$(addprefix $3/, $(MAKE_MAKEDIR_LIST))))) \ 158 MODULE=$2) 159 endif 160 161endef 162 163# Helper macro for DeclareRecipesForPhase 164# Param 1: Name of list to add targets to 165# Param 2: Module name 166define DeclareRecipesForPhaseAndModule 167 $1_$2_TOPDIRS := $$(strip $$(sort $$(foreach d, $(MAKE_TOPDIR_LIST), \ 168 $$(patsubst $$d/%, $$d, $$(filter $$d/%, \ 169 $$(wildcard $$(patsubst %, %/$$($1_MAKE_SUBDIR)/$$($1_FILE_PREFIX)-$2.gmk, \ 170 $$(foreach s, $(MAKE_MAKEDIR_LIST), \ 171 $$(addsuffix /$$s, $(MAKE_TOPDIR_LIST)))))))))) 172 173 # Only declare recipes if there are makefiles to call 174 ifneq ($$($1_$2_TOPDIRS), ) 175 # Add the top dir specific target to target list regardless of if recipe 176 # generation is disabled. 177 ifeq ($$($1_MULTIPLE_MAKEFILES), true) 178 $$(foreach d, $$($1_$2_TOPDIRS), \ 179 $$(eval $1 += $2-$$($1_TARGET_SUFFIX)-$$(notdir $$d))) 180 endif 181 ifeq ($(NO_RECIPES),) 182 $$(foreach d, $$($1_$2_TOPDIRS), \ 183 $$(eval $$(call DeclareRecipeForModuleMakefile,$1,$2,$$d))) 184 endif 185 $1 += $2-$$($1_TARGET_SUFFIX) 186 $1_MODULES += $2 187 endif 188endef 189 190# Declare recipes for a specific module and build phase if there are makefiles 191# present for the specific combination. 192# Param 1: Name of list to add targets to 193# Named params: 194# TARGET_SUFFIX : Suffix of target to create for recipe 195# MAKE_SUBDIR : Subdir for this build phase 196# FILE_PREFIX : File prefix for this build phase 197# USE_WRAPPER : Set to true to use ModuleWrapper.gmk 198# CHECK_MODULES : List of modules to try 199# MULTIPLE_MAKEFILES : Set to true to handle makefiles for the same module and 200# phase in multiple repos 201# Exported variables: 202# $1_MODULES : All modules that had rules generated 203# $1_TARGETS : All targets generated 204define DeclareRecipesForPhase 205 $(foreach i,2 3 4 5 6 7, $(if $($i),$(strip $1)_$(strip $($i)))$(NEWLINE)) 206 $(if $(8),$(error Internal makefile error: Too many arguments to \ 207 DeclareRecipesForPhase, please update MakeHelper.gmk)) 208 209 $$(foreach m, $$($(strip $1)_CHECK_MODULES), \ 210 $$(eval $$(call DeclareRecipesForPhaseAndModule,$(strip $1),$$m))) 211 212 $(strip $1)_TARGETS := $$($(strip $1)) 213endef 214 215################################################################################ 216 217endif # _MAINSUPPORT_GMK 218