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