summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorMika Westerberg <ext-mika.1.westerberg@nokia.com>2008-10-22 13:45:12 +0300
committerLauri Leukkunen <lle@rahina.org>2008-10-23 19:18:01 +0300
commitb779e037736239d3b8005506b898456c66c11a2a (patch)
tree8f263a62211de3027407acb65fa0a376168a26f1 /utils
parentc611922af0c5cc54ffb7f4f5519d2ecbd8753b85 (diff)
Introduced basic support for exec_policy based localization.
With this commit it is possible to instruct sb2 to load localization files and message catalogs from specific path (for example under target_root). (Reviewed by Lauri T. Aarnio)
Diffstat (limited to 'utils')
-rwxr-xr-xutils/sb225
-rw-r--r--utils/sb2-generate-locales141
-rwxr-xr-xutils/sb2-init17
3 files changed, 182 insertions, 1 deletions
diff --git a/utils/sb2 b/utils/sb2
index f553b0a..ed64882 100755
--- a/utils/sb2
+++ b/utils/sb2
@@ -432,6 +432,24 @@ function write_libsb2_and_ld_so_state_to_exec_config()
fi
}
+function write_locale_paths_to_exec_config()
+{
+ local rootdir
+ local locale_path_varname
+ local message_catalog_prefix_varname
+ locale locale_path
+
+ rootdir=$1
+ locale_path_varname=$2
+ message_catalog_prefix_varname=$3
+ locale_path=$HOME/.scratchbox2/$SBOX_TARGET/locales
+
+ echo "$locale_path_varname=\"$locale_path\"" \
+ >> $SBOX_SESSION_DIR/exec_config.lua
+ echo "$message_catalog_prefix_varname=\"$SBOX_TARGET_ROOT\"" \
+ >> $SBOX_SESSION_DIR/exec_config.lua
+}
+
# Write configuration file $SBOX_SESSION_DIR/exec_config.lua
function create_exec_config_file()
{
@@ -487,6 +505,11 @@ END
$SBOX_TARGET_ROOT \
conf_target_sb2_installed conf_target_sbox_dir \
conf_target_ld_so conf_target_ld_so_supports_argv0
+
+ write_locale_paths_to_exec_config \
+ $SBOX_TARGET_ROOT \
+ conf_target_locale_path \
+ conf_target_message_catalog_prefix
else
# SBOX_TOOLS_ROOT was empty, tools will be used from
# host environment.
@@ -496,6 +519,8 @@ conf_target_sb2_installed = false
conf_target_sbox_dir = ""
conf_target_ld_so = nil
conf_target_ld_so_supports_argv0 = false
+conf_target_locale_path = nil
+conf_target_message_catalog_prefix = nil
END
case "$SBOX_CPUTRANSPARENCY_METHOD" in
diff --git a/utils/sb2-generate-locales b/utils/sb2-generate-locales
new file mode 100644
index 0000000..7a6ad7d
--- /dev/null
+++ b/utils/sb2-generate-locales
@@ -0,0 +1,141 @@
+#!/bin/sh
+#
+# Copyright (C) 2008 Nokia Corporation.
+# Licensed under GPL version 2
+#
+# Generate locale definition files under $HOME/.scratchbox2/$sbox_target
+# in extracted form. We need to do this because otherwise it is impossible
+# to map locales under sb2 to $sbox_target_root using environment variable
+# $LOCPATH.
+#
+# $LOCPATH is the only way to change path of locale files when using
+# glibc (other systems use $NLSPATH but we don't need to do this extraction
+# there). Problem is that when $LOCPATH is defined, glibc doesn't want
+# to read file named '$LOCPATH/locale-archive' but it assumes that files
+# under $LOCPATH are in extracted form.
+#
+# This is only needed when we are running binaries without cpu transparency.
+#
+
+prog="$0"
+progbase=`basename $0`
+
+generate_localization_files()
+{
+ local sbox_target
+ local force
+
+ sbox_target=$1
+ force=$2
+
+ # this is where new extracted locales are generated
+ gendir=$HOME/.scratchbox2/$sbox_target/locales
+ if [ -d $gendir ]; then
+ if [ $force -eq 0 ]; then
+ return
+ fi
+ fi
+
+ # do we have locale-archive in target_root?
+ if [ ! -f /target_root/usr/lib/locale/locale-archive ]; then
+ return
+ fi
+
+ # does localedef exist?
+ if [ ! -x /target_root/usr/bin/localedef ]; then
+ # nothing to do
+ return
+ fi
+
+ # list currently archived locales
+ archived_locales=`/target_root/usr/bin/localedef --list-archive \
+ --prefix /target_root`
+
+ if [ -z "$archived_locales" ]; then
+ return
+ fi
+
+ echo "Generating locales under '$gendir'"
+
+ /bin/mkdir $gendir > /dev/null 2>&1
+
+ #
+ # Now we force localedef to use our target_root as
+ # root for all locale operations.
+ #
+ I18NPATH=/target_root/usr/share/i18n; export I18NPATH
+ LOCPATH=/target_root/usr/lib/locale; export LOCPATH
+
+ #
+ # Find out supported variations for a locale and generate
+ # the files.
+ #
+ for l in $archived_locales; do
+ echo -n "generating locale $l ..."
+ /target_root/usr/bin/localedef \
+ --no-archive \
+ -c \
+ -i $l \
+ $gendir/$l > /dev/null 2>&1
+ echo " done"
+ done
+
+ unset I18NPATH
+ unset LOCPATH
+}
+
+usage()
+{
+ cat <<EOF
+Usage: $progbase [OPTION]
+
+Options:
+ -f forces generation of locales even if they already exists
+ -h displays this help text
+
+Generates locale specific files based on archived ones under
+target_root/usr/lib/locale/locale-archive. These files are
+used to map locales into target_root by scratchbox2.
+
+You need to do this only with binaries that have same architecture
+than host has. Binaries that are run through cpu transparency get
+mapped correctly.
+EOF
+ exit 1
+}
+
+error_not_inside_sb2()
+{
+ echo "SB2: $progbase: This program can only be used from inside"
+ echo "the scratchbox 2'ed environment"
+ exit 1
+}
+
+if [ -z "$SBOX_SESSION_DIR" ]; then
+ error_not_inside_sb2
+fi
+
+. $SBOX_SESSION_DIR/sb2-session.conf
+
+args=`getopt hf $*`
+if [ $? -ne 0 ]; then
+ usage
+fi
+
+force=0
+for a in $args; do
+ case $a in
+ -f)
+ force=1;
+ shift
+ ;;
+ --)
+ break
+ ;;
+ *)
+ usage
+ ;;
+ esac
+done
+
+generate_localization_files $sbox_target $force
diff --git a/utils/sb2-init b/utils/sb2-init
index 5c4866a..27e3c06 100755
--- a/utils/sb2-init
+++ b/utils/sb2-init
@@ -65,6 +65,7 @@ Options:
-m [mapping_mode] use mapping_mode as default
-h print this help
-n don't build libtool for the target
+ -N don't generate localization files for the target
-s skip checks for target root's /usr/include etc.
-t [tools_dir] set directory containing the build tools distribution
-C "options" add extra options for the compiler, for example:
@@ -228,6 +229,7 @@ LOCALHOST=
set_as_default=0
with_libtool=1
+with_locales=1
skip_checks=false
SBOX_EXTRA_CROSS_COMPILER_ARGS=""
@@ -236,7 +238,7 @@ if [ -z "$*" ]; then
usage
fi
-while getopts A:c:C:r:l:m:dhnst:v foo
+while getopts A:c:C:r:l:m:dhnNst:v foo
do
case $foo in
(A) ARCH=$OPTARG ;;
@@ -247,6 +249,7 @@ do
(h) usage ;;
(m) MAPPING_MODE=$OPTARG ;;
(n) with_libtool=0 ;;
+ (N) with_locales=0 ;;
(s) skip_checks=true ;;
(t) TOOLS_ROOT=$OPTARG ;;
(v) version ;;
@@ -424,6 +427,18 @@ if [ $set_as_default == 1 ]; then
sb2-config -d $TARGET
fi
+#
+# If target architecture is same as host (currently i386)
+# we need to extract localization archive from target and
+# place resulting files under ~/.scratchbox2/locales.
+#
+if [ $with_locales == 1 ]; then
+ if [ -z "$CPUTRANSP" ]; then
+ $SBOX_DIR/bin/sb2 -t $TARGET \
+ $SBOX_DIR/share/scratchbox2/scripts/sb2-generate-locales
+ fi
+fi
+
if [ $with_libtool == 1 ]; then
$SBOX_DIR/bin/sb2 -t $TARGET $SBOX_DIR/bin/sb2-build-libtool
TEST=$?