2009-09-24 Eric Blake <ebb9@byu.net>
+ 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
+ <getopt.h>.
+ * lib/getopt.in.h (includes): Use split inclusion guard, and
+ prefer <getopt.h> over include <unistd.h> 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.
/* 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.
#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
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 <getopt.h>,
+ 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 <stdlib.h>
-# include <stdio.h>
-# include <unistd.h>
+# if !@HAVE_GETOPT_H@
+# include <stdlib.h>
+# include <stdio.h>
+# include <unistd.h>
+# endif
# undef __need_getopt
# undef getopt
# undef getopt_long
# 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)
# 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
#undef __need_getopt
#endif /* getopt.h */
+#endif /* getopt.h */
dnl Persuade Solaris <unistd.h> 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 <getopt.h> is available.
gettext-h
unistd
extensions
+include_next
configure.ac:
gl_FUNC_GETOPT_POSIX
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