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