# HG changeset patch # User Eric Blake # Date 1253811434 21600 # Node ID f098f1865179dc5d37d2a2fa009e119fc5275e1d # Parent 1a57a12a6e7f3581d0727ca4b27c3440e1ba3b0a getopt: fix inclusion guards for cygwin cygwin includes , but gnulib includes , so system declarations were happening after gnulib replacements, leading to multiply-defined rpl_readlink error on cygwin 1.5. The solution is to ensure that the system is complete prior to any of gnulib's contents, by picking up system in preference to a cycle to . * modules/getopt-posix (Depends-on): Add include-next. (Makefile.am): Substitute more items in replacement header. * m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Also check for native . * lib/getopt.in.h (includes): Use split inclusion guard, and prefer over include when one is present. (option): Also override name of 'struct option'. Signed-off-by: Eric Blake diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2009-09-24 Eric Blake + getopt: fix inclusion guards for cygwin + * modules/getopt-posix (Depends-on): Add include-next. + (Makefile.am): Substitute more items in replacement header. + * m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Also check for native + . + * lib/getopt.in.h (includes): Use split inclusion guard, and + prefer over include when one is present. + (option): Also override name of 'struct option'. + same-inode: revert prior change; it is not yet ready * NEWS: Undo mention of this change. * lib/same-inode.h (same-inode.h): Undo tri-state change. diff --git a/lib/getopt.in.h b/lib/getopt.in.h --- a/lib/getopt.in.h +++ b/lib/getopt.in.h @@ -1,5 +1,5 @@ /* Declarations for getopt. - Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2005,2006,2007 + Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2005,2006,2007,2009 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -18,6 +18,17 @@ #ifndef _GETOPT_H +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif + +/* The include_next requires a split double-inclusion guard. */ +#if @HAVE_GETOPT_H@ +# @INCLUDE_NEXT@ @NEXT_GETOPT_H@ +#endif + +#ifndef _GETOPT_H + #ifndef __need_getopt # define _GETOPT_H 1 #endif @@ -26,14 +37,17 @@ identifier that prefixes the external functions and variables defined in this header. When this happens, include the headers that might declare getopt so that they will not cause - confusion if included after this file. Then systematically rename + confusion if included after this file (if the system had , + we have already included it). Then systematically rename identifiers so that they do not collide with the system functions and variables. Renaming avoids problems with some compilers and linkers. */ #if defined __GETOPT_PREFIX && !defined __need_getopt -# include -# include -# include +# if !@HAVE_GETOPT_H@ +# include +# include +# include +# endif # undef __need_getopt # undef getopt # undef getopt_long @@ -42,6 +56,7 @@ # undef opterr # undef optind # undef optopt +# undef option # define __GETOPT_CONCAT(x, y) x ## y # define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y) # define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y) @@ -52,6 +67,7 @@ # define opterr __GETOPT_ID (opterr) # define optind __GETOPT_ID (optind) # define optopt __GETOPT_ID (optopt) +# define option __GETOPT_ID (option) #endif /* Standalone applications get correct prototypes for getopt_long and @@ -223,3 +239,4 @@ #undef __need_getopt #endif /* getopt.h */ +#endif /* getopt.h */ diff --git a/m4/getopt.m4 b/m4/getopt.m4 --- a/m4/getopt.m4 +++ b/m4/getopt.m4 @@ -54,6 +54,15 @@ dnl Persuade Solaris to declare optarg, optind, opterr, optopt. AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + gl_CHECK_NEXT_HEADERS([getopt.h]) + AC_CHECK_HEADERS_ONCE([getopt.h]) + if test $ac_cv_header_getopt_h = yes; then + HAVE_GETOPT_H=1 + else + HAVE_GETOPT_H=0 + fi + AC_SUBST([HAVE_GETOPT_H]) + gl_replace_getopt= dnl Test whether is available. diff --git a/modules/getopt-posix b/modules/getopt-posix --- a/modules/getopt-posix +++ b/modules/getopt-posix @@ -12,6 +12,7 @@ gettext-h unistd extensions +include_next configure.ac: gl_FUNC_GETOPT_POSIX @@ -24,7 +25,12 @@ getopt.h: getopt.in.h $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ - cat $(srcdir)/getopt.in.h; \ + sed -e 's|@''HAVE_GETOPT_H''@|$(HAVE_GETOPT_H)|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''NEXT_GETOPT_H''@|$(NEXT_GETOPT_H)|g' \ + -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + < $(srcdir)/getopt.in.h; \ } > $@-t && \ mv -f $@-t $@ MOSTLYCLEANFILES += getopt.h getopt.h-t