bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: #ifndef __need_getopt not working in getopt.h


From: Bruce Korb
Subject: Re: #ifndef __need_getopt not working in getopt.h
Date: Sat, 14 Nov 2009 12:48:23 -0800
User-agent: Thunderbird 2.0.0.21 (X11/20090310)

This only seems to be happening during "make check".

> make  check-recursive
> make[2]: Entering directory `/home/gnu/proj/sharutils-bld/lib'
> make[3]: Entering directory `/home/gnu/proj/sharutils-bld/lib'
> rm -f getopt.h-t getopt.h && \
>         { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
>           sed -e 's|@''HAVE_GETOPT_H''@|1|g' \
>               -e 's|@''INCLUDE_NEXT''@|include_next|g' \
>               -e 's|@''PRAGMA_SYSTEM_HEADER''@|#pragma GCC system_header|g' \
>               -e 's|@''NEXT_GETOPT_H''@|<getopt.h>|g' \
>               -e '/definition of GL_LINK_WARNING/r .././link-warning.h' \
>               < ./getopt.in.h; \
>         } > getopt.h-t && \
>         mv -f getopt.h-t getopt.h
> gcc -DHAVE_CONFIG_H -I. -I..     -g -Wall -MT close-hook.o -MD -MP -MF 
> .deps/close-hook.Tpo -c -o close-hook.o close-hook.c
> In file included from ./xstrtol.h:22,
>                  from ../config.h:990,
>                  from close-hook.c:18:
> ./getopt.h:183: error: redefinition of 'struct option'
> make[3]: *** [close-hook.o] Error 1
> make[3]: Leaving directory `/home/gnu/proj/sharutils-bld/lib'
> make[2]: *** [check-recursive] Error 1
> make[2]: Leaving directory `/home/gnu/proj/sharutils-bld/lib'
> make[1]: *** [check] Error 2
> make[1]: Leaving directory `/home/gnu/proj/sharutils-bld/lib'
> make: *** [check-recursive] Error 1

This means I got through it on the main build.  On the repeat
build, it fails.  Won't even do a plain "make" this  time
through.

>From earlier in the build:

> rm -f libgnu.a
> ar cru libgnu.a close-hook.o openat-die.o xalloc-die.o xstrtoimax.o \
>   basename-lgpl.o chdir-long.o dirname-lgpl.o dup-safer.o dup2.o exitfail.o \
>  fd-safer.o fdopendir.o getcwd.o imaxtostr.o offtostr.o openat-proc.o \
>  pipe-safer.o save-cwd.o stripslash.o uinttostr.o umaxtostr.o xgetcwd.o \
>  xmalloc.o xstrtol.o xstrtol-error.o xstrtoul.o
> ranlib libgnu.a
> make[4]: Leaving directory `/home/gnu/proj/sharutils-bld/lib'

Looks good.  For anybody's possible amusement, attached is
the full diff between "lib" as it existed after the first build
and the current directory.  getopt.h is quite different.

Why is this so hard?  sharutils used to just compile.
Then all the m4 configury macros changed and it has been
hell every time I try to build the thing.  It has not
been built for closing on 3 years now.  I think I could do
this if I reverted all the auto* tools to the current set
from several years ago.

Extract from config.log:

> configure:6169: checking getopt.h usability
> configure:6169: gcc -c -g -Wall  conftest.c >&5
> configure:6169: $? = 0
> configure:6169: result: yes
> configure:6169: checking getopt.h presence
> configure:6169: gcc -E  conftest.c
> configure:6169: $? = 0
> configure:6169: result: yes
> configure:6169: checking for getopt.h
> configure:6169: result: yes

Extract from lib/Makefile:

> # We need the following in order to create <getopt.h> when the system
> # doesn't have one that works with the given compiler.
> getopt.h: getopt.in.h
>       $(AM_V_GEN)rm -f address@hidden $@ && \
>       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
>         sed -e 's|@''HAVE_GETOPT_H''@|$(HAVE_GETOPT_H)|g' \
>             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
>             -e 's|@''PRAGMA_SYSTEM_HEADER''@|#pragma GCC 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; \
>       } > address@hidden && \
>       mv -f address@hidden $@

I'm running on linux.  There is a /usr/include/getopt.h.
I bet it works with GCC.

Bruce Korb wrote:
> $ gcc -H -DHAVE_CONFIG_H -I. -I.. -g -Wall -MT close-hook.o \
> -MD -MP -MF .deps/close-hook.Tpo -c -o close-hook.o close-hook.c
........
> .. ./xstrtol.h
> ... ./getopt.h
> .... /usr/include/getopt.h
> In file included from ./xstrtol.h:22,
>                  from ../config.h:990,
>                  from close-hook.c:18:
> ./getopt.h:183: error: redefinition of 'struct option'
> 
> I  poked around a bit, but it is pretty tangled in there.
Only in lib/.deps: close-hook.Tpo
diff -ur lib/getopt.h lib-saved//getopt.h
--- lib/getopt.h        2009-11-14 12:45:08.000000000 -0800
+++ lib-saved//getopt.h 2005-06-07 14:51:19.000000000 -0700
@@ -1,103 +1,26 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
 /* Declarations for getopt.
-   Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2005,2006,2007,2009
-   Free Software Foundation, Inc.
+   Copyright (C) 1989-1994, 1996-1999, 2001 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
-   This program is free software: you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
 
-   This program is distributed in the hope that it will be useful,
+   The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.  */
 
-#ifndef _GL_GETOPT_H
-
-#if __GNUC__ >= 3
-#pragma GCC system_header
-#endif
-
-/* The include_next requires a split double-inclusion guard.  We must
-   also inform the replacement unistd.h to not recursively use
-   <getopt.h>; our definitions will be present soon enough.  */
-#if 1
-# define _GL_SYSTEM_GETOPT
-# include_next <getopt.h>
-# undef _GL_SYSTEM_GETOPT
-#endif
-
-#ifndef _GL_GETOPT_H
+#ifndef _GETOPT_H
 
 #ifndef __need_getopt
-# define _GL_GETOPT_H 1
-#endif
-
-/* Standalone applications should #define __GETOPT_PREFIX to an
-   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 (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
-# if !1
-#  include <stdlib.h>
-#  include <stdio.h>
-#  include <unistd.h>
-# endif
-# undef __need_getopt
-# undef getopt
-# undef getopt_long
-# undef getopt_long_only
-# undef optarg
-# 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 getopt __GETOPT_ID (getopt)
-# define getopt_long __GETOPT_ID (getopt_long)
-# define getopt_long_only __GETOPT_ID (getopt_long_only)
-# define optarg __GETOPT_ID (optarg)
-# define opterr __GETOPT_ID (opterr)
-# define optind __GETOPT_ID (optind)
-# define optopt __GETOPT_ID (optopt)
-# define option __GETOPT_ID (option)
-# define _getopt_internal __GETOPT_ID (getopt_internal)
-#endif
-
-/* Standalone applications get correct prototypes for getopt_long and
-   getopt_long_only; they declare "char **argv".  libc uses prototypes
-   with "char *const *argv" that are incorrect because getopt_long and
-   getopt_long_only can permute argv; this is required for backward
-   compatibility (e.g., for LSB 2.0.1).
-
-   This used to be `#if defined __GETOPT_PREFIX && !defined __need_getopt',
-   but it caused redefinition warnings if both unistd.h and getopt.h were
-   included, since unistd.h includes getopt.h having previously defined
-   __need_getopt.
-
-   The only place where __getopt_argv_const is used is in definitions
-   of getopt_long and getopt_long_only below, but these are visible
-   only if __need_getopt is not defined, so it is quite safe to rewrite
-   the conditional as follows:
-*/
-#if !defined __need_getopt
-# if defined __GETOPT_PREFIX
-#  define __getopt_argv_const /* empty */
-# else
-#  define __getopt_argv_const const
-# endif
+# define _GETOPT_H 1
 #endif
 
 /* If __GNU_LIBRARY__ is not already defined, either we are being used
@@ -111,18 +34,7 @@
 # include <ctype.h>
 #endif
 
-#ifndef __THROW
-# ifndef __GNUC_PREREQ
-#  define __GNUC_PREREQ(maj, min) (0)
-# endif
-# if defined __cplusplus && __GNUC_PREREQ (2,8)
-#  define __THROW      throw ()
-# else
-#  define __THROW
-# endif
-#endif
-
-#ifdef __cplusplus
+#ifdef __cplusplus
 extern "C" {
 #endif
 
@@ -166,7 +78,7 @@
    The field `has_arg' is:
    no_argument         (or 0) if the option does not take an argument,
    required_argument   (or 1) if the option requires an argument,
-   optional_argument   (or 2) if the option takes an optional argument.
+   optional_argument   (or 2) if the option takes an optional argument.
 
    If the field `flag' is not NULL, it points to a variable that is set
    to the value given in the field `val' when the option is found, but
@@ -181,7 +93,11 @@
 
 struct option
 {
+# if (defined __STDC__ && __STDC__) || defined __cplusplus
   const char *name;
+# else
+  char *name;
+# endif
   /* has_arg can't be an enum because some compilers complain about
      type mismatches in all the code that assumes it is an int.  */
   int has_arg;
@@ -217,27 +133,44 @@
    scanning, explicitly telling `getopt' that there are no more
    options.
 
-   If OPTS begins with `-', then non-option arguments are treated as
-   arguments to the option '\1'.  This behavior is specific to the GNU
-   `getopt'.  If OPTS begins with `+', or POSIXLY_CORRECT is set in
-   the environment, then do not permute arguments.  */
-
-extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
-       __THROW;
+   If OPTS begins with `--', then non-option arguments are treated as
+   arguments to the option '\0'.  This behavior is specific to the GNU
+   `getopt'.  */
+
+#if (defined __STDC__ && __STDC__) || defined __cplusplus
+# ifdef __GNU_LIBRARY__
+/* Many other libraries have conflicting prototypes for getopt, with
+   differences in the consts, in stdlib.h.  To avoid compilation
+   errors, only prototype getopt for the GNU C library.  */
+extern int getopt (int __argc, char *const *__argv, const char *__shortopts);
+# else /* not __GNU_LIBRARY__ */
+extern int getopt ();
+# endif /* __GNU_LIBRARY__ */
+
+# ifndef __need_getopt
+extern int getopt_long (int __argc, char *const *__argv, const char 
*__shortopts,
+                       const struct option *__longopts, int *__longind);
+extern int getopt_long_only (int __argc, char *const *__argv,
+                            const char *__shortopts,
+                            const struct option *__longopts, int *__longind);
 
-#ifndef __need_getopt
-extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
-                       const char *__shortopts,
-                       const struct option *__longopts, int *__longind)
-       __THROW;
-extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
+/* Internal only.  Users should not call this directly.  */
+extern int _getopt_internal (int __argc, char *const *__argv,
                             const char *__shortopts,
-                            const struct option *__longopts, int *__longind)
-       __THROW;
+                            const struct option *__longopts, int *__longind,
+                            int __long_only);
+# endif
+#else /* not __STDC__ */
+extern int getopt ();
+# ifndef __need_getopt
+extern int getopt_long ();
+extern int getopt_long_only ();
 
-#endif
+extern int _getopt_internal ();
+# endif
+#endif /* __STDC__ */
 
-#ifdef __cplusplus
+#ifdef __cplusplus
 }
 #endif
 
@@ -245,4 +178,3 @@
 #undef __need_getopt
 
 #endif /* getopt.h */
-#endif /* getopt.h */

reply via email to

[Prev in Thread] Current Thread [Next in Thread]