I got a copy of preprocessed sources from bryan d. o'connor.
Here's what seems to be the problem:
* <config.h> has "#define __GETOPT_PREFIX rpl_" as expected.
* unexmacosx.c includes the Gnulib <unistd.h>.
* The Gnulib <unistd.h> includes the system unistd.h, which declares
the getopt-related names itself (without including anything) and then
finishes.
* The Gnulib <unistd.h> then includes the Gnulib <getopt.h>.
* The Gnulib <getopt.h> includes the system getopt.h.
* The system getopt.h includes the Gnulib <unistd.h>.
* This inner Gnulib <unistd.h> does nothing, and finishes.
* The system getopt.h declares 'struct option' and other stuff, and finishes.
* The Gnulib <getopt.h> then does this:
#if defined __GETOPT_PREFIX && !defined __need_getopt
# if !@HAVE_GETOPT_H@
# include <stdlib.h>
# include <stdio.h>
# include <unistd.h>
# endif
# undef __need_getopt
...
# 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 option __GETOPT_ID (option)
...
#endif
* This should "#define option rpl_option", but apparently it doesn't.
* Presumably __GETOPT_PREFIX is defined, but __need_getopt is also defined,
so the entire #if is skipped.
* And when Gnulib <getopt.h> declares a 'struct option', this clashes
with the 'struct option' declared in the system getopt.h.
If my analysis is right, we need to figure out why __need_getopt is
defined. Can you send the output of the following?
cd emacs
grep -r __need_getopt . /usr/include
PS. This all seems to be a case where we should be using Gnulib's
identifier replacement mechanism, but I don't understand it that
well and if memory serves it doesn't work with struct tags anyway.