Include a printf implementation supporting C99 snprintf and SUS
[platform/upstream/glib.git] / acinclude.m4
index e4b70de..a969c70 100644 (file)
@@ -85,29 +85,39 @@ AC_DEFUN(AM_GLIB_WITH_NLS,
       nls_cv_header_intl=
       nls_cv_header_libgt=
       CATOBJEXT=NONE
+      XGETTEXT=:
 
       AC_CHECK_HEADER(libintl.h,
         [AC_CACHE_CHECK([for dgettext in libc], gt_cv_func_dgettext_libc,
          [AC_TRY_LINK([#include <libintl.h>], [return (int) dgettext ("","")],
            gt_cv_func_dgettext_libc=yes, gt_cv_func_dgettext_libc=no)])
 
-         if test "$gt_cv_func_dgettext_libc" != "yes"; then
+          gt_cv_func_dgettext_libintl="no"
+          libintl_extra_libs=""
+
+         if test "$gt_cv_func_dgettext_libc" != "yes" ; then
            AC_CHECK_LIB(intl, bindtextdomain,
-             [AC_CACHE_CHECK([for dgettext in libintl],
-               gt_cv_func_dgettext_libintl,
-               [AC_CHECK_LIB(intl, dgettext,
-                 gt_cv_func_dgettext_libintl=yes,
-                 gt_cv_func_dgettext_libintl=no)],
-               gt_cv_func_dgettext_libintl=no)])
-         fi
+              [AC_CHECK_LIB(intl, dgettext,
+                            gt_cv_func_dgettext_libintl=yes)])
+
+           if test "$gt_cv_func_dgettext_libc" != "yes" ; then
+              AC_MSG_CHECKING([if -liconv is needed to use gettext])
+              AC_MSG_RESULT([])
+              AC_CHECK_LIB(intl, dcgettext,
+                           [gt_cv_func_dgettext_libintl=yes
+                            libintl_extra_libs=-liconv],
+                           :,-liconv)
+            fi
+          fi
 
           if test "$gt_cv_func_dgettext_libintl" = "yes"; then
-           LIBS="$LIBS -lintl";
+           LIBS="$LIBS -lintl $libintl_extra_libs";
           fi
 
          if test "$gt_cv_func_dgettext_libc" = "yes" \
            || test "$gt_cv_func_dgettext_libintl" = "yes"; then
-           AC_DEFINE(HAVE_GETTEXT)
+           AC_DEFINE(HAVE_GETTEXT,1,
+              [Define if the GNU gettext() function is already present or preinstalled.])
            AM_GLIB_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
              [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)dnl
            if test "$MSGFMT" != "no"; then
@@ -128,7 +138,7 @@ AC_DEFUN(AM_GLIB_WITH_NLS,
          # Added by Martin Baulig 12/15/98 for libc5 systems
          if test "$gt_cv_func_dgettext_libc" != "yes" \
            && test "$gt_cv_func_dgettext_libintl" = "yes"; then
-           INTLLIBS=-lintl
+           INTLLIBS="-lintl $libintl_extra_libs"
            LIBS=`echo $LIBS | sed -e 's/-lintl//'`
          fi
       ])
@@ -141,7 +151,8 @@ AC_DEFUN(AM_GLIB_WITH_NLS,
     fi
 
     if test "$nls_cv_use_gnu_gettext" != "yes"; then
-      AC_DEFINE(ENABLE_NLS)
+      AC_DEFINE(ENABLE_NLS, 1,
+        [always defined to indicate that i18n is enabled])
     else
       dnl Unset this variable since we use the non-zero value as a flag.
       CATOBJEXT=
@@ -241,9 +252,6 @@ strdup __argz_count __argz_stringify __argz_next])
      dnl cannot handle comments.
      sed -e '/^#/d' $srcdir/po/$msgformat-msg.sed > po/po2msg.sed
    fi
-   dnl po2tbl.sed is always needed.
-   sed -e '/^#.*[^\\]$/d' -e '/^#$/d' \
-     $srcdir/po/po2tbl.sed.in > po/po2tbl.sed
 
    dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
    dnl find the mkinstalldirs script in another subdir but ($top_srcdir).
@@ -319,3 +327,37 @@ if test $ac_cv_func_vsnprintf_c99 = yes; then
 fi
 ])# AC_FUNC_VSNPRINTF_C99
 
+
+dnl @synopsis AC_FUNC_PRINTF_UNIX98
+dnl
+dnl Check whether the printf() family supports Unix98 %n$ positional parameters 
+dnl
+AC_DEFUN([AC_FUNC_PRINTF_UNIX98],
+[AC_CACHE_CHECK(whether printf supports positional parameters,
+  ac_cv_func_printf_unix98,
+[AC_TRY_RUN(
+[#include <stdio.h>
+
+int
+main (void)
+{
+  char buffer[128];
+
+  sprintf (buffer, "%2\$d %3\$d %1\$d", 1, 2, 3);
+  if (strcmp ("2 3 1", buffer) == 0)
+    exit (0);
+  exit (1);
+}], ac_cv_func_printf_unix98=yes, ac_cv_func_printf_unix98=no, ac_cv_func_printf_unix98=no)])
+dnl Note that the default is to be pessimistic in the case of cross compilation.
+dnl If you know that the target printf() supports positional parameters, you can get around 
+dnl this by setting ac_func_printf_unix98 to yes, as described in the Autoconf manual.
+if test $ac_cv_func_printf_unix98 = yes; then
+  AC_DEFINE(HAVE_UNIX98_PRINTF, 1,
+            [Define if your printf function family supports positional parameters
+             as specified by Unix98.])
+fi
+])# AC_FUNC_PRINTF_UNIX98
+
+
+
+