5 # This is a helper script for the Makefile in the parent directory.
6 # When the localization definitions are generated in the draft area,
7 # this script will copy base ones that others symlink to, and rearrange
8 # the generate makefile to pull the LOCALES first.
15 echo "finalize <type>' to package standard localization"
16 echo "type must be one of { monetdef, msgdef, numericdef, timedef, colldef, ctypedef }"
21 [ $1 = "monetdef" -o $1 = "msgdef" -o $1 = "colldef" -o \
22 $1 = "numericdef" -o $1 = "timedef" -o $1 = "ctypedef" ] || usage
25 base=$(dirname ${self})
26 old=${base}/../${1}.draft
28 TEMP=/tmp/${1}.locales
29 TEMP2=/tmp/${1}.hashes
30 TEMP3=/tmp/${1}.symlinks
31 TEMP4=/tmp/${1}.mapped
33 FULLEXTRACT=/tmp/extracted-names
34 AWKCMD="/## PLACEHOLDER/ { \
35 while ( getline line < \"${TEMP}\" ) {print line} } \
37 while ( getline line < \"${TEMP3}\" ) {print line} } \
38 /## LOCALES_MAPPED/ { \
39 while ( getline line < \"${TEMP4}\" ) {print line} } \
42 # Rename the sources with 3 components name into the POSIX version of the name using @modifier
44 for i in *_*_*.*.src; do
46 nname=`echo $oldname | awk '{ split($0, a, "_"); print a[1]"_"a[3]"@"a[2];} '`
47 mv -i ${oldname}.src ${nname}.src
49 sed -i '' -Ee "s/([a-zA-Z]{2})_([a-zA-Z]+)_([a-zA-Z]{2}).([a-zA-Z0-9-]+)/\1_\3.\4@\2/g" ${old}/Makefile
51 # For variable without @modifier ambiguity do not keep the @modifier
54 shortname=${oldname%@*}
55 if [ $(ls ${shortname}@* | wc -l) -eq 1 -a ! -f ${shortname}.src ] ; then
56 mv -i $i ${shortname}.src
57 sed -i '' -e "s/${oldname}/${shortname}/g" ${old}/Makefile
61 # Rename the modifiers into non abbreviated version
62 for i in *@Latn.src; do
63 if [ "$i" = "*@Latn.src" ]; then
66 mv ${i} ${i%@*}@latin.src
68 sed -i '' -e "s/@Latn/@latin/g" ${old}/Makefile
69 for i in *@Cyrl.src; do
70 if [ "$i" = "*@Cyrl.src" ]; then
73 mv ${i} ${i%@*}@cyrillic.src
75 sed -i '' -e "s/@Cyrl/@cyrillic/g" ${old}/Makefile
77 # On locales with multiple modifiers rename the "default" version without the @modifier
78 default_locales="sr_RS@cyrillic"
79 for i in ${default_locales}; do
82 for l in ${localename}.*@${mod}.src; do
83 if [ "$l" = "${localename}.*@${mod}.src" ]; then
87 sed -i '' -e "s/${l%.*}/${l%@*}/g" ${old}/Makefile
92 grep '^LOCALES+' ${old}/Makefile > ${TEMP}
94 if [ $1 = "ctypedef" ]
96 keep=$(cat ${TEMP} | awk '{ print $2 ".src" }')
97 (cd ${old} && md5 -r ${keep} | sort) > ${TEMP2}
98 keep=$(awk '{ if ($1 != last1) print $2; last1 = $1; }' ${TEMP2})
99 for original in ${keep}
101 cp ${old}/${original} ${new}/
103 awk '{ if ($1 == last1) { print "SYMPAIRS+=\t" last2 " " $2 } \
104 else {last1 = $1; last2 = $2}}' ${TEMP2} > ${TEMP3}
106 /usr/bin/sed -E -e 's/[ ]+/ /g' \
107 ${CLDRDIR}/posix/UTF-8.cm \
108 > ${base}/../etc/final-maps/map.UTF-8
109 /usr/bin/sed -E -e 's/[ ]+/ /g' \
110 ${CLDRDIR}/posix/eucCN.cm \
111 > ${base}/../etc/final-maps/map.eucCN
112 /usr/bin/sed -E -e 's/[ ]+/ /g' \
113 ${CLDRDIR}/posix/eucCN.cm \
114 > ${base}/../etc/final-maps/map.GB2312
115 CHARMAPS="ARMSCII-8 Big5 CP1131 CP1251 \
116 CP866 GBK ISCII-DEV ISO8859-1 \
117 ISO8859-13 ISO8859-15 ISO8859-2 ISO8859-4 \
118 ISO8859-5 ISO8859-7 ISO8859-9 KOI8-R KOI8-U \
119 PT154 SJIS US-ASCII eucJP eucKR"
121 # GB18030 blows up, use pre-generate Illumos version
123 for map in ${CHARMAPS}
126 /usr/local/bin/perl ${base}/convert_map.pl \
127 ${base}/../etc/charmaps/${map}.TXT ${encoding} \
128 | /usr/bin/sed -E -e 's/ +/ /g' \
129 > ${base}/../etc/final-maps/map.${map}
130 echo map ${map} converted.
133 elif [ $1 = "colldef" ]
135 awk -v tmp4=${TEMP4} '$1 == "SAME+=" && $0 !~ /legacy/ {
138 gsub(/.*\./, "", orig)
139 gsub(/.*\./, "", dest)
141 print "LOCALES_MAPPED+=\t"$2 " "$3 > tmp4
144 for line in $(awk '{ print $3 }' ${TEMP4}); do
145 sed -i '' "/^SAME.*$line$/d" ${old}/Makefile
148 for enc in ${COLLATIONS_SPECIAL}; do
149 nname=`echo $enc | sed -e 's/_Hans//g'`
150 sed -i '' "/^.*${nname}$/d" ${TEMP4}
151 echo "LOCALES+= ${nname}" >> ${TEMP4}
154 keep=$(cat ${TEMP} | awk '{ print $2 }')
155 for original in ${keep}
157 cp ${old}/${original}.src ${new}/
159 else # below is everything but ctypedef
161 keep=$(cat ${TEMP} | awk '{ print $2 }')
162 for original in ${keep}
164 cp ${old}/${original}.src ${new}/
169 grep -v '^LOCALES+' ${old}/Makefile | awk "${AWKCMD}" > ${new}/Makefile
171 rm -f ${TEMP} ${TEMP3} ${TEMP4}