According to POSIX, <unistd.h> should declare optarg, optind, etc. But on Solaris, the system header does this only if __EXTENSIONS__ is defined. This makes its use in gnulib automatic:
2009-08-12 Bruno Haible <br...@clisp.org> Ensure that optarg etc. get declared by <unistd.h>. * m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Require AC_USE_SYSTEM_EXTENSIONS. * modules/getopt (Depends-on): Add 'extensions'. --- m4/getopt.m4.orig 2009-08-13 01:07:50.000000000 +0200 +++ m4/getopt.m4 2009-08-13 01:07:32.000000000 +0200 @@ -1,4 +1,4 @@ -# getopt.m4 serial 19 +# getopt.m4 serial 20 dnl Copyright (C) 2002-2006, 2008-2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -41,6 +41,9 @@ # Determine whether to replace the entire getopt facility. AC_DEFUN([gl_GETOPT_CHECK_HEADERS], [ + dnl Persuade Solaris <unistd.h> to declare optarg, optind, opterr, optopt. + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + gl_replace_getopt= if test -z "$gl_replace_getopt"; then AC_CHECK_HEADERS([getopt.h], [], [gl_replace_getopt=yes]) --- modules/getopt.orig 2009-08-13 01:07:50.000000000 +0200 +++ modules/getopt 2009-08-13 01:01:34.000000000 +0200 @@ -11,6 +11,7 @@ Depends-on: gettext-h unistd +extensions configure.ac: gl_GETOPT