1 #
   2 # Copyright (c) 2011, 2017, 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 # Scan for all locale resources and extract for which locales there exists
  27 # resources. Then put this meta information about existing (supported?) locales
  28 # into LocaleDataMetaInfo.java
  29 
  30 # First go look for all locale files
  31 LOCALE_FILES := $(shell $(FIND) \
  32     $(TOPDIR)/src/$(MODULE)/share/classes/sun/text/resources \
  33     $(TOPDIR)/src/$(MODULE)/share/classes/sun/util/resources \
  34     -name "FormatData_*.java" -o -name "FormatData_*.properties" -o \
  35     -name "CollationData_*.java" -o -name "CollationData_*.properties" -o \
  36     -name "TimeZoneNames_*.java" -o -name "TimeZoneNames_*.properties" -o \
  37     -name "LocaleNames_*.java" -o -name "LocaleNames_*.properties" -o \
  38     -name "CurrencyNames_*.java" -o -name "CurrencyNames_*.properties" -o \
  39     -name "CalendarData_*.java" -o -name "CalendarData_*.properties" -o \
  40     -name "BreakIteratorInfo_*.java" -o -name "BreakIteratorRules_*.java")
  41 
  42 # Then translate the locale files into for example: FormatData_sv
  43 LOCALE_RESOURCES := $(sort $(subst .properties,,$(subst .java,,$(notdir $(LOCALE_FILES)))))
  44 
  45 # Include the list of resources found during the previous compile.
  46 -include $(SUPPORT_OUTPUTDIR)/gensrc/$(MODULE)/_the.locale_resources
  47 
  48 MISSING_RESOURCES := $(filter-out $(LOCALE_RESOURCES), $(PREV_LOCALE_RESOURCES))
  49 NEW_RESOURCES := $(filter-out $(PREV_LOCALE_RESOURCES), $(LOCALE_RESOURCES))
  50 
  51 ifneq (, $(MISSING_RESOURCES)$(NEW_RESOURCES))
  52   # There is a difference in the number of supported resources. Trigger a regeneration.
  53   ifeq ($(MODULE), java.base)
  54     $(shell $(RM) $(SUPPORT_OUTPUTDIR)/gensrc/java.base/sun/util/locale/provider/BaseLocaleDataMetaInfo.java \
  55         $(SUPPORT_OUTPUTDIR)/gensrc/java.base/sun/util/cldr/CLDRBaseLocaleDataMetaInfo.java)
  56   endif
  57   ifeq ($(MODULE), jdk.localedata)
  58     $(shell $(RM) $(SUPPORT_OUTPUTDIR)/gensrc/jdk.localedata/sun/util/resources/provider/NonBaseLocaleDataMetaInfo.java \
  59         $(SUPPORT_OUTPUTDIR)/gensrc/jdk.localedata/sun/util/resources/cldr/provider/CLDRLocaleDataMetaInfo_jdk_localedata.java)
  60   endif
  61 endif
  62 
  63 # The base locales
  64 BASE_LOCALES := en en-US
  65 
  66 # Locales that don't have any resource files should be included here.
  67 ALL_NON_BASE_LOCALES := ja-JP-JP th-TH-TH
  68 
  69 SED_BASEARGS := -e 's|$(HASH)warn This file is preprocessed before being compiled|// -- This file was mechanically generated: Do not edit! -- //|g'
  70 SED_NONBASEARGS := $(SED_BASEARGS)
  71 
  72 # Fill in the languages and package names
  73 SED_BASEARGS += -e 's/$(HASH)Lang$(HASH)/Base/' \
  74     -e 's/$(HASH)Package$(HASH)/sun.util.locale.provider/'
  75 SED_NONBASEARGS += -e 's/$(HASH)Lang$(HASH)/NonBase/' \
  76     -e 's/$(HASH)Package$(HASH)/sun.util.resources.provider/'
  77 
  78 # This macro creates a sed expression that substitues for example:
  79 # #FormatData_Locales# with: en-US locales.
  80 define CaptureLocale
  81   $1_LOCALES := $$(subst _,-,$$(filter-out $1, $$(subst $1_,,$$(filter $1_%, $(LOCALE_RESOURCES)))))
  82   $1_BASE_LOCALES := $$(filter $(BASE_LOCALES), $$($1_LOCALES))
  83   $1_NON_BASE_LOCALES := $$(filter-out $(BASE_LOCALES), $$($1_LOCALES))
  84 
  85   # Special handling for Chinese locales to include implicit scripts
  86   $1_NON_BASE_LOCALES := $$(subst zh-CN,zh-CN$$(SPACE)zh-Hans-CN, $$($1_NON_BASE_LOCALES))
  87   $1_NON_BASE_LOCALES := $$(subst zh-SG,zh-SG$$(SPACE)zh-Hans-SG, $$($1_NON_BASE_LOCALES))
  88   $1_NON_BASE_LOCALES := $$(subst zh-HK,zh-HK$$(SPACE)zh-Hant-HK, $$($1_NON_BASE_LOCALES))
  89   $1_NON_BASE_LOCALES := $$(subst zh-MO,zh-MO$$(SPACE)zh-Hant-MO, $$($1_NON_BASE_LOCALES))
  90   $1_NON_BASE_LOCALES := $$(subst zh-TW,zh-TW$$(SPACE)zh-Hant-TW, $$($1_NON_BASE_LOCALES))
  91 
  92 # Adding implict locales nb nn-NO and nb-NO
  93   $1_NON_BASE_LOCALES += nb  nn-NO  nb-NO
  94   $1_NON_BASE_LOCALES := $$(sort $$($1_NON_BASE_LOCALES))
  95 
  96   ALL_BASE_LOCALES += $$($1_BASE_LOCALES)
  97   ALL_NON_BASE_LOCALES += $$($1_NON_BASE_LOCALES)
  98 
  99   # Don't sed in a space if there are no locales.
 100   SED_BASEARGS += -e 's/$$(HASH)$1_Locales$$(HASH)/$$(if $$($1_BASE_LOCALES),$$(SPACE)$$($1_BASE_LOCALES),)/g'
 101   SED_NONBASEARGS += -e 's/$$(HASH)$1_Locales$$(HASH)/$$(if $$($1_NON_BASE_LOCALES),$$(SPACE)$$($1_NON_BASE_LOCALES),)/g'
 102 endef
 103 
 104 #sun.text.resources.FormatData
 105 $(eval $(call CaptureLocale,FormatData))
 106 
 107 #sun.text.resources.CollationData
 108 $(eval $(call CaptureLocale,CollationData))
 109 
 110 #sun.text.resources.BreakIteratorInfo
 111 $(eval $(call CaptureLocale,BreakIteratorInfo))
 112 
 113 #sun.text.resources.BreakIteratorRules
 114 $(eval $(call CaptureLocale,BreakIteratorRules))
 115 
 116 #sun.util.resources.TimeZoneNames
 117 $(eval $(call CaptureLocale,TimeZoneNames))
 118 
 119 #sun.util.resources.LocaleNames
 120 $(eval $(call CaptureLocale,LocaleNames))
 121 
 122 #sun.util.resources.CurrencyNames
 123 $(eval $(call CaptureLocale,CurrencyNames))
 124 
 125 #sun.util.resources.CalendarData
 126 $(eval $(call CaptureLocale,CalendarData))
 127 
 128 SED_BASEARGS += -e 's/$(HASH)AvailableLocales_Locales$(HASH)/$(sort $(ALL_BASE_LOCALES))/g'
 129 SED_NONBASEARGS += -e 's/$(HASH)AvailableLocales_Locales$(HASH)/$(sort $(ALL_NON_BASE_LOCALES))/g'
 130 
 131 $(SUPPORT_OUTPUTDIR)/gensrc/java.base/sun/util/locale/provider/BaseLocaleDataMetaInfo.java: \
 132     $(TOPDIR)/src/java.base/share/classes/sun/util/locale/provider/LocaleDataMetaInfo-XLocales.java.template
 133         $(call LogInfo, Creating sun/util/locale/provider/BaseLocaleDataMetaInfo.java from $(words $(LOCALE_RESOURCES)) found resources)
 134         $(call MakeTargetDir)
 135         $(PRINTF) "PREV_LOCALE_RESOURCES:=$(LOCALE_RESOURCES)" \
 136             > $(SUPPORT_OUTPUTDIR)/gensrc/java.base/_the.locale_resources
 137         $(SED) $(SED_BASEARGS) $< > $@
 138 
 139 $(SUPPORT_OUTPUTDIR)/gensrc/jdk.localedata/sun/util/resources/provider/NonBaseLocaleDataMetaInfo.java: \
 140     $(TOPDIR)/src/java.base/share/classes/sun/util/locale/provider/LocaleDataMetaInfo-XLocales.java.template
 141         $(call LogInfo, Creating sun/util/resources/provider/NonBaseLocaleDataMetaInfo.java from $(words $(LOCALE_RESOURCES)) found resources)
 142         $(call MakeTargetDir)
 143         $(PRINTF) "PREV_LOCALE_RESOURCES:=$(LOCALE_RESOURCES)" \
 144             > $(SUPPORT_OUTPUTDIR)/gensrc/jdk.localedata/_the.locale_resources
 145         $(SED) $(SED_NONBASEARGS) $< > $@
 146 
 147 GENSRC_BASELOCALEDATA := $(SUPPORT_OUTPUTDIR)/gensrc/java.base/sun/util/locale/provider/BaseLocaleDataMetaInfo.java
 148 GENSRC_LOCALEDATA := $(SUPPORT_OUTPUTDIR)/gensrc/jdk.localedata/sun/util/resources/provider/NonBaseLocaleDataMetaInfo.java
 149 
 150 GENSRC_JAVA_BASE += $(GENSRC_BASELOCALEDATA)
 151 GENSRC_JDK_LOCALEDATA += $(GENSRC_LOCALEDATA)
 152 
 153 ################################################################################