Skip to contentSkip to conversation

Compilation with external intl library

PATCH New Yves Blusseau 2 participants 6 messages Dec 31, 2009 – Jan 1, 2010 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Compilation with external intl library

Hi,

this is the NEW patch to "fix" compilation with external intl library. It fix the #28356 bug (http://savannah.gnu.org/bugs/?28356).

I follow strictly the guideline of gettext, and now we can compile grub with external intl library.

Some enhancements;
- We can disable NLS (Native Language Support) with the --disable-nls configure flag.
- We can choose where the external intl library is with the --with-libintl-prefix configure flag.

Under linux the gettext macro detect that the gettext function is in libc and so don't add any flags (like before).
On other platform like Mac OSX, the macro add the proper compile and link flags (ex: -lintl -liconv -lc -Wl,-framework -Wl,CoreFoundation in OSX)

Best Regards,
Yves Blusseau

PS: if it ok i'll commit this patch and will add another one to make on error if the intl library can't be use and show alternative to compile grub.

---

 ChangeLog.bad-cast                      |    6 
 ChangeLog.config.rpath                  |    5 
 ChangeLog.intl                          |   27 +
 Makefile.in                             |    7 
 conf/common.rmk                         |    2 
 config.rpath                            |  666 +++++++++++++++++++++++++++++++
 configure.ac                            |    2 
 include/grub/i18n.h                     |   36 +-
 include/grub/util/misc.h                |    2 
 util/grub-editenv.c                     |    5 
 util/grub-emu.c                         |    5 
 util/grub-fstest.c                      |    5 
 util/grub-probe.c                       |    5 
 util/i386/pc/grub-setup.c               |    5 
 util/misc.c                             |   11 +
 util/mkisofs/mkisofs.c                  |    7 
 util/mkisofs/mkisofs.h                  |    5 
 util/sparc64/ieee1275/grub-ofpathname.c |    5 
 util/sparc64/ieee1275/grub-setup.c      |    5 
 19 files changed, 773 insertions(+), 38 deletions(-)
 create mode 100644 ChangeLog.bad-cast
 create mode 100644 ChangeLog.config.rpath
 create mode 100644 ChangeLog.intl
 create mode 100644 config.rpath
Signature · 1 line
Yves Blusseau
#1 lore raw

PATCH 1/3 Compilation with external intl library

From: Yves <[email protected]>

2009-12-31 Yves Blusseau <[email protected]>

* config.rpath: new file used to configure compilation with NLS

---
 ChangeLog.config.rpath |    5 
 config.rpath           |  666 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 671 insertions(+), 0 deletions(-)
 create mode 100644 ChangeLog.config.rpath
 create mode 100644 config.rpath
ChangeLog.config.rpath new file +5 -0
new file mode 100644
index 0000000..e7d7347
@@ -0,0 +1,5 @@
+Compilation with external intl library
+
+2009-12-31  Yves Blusseau  <[email protected]>
+
+	* config.rpath: new file used to configure compilation with NLS
config.rpath new file +666 -0

666 lines not on this page · raw message

#2 lore raw

PATCH 2/3 Compilation with external intl library

In reply to Yves Blusseau

2009-12-31 Yves Blusseau <[email protected]>

* configure.ac: check external intl library
* Makefile.in: add compiler and linker flags to properly compile with intl library
* include/grub/i18n.h: add a check to disable NLS
* util/misc.c (grub_util_init_nls): new function
* include/grub/util/misc.h: likewise
* conf/common.rmk (grub_mkisofs_SOURCES): adding grub/misc.c to dependencies
* util/elf/grub-mkimage.c: use the new function below to initialize NLS
* util/grub-editenv.c: likewise
* util/grub-emu.c: likewise
* util/grub-fstest.c: likewise
* util/grub-mkdevicemap.c: likewise
* util/grub-mkfont.c: likewise
* util/grub-mkrelpath.c: likewise
* util/grub-probe.c: likewise
* util/i386/pc/grub-mkimage.c: likewise
* util/i386/pc/grub-setup.c: likewise
* util/sparc64/ieee1275/grub-mkimage.c: likewise
* util/sparc64/ieee1275/grub-ofpathname.c: likewise
* util/sparc64/ieee1275/grub-setup.c: likewise
* util/mkisofs/mkisofs.c: likewise
* util/mkisofs/mkisofs.h: use the new i18n.h header

---
 ChangeLog.intl                          |   27 +++++++++++++++++++++++
 Makefile.in                             |    7 +++++-
 conf/common.rmk                         |    2 ++
 configure.ac                            |    2 +-
 include/grub/i18n.h                     |   36 +++++++++++++++++++++++++------
 include/grub/util/misc.h                |    2 ++
 util/grub-editenv.c                     |    5 ++--
 util/grub-emu.c                         |    5 ++--
 util/grub-fstest.c                      |    5 ++--
 util/grub-probe.c                       |    5 ++--
 util/i386/pc/grub-setup.c               |    5 ++--
 util/misc.c                             |   11 +++++++++
 util/mkisofs/mkisofs.c                  |    5 ++--
 util/mkisofs/mkisofs.h                  |    5 +---
 util/sparc64/ieee1275/grub-ofpathname.c |    5 ++--
 util/sparc64/ieee1275/grub-setup.c      |    5 ++--
 16 files changed, 95 insertions(+), 37 deletions(-)
 create mode 100644 ChangeLog.intl
ChangeLog.intl new file +27 -0
new file mode 100644
index 0000000..42a1014
@@ -0,0 +1,27 @@
+Compilation with external intl library
+
+2009-12-31  Yves Blusseau  <[email protected]>
+
+	* configure.ac: check external intl library
+	* Makefile.in: add compiler and linker flags to properly compile with
+	intl library
+	* include/grub/i18n.h: add a check to disable NLS
+	* util/misc.c (grub_util_init_nls): new function
+	* include/grub/util/misc.h: likewise
+	* conf/common.rmk (grub_mkisofs_SOURCES): adding grub/misc.c to
+	dependencies
+	* util/elf/grub-mkimage.c: use the new function below to initialize NLS
+	* util/grub-editenv.c: likewise
+	* util/grub-emu.c: likewise
+	* util/grub-fstest.c: likewise
+	* util/grub-mkdevicemap.c: likewise
+	* util/grub-mkfont.c: likewise
+	* util/grub-mkrelpath.c: likewise
+	* util/grub-probe.c: likewise
+	* util/i386/pc/grub-mkimage.c: likewise
+	* util/i386/pc/grub-setup.c: likewise
+	* util/sparc64/ieee1275/grub-mkimage.c: likewise
+	* util/sparc64/ieee1275/grub-ofpathname.c: likewise
+	* util/sparc64/ieee1275/grub-setup.c: likewise
+	* util/mkisofs/mkisofs.c: likewise
+	* util/mkisofs/mkisofs.h: use the new i18n.h header
Makefile.in +6 -1
index 46b380c..62e38dc 100644
@@ -41,6 +41,9 @@ includedir = @includedir@
 pkgdatadir = $(datadir)/`echo @PACKAGE_TARNAME@ | sed '$(transform)'`
 pkglibdir =  $(libdir)/`echo @PACKAGE_TARNAME@/$(target_cpu)-$(platform) | sed '$(transform)'`
 
+# Internationalization library.
+LIBINTL = @LIBINTL@
+
 XGETTEXT = @XGETTEXT@
 MSGMERGE = @MSGMERGE@
 MSGFMT = @MSGFMT@
@@ -72,10 +75,12 @@ MKDIR_P = @MKDIR_P@
 
 mkinstalldirs = $(srcdir)/mkinstalldirs
 
+LIBS = @LIBS@ $(LIBINTL)
+
 CC = @CC@
 CFLAGS = @CFLAGS@
 ASFLAGS = @ASFLAGS@
-LDFLAGS = @LDFLAGS@
+LDFLAGS = @LDFLAGS@ $(LIBS)
 CPPFLAGS = @CPPFLAGS@ -I$(builddir) -I$(builddir)/include -I$(srcdir)/gnulib -I$(srcdir)/include -Wall -W \
 	 -DGRUB_LIBDIR=\"$(pkglibdir)\" -DLOCALEDIR=\"$(localedir)\"
 TARGET_CC = @TARGET_CC@
conf/common.rmk +2 -0
index 4fd0057..8a71c33 100644
@@ -48,6 +48,8 @@ grub_mkisofs_SOURCES = util/mkisofs/eltorito.c 				\
 	util/mkisofs/rock.c util/mkisofs/tree.c				\
 	util/mkisofs/write.c						\
 	\
+	util/misc.c 	\
+	\
 	gnulib/fnmatch.c gnulib/getopt1.c gnulib/getopt.c		\
 	gnulib/error.c gnulib/progname.c
 grub_mkisofs_CFLAGS = -D_FILE_OFFSET_BITS=64 				\
configure.ac +1 -1
index 3cac421..63ea844 100644
@@ -178,7 +178,7 @@ AC_PROG_CC
 test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required])
 
 AC_GNU_SOURCE
-AM_GNU_GETTEXT
+AM_GNU_GETTEXT([external])
 AC_SYS_LARGEFILE
 
 # Identify characteristics of the host architecture.
include/grub/i18n.h +29 -7
index f6f4687..273caeb 100644
@@ -19,17 +19,39 @@
 #ifndef	GRUB_I18N_H
 #define	GRUB_I18N_H	1
 
-#ifdef GRUB_UTIL
-# include <locale.h>
-# include <libintl.h>
-# define _(str) gettext(str)
-#else
-# define _(str) grub_gettext(str)
+#include <config.h>
+#include <grub/symbol.h>
 
 const char *EXPORT_FUNC(grub_gettext_dummy) (const char *s);
 extern const char *(*EXPORT_VAR(grub_gettext)) (const char *s);
 
-#endif
+/* NLS can be disabled through the configure --disable-nls option.  */
+#if ENABLE_NLS
+
+# ifdef GRUB_UTIL
+
+#  include <locale.h>
+#  include <libintl.h>
+
+# endif /* GRUB_UTIL */
+
+#else /* ! ENABLE_NLS */
+
+/* Disabled NLS.
+   The casts to 'const char *' serve the purpose of producing warnings
+   for invalid uses of the value returned from these functions.
+   On pre-ANSI systems without 'const', the config.h file is supposed to
+   contain "#define const".  */
+# define gettext(Msgid) ((const char *) (Msgid))
+# define grub_gettext(str) ((const char *) (str))
+
+#endif /* ENABLE_NLS */
+
+#ifdef GRUB_UTIL
+# define _(str) gettext(str)
+#else
+# define _(str) grub_gettext(str)
+#endif /* GRUB_UTIL */
 
 #define N_(str) str
 
include/grub/util/misc.h +2 -0
index 0910854..b454480 100644
@@ -88,4 +88,6 @@ grub_int64_t grub_util_get_disk_size (char *name);
 
 char *make_system_path_relative_to_its_root (const char *path);
 
+void grub_util_init_nls (void);
+
 #endif /* ! GRUB_UTIL_MISC_HEADER */
util/grub-editenv.c +2 -3
index 68fb23b..7718b6d 100644
@@ -256,9 +256,8 @@ main (int argc, char *argv[])
   char *command;
 
   set_program_name (argv[0]);
-  setlocale (LC_ALL, "");
-  bindtextdomain (PACKAGE, LOCALEDIR);
-  textdomain (PACKAGE);
+
+  grub_util_init_nls();
 
   /* Check for options.  */
   while (1)
util/grub-emu.c +2 -3
index e65c858..9214c9a 100644
@@ -159,9 +159,8 @@ main (int argc, char *argv[])
   int opt;
 
   set_program_name (argv[0]);
-  setlocale (LC_ALL, "");
-  bindtextdomain (PACKAGE, LOCALEDIR);
-  textdomain (PACKAGE);
+
+  grub_util_init_nls();
 
   while ((opt = getopt_long (argc, argv, "r:d:m:vH:hV", options, 0)) != -1)
     switch (opt)
util/grub-fstest.c +2 -3
index fa54fe4..d1cc757 100644
@@ -384,9 +384,8 @@ main (int argc, char *argv[])
   int i, cmd, num_opts, image_index, num_disks = 1;
 
   set_program_name (argv[0]);
-  setlocale (LC_ALL, "");
-  bindtextdomain (PACKAGE, LOCALEDIR);
-  textdomain (PACKAGE);
+
+  grub_util_init_nls();
 
   /* Find the first non option entry.  */
   for (num_opts = 1; num_opts < argc; num_opts++)
util/grub-probe.c +2 -3
index ebf5142..27195d3 100644
@@ -338,9 +338,8 @@ main (int argc, char *argv[])
   char *argument;
 
   set_program_name (argv[0]);
-  setlocale (LC_ALL, "");
-  bindtextdomain (PACKAGE, LOCALEDIR);
-  textdomain (PACKAGE);
+
+  grub_util_init_nls();
 
   /* Check for options.  */
   while (1)
util/i386/pc/grub-setup.c +2 -3
index c2b9b92..cffec9a 100644
@@ -641,9 +641,8 @@ main (int argc, char *argv[])
   int must_embed = 0, force = 0, fs_probe = 1;
 
   set_program_name (argv[0]);
-  setlocale (LC_ALL, "");
-  bindtextdomain (PACKAGE, LOCALEDIR);
-  textdomain (PACKAGE);
+
+  grub_util_init_nls();
 
   /* Check for options.  */
   while (1)
util/misc.c +11 -0
index 6aa92fb..d838fcd 100644
@@ -38,6 +38,7 @@
 #include <grub/mm.h>
 #include <grub/term.h>
 #include <grub/time.h>
+#include <grub/i18n.h>
 
 #include "progname.h"
 
@@ -566,3 +567,13 @@ make_system_path_relative_to_its_root (const char *path)
 
   return buf3;
 }
+
+void
+grub_util_init_nls (void)
+{
+#if ENABLE_NLS
+  setlocale (LC_ALL, "");
+  bindtextdomain (PACKAGE, LOCALEDIR);
+  textdomain (PACKAGE);
+#endif /* ENABLE_NLS */
+}
util/mkisofs/mkisofs.c +2 -3
index 8e99d5c..4ed091b 100644
@@ -645,9 +645,8 @@ int FDECL2(main, int, argc, char **, argv){
   char *log_file = 0;
 
   set_program_name (argv[0]);
-  setlocale (LC_ALL, "");
-  bindtextdomain (PACKAGE, LOCALEDIR);
-  textdomain (PACKAGE);
+
+  grub_util_init_nls();
 
   if (argc < 2)
     usage();
util/mkisofs/mkisofs.h +1 -4
index 79ae502..55b4aa6 100644
@@ -30,10 +30,7 @@
 #include <prototyp.h>
 #include <sys/stat.h>
 
-#include <locale.h>
-#include <libintl.h>
-#define _(str) gettext(str)
-#define N_(str) str
+#include <grub/i18n.h>
 
 /* This symbol is used to indicate that we do not have things like
    symlinks, devices, and so forth available.  Just files and dirs */
util/sparc64/ieee1275/grub-ofpathname.c +2 -3
index 166ce4c..9f5bc39 100644
@@ -29,9 +29,8 @@ int main(int argc, char **argv)
   char *of_path;
 
   set_program_name (argv[0]);
-  setlocale (LC_ALL, "");
-  bindtextdomain (PACKAGE, LOCALEDIR);
-  textdomain (PACKAGE);
+
+  grub_util_init_nls();
 
   if (argc != 2)
     {
util/sparc64/ieee1275/grub-setup.c +2 -3
index ade1bd5..6f205b6 100644
@@ -620,9 +620,8 @@ main (int argc, char *argv[])
   struct grub_setup_info ginfo;
 
   set_program_name (argv[0]);
-  setlocale (LC_ALL, "");
-  bindtextdomain (PACKAGE, LOCALEDIR);
-  textdomain (PACKAGE);
+
+  grub_util_init_nls();
 
   init_info (&ginfo);
   if (!parse_options (&ginfo, argc, argv))
#3 lore raw

include/grub/i18n.h line 46

Quoted 7 lines · Yves Blusseau
include/grub/i18n.h +7 -0
+/* Disabled NLS.
+   The casts to 'const char *' serve the purpose of producing warnings
+   for invalid uses of the value returned from these functions.
+   On pre-ANSI systems without 'const', the config.h file is supposed to
+   contain "#define const".  */
+# define gettext(Msgid) ((const char *) (Msgid))
+# define grub_gettext(str) ((const char *) (str))

This should have #ifdef GRUB_UTIL / #else.

Quoted 1 line

+ grub_util_init_nls();

Please add a space in-between (in this and other calls).

util/mkisofs/mkisofs.h line 33

Quoted 13 lines
util/mkisofs/mkisofs.h +1 -4
index 79ae502..55b4aa6 100644
@@ -30,10 +30,7 @@
 #include <prototyp.h>
 #include <sys/stat.h>
 
-#include <locale.h>
-#include <libintl.h>
-#define _(str) gettext(str)
-#define N_(str) str
+#include <grub/i18n.h>

Please don't make mkisofs depend on GRUB headers. It's a bit confusing, but mkisofs is supposed to be a separate package.

Signature · 3 lines
Robert Millan

  "Be the change you want to see in the world" -- Gandhi
#4 lore raw

PATCH 3/3 Compilation with external intl library

In reply to Yves Blusseau

2009-12-31 Yves Blusseau <[email protected]>

* util/mkisofs/mkisofs.c: fix a warning about a bad cast when NLS is disabled

---
 ChangeLog.bad-cast     |    6 ++++++
 util/mkisofs/mkisofs.c |    2 +-
 2 files changed, 7 insertions(+), 1 deletions(-)
 create mode 100644 ChangeLog.bad-cast
ChangeLog.bad-cast new file +6 -0
new file mode 100644
index 0000000..97ee16b
@@ -0,0 +1,6 @@
+Compilation with external intl library
+
+2009-12-31  Yves Blusseau  <[email protected]>
+
+	* util/mkisofs/mkisofs.c: fix a warning about a bad cast when NLS
+	is disabled
util/mkisofs/mkisofs.c +1 -1
index 4ed091b..57e77dd 100644
@@ -490,7 +490,7 @@ void usage(){
 	  int comma;
 	  int len;
 	  unsigned int j;
-	  char *arg;
+	  const char *arg;
 
 	  printf ("  ");
 
#5 lore raw
Quoted 27 lines · Yves Blusseau

2009-12-31 Yves Blusseau <[email protected]>

* util/mkisofs/mkisofs.c: fix a warning about a bad cast when NLS is disabled

---
 ChangeLog.bad-cast     |    6 ++++++
 util/mkisofs/mkisofs.c |    2 +-
 2 files changed, 7 insertions(+), 1 deletions(-)
 create mode 100644 ChangeLog.bad-cast
ChangeLog.bad-cast new file +6 -0
new file mode 100644
index 0000000..97ee16b
@@ -0,0 +1,6 @@
+Compilation with external intl library
+
+2009-12-31  Yves Blusseau  <[email protected]>
+
+	* util/mkisofs/mkisofs.c: fix a warning about a bad cast when NLS
+	is disabled
util/mkisofs/mkisofs.c +0 -0
index 4ed091b..57e77dd 100644

util/mkisofs/mkisofs.c void usage(){ · line 495

Quoted 7 lines
util/mkisofs/mkisofs.c +1 -1
@@ -490,7 +490,7 @@ void usage(){
 	  int comma;
 	  int len;
 	  unsigned int j;
-	  char *arg;
+	  const char *arg;
 
 	  printf ("  ");

This is fine. In the future, feel free to commit this kind of obvious cleanup directly.

Thanks!

Signature · 3 lines
Robert Millan

  "Be the change you want to see in the world" -- Gandhi