jdk/make/gensrc/GensrcCharsetMapping.gmk
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 22639 37f4508257fe
child 26717 d65c07a65486
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com

#
# Copyright (c) 2011, 2014, Oracle and/or its affiliates. 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.  Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#

GENSRC_CHARSETMAPPING :=

CHARSET_DATA_DIR := $(JDK_TOPDIR)/make/data/charsetmapping

###
### Generate files using the charsetmapping tool
###

CHARSET_GENSRC_JAVA_DIR_CS := $(JDK_OUTPUTDIR)/gensrc/jdk.charsets/sun/nio/cs/ext
CHARSET_GENSRC_JAVA_DIR_BASE := $(JDK_OUTPUTDIR)/gensrc/java.base/sun/nio/cs
CHARSET_DONE_CS := $(CHARSET_GENSRC_JAVA_DIR_CS)/_the.charsetmapping
CHARSET_DONE_BASE := $(CHARSET_GENSRC_JAVA_DIR_BASE)/_the.charsetmapping
CHARSET_COPYRIGHT_HEADER_BASE := $(JDK_TOPDIR)/make/src/classes/build/tools/charsetmapping
CHARSET_TEMPLATES := \
    $(CHARSET_DATA_DIR)/SingleByte-X.java.template \
    $(CHARSET_DATA_DIR)/DoubleByte-X.java.template

# This target should be referenced using the order-only operator (|)
$(CHARSET_GENSRC_JAVA_DIR_CS):
	$(ECHO)	"Generating charset mappings"
	$(MKDIR) -p $(CHARSET_GENSRC_JAVA_DIR_CS)
	$(MKDIR) -p $(CHARSET_GENSRC_JAVA_DIR_BASE)

$(CHARSET_DONE_BASE)-sbcs: $(CHARSET_DATA_DIR)/sbcs \
    $(CHARSET_TEMPLATES) $(BUILD_TOOLS_JDK) | $(CHARSET_GENSRC_JAVA_DIR_CS)
	$(TOOL_CHARSETMAPPING) $(CHARSET_DATA_DIR) $(CHARSET_GENSRC_JAVA_DIR_BASE) sbcs
	$(TOUCH) '$@'

$(CHARSET_DONE_CS)-extsbcs: $(CHARSET_DATA_DIR)/extsbcs  \
    $(CHARSET_DONE_BASE)-sbcs $(CHARSET_TEMPLATES) $(BUILD_TOOLS_JDK) 
	$(TOOL_CHARSETMAPPING) $(CHARSET_DATA_DIR) $(CHARSET_GENSRC_JAVA_DIR_CS) extsbcs
	$(TOUCH) '$@'

$(CHARSET_DONE_CS)-dbcs: $(CHARSET_DATA_DIR)/dbcs \
    $(CHARSET_DONE_BASE)-sbcs $(CHARSET_TEMPLATES) $(BUILD_TOOLS_JDK) 
	$(TOOL_CHARSETMAPPING) $(CHARSET_DATA_DIR) $(CHARSET_GENSRC_JAVA_DIR_CS) dbcs
	$(TOUCH) '$@'

$(CHARSET_DONE_CS)-hkscs: $(CHARSET_COPYRIGHT_HEADER_BASE)/HKSCS.java \
    $(CHARSET_DONE_BASE)-sbcs $(BUILD_TOOLS_JDK)
	$(TOOL_CHARSETMAPPING) $(CHARSET_DATA_DIR) $(CHARSET_GENSRC_JAVA_DIR_CS) hkscs '$<'
	$(TOUCH) '$@'

$(CHARSET_DONE_CS)-euctw: $(CHARSET_COPYRIGHT_HEADER_BASE)/EUC_TW.java \
    $(CHARSET_DONE_BASE)-sbcs $(BUILD_TOOLS_JDK)
	$(TOOL_CHARSETMAPPING) $(CHARSET_DATA_DIR) $(CHARSET_GENSRC_JAVA_DIR_CS) euctw '$<'
	$(TOUCH) '$@'

$(CHARSET_GENSRC_JAVA_DIR_CS)/sjis0213.dat: $(CHARSET_DATA_DIR)/sjis0213.map \
    $(CHARSET_DONE_BASE)-sbcs $(BUILD_TOOLS_JDK)
	$(TOOL_CHARSETMAPPING) '$<' '$@' sjis0213

GENSRC_JAVA_BASE += $(CHARSET_DONE_BASE)-sbcs
GENSRC_JDK_CHARSETS += \
    $(CHARSET_DONE_CS)-extsbcs \
    $(CHARSET_DONE_CS)-dbcs \
    $(CHARSET_DONE_CS)-hkscs \
    $(CHARSET_DONE_CS)-euctw \
    $(CHARSET_GENSRC_JAVA_DIR_CS)/sjis0213.dat \
    #

###
### Generate the sun/nio/cs/StandardCharsets.java file
###

CHARSET_STANDARD_GENSRC_DIR := $(JDK_OUTPUTDIR)/gensrc/standardcharsets
CHARSET_STANDARD_DATA := $(CHARSET_DATA_DIR)/standard-charsets
CHARSET_STANDARD_JAVA :=  sun/nio/cs/StandardCharsets.java

CHARSET_ALIASES_TABLES_AWK := ' \
    BEGIN { n = 1; m = 1; } \
    /^[ \t]*charset / { \
      csn = $$2; cln = $$3; \
      lcsn = tolower(csn); \
      lcsns[n++] = lcsn; \
      csns[lcsn] = csn; \
      classMap[lcsn] = cln; \
      if (n > 2) \
        printf "    };\n\n"; \
      printf "    static final String[] aliases_%s = new String[] {\n", cln; \
    } \
    /^[ \t]*alias / { \
      acsns[m++] = tolower($$2); \
      aliasMap[tolower($$2)] = lcsn; \
      printf "        \"%s\",\n", $$2; \
    } \
    END { \
      printf "    };\n\n"; \
    } '

CHARSET_ALIASES_MAP_AWK := ' \
    /^[ \t]*charset / { \
      csn = $$2; \
      lcsn = tolower(csn); \
    } \
    /^[ \t]*alias / { \
      an = tolower($$2); \
      printf "%-20s \"%s\"\n", an, lcsn; \
    } '

CHARSET_CLASSES_MAP_AWK := ' \
    /^[ \t]*charset / { \
      csn = $$2; cln = $$3; \
      lcsn = tolower(csn); \
      printf "%-20s \"%s\"\n", lcsn, cln; \
    } '

# This target should be referenced using the order-only operator (|)
$(CHARSET_STANDARD_GENSRC_DIR):
	$(MKDIR) -p '$@'

$(CHARSET_STANDARD_GENSRC_DIR)/aliases-tables.java.snippet: $(CHARSET_STANDARD_DATA) \
    | $(CHARSET_STANDARD_GENSRC_DIR)
	$(NAWK) < '$<' > '$@' $(CHARSET_ALIASES_TABLES_AWK)

$(CHARSET_STANDARD_GENSRC_DIR)/aliases-map: $(CHARSET_STANDARD_DATA) \
    | $(CHARSET_STANDARD_GENSRC_DIR)
	$(NAWK) < '$<' > '$@' $(CHARSET_ALIASES_MAP_AWK)

$(CHARSET_STANDARD_GENSRC_DIR)/classes-map: $(CHARSET_STANDARD_DATA) \
    | $(CHARSET_STANDARD_GENSRC_DIR)
	$(NAWK) < '$<' > '$@' $(CHARSET_CLASSES_MAP_AWK)

$(CHARSET_STANDARD_GENSRC_DIR)/aliases-map.java.snippet: $(CHARSET_STANDARD_GENSRC_DIR)/aliases-map \
    $(BUILD_TOOLS_JDK) | $(CHARSET_STANDARD_GENSRC_DIR)
	$(TOOL_HASHER) -i Aliases < '$<' > '$@'

$(CHARSET_STANDARD_GENSRC_DIR)/classes-map.java.snippet: $(CHARSET_STANDARD_GENSRC_DIR)/classes-map \
    $(BUILD_TOOLS_JDK) | $(CHARSET_STANDARD_GENSRC_DIR)
	$(TOOL_HASHER) -i Classes < '$<' > '$@'

$(CHARSET_STANDARD_GENSRC_DIR)/cache-map.java.snippet: $(CHARSET_STANDARD_GENSRC_DIR)/classes-map \
    $(BUILD_TOOLS_JDK) | $(CHARSET_STANDARD_GENSRC_DIR)
	$(TOOL_HASHER) -i -e Cache -t Charset < '$<' > '$@'

$(eval $(call SetupTextFileProcessing, BUILD_CHARSET_STANDARD, \
    SOURCE_FILES := $(JDK_TOPDIR)/src/java.base/share/classes/$(CHARSET_STANDARD_JAVA).template, \
    OUTPUT_FILE := $(JDK_OUTPUTDIR)/gensrc/java.base/$(CHARSET_STANDARD_JAVA), \
    INCLUDES := \
        _INCLUDE_ALIASES_TABLES_ => $(CHARSET_STANDARD_GENSRC_DIR)/aliases-tables.java.snippet ; \
        _INCLUDE_ALIASES_MAP_ => $(CHARSET_STANDARD_GENSRC_DIR)/aliases-map.java.snippet ; \
        _INCLUDE_CLASSES_MAP_ => $(CHARSET_STANDARD_GENSRC_DIR)/classes-map.java.snippet ; \
        _INCLUDE_CACHE_MAP_ => $(CHARSET_STANDARD_GENSRC_DIR)/cache-map.java.snippet ; , \
))

# Processing of template depends on the snippets being generated first
$(BUILD_CHARSET_STANDARD): \
    $(CHARSET_STANDARD_GENSRC_DIR)/aliases-tables.java.snippet \
    $(CHARSET_STANDARD_GENSRC_DIR)/aliases-map.java.snippet \
    $(CHARSET_STANDARD_GENSRC_DIR)/classes-map.java.snippet \
    $(CHARSET_STANDARD_GENSRC_DIR)/cache-map.java.snippet

GENSRC_JAVA_BASE += $(BUILD_CHARSET_STANDARD)