1 #
   2 # Copyright (c) 2011, 2019, 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 # This file defines macros that sets up rules for generating java classes
  27 # from resource bundle properties files.
  28 
  29 ################################################################################
  30 # Helper macro for SetupCopy-zh_HK.
  31 define SetupOneCopy-zh_HK
  32   $1_$2_TARGET := $$(patsubst $(TOPDIR)/src/$(MODULE)/share/classes/%, \
  33       $(SUPPORT_OUTPUTDIR)/gensrc/$(MODULE)/%, \
  34       $$(subst _zh_TW,_zh_HK, $2))
  35 
  36   $$($1_$2_TARGET): $2
  37         $$(call MakeTargetDir)
  38         $(CAT) $$< | $(SED) -e '/class/s/_zh_TW/_zh_HK/' > $$@
  39 
  40   $1 += $$($1_$2_TARGET)
  41 endef
  42 
  43 ################################################################################
  44 # Creates rules for copying zh_TW resources to zh_HK.
  45 # Param 1 - Variable to add targets to
  46 # Param 2 - Files to copy from
  47 define SetupCopy-zh_HK
  48   $$(foreach f, $2, $$(eval $$(call SetupOneCopy-zh_HK,$1,$$f)))
  49 endef
  50 
  51 ################################################################################
  52 # Setup make rules that runs CompileProperties on a set of properties files.
  53 #
  54 # Parameter 1 is the name of the rule. This name is used as variable prefix,
  55 # and the targets generated are listed in a variable by that name.
  56 #
  57 # Remaining parameters are named arguments. These include:
  58 # SRC_DIRS   Directories containing properties files to process.
  59 # EXCLUDE   Exclude files matching this pattern.
  60 # CLASS   The super class for the generated classes.
  61 # MODULE_PATH_ROOT   Module path root, defaults to $(TOPDIR)/src.
  62 # KEEP_ALL_TRANSLATIONS Set to true to skip filtering of excluded translations.
  63 SetupCompileProperties = $(NamedParamsMacroTemplate)
  64 define SetupCompilePropertiesBody
  65   # Set default value unless overridden
  66   ifeq ($$($1_MODULE_PATH_ROOT), )
  67     $1_MODULE_PATH_ROOT := $(TOPDIR)/src
  68   endif
  69 
  70   # Locate all properties files in the given source dirs.
  71   $1_SRC_FILES := $$(call FindFiles, $$($1_SRC_DIRS), *.properties)
  72 
  73   ifneq ($$($1_EXCLUDE), )
  74     $1_SRC_FILES := $$(filter-out $$($1_EXCLUDE), $$($1_SRC_FILES))
  75   endif
  76 
  77   # Filter out any excluded translations
  78   ifneq ($$($1_KEEP_ALL_TRANSLATIONS), true)
  79     $1_SRC_FILES := $$(call FilterExcludedTranslations, $$($1_SRC_FILES), .properties)
  80   endif
  81 
  82   # Convert .../src/<module>/share/classes/com/sun/tools/javac/resources/javac_zh_CN.properties
  83   # to .../support/gensrc/<module>/com/sun/tools/javac/resources/javac_zh_CN.java
  84   $1_JAVAS := $$(patsubst $$($1_MODULE_PATH_ROOT)/%, \
  85       $(SUPPORT_OUTPUTDIR)/gensrc/%, \
  86       $$(patsubst %.properties, %.java, \
  87       $$(subst /$(OPENJDK_TARGET_OS)/classes,, \
  88       $$(subst /$(OPENJDK_TARGET_OS_TYPE)/classes,, \
  89       $$(subst /share/classes,, $$($1_SRC_FILES))))))
  90 
  91   # Generate the package dirs for the to be generated java files. Sort to remove
  92   # duplicates.
  93   $1_DIRS := $$(sort $$(dir $$($1_JAVAS)))
  94 
  95   # Now generate a sequence of:
  96   # "-compile ...javac_zh_CN.properties ...javac_zh_CN.java java.util.ListResourceBundle"
  97   # suitable to be fed into the CompileProperties command.
  98   $1_CMDLINE := $$(subst _SPACE_, $(SPACE), \
  99       $$(join $$(addprefix -compile_SPACE_, $$($1_SRC_FILES)), \
 100       $$(addsuffix _SPACE_$$($1_CLASS), \
 101       $$(addprefix _SPACE_, $$($1_JAVAS)))))
 102 
 103   $1_TARGET := $(SUPPORT_OUTPUTDIR)/gensrc/$(MODULE)/_the.$1.marker
 104   $1_CMDLINE_FILE := $(SUPPORT_OUTPUTDIR)/gensrc/$(MODULE)/_the.$1.cmdline
 105 
 106   # Now setup the rule for the generation of the resource bundles.
 107   $$($1_TARGET): $$($1_SRC_FILES) $$($1_JAVAS) $(BUILD_TOOLS_JDK)
 108         $$(call LogWarn, Compiling $$(words $$($1_SRC_FILES)) properties into resource bundles for $(MODULE))
 109         $$(call MakeDir, $$(@D) $$($1_DIRS))
 110         $$(eval $$(call ListPathsSafely, $1_CMDLINE, $$($1_CMDLINE_FILE)))
 111         $(TOOL_COMPILEPROPERTIES) -quiet @$$($1_CMDLINE_FILE)
 112         $(TOUCH) $$@
 113 
 114   $$($1_JAVAS): $$($1_SRC_FILES)
 115 
 116   # Create zh_HK versions of all zh_TW files created above
 117   $$(eval $$(call SetupCopy-zh_HK,$1_HK,$$(filter %_zh_TW.java, $$($1_JAVAS))))
 118   # The zh_HK copy must wait for the compile properties tool to run
 119   $$($1_HK): $$($1_TARGET)
 120 
 121   $1 += $$($1_JAVAS) $$($1_TARGET) $$($1_HK)
 122 endef
 123 
 124 ################################################################################