Resources.gmk 10.0 KB
Newer Older
D
duke 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#
# Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.  Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#

# 
# Generic mechanism for installing properties files, resource bundles,
#   and other resource files.
#
# FILES_properties should be defined.
# FILES_compiled_properties should be defined.
# 
# If COMPILED_PROPERTIES_SUPERCLASS is defined, ALL the FILES_properties
# files will be compiled into java with this super class.
#
# You can add locales to LOCALE_SUFFIXES explicitly, or use the
# LOCALE_SET_DEFINITION variable to add some pre-defined locale lists.
# The LOCALE_SET_DEFINITION can have the value: jre, plugin, or jdk.
#
# Resource bundles to be installed are identified using the following variables.
# Note that only the file name of the base bundle is given; localized versions
# are added automatically. For Java files, use a format suitable for inclusion
# in the FILES_java list; dito for properties, all relative paths.
#
#   NEW_RESOURCE_BUNDLES_JAVA        - new resource bundles implemented in
#                                      Java, not localized
#   RESOURCE_BUNDLES_JAVA            - resource bundles implemented in
#                                      Java, localized
#
# The following variable is now used for most .properties files in the JDK. 
# These properties files are converted into java and compiled with javac.
# The resulting .class files are usually smaller and are always faster to load. 
# The relative path to the properties file becomes a relative path to a
# java source file.
#
#   RESOURCE_BUNDLES_COMPILED_PROPERTIES - resource bundles implemented as
#                                          properties files, localized
#   NEW_RESOURCE_BUNDLES_COMPILED_PROPERTIES - same as above, not localized
#
60 61 62 63 64 65 66
# For non-compiled properties files, use the following variables:
#
#   NEW_RESOURCE_BUNDLES_UNCOMPILED_PROPERTIES  - new resource bundles implemented as
#                                      properties files, not localized
#   RESOURCE_BUNDLES_UNCOMPILED_PROPERTIES      - resource bundles implemented as
#                                      properties files, localized
#
D
duke 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
# Other properties files to be installed are identified using the variable:
#
#   OTHER_PROPERTIES
#

# Compile properties files into java source?
ifdef COMPILED_PROPERTIES_SUPERCLASS
  # Add all properties files to the compiled properties list (all or nothing)
  COMPILED_PROPERTIES += $(FILES_compiled_properties) $(FILES_properties)
else
  COMPILED_PROPERTIES_SUPERCLASS = ListResourceBundle
  COMPILED_PROPERTIES += $(FILES_compiled_properties)
endif

# Determine the locale suffixes needed beyond the base bundle

ifeq ($(LOCALE_SET_DEFINITION), plugin)
  LOCALE_SUFFIXES += $(PLUGIN_LOCALES)
endif
ifeq ($(LOCALE_SET_DEFINITION), jdk)
  LOCALE_SUFFIXES += $(JDK_LOCALES)
endif
ifeq ($(LOCALE_SET_DEFINITION), jre)
  LOCALE_SUFFIXES += $(JRE_LOCALES)
endif

# Java files get tacked onto the standard list of files to compile
RESOURCE_BUNDLE_FILES_java += $(NEW_RESOURCE_BUNDLES_JAVA)
RESOURCE_BUNDLE_FILES_java += $(RESOURCE_BUNDLES_JAVA) \
    $(foreach file,$(RESOURCE_BUNDLES_JAVA), \
       $(foreach locale,$(LOCALE_SUFFIXES), \
	  $(basename $(file))_$(locale).java))

# Add to java sources list
FILES_java += $(RESOURCE_BUNDLE_FILES_java)

# Compiled properties files are translated to .java.
#   The .java files are generated into GENSRCDIR.
COMPILED_PROPERTIES += $(NEW_RESOURCE_BUNDLES_COMPILED_PROPERTIES)
COMPILED_PROPERTIES += $(RESOURCE_BUNDLES_COMPILED_PROPERTIES) \
    $(foreach file,$(RESOURCE_BUNDLES_COMPILED_PROPERTIES),\
      $(foreach locale,$(LOCALE_SUFFIXES),\
	 $(basename $(file))_$(locale)$(suffix $(file))))

# Add to java sources list
FILES_java += $(COMPILED_PROPERTIES:%.properties=%.java)

# Non-compiled files
115 116 117
PROPERTIES_FILES += $(NEW_RESOURCE_BUNDLES_UNCOMPILED_PROPERTIES)
PROPERTIES_FILES += $(RESOURCE_BUNDLES_UNCOMPILED_PROPERTIES) \
    $(foreach file,$(RESOURCE_BUNDLES_UNCOMPILED_PROPERTIES), \
D
duke 已提交
118 119
       $(foreach locale,$(LOCALE_SUFFIXES), \
	  $(basename $(file))_$(locale)$(suffix $(file))))
120
# other properties
D
duke 已提交
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
PROPERTIES_FILES += $(OTHER_PROPERTIES)

#
# Compile Properties tool
#
COMPILEPROPERTIES_JARFILE = $(BUILDTOOLJARDIR)/compileproperties.jar

#
# Strip Properties tool
#
STRIPPROPERTIES_JARFILE = $(BUILDTOOLJARDIR)/stripproperties.jar

#
# Process and strip all non-compiled properties files (in a batch mode)
#
STRIP_PROP_FILES = $(PROPERTIES_FILES:%=$(CLASSDESTDIR)/%)
# To efficiently strip properties we use one run of StripProperties. 
# This macro gathers an option for use later.
STRIP_PROP_options=$(TEMPDIR)/strip_prop_options
define install-properties-file
$(install-file)
142
$(call chmod-file, a+rw)
D
duke 已提交
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
@$(ECHO) "# Adding to strip properties list: $@"
$(ECHO) "$@" >> $(STRIP_PROP_options)
endef

# Constructs command line options file
$(STRIP_PROP_options): $(STRIP_PROP_FILES)
	@$(TOUCH) $@
strip_prop_options_clean:
	@$(RM) $(STRIP_PROP_options)

# Strip the properties files
strip_all_props: $(STRIPPROPERTIES_JARFILE) $(STRIP_PROP_options)
	@if [ -s $(STRIP_PROP_options) ] ; then \
          $(ECHO) "$(BOOT_JAVA_CMD) -jar $(STRIPPROPERTIES_JARFILE) -optionsfile $(STRIP_PROP_options)" ; \
          $(BOOT_JAVA_CMD) -jar $(STRIPPROPERTIES_JARFILE) -optionsfile $(STRIP_PROP_options) ; \
        fi
	@$(java-vm-cleanup)

#
# Creates files in CLASSDESTDIR
#

# In some cases, we move files from package to resources subdir
$(CLASSDESTDIR)/$(PKGDIR)/resources/%.properties: \
	     $(SHARE_SRC)/classes/$(PKGDIR)/%.properties
	$(install-properties-file)
$(CLASSDESTDIR)/%.properties: $(SHARE_SRC)/classes/%.properties
	$(install-properties-file)
$(CLASSDESTDIR)/%.res: $(SHARE_SRC)/classes/%.res
	$(install-file)
$(CLASSDESTDIR)/%.dtd: $(SHARE_SRC)/classes/%.dtd
	$(install-file)
$(CLASSDESTDIR)/%.xml: $(SHARE_SRC)/classes/%.xml
	$(install-file)
$(CLASSDESTDIR)/%.prp: $(SHARE_SRC)/classes/%.prp
	$(install-file)

#
# To efficiently compile properties into java sources we use one run
#   of compileproperties. This macro gathers an option for use later.
#   Note: The properties file and java source name can be different
#         locales, e.g. zh_TW and zh_HK. The java source filename
#         determines the name of the class.
COMPILE_PROP_options=$(TEMPDIR)/compile_prop_options
define add-property-java-file
@$(prep-target)
@$(ECHO) "# Adding to compile properties list: $? -> $@"
$(ECHO) "-compile $? $@ $(COMPILED_PROPERTIES_SUPERCLASS)" \
   >> $(COMPILE_PROP_options)
endef

$(GENSRCDIR)/%.java: $(PLATFORM_SRC)/classes/%.properties
	$(add-property-java-file)
$(GENSRCDIR)/%.java: $(SHARE_SRC)/classes/%.properties
	$(add-property-java-file)
$(GENSRCDIR)/%.java: $(GENSRCDIR)/%.properties
	$(add-property-java-file)
ifndef OPENJDK
$(GENSRCDIR)/%.java: $(CLOSED_PLATFORM_SRC)/classes/%.properties
	$(add-property-java-file)
$(GENSRCDIR)/%.java: $(CLOSED_SHARE_SRC)/classes/%.properties
	$(add-property-java-file)
endif

# Create HK java file from zh_TW (explicit resource bundles only)
define create-hk-java-file
@$(prep-target)
$(CAT) $< | $(SED) -e '/class/s/_zh_TW/_zh_HK/' > $@
endef

# Explicit resource bundles
$(GENSRCDIR)/%_zh_HK.java: $(PLATFORM_SRC)/classes/%_zh_TW.java
	$(create-hk-java-file)
$(GENSRCDIR)/%_zh_HK.java: $(SHARE_SRC)/classes/%_zh_TW.java
	$(create-hk-java-file)

# Compile of zh_HK properties just uses the zh_TW properties files
$(GENSRCDIR)/%_zh_HK.java: $(PLATFORM_SRC)/classes/%_zh_TW.properties
	$(add-property-java-file)
$(GENSRCDIR)/%_zh_HK.java: $(SHARE_SRC)/classes/%_zh_TW.properties
	$(add-property-java-file)

# Simple delivery of zh_HK properties files just copies zh_TW properties files
$(CLASSDESTDIR)/%_zh_HK.properties: \
             $(PLATFORM_SRC)/classes/%_zh_TW.properties
	$(install-properties-file)
$(CLASSDESTDIR)/%_zh_HK.properties: \
             $(SHARE_SRC)/classes/%_zh_TW.properties
	$(install-properties-file)

# List of java files converted from properties files needed
COMPILE_PROP_JAVA_FILES = $(COMPILED_PROPERTIES:%.properties=$(GENSRCDIR)/%.java)

# Constructs command line options file
$(COMPILE_PROP_options): $(COMPILE_PROP_JAVA_FILES)
	@$(TOUCH) $@
compile_prop_options_clean:
	@$(RM) $(COMPILE_PROP_options)

# Make sure all are compiled, one compiler run
compile_all_props: $(COMPILEPROPERTIES_JARFILE) $(COMPILE_PROP_options)
	@if [ `$(CAT) $(COMPILE_PROP_options) | $(WC) -l` -ge 1 ] ; then \
	  $(MKDIR) -p $(GENSRCDIR); \
	  $(ECHO) "$(BOOT_JAVA_CMD) -jar $(COMPILEPROPERTIES_JARFILE) -optionsfile $(COMPILE_PROP_options)";\
	  $(BOOT_JAVA_CMD) -jar $(COMPILEPROPERTIES_JARFILE) -optionsfile $(COMPILE_PROP_options) ; \
	  $(java-vm-cleanup); \
	fi

# Make sure the build rule creates all the properties
resources:

ifneq ($(PROPERTIES_FILES),)
  resources: strip_prop_options_clean   strip_all_props
  clobber clean:: 
	$(RM) $(STRIP_PROP_FILES) $(STRIP_PROP_options)
endif

ifneq ($(COMPILED_PROPERTIES),)
  resources: compile_prop_options_clean compile_all_props
  clobber clean:: 
	$(RM) $(COMPILE_PROP_JAVA_FILES) $(COMPILE_PROP_options)
endif

.PHONY: resources \
	compile_prop_options_clean compile_all_props \
	strip_prop_options_clean   strip_all_props