3 # SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 # Copyright 2015 John Marino <draco@marino.st>
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # This is a helper script for the Makefile in the parent directory.
31 # When the localization definitions are generated in the draft area,
32 # this script will copy base ones that others symlink to, and rearrange
33 # the generate makefile to pull the LOCALES first.
40 echo "finalize <type>' to package standard localization"
41 echo "type must be one of { monetdef, msgdef, numericdef, timedef, colldef, ctypedef }"
46 [ $1 = "monetdef" -o $1 = "msgdef" -o $1 = "colldef" -o \
47 $1 = "numericdef" -o $1 = "timedef" -o $1 = "ctypedef" ] || usage
50 base=$(dirname ${self})
51 old=${base}/../${1}.draft
53 TEMP=/tmp/${1}.locales
54 TEMP2=/tmp/${1}.hashes
55 TEMP3=/tmp/${1}.symlinks
56 TEMP4=/tmp/${1}.mapped
58 FULLEXTRACT=/tmp/extracted-names
59 AWKCMD="/## PLACEHOLDER/ { \
60 while ( getline line < \"${TEMP}\" ) {print line} } \
62 while ( getline line < \"${TEMP3}\" ) {print line} } \
63 /## LOCALES_MAPPED/ { \
64 while ( getline line < \"${TEMP4}\" ) {print line} } \
67 # Rename the sources with 3 components name into the POSIX version of the name using @modifier
70 for i in *_*_*.*.src; do
71 if [ "$i" = "*_*_*.*.src" ]; then
75 nname=`echo $oldname | awk '{ split($0, a, "_"); print a[1]"_"a[3]"@"a[2];} '`
76 mv -f ${oldname}.src ${nname}.src
77 sed -i '' -e "s/${oldname}/${nname}/g" Makefile
78 COLLATIONS_SPECIAL=$(echo ${COLLATIONS_SPECIAL} | sed -e "s/${oldname}/${nname}/g")
81 # For variable without @modifier ambiguity do not keep the @modifier
83 if [ "$i" = "*@*.src" ]; then
87 shortname=${oldname%@*}
88 if [ $(ls ${shortname}@* | wc -l) -eq 1 ] ; then
89 mv -f $i ${shortname}.src
90 sed -i '' -e "s/${oldname}/${shortname}/g" Makefile
91 COLLATIONS_SPECIAL=$(echo ${COLLATIONS_SPECIAL} | sed -e "s/${oldname}/${shortname}/g")
95 # Rename the modifiers into non abbreviated version
96 for i in *@Latn.src; do
97 if [ "$i" = "*@Latn.src" ]; then
100 mv -f ${i} ${i%@*}@latin.src
101 sed -i '' -e "s/${i%.*}/${i%@*}@latin/g" Makefile
102 COLLATIONS_SPECIAL=$(echo ${COLLATIONS_SPECIAL} | sed -e "s/${i%.*}/${i%@*}@latin/g")
105 for i in *@Cyrl.src; do
106 if [ "$i" = "*@Cyrl.src" ]; then
109 mv -f ${i} ${i%@*}@cyrillic.src
110 sed -i '' -e "s/${i%.*}/${i%@*}@cyrillic/g" Makefile
111 COLLATIONS_SPECIAL=$(echo ${COLLATIONS_SPECIAL} | sed -e "s/${i%.*}/${i%@*}@cyrillic/g")
114 # On locales with multiple modifiers rename the "default" version without the @modifier
115 default_locales="sr_RS@cyrillic"
116 for i in ${default_locales}; do
119 for l in ${localename}.*@${mod}.src; do
120 if [ "$l" = "${localename}.*@${mod}.src" ]; then
123 mv -f ${l} ${l%@*}.src
124 sed -i '' -e "s/${l%.*}/${l%@*}/g" Makefile
129 grep '^LOCALES+' ${old}/Makefile > ${TEMP}
131 if [ $1 = "ctypedef" ]
133 keep=$(cat ${TEMP} | awk '{ print $2 ".src" }')
134 (cd ${old} && md5 -r ${keep} | sort) > ${TEMP2}
135 keep=$(awk '{ if ($1 != last1) print $2; last1 = $1; }' ${TEMP2})
136 for original in ${keep}
138 cp ${old}/${original} ${new}/
140 awk '{ if ($1 == last1) { print "SYMPAIRS+=\t" last2 " " $2 } \
141 else {last1 = $1; last2 = $2}}' ${TEMP2} > ${TEMP3}
143 /usr/bin/sed -E -e 's/[ ]+/ /g' \
144 ${UNIDIR}/posix/UTF-8.cm \
145 > ${base}/../etc/final-maps/map.UTF-8
146 /usr/bin/sed -E -e 's/[ ]+/ /g' \
147 ${UNIDIR}/posix/eucCN.cm \
148 > ${base}/../etc/final-maps/map.eucCN
149 /usr/bin/sed -E -e 's/[ ]+/ /g' \
150 ${UNIDIR}/posix/eucCN.cm \
151 > ${base}/../etc/final-maps/map.GB2312
152 CHARMAPS="ARMSCII-8 Big5 CP1131 CP1251 \
153 CP866 GBK ISCII-DEV ISO8859-1 \
154 ISO8859-13 ISO8859-15 ISO8859-2 ISO8859-4 \
155 ISO8859-5 ISO8859-7 ISO8859-9 KOI8-R KOI8-U \
156 PT154 SJIS US-ASCII eucJP eucKR"
158 # GB18030 blows up, use pre-generate Illumos version
160 for map in ${CHARMAPS}
163 /usr/local/bin/perl ${base}/convert_map.pl \
164 ${base}/../etc/charmaps/${map}.TXT ${encoding} \
165 | /usr/bin/sed -E -e 's/ +/ /g' \
166 > ${base}/../etc/final-maps/map.${map}
167 echo map ${map} converted.
170 elif [ $1 = "colldef" ]
172 awk -v tmp4=${TEMP4} '$1 == "SAME+=" && $0 !~ /legacy/ {
175 gsub(/.*\./, "", orig)
176 gsub(/.*\./, "", dest)
178 print "LOCALES_MAPPED+=\t"$2 " "$3 > tmp4
181 for line in $(awk '{ print $3 }' ${TEMP4}); do
182 sed -i '' "/^SAME.*$line$/d" ${old}/Makefile
185 for enc in ${COLLATIONS_SPECIAL}; do
186 sed -i '' "/^.*${enc}$/d" ${TEMP4}
187 echo "LOCALES+= ${enc}" >> ${TEMP4}
190 keep=$(cat ${TEMP} | awk '{ print $2 }')
191 for original in ${keep} ${COLLATIONS_SPECIAL}
193 cp ${old}/${original}.src ${new}/
195 else # below is everything but ctypedef
197 keep=$(cat ${TEMP} | awk '{ print $2 }')
198 for original in ${keep}
200 cp ${old}/${original}.src ${new}/
205 grep -v '^LOCALES+' ${old}/Makefile | awk "${AWKCMD}" > ${new}/Makefile
207 rm -f ${TEMP} ${TEMP3} ${TEMP4}