From 38ffd03cd6e0f4d466d468100ad39010b8a30025 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 5 Dec 2022 19:26:50 -0700 Subject: [PATCH] Move gettext checks to m4/gettext.m4 --- MANIFEST | 1 + aclocal.m4 | 1 + configure | 108 +++++++++++++++++++++++++------------------------- configure.ac | 60 +--------------------------- m4/gettext.m4 | 61 ++++++++++++++++++++++++++++ 5 files changed, 119 insertions(+), 112 deletions(-) create mode 100644 m4/gettext.m4 diff --git a/MANIFEST b/MANIFEST index 5e69dd7b5..4d0c98fef 100644 --- a/MANIFEST +++ b/MANIFEST @@ -425,6 +425,7 @@ m4/ax_check_link_flag.m4 m4/ax_func_getaddrinfo.m4 m4/ax_func_snprintf.m4 m4/ax_prog_cc_for_build.m4 +m4/gettext.m4 m4/hardening.m4 m4/ldap.m4 m4/libtool.m4 diff --git a/aclocal.m4 b/aclocal.m4 index 453e96897..336e610dd 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -18,6 +18,7 @@ m4_include([m4/ax_check_link_flag.m4]) m4_include([m4/ax_func_getaddrinfo.m4]) m4_include([m4/ax_func_snprintf.m4]) m4_include([m4/ax_prog_cc_for_build.m4]) +m4_include([m4/gettext.m4]) m4_include([m4/hardening.m4]) m4_include([m4/ldap.m4]) m4_include([m4/libtool.m4]) diff --git a/configure b/configure index bf6ccebd2..e4f5e153a 100755 --- a/configure +++ b/configure @@ -27286,14 +27286,15 @@ printf "%s\n" "#define __func__ __FUNCTION__" >>confdefs.h fi fi -# gettext() and friends may be located in libc (Linux and Solaris) -# or in libintl. However, it is possible to have libintl installed -# even when gettext() is present in libc. In the case of GNU libintl, -# gettext() will be defined to gettext_libintl in libintl.h. -# Since gcc prefers /usr/local/include to /usr/include, we need to -# make sure we use the gettext() that matches the include file. -if test "$enable_nls" != "no"; then - if test "$enable_nls" != "yes"; then + + # gettext() and friends may be located in libc (Linux and Solaris) + # or in libintl. However, it is possible to have libintl installed + # even when gettext() is present in libc. In the case of GNU libintl, + # gettext() will be defined to gettext_libintl in libintl.h. + # Since gcc prefers /usr/local/include to /usr/include, we need to + # make sure we use the gettext() that matches the include file. + if test "$enable_nls" != "no"; then + if test "$enable_nls" != "yes"; then if test ${CPPFLAGS+y} then : @@ -27400,32 +27401,32 @@ fi fi - fi - OLIBS="$LIBS" - for l in "libc" "-lintl" "-lintl -liconv"; do - if test "$l" = "libc"; then - # If user specified a dir for libintl ignore libc - if test "$enable_nls" != "yes"; then - continue - fi - gettext_name=sudo_cv_gettext - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for gettext" >&5 -printf %s "checking for gettext... " >&6; } - else - LIBS="$OLIBS $l" - gettext_name=sudo_cv_gettext"`echo $l|sed -e 's/ //g' -e 's/-/_/g'`" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for gettext in $l" >&5 -printf %s "checking for gettext in $l... " >&6; } fi - if eval test \${$gettext_name+y} + OLIBS="$LIBS" + for l in "libc" "-lintl" "-lintl -liconv"; do + if test "$l" = "libc"; then + # If user specified a dir for libintl ignore libc + if test "$enable_nls" != "yes"; then + continue + fi + gettext_name=sudo_cv_gettext + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for gettext" >&5 +printf %s "checking for gettext... " >&6; } + else + LIBS="$OLIBS $l" + gettext_name=sudo_cv_gettext"`echo $l|sed -e 's/ //g' -e 's/-/_/g'`" + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for gettext in $l" >&5 +printf %s "checking for gettext in $l... " >&6; } + fi + if eval test \${$gettext_name+y} then : printf %s "(cached) " >&6 else case e in #( e) - cat confdefs.h - <<_ACEOF >conftest.$ac_ext + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - #include + #include int main (void) { @@ -27440,46 +27441,46 @@ then : eval $gettext_name=yes else case e in #( e) eval $gettext_name=no - ;; + ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext - ;; + ;; esac fi - eval gettext_result="\$$gettext_name" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $gettext_result" >&5 + eval gettext_result="\$$gettext_name" + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $gettext_result" >&5 printf "%s\n" "$gettext_result" >&6; } - if test "$gettext_result" = "yes"; then - ac_fn_c_check_func "$LINENO" "ngettext" "ac_cv_func_ngettext" + if test "$gettext_result" = "yes"; then + ac_fn_c_check_func "$LINENO" "ngettext" "ac_cv_func_ngettext" if test "x$ac_cv_func_ngettext" = xyes then : printf "%s\n" "#define HAVE_NGETTEXT 1" >>confdefs.h fi - break - fi - done - LIBS="$OLIBS" + break + fi + done + LIBS="$OLIBS" - if test "$sudo_cv_gettext" = "yes"; then - SUDO_NLS=enabled - # For Solaris we need links from lang to lang.UTF-8 in localedir - case "$host_os" in - solaris2*) LOCALEDIR_SUFFIX=".UTF-8";; - esac - elif test "$sudo_cv_gettext_lintl" = "yes"; then - SUDO_NLS=enabled - LIBINTL="-lintl" - elif test "$sudo_cv_gettext_lintl_liconv" = "yes"; then - SUDO_NLS=enabled - LIBINTL="-lintl -liconv" - fi - if test X"$SUDO_NLS" = X"enabled"; then - printf "%s\n" "#define HAVE_LIBINTL_H 1" >>confdefs.h + if test "$sudo_cv_gettext" = "yes"; then + SUDO_NLS=enabled + # For Solaris we need links from lang to lang.UTF-8 in localedir + case "$host_os" in + solaris2*) LOCALEDIR_SUFFIX=".UTF-8";; + esac + elif test "$sudo_cv_gettext_lintl" = "yes"; then + SUDO_NLS=enabled + LIBINTL="-lintl" + elif test "$sudo_cv_gettext_lintl_liconv" = "yes"; then + SUDO_NLS=enabled + LIBINTL="-lintl -liconv" + fi + if test X"$SUDO_NLS" = X"enabled"; then + printf "%s\n" "#define HAVE_LIBINTL_H 1" >>confdefs.h for _sym in sudo_warn_gettext_v1; do @@ -27487,8 +27488,9 @@ fi " done + fi fi -fi + case "$enable_zlib" in yes) diff --git a/configure.ac b/configure.ac index 6cd3a67c3..13cfbcdcf 100644 --- a/configure.ac +++ b/configure.ac @@ -3253,65 +3253,7 @@ elif test -n "$GCC"; then fi fi -# gettext() and friends may be located in libc (Linux and Solaris) -# or in libintl. However, it is possible to have libintl installed -# even when gettext() is present in libc. In the case of GNU libintl, -# gettext() will be defined to gettext_libintl in libintl.h. -# Since gcc prefers /usr/local/include to /usr/include, we need to -# make sure we use the gettext() that matches the include file. -if test "$enable_nls" != "no"; then - if test "$enable_nls" != "yes"; then - AX_APPEND_FLAG([-I${enable_nls}/include], [CPPFLAGS]) - SUDO_APPEND_LIBPATH(LDFLAGS, [$enable_nls/lib]) - fi - OLIBS="$LIBS" - for l in "libc" "-lintl" "-lintl -liconv"; do - if test "$l" = "libc"; then - # If user specified a dir for libintl ignore libc - if test "$enable_nls" != "yes"; then - continue - fi - gettext_name=sudo_cv_gettext - AC_MSG_CHECKING([for gettext]) - else - LIBS="$OLIBS $l" - gettext_name=sudo_cv_gettext"`echo $l|sed -e 's/ //g' -e 's/-/_/g'`" - AC_MSG_CHECKING([for gettext in $l]) - fi - AC_CACHE_VAL($gettext_name, [ - AC_LINK_IFELSE( - [ - AC_LANG_PROGRAM([[#include ]], [(void)gettext((char *)0);]) - ], [eval $gettext_name=yes], [eval $gettext_name=no] - ) - ]) - eval gettext_result="\$$gettext_name" - AC_MSG_RESULT($gettext_result) - if test "$gettext_result" = "yes"; then - AC_CHECK_FUNCS([ngettext]) - break - fi - done - LIBS="$OLIBS" - - if test "$sudo_cv_gettext" = "yes"; then - SUDO_NLS=enabled - # For Solaris we need links from lang to lang.UTF-8 in localedir - case "$host_os" in - solaris2*) LOCALEDIR_SUFFIX=".UTF-8";; - esac - elif test "$sudo_cv_gettext_lintl" = "yes"; then - SUDO_NLS=enabled - LIBINTL="-lintl" - elif test "$sudo_cv_gettext_lintl_liconv" = "yes"; then - SUDO_NLS=enabled - LIBINTL="-lintl -liconv" - fi - if test X"$SUDO_NLS" = X"enabled"; then - AC_DEFINE(HAVE_LIBINTL_H) - SUDO_APPEND_COMPAT_EXP(sudo_warn_gettext_v1) - fi -fi +SUDO_CHECK_GETTEXT dnl dnl Deferred zlib option processing. diff --git a/m4/gettext.m4 b/m4/gettext.m4 new file mode 100644 index 000000000..f25bf7b4a --- /dev/null +++ b/m4/gettext.m4 @@ -0,0 +1,61 @@ +AC_DEFUN([SUDO_CHECK_GETTEXT], [ + # gettext() and friends may be located in libc (Linux and Solaris) + # or in libintl. However, it is possible to have libintl installed + # even when gettext() is present in libc. In the case of GNU libintl, + # gettext() will be defined to gettext_libintl in libintl.h. + # Since gcc prefers /usr/local/include to /usr/include, we need to + # make sure we use the gettext() that matches the include file. + if test "$enable_nls" != "no"; then + if test "$enable_nls" != "yes"; then + AX_APPEND_FLAG([-I${enable_nls}/include], [CPPFLAGS]) + SUDO_APPEND_LIBPATH(LDFLAGS, [$enable_nls/lib]) + fi + OLIBS="$LIBS" + for l in "libc" "-lintl" "-lintl -liconv"; do + if test "$l" = "libc"; then + # If user specified a dir for libintl ignore libc + if test "$enable_nls" != "yes"; then + continue + fi + gettext_name=sudo_cv_gettext + AC_MSG_CHECKING([for gettext]) + else + LIBS="$OLIBS $l" + gettext_name=sudo_cv_gettext"`echo $l|sed -e 's/ //g' -e 's/-/_/g'`" + AC_MSG_CHECKING([for gettext in $l]) + fi + AC_CACHE_VAL($gettext_name, [ + AC_LINK_IFELSE( + [ + AC_LANG_PROGRAM([[#include ]], [(void)gettext((char *)0);]) + ], [eval $gettext_name=yes], [eval $gettext_name=no] + ) + ]) + eval gettext_result="\$$gettext_name" + AC_MSG_RESULT($gettext_result) + if test "$gettext_result" = "yes"; then + AC_CHECK_FUNCS([ngettext]) + break + fi + done + LIBS="$OLIBS" + + if test "$sudo_cv_gettext" = "yes"; then + SUDO_NLS=enabled + # For Solaris we need links from lang to lang.UTF-8 in localedir + case "$host_os" in + solaris2*) LOCALEDIR_SUFFIX=".UTF-8";; + esac + elif test "$sudo_cv_gettext_lintl" = "yes"; then + SUDO_NLS=enabled + LIBINTL="-lintl" + elif test "$sudo_cv_gettext_lintl_liconv" = "yes"; then + SUDO_NLS=enabled + LIBINTL="-lintl -liconv" + fi + if test X"$SUDO_NLS" = X"enabled"; then + AC_DEFINE(HAVE_LIBINTL_H) + SUDO_APPEND_COMPAT_EXP(sudo_warn_gettext_v1) + fi + fi +])