Re: getopt trouble on uClibc systems
Simon Josefsson <jas <at> extundo.com>
2004-07-01 16:24:36 GMT
Here's a first attempt. The important part from getopt.m4 is:
GETOPT_H=
AC_CHECK_HEADERS([getopt.h], [], [GETOPT_H=getopt.h])
AC_CHECK_FUNCS([optarg optind opterr optopt \
getopt getopt_long getopt_long_only], [],
[GETOPT_H=getopt.h; AC_LIBOBJ([getopt]) AC_LIBOBJ([getopt1])
AC_DEFINE([getopt], [rpl_getopt],
[Define to rpl_getopt if the replacement function should be used])])
AC_SUBST([GETOPT_H])
Comments (aka things I'm unsure about):
* The intention is to create a new getopt.h when it is needed. If
getopt.h doesn't exist on the system, it is created (of course). If
the system have getopt.h, but not getopt_long, be conservative and
assume the system header file might be incorrect as well, and
provide our own getopt.h.
* I'm abusing AC_CHECK_FUNCS for global variables. This appears to
work, but ignores the type of the variables. If some system ever
have those symbols, with other types, this part will have to be
improved.
* 'getopt' is only redefined to 'rpl_getopt' when the system doesn't
have all of the GNU getopt functions, like getopt_long. So
regardless of whether getopt is present or not on the system, as
long as it doesn't have full GNU getopt, we use rpl_getopt.
(Continue reading)