xref: /aosp_15_r20/external/bc/scripts/locale_install.sh (revision 5a6e848804d15c18a0125914844ee4eb0bda4fcf)
1*5a6e8488SAndroid Build Coastguard Worker#! /bin/sh
2*5a6e8488SAndroid Build Coastguard Worker#
3*5a6e8488SAndroid Build Coastguard Worker# SPDX-License-Identifier: BSD-2-Clause
4*5a6e8488SAndroid Build Coastguard Worker#
5*5a6e8488SAndroid Build Coastguard Worker# Copyright (c) 2018-2024 Gavin D. Howard and contributors.
6*5a6e8488SAndroid Build Coastguard Worker#
7*5a6e8488SAndroid Build Coastguard Worker# Redistribution and use in source and binary forms, with or without
8*5a6e8488SAndroid Build Coastguard Worker# modification, are permitted provided that the following conditions are met:
9*5a6e8488SAndroid Build Coastguard Worker#
10*5a6e8488SAndroid Build Coastguard Worker# * Redistributions of source code must retain the above copyright notice, this
11*5a6e8488SAndroid Build Coastguard Worker#   list of conditions and the following disclaimer.
12*5a6e8488SAndroid Build Coastguard Worker#
13*5a6e8488SAndroid Build Coastguard Worker# * Redistributions in binary form must reproduce the above copyright notice,
14*5a6e8488SAndroid Build Coastguard Worker#   this list of conditions and the following disclaimer in the documentation
15*5a6e8488SAndroid Build Coastguard Worker#   and/or other materials provided with the distribution.
16*5a6e8488SAndroid Build Coastguard Worker#
17*5a6e8488SAndroid Build Coastguard Worker# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18*5a6e8488SAndroid Build Coastguard Worker# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*5a6e8488SAndroid Build Coastguard Worker# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*5a6e8488SAndroid Build Coastguard Worker# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21*5a6e8488SAndroid Build Coastguard Worker# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22*5a6e8488SAndroid Build Coastguard Worker# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23*5a6e8488SAndroid Build Coastguard Worker# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*5a6e8488SAndroid Build Coastguard Worker# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25*5a6e8488SAndroid Build Coastguard Worker# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26*5a6e8488SAndroid Build Coastguard Worker# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27*5a6e8488SAndroid Build Coastguard Worker# POSSIBILITY OF SUCH DAMAGE.
28*5a6e8488SAndroid Build Coastguard Worker#
29*5a6e8488SAndroid Build Coastguard Worker
30*5a6e8488SAndroid Build Coastguard Worker# Just print the usage and exit with an error.
31*5a6e8488SAndroid Build Coastguard Worker# @param 1  A message to print.
32*5a6e8488SAndroid Build Coastguard Workerusage() {
33*5a6e8488SAndroid Build Coastguard Worker	if [ $# -eq 1 ]; then
34*5a6e8488SAndroid Build Coastguard Worker		printf '%s\n' "$1"
35*5a6e8488SAndroid Build Coastguard Worker	fi
36*5a6e8488SAndroid Build Coastguard Worker	printf "usage: %s [-l] NLSPATH main_exec [DESTDIR]\n" "$0" 1>&2
37*5a6e8488SAndroid Build Coastguard Worker	exit 1
38*5a6e8488SAndroid Build Coastguard Worker}
39*5a6e8488SAndroid Build Coastguard Worker
40*5a6e8488SAndroid Build Coastguard Worker# Run gencat on one file.
41*5a6e8488SAndroid Build Coastguard Worker# @param loc   The location of the resulting cat file.
42*5a6e8488SAndroid Build Coastguard Worker# @param file  The file to use as the source for the cat file.
43*5a6e8488SAndroid Build Coastguard Workergencatfile() {
44*5a6e8488SAndroid Build Coastguard Worker
45*5a6e8488SAndroid Build Coastguard Worker	_gencatfile_loc="$1"
46*5a6e8488SAndroid Build Coastguard Worker	shift
47*5a6e8488SAndroid Build Coastguard Worker
48*5a6e8488SAndroid Build Coastguard Worker	_gencatfile_file="$1"
49*5a6e8488SAndroid Build Coastguard Worker	shift
50*5a6e8488SAndroid Build Coastguard Worker
51*5a6e8488SAndroid Build Coastguard Worker	mkdir -p $(dirname "$_gencatfile_loc")
52*5a6e8488SAndroid Build Coastguard Worker	gencat "$_gencatfile_loc" "$_gencatfile_file" > /dev/null 2>&1
53*5a6e8488SAndroid Build Coastguard Worker}
54*5a6e8488SAndroid Build Coastguard Worker
55*5a6e8488SAndroid Build Coastguard Worker# Return an exit code based on whether a locale exists.
56*5a6e8488SAndroid Build Coastguard Worker# @param locales  The list of locales.
57*5a6e8488SAndroid Build Coastguard Worker# @param locale   The locale to search for.
58*5a6e8488SAndroid Build Coastguard Worker# @param destdir  The DESTDIR that locales should be installed to.
59*5a6e8488SAndroid Build Coastguard Workerlocaleexists() {
60*5a6e8488SAndroid Build Coastguard Worker
61*5a6e8488SAndroid Build Coastguard Worker	_localeexists_locales="$1"
62*5a6e8488SAndroid Build Coastguard Worker	shift
63*5a6e8488SAndroid Build Coastguard Worker
64*5a6e8488SAndroid Build Coastguard Worker	_localeexists_locale="$1"
65*5a6e8488SAndroid Build Coastguard Worker	shift
66*5a6e8488SAndroid Build Coastguard Worker
67*5a6e8488SAndroid Build Coastguard Worker	_localeexists_destdir="$1"
68*5a6e8488SAndroid Build Coastguard Worker	shift
69*5a6e8488SAndroid Build Coastguard Worker
70*5a6e8488SAndroid Build Coastguard Worker	if [ "$_localeexists_destdir" != "" ]; then
71*5a6e8488SAndroid Build Coastguard Worker		_localeexists_char="@"
72*5a6e8488SAndroid Build Coastguard Worker		_localeexists_locale="${_localeexists_locale%%_localeexists_char*}"
73*5a6e8488SAndroid Build Coastguard Worker		_localeexists_char="."
74*5a6e8488SAndroid Build Coastguard Worker		_localeexists_locale="${_localeexists_locale##*$_localeexists_char}"
75*5a6e8488SAndroid Build Coastguard Worker	fi
76*5a6e8488SAndroid Build Coastguard Worker
77*5a6e8488SAndroid Build Coastguard Worker	test ! -z "${_localeexists_locales##*$_localeexists_locale*}"
78*5a6e8488SAndroid Build Coastguard Worker	return $?
79*5a6e8488SAndroid Build Coastguard Worker}
80*5a6e8488SAndroid Build Coastguard Worker
81*5a6e8488SAndroid Build Coastguard Worker# Split a path into its components. They will be separated by newlines, so paths
82*5a6e8488SAndroid Build Coastguard Worker# cannot have newlines in them.
83*5a6e8488SAndroid Build Coastguard Worker# @param path  The path to split.
84*5a6e8488SAndroid Build Coastguard Workersplitpath() {
85*5a6e8488SAndroid Build Coastguard Worker
86*5a6e8488SAndroid Build Coastguard Worker	_splitpath_path="$1"
87*5a6e8488SAndroid Build Coastguard Worker	shift
88*5a6e8488SAndroid Build Coastguard Worker
89*5a6e8488SAndroid Build Coastguard Worker	if [ "$_splitpath_path" = "${_splitpath_path#/}" ]; then
90*5a6e8488SAndroid Build Coastguard Worker		printf 'Must use absolute paths\n'
91*5a6e8488SAndroid Build Coastguard Worker		exit 1
92*5a6e8488SAndroid Build Coastguard Worker	fi
93*5a6e8488SAndroid Build Coastguard Worker
94*5a6e8488SAndroid Build Coastguard Worker	if [ "${_splitpath_path#\n*}" != "$_splitpath_path" ]; then
95*5a6e8488SAndroid Build Coastguard Worker		exit 1
96*5a6e8488SAndroid Build Coastguard Worker	fi
97*5a6e8488SAndroid Build Coastguard Worker
98*5a6e8488SAndroid Build Coastguard Worker	_splitpath_list=""
99*5a6e8488SAndroid Build Coastguard Worker	_splitpath_item=""
100*5a6e8488SAndroid Build Coastguard Worker
101*5a6e8488SAndroid Build Coastguard Worker	while [ "$_splitpath_path" != "/" ]; do
102*5a6e8488SAndroid Build Coastguard Worker		_splitpath_item=$(basename "$_splitpath_path")
103*5a6e8488SAndroid Build Coastguard Worker		_splitpath_list=$(printf '\n%s%s' "$_splitpath_item" "$_splitpath_list")
104*5a6e8488SAndroid Build Coastguard Worker		_splitpath_path=$(dirname "$_splitpath_path")
105*5a6e8488SAndroid Build Coastguard Worker	done
106*5a6e8488SAndroid Build Coastguard Worker
107*5a6e8488SAndroid Build Coastguard Worker	if [ "$_splitpath_list" != "/" ]; then
108*5a6e8488SAndroid Build Coastguard Worker		_splitpath_list="${_splitpath_list#?}"
109*5a6e8488SAndroid Build Coastguard Worker	fi
110*5a6e8488SAndroid Build Coastguard Worker
111*5a6e8488SAndroid Build Coastguard Worker	printf '%s' "$_splitpath_list"
112*5a6e8488SAndroid Build Coastguard Worker}
113*5a6e8488SAndroid Build Coastguard Worker
114*5a6e8488SAndroid Build Coastguard Worker# Generate a relative path from one path to another.
115*5a6e8488SAndroid Build Coastguard Worker# @param path1  The target path.
116*5a6e8488SAndroid Build Coastguard Worker# @param path2  The other path.
117*5a6e8488SAndroid Build Coastguard Workerrelpath() {
118*5a6e8488SAndroid Build Coastguard Worker
119*5a6e8488SAndroid Build Coastguard Worker	_relpath_path1="$1"
120*5a6e8488SAndroid Build Coastguard Worker	shift
121*5a6e8488SAndroid Build Coastguard Worker
122*5a6e8488SAndroid Build Coastguard Worker	_relpath_path2="$1"
123*5a6e8488SAndroid Build Coastguard Worker	shift
124*5a6e8488SAndroid Build Coastguard Worker
125*5a6e8488SAndroid Build Coastguard Worker	# Very carefully set IFS in a portable way. No, you cannot do IFS=$'\n'.
126*5a6e8488SAndroid Build Coastguard Worker	_relpath_nl=$(printf '\nx')
127*5a6e8488SAndroid Build Coastguard Worker	_relpath_nl="${_relpath_nl%x}"
128*5a6e8488SAndroid Build Coastguard Worker
129*5a6e8488SAndroid Build Coastguard Worker	_relpath_splitpath1=`splitpath "$_relpath_path1"`
130*5a6e8488SAndroid Build Coastguard Worker	_relpath_splitpath2=`splitpath "$_relpath_path2"`
131*5a6e8488SAndroid Build Coastguard Worker
132*5a6e8488SAndroid Build Coastguard Worker	_relpath_path=""
133*5a6e8488SAndroid Build Coastguard Worker	_relpath_temp1="$_relpath_splitpath1"
134*5a6e8488SAndroid Build Coastguard Worker
135*5a6e8488SAndroid Build Coastguard Worker	IFS="$_relpath_nl"
136*5a6e8488SAndroid Build Coastguard Worker
137*5a6e8488SAndroid Build Coastguard Worker	# What this function does is find the parts that are the same and then
138*5a6e8488SAndroid Build Coastguard Worker	# calculates the difference based on how many folders up and down you must
139*5a6e8488SAndroid Build Coastguard Worker	# go.
140*5a6e8488SAndroid Build Coastguard Worker
141*5a6e8488SAndroid Build Coastguard Worker	# This first loop basically removes the parts that are the same between
142*5a6e8488SAndroid Build Coastguard Worker	# them.
143*5a6e8488SAndroid Build Coastguard Worker	for _relpath_part in $_relpath_temp1; do
144*5a6e8488SAndroid Build Coastguard Worker
145*5a6e8488SAndroid Build Coastguard Worker		_relpath_temp2="${_relpath_splitpath2#$_relpath_part$_relpath_nl}"
146*5a6e8488SAndroid Build Coastguard Worker
147*5a6e8488SAndroid Build Coastguard Worker		if [ "$_relpath_temp2" = "$_relpath_splitpath2" ]; then
148*5a6e8488SAndroid Build Coastguard Worker			break
149*5a6e8488SAndroid Build Coastguard Worker		fi
150*5a6e8488SAndroid Build Coastguard Worker
151*5a6e8488SAndroid Build Coastguard Worker		_relpath_splitpath2="$_relpath_temp2"
152*5a6e8488SAndroid Build Coastguard Worker		_relpath_splitpath1="${_relpath_splitpath1#$_relpath_part$_relpath_nl}"
153*5a6e8488SAndroid Build Coastguard Worker
154*5a6e8488SAndroid Build Coastguard Worker	done
155*5a6e8488SAndroid Build Coastguard Worker
156*5a6e8488SAndroid Build Coastguard Worker	# Go up the appropriate number of times.
157*5a6e8488SAndroid Build Coastguard Worker	for _relpath_part in $_relpath_splitpath2; do
158*5a6e8488SAndroid Build Coastguard Worker		_relpath_path="../$_relpath_path"
159*5a6e8488SAndroid Build Coastguard Worker	done
160*5a6e8488SAndroid Build Coastguard Worker
161*5a6e8488SAndroid Build Coastguard Worker	_relpath_path="${_relpath_path%../}"
162*5a6e8488SAndroid Build Coastguard Worker
163*5a6e8488SAndroid Build Coastguard Worker	# Go down the appropriate number of times.
164*5a6e8488SAndroid Build Coastguard Worker	for _relpath_part in $_relpath_splitpath1; do
165*5a6e8488SAndroid Build Coastguard Worker		_relpath_path="$_relpath_path$_relpath_part/"
166*5a6e8488SAndroid Build Coastguard Worker	done
167*5a6e8488SAndroid Build Coastguard Worker
168*5a6e8488SAndroid Build Coastguard Worker	_relpath_path="${_relpath_path%/}"
169*5a6e8488SAndroid Build Coastguard Worker
170*5a6e8488SAndroid Build Coastguard Worker	unset IFS
171*5a6e8488SAndroid Build Coastguard Worker
172*5a6e8488SAndroid Build Coastguard Worker	printf '%s\n' "$_relpath_path"
173*5a6e8488SAndroid Build Coastguard Worker}
174*5a6e8488SAndroid Build Coastguard Worker
175*5a6e8488SAndroid Build Coastguard Workerscript="$0"
176*5a6e8488SAndroid Build Coastguard Workerscriptdir=$(dirname "$script")
177*5a6e8488SAndroid Build Coastguard Worker
178*5a6e8488SAndroid Build Coastguard Worker. "$scriptdir/functions.sh"
179*5a6e8488SAndroid Build Coastguard Worker
180*5a6e8488SAndroid Build Coastguard Worker# Set a default.
181*5a6e8488SAndroid Build Coastguard Workerall_locales=0
182*5a6e8488SAndroid Build Coastguard Worker
183*5a6e8488SAndroid Build Coastguard Worker# Process command-line args.
184*5a6e8488SAndroid Build Coastguard Workerwhile getopts "l" opt; do
185*5a6e8488SAndroid Build Coastguard Worker
186*5a6e8488SAndroid Build Coastguard Worker	case "$opt" in
187*5a6e8488SAndroid Build Coastguard Worker		l) all_locales=1 ;;
188*5a6e8488SAndroid Build Coastguard Worker		?) usage "Invalid option: $opt" ;;
189*5a6e8488SAndroid Build Coastguard Worker	esac
190*5a6e8488SAndroid Build Coastguard Worker
191*5a6e8488SAndroid Build Coastguard Workerdone
192*5a6e8488SAndroid Build Coastguard Workershift $(($OPTIND - 1))
193*5a6e8488SAndroid Build Coastguard Worker
194*5a6e8488SAndroid Build Coastguard Workertest "$#" -ge 2 || usage "Must have at least two arguments"
195*5a6e8488SAndroid Build Coastguard Worker
196*5a6e8488SAndroid Build Coastguard Workernlspath="$1"
197*5a6e8488SAndroid Build Coastguard Workershift
198*5a6e8488SAndroid Build Coastguard Worker
199*5a6e8488SAndroid Build Coastguard Workermain_exec="$1"
200*5a6e8488SAndroid Build Coastguard Workershift
201*5a6e8488SAndroid Build Coastguard Worker
202*5a6e8488SAndroid Build Coastguard Workerif [ "$#" -ge 1 ]; then
203*5a6e8488SAndroid Build Coastguard Worker	destdir="$1"
204*5a6e8488SAndroid Build Coastguard Worker	shift
205*5a6e8488SAndroid Build Coastguard Workerelse
206*5a6e8488SAndroid Build Coastguard Worker	destdir=""
207*5a6e8488SAndroid Build Coastguard Workerfi
208*5a6e8488SAndroid Build Coastguard Worker
209*5a6e8488SAndroid Build Coastguard Worker# Uninstall locales first.
210*5a6e8488SAndroid Build Coastguard Worker"$scriptdir/locale_uninstall.sh" "$nlspath" "$main_exec" "$destdir"
211*5a6e8488SAndroid Build Coastguard Worker
212*5a6e8488SAndroid Build Coastguard Workerlocales_dir="$scriptdir/../locales"
213*5a6e8488SAndroid Build Coastguard Worker
214*5a6e8488SAndroid Build Coastguard Worker# What this does is if installing to a package, it installs all locales that
215*5a6e8488SAndroid Build Coastguard Worker# match supported charsets instead of installing all directly supported locales.
216*5a6e8488SAndroid Build Coastguard Workerif [ "$destdir" = "" ]; then
217*5a6e8488SAndroid Build Coastguard Worker	locales=$(locale -a)
218*5a6e8488SAndroid Build Coastguard Workerelse
219*5a6e8488SAndroid Build Coastguard Worker	locales=$(locale -m)
220*5a6e8488SAndroid Build Coastguard Workerfi
221*5a6e8488SAndroid Build Coastguard Worker
222*5a6e8488SAndroid Build Coastguard Worker# For each relevant .msg file, run gencat.
223*5a6e8488SAndroid Build Coastguard Workerfor file in $locales_dir/*.msg; do
224*5a6e8488SAndroid Build Coastguard Worker
225*5a6e8488SAndroid Build Coastguard Worker	locale=$(basename "$file" ".msg")
226*5a6e8488SAndroid Build Coastguard Worker
227*5a6e8488SAndroid Build Coastguard Worker	# If we are not installing all locales, there's a possibility we need to
228*5a6e8488SAndroid Build Coastguard Worker	# skip this one.
229*5a6e8488SAndroid Build Coastguard Worker	if [ "$all_locales" -eq 0 ]; then
230*5a6e8488SAndroid Build Coastguard Worker
231*5a6e8488SAndroid Build Coastguard Worker		# Check if the locale exists and if not skip.
232*5a6e8488SAndroid Build Coastguard Worker		localeexists "$locales" "$locale" "$destdir"
233*5a6e8488SAndroid Build Coastguard Worker		err="$?"
234*5a6e8488SAndroid Build Coastguard Worker
235*5a6e8488SAndroid Build Coastguard Worker		if [ "$err" -eq 0 ]; then
236*5a6e8488SAndroid Build Coastguard Worker			continue
237*5a6e8488SAndroid Build Coastguard Worker		fi
238*5a6e8488SAndroid Build Coastguard Worker	fi
239*5a6e8488SAndroid Build Coastguard Worker
240*5a6e8488SAndroid Build Coastguard Worker	# We skip the symlinks for now.
241*5a6e8488SAndroid Build Coastguard Worker	if [ -L "$file" ]; then
242*5a6e8488SAndroid Build Coastguard Worker		continue
243*5a6e8488SAndroid Build Coastguard Worker	fi
244*5a6e8488SAndroid Build Coastguard Worker
245*5a6e8488SAndroid Build Coastguard Worker	printf 'Installing %s...' "$locale"
246*5a6e8488SAndroid Build Coastguard Worker
247*5a6e8488SAndroid Build Coastguard Worker	# Generate the proper location for the cat file.
248*5a6e8488SAndroid Build Coastguard Worker	loc=$(gen_nlspath "$destdir/$nlspath" "$locale" "$main_exec")
249*5a6e8488SAndroid Build Coastguard Worker
250*5a6e8488SAndroid Build Coastguard Worker	gencatfile "$loc" "$file"
251*5a6e8488SAndroid Build Coastguard Worker
252*5a6e8488SAndroid Build Coastguard Worker	printf 'done\n'
253*5a6e8488SAndroid Build Coastguard Worker
254*5a6e8488SAndroid Build Coastguard Workerdone
255*5a6e8488SAndroid Build Coastguard Worker
256*5a6e8488SAndroid Build Coastguard Worker# Now that we have done the non-symlinks, it's time to do the symlinks. Think
257*5a6e8488SAndroid Build Coastguard Worker# that this second loop is unnecessary and that you can combine the two? Well,
258*5a6e8488SAndroid Build Coastguard Worker# make sure that when you figure out you are wrong that you add to this comment
259*5a6e8488SAndroid Build Coastguard Worker# with your story. Fortunately for me, I learned fast.
260*5a6e8488SAndroid Build Coastguard Workerfor file in $locales_dir/*.msg; do
261*5a6e8488SAndroid Build Coastguard Worker
262*5a6e8488SAndroid Build Coastguard Worker	locale=$(basename "$file" ".msg")
263*5a6e8488SAndroid Build Coastguard Worker
264*5a6e8488SAndroid Build Coastguard Worker	# Do the same skip as the above loop.
265*5a6e8488SAndroid Build Coastguard Worker	if [ "$all_locales" -eq 0 ]; then
266*5a6e8488SAndroid Build Coastguard Worker
267*5a6e8488SAndroid Build Coastguard Worker		localeexists "$locales" "$locale" "$destdir"
268*5a6e8488SAndroid Build Coastguard Worker		err="$?"
269*5a6e8488SAndroid Build Coastguard Worker
270*5a6e8488SAndroid Build Coastguard Worker		if [ "$err" -eq 0 ]; then
271*5a6e8488SAndroid Build Coastguard Worker			continue
272*5a6e8488SAndroid Build Coastguard Worker		fi
273*5a6e8488SAndroid Build Coastguard Worker	fi
274*5a6e8488SAndroid Build Coastguard Worker
275*5a6e8488SAndroid Build Coastguard Worker	# Generate the proper location for the cat file.
276*5a6e8488SAndroid Build Coastguard Worker	loc=$(gen_nlspath "$destdir/$nlspath" "$locale" "$main_exec")
277*5a6e8488SAndroid Build Coastguard Worker
278*5a6e8488SAndroid Build Coastguard Worker	# Make sure the directory exists.
279*5a6e8488SAndroid Build Coastguard Worker	mkdir -p $(dirname "$loc")
280*5a6e8488SAndroid Build Coastguard Worker
281*5a6e8488SAndroid Build Coastguard Worker	# Make sure to skip non-symlinks; they are already done.
282*5a6e8488SAndroid Build Coastguard Worker	if [ -L "$file" ]; then
283*5a6e8488SAndroid Build Coastguard Worker
284*5a6e8488SAndroid Build Coastguard Worker		printf 'Linking %s...' "$locale"
285*5a6e8488SAndroid Build Coastguard Worker
286*5a6e8488SAndroid Build Coastguard Worker		# This song and dance is because we want to generate relative symlinks.
287*5a6e8488SAndroid Build Coastguard Worker		# They take less space, but also, they are more resilient to being
288*5a6e8488SAndroid Build Coastguard Worker		# moved.
289*5a6e8488SAndroid Build Coastguard Worker		link=$(readlink "$file")
290*5a6e8488SAndroid Build Coastguard Worker		linkdir=$(dirname "$file")
291*5a6e8488SAndroid Build Coastguard Worker		locale=$(basename "$link" .msg)
292*5a6e8488SAndroid Build Coastguard Worker		linksrc=$(gen_nlspath "$nlspath" "$locale" "$main_exec")
293*5a6e8488SAndroid Build Coastguard Worker		relloc="${loc##$destdir/}"
294*5a6e8488SAndroid Build Coastguard Worker		rel=$(relpath "$linksrc" "$relloc")
295*5a6e8488SAndroid Build Coastguard Worker
296*5a6e8488SAndroid Build Coastguard Worker		# If the target file doesn't exist (because it's for a locale that is
297*5a6e8488SAndroid Build Coastguard Worker		# not installed), generate it anyway. It's easier this way.
298*5a6e8488SAndroid Build Coastguard Worker		if [ ! -f "$destdir/$linksrc" ]; then
299*5a6e8488SAndroid Build Coastguard Worker			gencatfile "$destdir/$linksrc" "$linkdir/$link"
300*5a6e8488SAndroid Build Coastguard Worker		fi
301*5a6e8488SAndroid Build Coastguard Worker
302*5a6e8488SAndroid Build Coastguard Worker		# Finally, symlink to the install of the generated cat file that
303*5a6e8488SAndroid Build Coastguard Worker		# corresponds to the correct msg file.
304*5a6e8488SAndroid Build Coastguard Worker		ln -fs "$rel" "$loc"
305*5a6e8488SAndroid Build Coastguard Worker
306*5a6e8488SAndroid Build Coastguard Worker		printf 'done\n'
307*5a6e8488SAndroid Build Coastguard Worker	fi
308*5a6e8488SAndroid Build Coastguard Worker
309*5a6e8488SAndroid Build Coastguard Workerdone
310