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 # 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 $(JDK_TOPDIR)/src/$(MODULE)/share/classes/%, \ 33 $(SUPPORT_OUTPUTDIR)/gensrc/$(MODULE)/%, \ 34 $$(subst _zh_TW,_zh_HK, $2)) 35 36 $$($1_$2_TARGET): $2 37 $(MKDIR) -p $$(@D) 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 $(JDK_TOPDIR)/src. 62 SetupCompileProperties = $(NamedParamsMacroTemplate) 63 define SetupCompilePropertiesBody 64 # Set default value unless overridden 65 ifeq ($$($1_MODULE_PATH_ROOT), ) 66 $1_MODULE_PATH_ROOT := $(JDK_TOPDIR)/src 67 endif 68 69 # Locate all properties files in the given source dirs. 70 $1_SRC_FILES := $$(filter %.properties, $$(call CacheFind, $$($1_SRC_DIRS))) 71 72 ifneq ($$($1_EXCLUDE), ) 73 $1_SRC_FILES := $$(filter-out $$($1_EXCLUDE), $$($1_SRC_FILES)) 74 endif 75 76 # Convert .../src/<module>/share/classes/com/sun/tools/javac/resources/javac_zh_CN.properties 77 # to .../support/gensrc/<module>/com/sun/tools/javac/resources/javac_zh_CN.java 78 # Strip away prefix and suffix, leaving for example only: 79 # "<module>/share/classes/com/sun/tools/javac/resources/javac_zh_CN" 80 $1_JAVAS := $$(patsubst $$($1_MODULE_PATH_ROOT)/%, \ 81 $(SUPPORT_OUTPUTDIR)/gensrc/%, \ 82 $$(patsubst %.properties, %.java, \ 83 $$(subst /$(OPENJDK_TARGET_OS)/classes,, \ 84 $$(subst /$(OPENJDK_TARGET_OS_TYPE)/classes,, \ 85 $$(subst /share/classes,, $$($1_SRC_FILES)))))) 86 87 # Generate the package dirs for the to be generated java files. Sort to remove 88 # duplicates. 89 $1_DIRS := $$(sort $$(dir $$($1_JAVAS))) 90 91 # Now generate a sequence of: 92 # "-compile ...javac_zh_CN.properties ...javac_zh_CN.java java.util.ListResourceBundle" 93 # suitable to be fed into the CompileProperties command. 94 $1_CMDLINE := $$(subst _SPACE_, $(SPACE), \ 95 $$(join $$(addprefix -compile_SPACE_, $$($1_SRC_FILES)), \ 96 $$(addsuffix _SPACE_$$($1_CLASS), \ 97 $$(addprefix _SPACE_, $$($1_JAVAS))))) 98 99 $1_TARGET := $(SUPPORT_OUTPUTDIR)/gensrc/$(MODULE)/_the.$1.marker 100 $1_CMDLINE_FILE := $(SUPPORT_OUTPUTDIR)/gensrc/$(MODULE)/_the.$1.cmdline 101 102 # Now setup the rule for the generation of the resource bundles. 103 $$($1_TARGET): $$($1_SRC_FILES) $$($1_JAVAS) $(BUILD_TOOLS_JDK) 104 $(MKDIR) -p $$(@D) $$($1_DIRS) 105 $(ECHO) Compiling $$(words $$($1_SRC_FILES)) properties into resource bundles for $(MODULE) 106 $$(eval $$(call ListPathsSafely, $1_CMDLINE, $$($1_CMDLINE_FILE))) 107 $(TOOL_COMPILEPROPERTIES) -quiet @$$($1_CMDLINE_FILE) 108 $(TOUCH) $$@ 109 110 $$($1_JAVAS): $$($1_SRC_FILES) 111 112 # Create zh_HK versions of all zh_TW files created above 113 $$(eval $$(call SetupCopy-zh_HK,$1_HK,$$(filter %_zh_TW.java, $$($1_JAVAS)))) 114 # The zh_HK copy must wait for the compile properties tool to run 115 $$($1_HK): $$($1_TARGET) 116 117 $1 += $$($1_JAVAS) $$($1_TARGET) $$($1_HK) 118 endef 119 120 ################################################################################