This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

message translation fixes


This patch should resolve the problems with libintl.h not being found
on systems that don't have gettext in libc.  Also, I factored out some
common setup logic from a bunch of places to intl.c.

Built stage1 with and without --with-included-gettext; bootstrap is
proceeding now.  I would appreciate testing on non-glibc-based
systems.  (Don't forget to re-run autoconf and autoheader after
applying the patch.)

zw

	* aclocal.m4 (AM_WITH_NLS): AC_DEFINE HAVE_LIBINTL_H and
	USE_INCLUDED_LIBINTL when appropriate.
	* configure, config.in: Regenerate.
	* Makefile.in (datadir): Set to @datadir@.
	(intl.o): Also depend on $(CONFIG_H) and system.h.

	* intl.c: Factor out common gettext initialization sequence.
	(gcc_init_libintl):  New function.
	* intl.h: Include intl/libgnuintl.h if USE_INCLUDED_LIBINTL;
	otherwise include libintl.h if HAVE_LIBINTL_H; otherwise turn
	off NLS.  Add multiple include guard.  No need to #ifdef-guard
	an #undef.  Prototype gcc_init_libintl here.

	* collect2.c (main), cppmain.c (general_init), gcc.c (main),
	gcov.c (main), protoize.c (main), toplev.c (toplev_main):
	Use gcc_init_libintl.

intl:
	* Makefile.in: Don't copy libgnuintl.h anywhere.


===================================================================
Index: Makefile.in
--- Makefile.in	2001/10/12 17:24:27	1.751
+++ Makefile.in	2001/10/14 01:08:14
@@ -313,7 +313,7 @@ infodir = @infodir@
 # Where cpp should go besides $prefix/bin if necessary
 cpp_install_dir = @cpp_install_dir@
 # where the locale files go
-datadir = $(prefix)/@DATADIRNAME@
+datadir = @datadir@
 localedir = $(datadir)/locale
 # Extension (if any) to put in installed man-page filename.
 manext = .1
@@ -1962,8 +1962,7 @@ $(HOST_PREFIX_1)ggc-none.o: ggc-none.c $
 
 #
 # Remake internationalization support.
-
-intl.o: intl.c intl.h Makefile
+intl.o: intl.c $(CONFIG_H) system.h intl.h Makefile
 	$(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
 	  -DLOCALEDIR=\"$(localedir)\" \
 	  -c $(srcdir)/intl.c
===================================================================
Index: aclocal.m4
--- aclocal.m4	2001/10/12 17:24:27	1.52
+++ aclocal.m4	2001/10/14 01:08:14
@@ -1406,8 +1406,11 @@ AC_DEFUN([AM_WITH_NLS],
         define(gt_cv_func_gnugettext_libc, [gt_cv_func_gnugettext]ifelse([$2], need-ngettext, 2, 1)[_libc])
         define(gt_cv_func_gnugettext_libintl, [gt_cv_func_gnugettext]ifelse([$2], need-ngettext, 2, 1)[_libintl])
 
+dnl GCC LOCAL: Expose presence of libintl.h to C code.
 	AC_CHECK_HEADER(libintl.h,
-	  [AC_CACHE_CHECK([for GNU gettext in libc], gt_cv_func_gnugettext_libc,
+	  [AC_DEFINE([HAVE_LIBINTL_H], 1,
+		[Define if you have the <libintl.h> header file.])
+           AC_CACHE_CHECK([for GNU gettext in libc], gt_cv_func_gnugettext_libc,
 	    [AC_TRY_LINK([#include <libintl.h>
 extern int _nl_msg_cat_cntr;],
 	       [bindtextdomain ("", "");
@@ -1605,6 +1608,12 @@ changequote([,])dnl
     AC_SUBST(INTLOBJS)
     AC_SUBST(POFILES)
     AC_SUBST(POSUB)
+dnl GCC LOCAL: Make USE_INCLUDED_LIBINTL visible to C code.
+    if test $USE_INCLUDED_LIBINTL = yes; then
+      AC_DEFINE([USE_INCLUDED_LIBINTL], 1,
+  [Define to use the libintl included with this package instead of any
+   version in the system libraries.])
+    fi
 
     dnl For backward compatibility. Some configure.ins may be using this.
     nls_cv_header_intl=
===================================================================
Index: collect2.c
--- collect2.c	2001/10/11 03:15:24	1.122
+++ collect2.c	2001/10/14 01:08:15
@@ -873,18 +873,7 @@ main (argc, argv)
   signal (SIGCHLD, SIG_DFL);
 #endif
 
-/* LC_CTYPE determines the character set used by the terminal so it has be set
-   to output messages correctly.  */
-
-#ifdef HAVE_LC_MESSAGES
-  setlocale (LC_CTYPE, "");
-  setlocale (LC_MESSAGES, "");
-#else
-  setlocale (LC_ALL, "");
-#endif
-
-  (void) bindtextdomain (PACKAGE, localedir);
-  (void) textdomain (PACKAGE);
+  gcc_init_libintl ();
 
   /* Do not invoke xcalloc before this point, since locale needs to be
      set first, in case a diagnostic is issued.  */
===================================================================
Index: cppmain.c
--- cppmain.c	2001/10/12 22:30:54	1.83
+++ cppmain.c	2001/10/14 01:08:17
@@ -100,18 +100,7 @@ general_init (argv0)
 
   xmalloc_set_program_name (progname);
 
-/* LC_CTYPE determines the character set used by the terminal so it
-   has to be set to output messages correctly.  */
-
-#ifdef HAVE_LC_MESSAGES
-  setlocale (LC_CTYPE, "");
-  setlocale (LC_MESSAGES, "");
-#else
-  setlocale (LC_ALL, "");
-#endif
-
-  (void) bindtextdomain (PACKAGE, localedir);
-  (void) textdomain (PACKAGE);
+  gcc_init_libintl ();
 }
 
 /* Handle switches, preprocess and output.  */
===================================================================
Index: gcc.c
--- gcc.c	2001/10/11 03:15:40	1.258
+++ gcc.c	2001/10/14 01:08:18
@@ -5559,18 +5559,7 @@ main (argc, argv)
   GCC_DRIVER_HOST_INITIALIZATION;
 #endif
 
-/* LC_CTYPE determines the character set used by the terminal so it has be set
-   to output messages correctly.  */
-
-#ifdef HAVE_LC_MESSAGES
-  setlocale (LC_CTYPE, "");
-  setlocale (LC_MESSAGES, "");
-#else
-  setlocale (LC_ALL, "");
-#endif
-
-  (void) bindtextdomain (PACKAGE, localedir);
-  (void) textdomain (PACKAGE);
+  gcc_init_libintl ();
 
   if (signal (SIGINT, SIG_IGN) != SIG_IGN)
     signal (SIGINT, fatal_error);
===================================================================
Index: gcov.c
--- gcov.c	2001/10/09 06:02:57	1.37
+++ gcov.c	2001/10/14 01:08:18
@@ -243,18 +243,7 @@ main (argc, argv)
      int argc;
      char **argv;
 {
-/* LC_CTYPE determines the character set used by the terminal so it has be set
-   to output messages correctly.  */
-
-#ifdef HAVE_LC_MESSAGES
-  setlocale (LC_CTYPE, "");
-  setlocale (LC_MESSAGES, "");
-#else
-  setlocale (LC_ALL, "");
-#endif
-
-  (void) bindtextdomain (PACKAGE, localedir);
-  (void) textdomain (PACKAGE);
+  gcc_init_libintl ();
 
   process_args (argc, argv);
 
===================================================================
Index: intl.c
--- intl.c	2001/04/04 00:46:26	1.3
+++ intl.c	2001/10/14 01:08:18
@@ -1,6 +1,46 @@
-/* intl.c - internationalization */
+/* Message translation utilities.
+   Copyright (C) 2001 Free Software Foundation, Inc.
 
-#include "ansidecl.h"
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.  */
+
+#include "config.h"
+#include "system.h"
 #include "intl.h"
+
+#ifdef ENABLE_NLS
+
+/* Initialize the translation library for GCC.  This performs the
+   appropriate sequence of calls - setlocale, bindtextdomain,
+   textdomain.  LC_CTYPE determines the character set used by the
+   terminal, so it has be set to output messages correctly.  */
+
+void
+gcc_init_libintl ()
+{
+#ifdef HAVE_LC_MESSAGES
+  setlocale (LC_CTYPE, "");
+  setlocale (LC_MESSAGES, "");
+#else
+  setlocale (LC_ALL, "");
+#endif
+
+  (void) bindtextdomain (PACKAGE, LOCALEDIR);
+  (void) textdomain (PACKAGE);
+}
 
-const char localedir[] = LOCALEDIR;
+#endif
===================================================================
Index: intl.h
--- intl.h	2001/10/09 22:40:12	1.3
+++ intl.h	2001/10/14 01:08:18
@@ -1,5 +1,5 @@
 /* intl.h - internationalization
-   Copyright 1998 Free Software Foundation, Inc.
+   Copyright 1998, 2001 Free Software Foundation, Inc.
 
    GCC is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -16,6 +16,9 @@
    Software Foundation, 59 Temple Place - Suite 330, Boston, MA
    02111-1307, USA.  */
 
+#ifndef GCC_INTL_H
+#define GCC_INTL_H
+
 #ifdef HAVE_LOCALE_H
 # include <locale.h>
 #endif
@@ -24,23 +27,27 @@
 # define setlocale(category, locale) (locale)
 #endif
 
-#ifdef ENABLE_NLS
-# include <libintl.h>
-  extern const char localedir[];
+#ifdef USE_INCLUDED_LIBINTL
+# include <intl/libgnuintl.h>
 #else
-/* Stubs that do something close enough.  */
-# ifdef textdomain
-#  undef textdomain
+# ifdef HAVE_LIBINTL_H
+#  include <libintl.h>
+# else
+#  undef ENABLE_NLS
 # endif
+#endif
+
+#ifdef ENABLE_NLS
+extern void gcc_init_libintl PARAMS ((void));
+#else
+/* Stubs.  */
+# undef textdomain
 # define textdomain(domain) (domain)
-# ifdef bindtextdomain
-#  undef bindtextdomain
-# endif
+# undef bindtextdomain
 # define bindtextdomain(domain, directory) (domain)
-# ifdef gettext
-#  undef gettext
-# endif
+# undef gettext
 # define gettext(msgid) (msgid)
+# define gcc_init_libintl()	/* nothing */
 #endif
 
 #ifndef _
@@ -50,3 +57,5 @@
 #ifndef N_
 # define N_(msgid) (msgid)
 #endif
+
+#endif /* intl.h */
===================================================================
Index: protoize.c
--- protoize.c	2001/10/10 11:33:27	1.66
+++ protoize.c	2001/10/14 01:08:19
@@ -4584,18 +4584,7 @@ main (argc, argv)
   signal (SIGCHLD, SIG_DFL);
 #endif
 
-/* LC_CTYPE determines the character set used by the terminal so it has be set
-   to output messages correctly.  */
-
-#ifdef HAVE_LC_MESSAGES
-  setlocale (LC_CTYPE, "");
-  setlocale (LC_MESSAGES, "");
-#else
-  setlocale (LC_ALL, "");
-#endif
-
-  (void) bindtextdomain (PACKAGE, localedir);
-  (void) textdomain (PACKAGE);
+  gcc_init_libintl ();
 
   cwd_buffer = getpwd ();
   if (!cwd_buffer)
===================================================================
Index: toplev.c
--- toplev.c	2001/10/12 03:34:39	1.520
+++ toplev.c	2001/10/14 01:08:21
@@ -4622,18 +4622,7 @@ toplev_main (argc, argv)
 
   xmalloc_set_program_name (progname);
 
-/* LC_CTYPE determines the character set used by the terminal so it has be set
-   to output messages correctly.  */
-
-#ifdef HAVE_LC_MESSAGES
-  setlocale (LC_CTYPE, "");
-  setlocale (LC_MESSAGES, "");
-#else
-  setlocale (LC_ALL, "");
-#endif
-
-  (void) bindtextdomain (PACKAGE, localedir);
-  (void) textdomain (PACKAGE);
+  gcc_init_libintl ();
 
   /* Install handler for SIGFPE, which may be received while we do
      compile-time floating point arithmetic.  */
===================================================================
Index: intl/Makefile.in
--- intl/Makefile.in	2001/10/12 17:24:30	1.4
+++ intl/Makefile.in	2001/10/14 01:08:22
@@ -105,8 +105,9 @@ LTV_AGE=0
 INCLUDES = -I.. -I. -I$(top_srcdir)/intl -I$(top_srcdir) \
 	   -I$(top_srcdir)/config -I$(top_srcdir)/../include
 
+# GCC LOCAL: Removed libintl.h from all-yes.
 all: all-@USE_INCLUDED_LIBINTL@
-all-yes: libintl.$la libintl.h charset.alias ref-add.sed ref-del.sed
+all-yes: libintl.$la charset.alias ref-add.sed ref-del.sed
 all-no: all-no-@BUILD_INCLUDED_LIBINTL@
 all-no-yes: libgnuintl.$la
 all-no-no:
@@ -124,8 +125,9 @@ libintl.la libgnuintl.la: $(OBJECTS)
 	  -rpath $(libdir) \
 	  -no-undefined
 
-libintl.h: libgnuintl.h
-	cp $(srcdir)/libgnuintl.h libintl.h
+#GCC LOCAL: Do not install this file.
+#libintl.h: libgnuintl.h
+#	cp $(srcdir)/libgnuintl.h libintl.h
 
 charset.alias: config.charset
 	$(SHELL) $(srcdir)/config.charset '@host@' > t-$@


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]