view j2se/make/common/Resources.gmk @ 2:16f2b6c91171 trunk

[svn] Load openjdk/jdk7/b14 into jdk/trunk.
author xiomara
date Fri, 22 Jun 2007 00:46:43 +0000
parents a4ed3fb96592
children 5937f8212f93
line wrap: on
line source

#
# Copyright 1997-2005 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: j2re, plugin, or j2sdk.
#
# 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
#   NEW_RESOURCE_BUNDLES_PROPERTIES  - new resource bundles implemented as
#                                      properties files, not localized
#   RESOURCE_BUNDLES_JAVA            - resource bundles implemented in
#                                      Java, localized
#   RESOURCE_BUNDLES_PROPERTIES      - new resource bundles implemented as
#                                      properties files, 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
#
# 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), j2sdk)
  LOCALE_SUFFIXES += $(J2SDK_LOCALES)
endif
ifeq ($(LOCALE_SET_DEFINITION), j2re)
  LOCALE_SUFFIXES += $(J2RE_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
PROPERTIES_FILES += $(NEW_RESOURCE_BUNDLES_PROPERTIES)
PROPERTIES_FILES += $(RESOURCE_BUNDLES_PROPERTIES) \
    $(foreach file,$(RESOURCE_BUNDLES_PROPERTIES), \
       $(foreach locale,$(LOCALE_SUFFIXES), \
	  $(basename $(file))_$(locale)$(suffix $(file))))
PROPERTIES_FILES += $(OTHER_PROPERTIES)

#
# Compile Properties tool
#
COMPILE_PROP_NAME    = CompileProperties
COMPILE_PROP_SRCDIR  = $(J2SE_TOPDIR)/make/tools/$(COMPILE_PROP_NAME)
COMPILE_PROP_TEMPDIR = $(OUTPUTDIR)/$(COMPILE_PROP_NAME)
COMPILE_PROP_JAVA    = $(COMPILE_PROP_SRCDIR)/$(COMPILE_PROP_NAME).java
COMPILE_PROP_CLASS   = $(COMPILE_PROP_TEMPDIR)/$(COMPILE_PROP_NAME).class
COMPILE_PROPERTIES   = \
    $(BOOTDIR)/bin/java -classpath $(COMPILE_PROP_TEMPDIR) $(COMPILE_PROP_NAME)
$(COMPILE_PROP_CLASS): $(COMPILE_PROP_JAVA)
	@$(prep-target)
	$(BOOTDIR)/bin/javac -d $(@D) $<
	@$(java-vm-cleanup)

#
# Strip Properties tool
#
STRIP_PROP_NAME    = StripProperties
STRIP_PROP_SRCDIR  = $(J2SE_TOPDIR)/make/tools/$(STRIP_PROP_NAME)
STRIP_PROP_TEMPDIR = $(OUTPUTDIR)/$(STRIP_PROP_NAME)
STRIP_PROP_JAVA    = $(STRIP_PROP_SRCDIR)/$(STRIP_PROP_NAME).java
STRIP_PROP_CLASS   = $(STRIP_PROP_TEMPDIR)/$(STRIP_PROP_NAME).class
STRIP_PROPERTIES   = \
    $(BOOTDIR)/bin/java -classpath $(STRIP_PROP_TEMPDIR) $(STRIP_PROP_NAME)
$(STRIP_PROP_CLASS): $(STRIP_PROP_JAVA)
	@$(prep-target)
	$(BOOTDIR)/bin/javac -d $(@D) $<
	@$(java-vm-cleanup)

#
# 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)
$(CHMOD) a+rw $@
@$(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: $(STRIP_PROP_CLASS) $(STRIP_PROP_options)
	@if [ -s $(STRIP_PROP_options) ] ; then \
          $(ECHO) "$(STRIP_PROPERTIES) -optionsfile $(STRIP_PROP_options)" ; \
          $(STRIP_PROPERTIES) -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: $(COMPILE_PROP_CLASS) $(COMPILE_PROP_options)
	$(MKDIR) -p $(GENSRCDIR)
	@if [ `$(CAT) $(COMPILE_PROP_options) | $(WC) -l` -ge 1 ] ; then \
	  $(ECHO) "$(COMPILE_PROPERTIES) -optionsfile $(COMPILE_PROP_options)";\
	  $(COMPILE_PROPERTIES) -optionsfile $(COMPILE_PROP_options) ; \
	  $(java-vm-cleanup); \
	fi

# Make sure the build rule creates all the properties
resources: strip_prop_options_clean   strip_all_props \
           compile_prop_options_clean compile_all_props

# Cleanup generated sources
clobber clean:: 
	$(RM) $(COMPILE_PROP_JAVA_FILES)
	$(RM) $(COMPILE_PROP_options)
	$(RM) $(COMPILE_PROP_CLASS)
	$(RM) $(STRIP_PROP_FILES)
	$(RM) $(STRIP_PROP_options)
	$(RM) $(STRIP_PROP_CLASS)

.PHONY: compile_prop_options_clean compile_all_props \
	strip_prop_options_clean   strip_all_props