From a96f69a534a91f5a97379e32aa62bacb84e65d82 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 16 Mar 2018 16:25:02 +0100 Subject: [PATCH] glob: Don't compile replacements on recent glibc systems. * lib/glob.in.h: Use the usual idiom for the double-inclusion guard. If REPLACE_GLOB is 0, include the system's and use _GL_CXXALIAS_SYS. * m4/glob.m4 (gl_GLOB): Set REPLACE_GLOB instead of GLOB_H. Accept _GNU_GLOB_INTERFACE_VERSION 2 as well. Delete the file conf$$-globtest inside the AC_RUN_IFELSE block. Remove GL_GENERATE_GLOB_H conditional. * modules/glob (Dependencies): Test REPLACE_GLOB instead of GLOB_H. Remove snippet/warn-on-use. (configure.ac): Test REPLACE_GLOB instead of GLOB_H. (Makefile.am): Create glob.h always. Update list of substitutions in glob.h. Don't depend on $(WARN_ON_USE_H). --- ChangeLog | 15 +++++++++ lib/glob.in.h | 91 ++++++++++++++++++++++++++++++++++++--------------- m4/glob.m4 | 64 +++++++++++++++++++----------------- modules/glob | 64 ++++++++++++++++++------------------ 4 files changed, 144 insertions(+), 90 deletions(-) diff --git a/ChangeLog b/ChangeLog index b4dda43571..fde5ce3c9b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2018-03-16 Bruno Haible + + glob: Don't compile replacements on recent glibc systems. + * lib/glob.in.h: Use the usual idiom for the double-inclusion guard. If + REPLACE_GLOB is 0, include the system's and use + _GL_CXXALIAS_SYS. + * m4/glob.m4 (gl_GLOB): Set REPLACE_GLOB instead of GLOB_H. Accept + _GNU_GLOB_INTERFACE_VERSION 2 as well. Delete the file conf$$-globtest + inside the AC_RUN_IFELSE block. Remove GL_GENERATE_GLOB_H conditional. + * modules/glob (Dependencies): Test REPLACE_GLOB instead of GLOB_H. + Remove snippet/warn-on-use. + (configure.ac): Test REPLACE_GLOB instead of GLOB_H. + (Makefile.am): Create glob.h always. Update list of substitutions in + glob.h. Don't depend on $(WARN_ON_USE_H). + 2018-03-16 Bruno Haible glob: Fix link error on native Windows. diff --git a/lib/glob.in.h b/lib/glob.in.h index cc3f48c43a..656c1eb481 100644 --- a/lib/glob.in.h +++ b/lib/glob.in.h @@ -17,21 +17,22 @@ You should have received a copy of the GNU General Public License along with this program; if not, see . */ -#ifndef _GL_GLOB_H -#define _GL_GLOB_H +#ifndef _@GUARD_PREFIX@_GLOB_H -#include +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif +@PRAGMA_COLUMNS@ -#include +/* The include_next requires a split double-inclusion guard. */ +#if !@REPLACE_GLOB@ +# @INCLUDE_NEXT@ @NEXT_GLOB_H@ +#endif -/* On some systems, such as AIX 5.1, does a "#define stat stat64". - Make sure this definition is seen before glob-libc.h defines types that - rely on 'struct stat'. */ -#include +#ifndef _@GUARD_PREFIX@_GLOB_H +#define _@GUARD_PREFIX@_GLOB_H -#ifndef __USE_GNU -# define __USE_GNU 1 -#endif +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ /* GCC 2.95 and later have "__restrict"; C99 compilers have "restrict", and "configure" may have defined "restrict". @@ -48,35 +49,71 @@ # endif #endif +#ifdef __cplusplus +extern "C" { +#endif +typedef int (*_gl_glob_errfunc_fn) (const char *, int); +#ifdef __cplusplus +} +#endif + + +#if @REPLACE_GLOB@ + + +/* Preparations for including the standard GNU C Library header. */ + +# include + +# include + +/* On some systems, such as AIX 5.1, does a "#define stat stat64". + Make sure this definition is seen before glob-libc.h defines types that + rely on 'struct stat'. */ +# include + +# ifndef __USE_GNU +# define __USE_GNU 1 +# endif + +# define glob rpl_glob +# define globfree rpl_globfree +# define glob_pattern_p rpl_glob_pattern_p +# define __glob_pattern_p glob_pattern_p -#define glob rpl_glob -#define globfree rpl_globfree -#define glob_pattern_p rpl_glob_pattern_p -#define __glob_pattern_p glob_pattern_p +# define __GLOB_GNULIB 1 -#define __GLOB_GNULIB 1 /* Now the standard GNU C Library header should work. */ -#include "glob-libc.h" +# include "glob-libc.h" -__BEGIN_DECLS -typedef int (*_gl_glob_errfunc_fn) (const char *, int); -__END_DECLS -#if defined __cplusplus && defined GNULIB_NAMESPACE -# undef glob -# undef globfree -# undef glob_pattern_p +# if defined __cplusplus && defined GNULIB_NAMESPACE +# undef glob +# undef globfree +# undef glob_pattern_p _GL_CXXALIAS_RPL (glob, int, (const char *_Restrict_ __pattern, int __flags, _gl_glob_errfunc_fn __errfunc, glob_t *_Restrict_ __pglob)); _GL_CXXALIAS_RPL (globfree, void, (glob_t *__pglob)); _GL_CXXALIAS_RPL (glob_pattern_p, int, (const char *__pattern, int __quote)); -# if 0 /* The C function name is rpl_glob, not glob. */ +# endif + +#else + +_GL_CXXALIAS_SYS (glob, int, (const char *_Restrict_ __pattern, int __flags, + _gl_glob_errfunc_fn __errfunc, + glob_t *_Restrict_ __pglob)); +_GL_CXXALIAS_SYS (globfree, void, (glob_t *__pglob)); +_GL_CXXALIAS_SYS (glob_pattern_p, int, (const char *__pattern, int __quote)); + +#endif + +#if 0 /* The C function name is rpl_glob in some cases, not glob. */ _GL_CXXALIASWARN (glob); _GL_CXXALIASWARN (globfree); _GL_CXXALIASWARN (glob_pattern_p); -# endif #endif -#endif /* _GL_GLOB_H */ +#endif /* _@GUARD_PREFIX@_GLOB_H */ +#endif /* _@GUARD_PREFIX@_GLOB_H */ diff --git a/m4/glob.m4 b/m4/glob.m4 index 9dedb41306..37cb91745c 100644 --- a/m4/glob.m4 +++ b/m4/glob.m4 @@ -1,4 +1,4 @@ -# glob.m4 serial 16 +# glob.m4 serial 18 dnl Copyright (C) 2005-2007, 2009-2018 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -9,54 +9,58 @@ dnl with or without modifications, as long as this notice is preserved. # always include for the glob prototypes. AC_DEFUN([gl_GLOB], -[ GLOB_H= - AC_CHECK_HEADERS([glob.h], [], [GLOB_H=glob.h]) +[ + dnl is always overridden, because of the C++ GNULIB_NAMESPACE. + gl_CHECK_NEXT_HEADERS([glob.h]) + if test $ac_cv_header_glob_h = yes; then + REPLACE_GLOB=0 + else + REPLACE_GLOB=1 + fi - if test -z "$GLOB_H"; then - AC_CACHE_CHECK([for GNU glob interface version 1], - [gl_cv_gnu_glob_interface_version_1], + if test $REPLACE_GLOB = 0; then + AC_CACHE_CHECK([for GNU glob interface version 1 or 2], + [gl_cv_gnu_glob_interface_version_1_2], [ AC_COMPILE_IFELSE([AC_LANG_SOURCE( [[#include -char a[_GNU_GLOB_INTERFACE_VERSION == 1 ? 1 : -1];]])], - [gl_cv_gnu_glob_interface_version_1=yes], - [gl_cv_gnu_glob_interface_version_1=no])]) +char a[_GNU_GLOB_INTERFACE_VERSION == 1 || _GNU_GLOB_INTERFACE_VERSION == 2 ? 1 : -1];]])], + [gl_cv_gnu_glob_interface_version_1_2=yes], + [gl_cv_gnu_glob_interface_version_1_2=no])]) - if test "$gl_cv_gnu_glob_interface_version_1" = "no"; then - GLOB_H=glob.h + if test "$gl_cv_gnu_glob_interface_version_1_2" = "no"; then + REPLACE_GLOB=1 fi fi - if test -z "$GLOB_H"; then + if test $REPLACE_GLOB = 0; then AC_CACHE_CHECK([whether glob lists broken symlinks], [gl_cv_glob_lists_symlinks], -[ if ln -s conf-doesntexist conf$$-globtest 2>/dev/null; then - gl_cv_glob_lists_symlinks=maybe - else - # If we can't make a symlink, then we cannot test this issue. Be - # pessimistic about this. - gl_cv_glob_lists_symlinks=no - fi - - if test $gl_cv_glob_lists_symlinks = maybe; then - AC_RUN_IFELSE([ + [if ln -s conf-doesntexist conf$$-globtest 2>/dev/null; then + gl_cv_glob_lists_symlinks=maybe + else + # If we can't make a symlink, then we cannot test this issue. Be + # pessimistic about this. + gl_cv_glob_lists_symlinks=no + fi + if test $gl_cv_glob_lists_symlinks = maybe; then + AC_RUN_IFELSE([ AC_LANG_PROGRAM( [[#include #include ]], [[glob_t found; if (glob ("conf*-globtest", 0, NULL, &found) == GLOB_NOMATCH) return 1;]])], - [gl_cv_glob_lists_symlinks=yes], - [gl_cv_glob_lists_symlinks=no], [gl_cv_glob_lists_symlinks=no]) - fi]) + [gl_cv_glob_lists_symlinks=yes], + [gl_cv_glob_lists_symlinks=no], [gl_cv_glob_lists_symlinks=no]) + fi + rm -f conf$$-globtest + ]) if test $gl_cv_glob_lists_symlinks = no; then - GLOB_H=glob.h + REPLACE_GLOB=1 fi fi - rm -f conf$$-globtest - - AC_SUBST([GLOB_H]) - AM_CONDITIONAL([GL_GENERATE_GLOB_H], [test -n "$GLOB_H"]) + AC_SUBST([REPLACE_GLOB]) ]) # Prerequisites of lib/glob.*. diff --git a/modules/glob b/modules/glob index 3a43222a28..94b3fd05ff 100644 --- a/modules/glob +++ b/modules/glob @@ -16,31 +16,30 @@ c99 extensions largefile snippet/c++defs -snippet/warn-on-use -alloca [test -n "$GLOB_H"] -builtin-expect [test -n "$GLOB_H"] -closedir [test -n "$GLOB_H"] -d-type [test -n "$GLOB_H"] -flexmember [test -n "$GLOB_H"] -fnmatch [test -n "$GLOB_H"] -getlogin_r [test -n "$GLOB_H"] -libc-config [test -n "$GLOB_H"] -lstat [test -n "$GLOB_H"] -memchr [test -n "$GLOB_H"] -mempcpy [test -n "$GLOB_H"] -opendir [test -n "$GLOB_H"] -readdir [test -n "$GLOB_H"] -scratch_buffer [test -n "$GLOB_H"] -stdbool [test -n "$GLOB_H"] -stdint [test -n "$GLOB_H"] -strdup [test -n "$GLOB_H"] -sys_stat [test -n "$GLOB_H"] -unistd [test -n "$GLOB_H"] -malloc-posix [test -n "$GLOB_H"] +alloca [test $REPLACE_GLOB = 1] +builtin-expect [test $REPLACE_GLOB = 1] +closedir [test $REPLACE_GLOB = 1] +d-type [test $REPLACE_GLOB = 1] +flexmember [test $REPLACE_GLOB = 1] +fnmatch [test $REPLACE_GLOB = 1] +getlogin_r [test $REPLACE_GLOB = 1] +libc-config [test $REPLACE_GLOB = 1] +lstat [test $REPLACE_GLOB = 1] +memchr [test $REPLACE_GLOB = 1] +mempcpy [test $REPLACE_GLOB = 1] +opendir [test $REPLACE_GLOB = 1] +readdir [test $REPLACE_GLOB = 1] +scratch_buffer [test $REPLACE_GLOB = 1] +stdbool [test $REPLACE_GLOB = 1] +stdint [test $REPLACE_GLOB = 1] +strdup [test $REPLACE_GLOB = 1] +sys_stat [test $REPLACE_GLOB = 1] +unistd [test $REPLACE_GLOB = 1] +malloc-posix [test $REPLACE_GLOB = 1] configure.ac: gl_GLOB -if test -n "$GLOB_H"; then +if test $REPLACE_GLOB = 1; then AC_LIBOBJ([glob]) AC_LIBOBJ([glob_pattern_p]) AC_LIBOBJ([globfree]) @@ -48,23 +47,22 @@ if test -n "$GLOB_H"; then fi Makefile.am: -BUILT_SOURCES += $(GLOB_H) +BUILT_SOURCES += glob.h -# We need the following in order to create when the system -# doesn't have one that works with the given compiler. -if GL_GENERATE_GLOB_H -glob.h: glob.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) +# We need the following in order to create . +glob.h: glob.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ - sed -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ - -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ + sed -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \ + -e 's|@''REPLACE_GLOB''@|$(REPLACE_GLOB)|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_GLOB_H''@|$(NEXT_GLOB_H)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ < $(srcdir)/glob.in.h; \ } > $@-t && \ mv -f $@-t $@ -else -glob.h: $(top_builddir)/config.status - rm -f $@ -endif MOSTLYCLEANFILES += glob.h glob.h-t Include: -- 2.39.5