From patchwork Mon Jul 7 09:31:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenqiang Chen X-Patchwork-Id: 33137 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f72.google.com (mail-pa0-f72.google.com [209.85.220.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2279220969 for ; Mon, 7 Jul 2014 09:31:39 +0000 (UTC) Received: by mail-pa0-f72.google.com with SMTP id rd3sf31229984pab.3 for ; Mon, 07 Jul 2014 02:31:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mailing-list:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:sender :delivered-to:mime-version:date:message-id:subject:from:to :x-original-sender:x-original-authentication-results:content-type; bh=6Ekbui5YT/WrOo3AuTgJAcqwGHry7S4DPxWiySJfwX0=; b=h5jqYHyOSiL1CPmoHxX/tZLzATy64z8MKZ1PsG1sEKPY9UCqEIwG/zXomk7LkM1SOf H0TKGRxnNMpek3I+wjRpc5kR2oWRwAa438H0KvxGdniHKgfQLLVRtjnoMPH9b0ZS9PQj +VPikAG7vGg9ZHDXDq4z2dgQ3auhxrbMEDXEuYKaBz/OeVfFK+V5Y3BxR95v6YeJVnf5 gFzSpF457upnvitl0hWmLrJ5k1mkQFdwLckG3lUVitWWJGiSApI89/rnLe2e6GWJY2qw inE1lx3NsZkCk27DUP54TCBNTst3ir5Z+XPGlA7agKpZ3cQBNeSrtFxzsaTetqJDXzom LYvw== X-Gm-Message-State: ALoCoQlnzcpE09s9ERZ4URBRuVPQMAXBgeZtz8M+B99DIQvb3sW0rFzzlEOCleu9lNMoxNHZ3o1f X-Received: by 10.66.252.70 with SMTP id zq6mr5398689pac.40.1404725496704; Mon, 07 Jul 2014 02:31:36 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.20.132 with SMTP id 4ls836947qgj.12.gmail; Mon, 07 Jul 2014 02:31:36 -0700 (PDT) X-Received: by 10.220.94.135 with SMTP id z7mr2130669vcm.46.1404725496602; Mon, 07 Jul 2014 02:31:36 -0700 (PDT) Received: from mail-vc0-x236.google.com (mail-vc0-x236.google.com [2607:f8b0:400c:c03::236]) by mx.google.com with ESMTPS id o5si18581224vcj.31.2014.07.07.02.31.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 07 Jul 2014 02:31:36 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::236 as permitted sender) client-ip=2607:f8b0:400c:c03::236; Received: by mail-vc0-f182.google.com with SMTP id il7so3619657vcb.41 for ; Mon, 07 Jul 2014 02:31:36 -0700 (PDT) X-Received: by 10.221.32.202 with SMTP id sl10mr8427vcb.55.1404725496517; Mon, 07 Jul 2014 02:31:36 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp651882vcb; Mon, 7 Jul 2014 02:31:36 -0700 (PDT) X-Received: by 10.66.228.37 with SMTP id sf5mr28067416pac.19.1404725495681; Mon, 07 Jul 2014 02:31:35 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id yr10si40693601pac.82.2014.07.07.02.31.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Jul 2014 02:31:35 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-371977-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 24940 invoked by alias); 7 Jul 2014 09:31:24 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 24921 invoked by uid 89); 7 Jul 2014 09:31:23 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-lb0-f174.google.com Received: from mail-lb0-f174.google.com (HELO mail-lb0-f174.google.com) (209.85.217.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Mon, 07 Jul 2014 09:31:22 +0000 Received: by mail-lb0-f174.google.com with SMTP id u10so2622699lbd.5 for ; Mon, 07 Jul 2014 02:31:18 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.112.63.65 with SMTP id e1mr855545lbs.81.1404725478744; Mon, 07 Jul 2014 02:31:18 -0700 (PDT) Received: by 10.112.136.66 with HTTP; Mon, 7 Jul 2014 02:31:18 -0700 (PDT) Date: Mon, 7 Jul 2014 17:31:18 +0800 Message-ID: Subject: [PATCH, NLS] try to search relative dir From: Zhenqiang Chen To: "gcc-patches@gcc.gnu.org" X-IsSubscribed: yes X-Original-Sender: zhenqiang.chen@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::236 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gcc.gnu.org X-Google-Group-Id: 836684582541 Hi, LOCALEDIR seams a build-time constant, which is an absolute path. But * When releasing gcc binaries as a tarball, users can put it at any dir. * For "Canadian" build, the dir layout on the build machine might be different from the host machine. For such cases, gcc most likely can not find the gcc.mo. The patch tries to search relative dir "../share/locale" from gcc. Although it can not cover all cases, I think it can cover most cases. Bootstrap and no make check regression on X86-64. OK for trunk? Thanks! -Zhenqiang ChangeLog: 2014-07-07 Zhenqiang Chen * gcc.c (main): Call gcc_init_libintl_program. * intl.c (gcc_init_libintl): Likewise. (gcc_init_libintl_program): New function. * intl.h (gcc_init_libintl_program): New prototype. diff --git a/gcc/gcc.c b/gcc/gcc.c index 6cd08ea..0addc0c5 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -6409,7 +6409,7 @@ main (int argc, char **argv) /* Unlock the stdio streams. */ unlock_std_streams (); - gcc_init_libintl (); + gcc_init_libintl_program (argv[0]); diagnostic_initialize (global_dc, 0); diff --git a/gcc/intl.c b/gcc/intl.c index 2509c1a..6d1a45c 100644 --- a/gcc/intl.c +++ b/gcc/intl.c @@ -48,6 +48,14 @@ bool locale_utf8 = false; void gcc_init_libintl (void) { + gcc_init_libintl_program ("gcc"); +} + +#define LIBINTL_RELATIVE_DIR "../share/locale" + +void +gcc_init_libintl_program (const char * program_name) +{ #ifdef HAVE_LC_MESSAGES setlocale (LC_CTYPE, ""); setlocale (LC_MESSAGES, ""); @@ -55,7 +63,32 @@ gcc_init_libintl (void) setlocale (LC_ALL, ""); #endif - (void) bindtextdomain ("gcc", LOCALEDIR); + if (!access (LOCALEDIR, X_OK)) + { + /* If LOCALEDIR exists, use LOCALEDIR. */ + (void) bindtextdomain ("gcc", LOCALEDIR); + } + else + { + /* Try relative dir, i.e. .../bin/../share/locale. */ + int len1, len2; + char *prefix_dir, *locale_dir; + prefix_dir = make_relative_prefix (program_name, ".", "."); + len1 = strlen (prefix_dir); + len2 = strlen (LIBINTL_RELATIVE_DIR); + locale_dir = (char*) xmalloc (len1 + len2 + 1); + if (locale_dir != NULL) + { + strcpy (locale_dir, prefix_dir); + strcpy (locale_dir + len1, LIBINTL_RELATIVE_DIR); + (void) bindtextdomain ("gcc", locale_dir); + } + else + (void) bindtextdomain ("gcc", LOCALEDIR); + + free (prefix_dir); + } + (void) textdomain ("gcc"); /* Opening quotation mark. */ diff --git a/gcc/intl.h b/gcc/intl.h index 91e7440..84b9d58 100644 --- a/gcc/intl.h +++ b/gcc/intl.h @@ -30,6 +30,7 @@ #include extern void gcc_init_libintl (void); extern size_t gcc_gettext_width (const char *); +extern void gcc_init_libintl_program (const char *); #else /* Stubs. */ # undef textdomain @@ -41,6 +42,7 @@ extern size_t gcc_gettext_width (const char *); # define ngettext(singular,plural,n) fake_ngettext (singular, plural, n) # define gcc_init_libintl() /* nothing */ # define gcc_gettext_width(s) strlen (s) +# define gcc_init_libintl_program (s) /* Nothing. */ extern const char *fake_ngettext (const char *singular, const char *plural, unsigned long int n);