MainSupport.gmk revision 1827:e79b5043fd02
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. 34define RunTests 35 ($(CD) $(SRC_ROOT)/test && $(MAKE) $(MAKE_ARGS) -j1 -k MAKEFLAGS= \ 36 JT_HOME=$(JT_HOME) PRODUCT_HOME=$(JDK_IMAGE_DIR) \ 37 TEST_IMAGE_DIR=$(TEST_IMAGE_DIR) \ 38 ALT_OUTPUTDIR=$(OUTPUT_ROOT) TEST_JOBS=$(TEST_JOBS) \ 39 JOBS=$(JOBS) $1) || true 40endef 41 42# Cleans the dir given as $1 43define CleanDir 44 @$(PRINTF) "Cleaning $(strip $1) build artifacts ..." 45 @$(PRINTF) "\n" $(LOG_DEBUG) 46 ($(CD) $(OUTPUT_ROOT) && $(RM) -r $1) 47 @$(PRINTF) " done\n" 48endef 49 50define CleanSupportDir 51 @$(PRINTF) "Cleaning $(strip $1) build artifacts ..." 52 @$(PRINTF) "\n" $(LOG_DEBUG) 53 $(RM) -r $(SUPPORT_OUTPUTDIR)/$(strip $1) 54 @$(PRINTF) " done\n" 55endef 56 57define CleanTest 58 @$(PRINTF) "Cleaning test $(strip $1) ..." 59 @$(PRINTF) "\n" $(LOG_DEBUG) 60 $(RM) -r $(SUPPORT_OUTPUTDIR)/test/$(strip $(subst -,/,$1)) 61 # Remove as much of the test directory structure as is empty 62 $(RMDIR) -p $(dir $(SUPPORT_OUTPUTDIR)/test/$(strip $(subst -,/,$1))) 2> /dev/null || true 63 @$(PRINTF) " done\n" 64endef 65 66define Clean-gensrc 67 @$(PRINTF) "Cleaning gensrc $(if $1,for $(strip $1) )..." 68 @$(PRINTF) "\n" $(LOG_DEBUG) 69 $(RM) -r $(SUPPORT_OUTPUTDIR)/gensrc/$(strip $1) 70 $(RM) -r $(SUPPORT_OUTPUTDIR)/gensrc_no_docs/$(strip $1) 71 @$(PRINTF) " done\n" 72endef 73 74define Clean-java 75 @$(PRINTF) "Cleaning java $(if $1,for $(strip $1) )..." 76 @$(PRINTF) "\n" $(LOG_DEBUG) 77 $(RM) -r $(JDK_OUTPUTDIR)/modules/$(strip $1) 78 $(RM) -r $(SUPPORT_OUTPUTDIR)/special_classes/$(strip $1) 79 $(PRINTF) " done\n" 80 $(PRINTF) "Cleaning headers $(if $1,for $(strip $1)) ..." 81 $(RM) -r $(SUPPORT_OUTPUTDIR)/headers/$(strip $1) 82 @$(PRINTF) " done\n" 83endef 84 85define Clean-native 86 @$(PRINTF) "Cleaning native $(if $1,for $(strip $1) )..." 87 @$(PRINTF) "\n" $(LOG_DEBUG) 88 $(RM) -r $(SUPPORT_OUTPUTDIR)/native/$(strip $1) 89 $(RM) -r $(SUPPORT_OUTPUTDIR)/modules_libs/$(strip $1) 90 $(RM) -r $(SUPPORT_OUTPUTDIR)/modules_libs-stripped/$(strip $1) 91 $(RM) -r $(SUPPORT_OUTPUTDIR)/modules_cmds/$(strip $1) 92 $(RM) -r $(SUPPORT_OUTPUTDIR)/modules_cmds-stripped/$(strip $1) 93 @$(PRINTF) " done\n" 94endef 95 96define Clean-include 97 @$(PRINTF) "Cleaning include $(if $1,for $(strip $1) )..." 98 @$(PRINTF) "\n" $(LOG_DEBUG) 99 $(RM) -r $(SUPPORT_OUTPUTDIR)/modules_include/$(strip $1) 100 @$(PRINTF) " done\n" 101endef 102 103define Clean-docs 104 @$(PRINTF) "Cleaning docs ..." 105 @$(PRINTF) "\n" $(LOG_DEBUG) 106 $(RM) -r $(SUPPORT_OUTPUTDIR)/docs 107 $(RM) -r $(IMAGES_OUTPUTDIR)/docs 108 @$(PRINTF) " done\n" 109endef 110 111define CleanModule 112 $(call Clean-gensrc, $1) 113 $(call Clean-java, $1) 114 $(call Clean-native, $1) 115 $(call Clean-include, $1) 116endef 117 118 119################################################################################ 120 121MAKE_TOPDIR_LIST := $(JDK_TOPDIR) $(CORBA_TOPDIR) $(LANGTOOLS_TOPDIR) \ 122 $(HOTSPOT_TOPDIR) 123MAKE_MAKEDIR_LIST := make 124 125# Helper macro for DeclareRecipesForPhase 126# Declare a recipe for calling the module and phase specific makefile. 127# If there are multiple makefiles to call, create a rule for each topdir 128# that contains a makefile with the target $module-$suffix-$repodir, 129# (i.e: java.base-gensrc-jdk) 130# Normally there is only one makefile, and the target will just be 131# $module-$suffix 132# Param 1: Name of list to add targets to 133# Param 2: Module name 134# Param 3: Topdir 135define DeclareRecipeForModuleMakefile 136 ifeq ($$($1_MULTIPLE_MAKEFILES), true) 137 $2-$$($1_TARGET_SUFFIX): $2-$$($1_TARGET_SUFFIX)-$$(notdir $3) 138 $1 += $2-$$($1_TARGET_SUFFIX)-$$(notdir $3) 139 140 $2-$$($1_TARGET_SUFFIX)-$$(notdir $3): 141 else 142 $2-$$($1_TARGET_SUFFIX): 143 endif 144 $(ECHO) $(LOG_INFO) "Building $$@" 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 ifeq ($(NO_RECIPES),) 176 $$(foreach d, $$($1_$2_TOPDIRS), \ 177 $$(eval $$(call DeclareRecipeForModuleMakefile,$1,$2,$$d))) 178 endif 179 $1 += $2-$$($1_TARGET_SUFFIX) 180 $1_MODULES += $2 181 endif 182endef 183 184# Declare recipes for a specific module and build phase if there are makefiles 185# present for the specific combination. 186# Param 1: Name of list to add targets to 187# Named params: 188# TARGET_SUFFIX : Suffix of target to create for recipe 189# MAKE_SUBDIR : Subdir for this build phase 190# FILE_PREFIX : File prefix for this build phase 191# USE_WRAPPER : Set to true to use ModuleWrapper.gmk 192# CHECK_MODULES : List of modules to try 193# MULTIPLE_MAKEFILES : Set to true to handle makefiles for the same module and 194# phase in multiple repos 195# Exported variables: 196# $1_MODULES : All modules that had rules generated 197# $1_TARGETS : All targets generated 198define DeclareRecipesForPhase 199 $(foreach i,2 3 4 5 6 7, $(if $($i),$(strip $1)_$(strip $($i)))$(NEWLINE)) 200 $(if $(8),$(error Internal makefile error: Too many arguments to \ 201 DeclareRecipesForPhase, please update MakeHelper.gmk)) 202 203 $$(foreach m, $$($(strip $1)_CHECK_MODULES), \ 204 $$(eval $$(call DeclareRecipesForPhaseAndModule,$(strip $1),$$m))) 205 206 $(strip $1)_TARGETS := $$($(strip $1)) 207endef 208 209################################################################################ 210 211endif # _MAINSUPPORT_GMK 212