From 12a1392fc96e32ed6d55208a2a7fc040617a9cb7 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 15 Jan 2010 22:20:56 -0800 Subject: Integrate gettext support with autotools build system Signed-off-by: Alan Coopersmith --- Makefile.am | 9 +++++++++ acinclude.m4 | 47 +++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 19 +++++++++++++++++++ xfd.c | 14 +++++++++++--- 4 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 acinclude.m4 diff --git a/Makefile.am b/Makefile.am index e8a16a3..26b8a83 100644 --- a/Makefile.am +++ b/Makefile.am @@ -85,3 +85,12 @@ ChangeLog: $(CHANGELOG_CMD) dist-hook: ChangeLog INSTALL + +if USE_GETTEXT +noinst_DATA = xfd.po + +xfd.po: $(xfd_SOURCES:%=$(srcdir)/%) + $(AM_V_GEN)xgettext -d xfd -n $(xfd_SOURCES:%=$(srcdir)/%) + +CLEANFILES += xfd.po +endif diff --git a/acinclude.m4 b/acinclude.m4 new file mode 100644 index 0000000..8e80584 --- /dev/null +++ b/acinclude.m4 @@ -0,0 +1,47 @@ +# =========================================================================== +# http://www.nongnu.org/autoconf-archive/ax_define_dir.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_DEFINE_DIR(VARNAME, DIR [, DESCRIPTION]) +# +# DESCRIPTION +# +# This macro sets VARNAME to the expansion of the DIR variable, taking +# care of fixing up ${prefix} and such. +# +# VARNAME is then offered as both an output variable and a C preprocessor +# symbol. +# +# Example: +# +# AX_DEFINE_DIR([DATADIR], [datadir], [Where data are placed to.]) +# +# LICENSE +# +# Copyright (c) 2008 Stepan Kasal +# Copyright (c) 2008 Andreas Schwab +# Copyright (c) 2008 Guido U. Draheim +# Copyright (c) 2008 Alexandre Oliva +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +AU_ALIAS([AC_DEFINE_DIR], [AX_DEFINE_DIR]) +AC_DEFUN([AX_DEFINE_DIR], [ + prefix_NONE= + exec_prefix_NONE= + test "x$prefix" = xNONE && prefix_NONE=yes && prefix=$ac_default_prefix + test "x$exec_prefix" = xNONE && exec_prefix_NONE=yes && exec_prefix=$prefix +dnl In Autoconf 2.60, ${datadir} refers to ${datarootdir}, which in turn +dnl refers to ${prefix}. Thus we have to use `eval' twice. + eval ax_define_dir="\"[$]$2\"" + eval ax_define_dir="\"$ax_define_dir\"" + AC_SUBST($1, "$ax_define_dir") + AC_DEFINE_UNQUOTED($1, "$ax_define_dir", [$3]) + test "$prefix_NONE" && prefix=NONE + test "$exec_prefix_NONE" && exec_prefix=NONE +]) diff --git a/configure.ac b/configure.ac index 21c5d7c..173d881 100644 --- a/configure.ac +++ b/configure.ac @@ -38,6 +38,25 @@ AC_PROG_CC AM_PROG_CC_C_O AC_PROG_INSTALL +# Internationalization & localization support +AC_SEARCH_LIBS([gettext], [intl], [USE_GETTEXT="yes"], [USE_GETTEXT="no"]) +AC_MSG_CHECKING([where to install localized messages]) +AC_ARG_WITH([localedir], AS_HELP_STRING([--with-localedir=], + [Path to install message files in (default: datadir/locale)]), + [LOCALEDIR=${withval}], [LOCALEDIR=${datadir}/locale]) +AX_DEFINE_DIR([LOCALEDIR], [LOCALEDIR], [Location of translated messages]) +if test "x$LOCALEDIR" = "xno" -o "x$USE_GETTEXT" = "xno" ; then + AC_MSG_RESULT([nowhere]) + USE_GETTEXT="no" +else + AC_MSG_RESULT([$LOCALEDIR]) +fi + +if test "x$USE_GETTEXT" = "xyes" ; then + AC_DEFINE([USE_GETTEXT], 1, + [Define to 1 if you want to use the gettext() function.]) +fi +AM_CONDITIONAL(USE_GETTEXT, test "x$USE_GETTEXT" = "xyes") # Checks for pkg-config packages PKG_CHECK_MODULES(XAW, xaw7) diff --git a/xfd.c b/xfd.c index 3879d0d..aa1f4a6 100644 --- a/xfd.c +++ b/xfd.c @@ -28,6 +28,10 @@ in this Software without prior written authorization from The Open Group. */ /* $XFree86: xc/programs/xfd/xfd.c,v 1.8 2003/02/20 02:56:40 dawes Exp $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include #include @@ -40,8 +44,12 @@ in this Software without prior written authorization from The Open Group. #include #include #include -#include -#include +#ifdef USE_GETTEXT +# include +# include +#else +# define gettext(a) (a) +#endif #include "grid.h" #ifdef XRENDER #include @@ -192,7 +200,7 @@ main(int argc, char *argv[]) /* mainly for debugging */ if ((domaindir = getenv ("TEXTDOMAINDIR")) == NULL) { - domaindir = "/usr/share/locale"; + domaindir = LOCALEDIR; } bindtextdomain ("xfd", domaindir); -- cgit v1.2.3