1 dnl SPDX-License-Identifier: FSFULLR
3 # getopt.m4 serial 49 (modified version)
4 dnl Copyright (C) 2002-2006, 2008-2023 Free Software Foundation, Inc.
5 dnl This file is free software; the Free Software Foundation
6 dnl gives unlimited permission to copy and/or distribute it,
7 dnl with or without modifications, as long as this notice is preserved.
9 # This version has been modified to reduce complexity since we only need
10 # GNU getopt_long and do not care about replacing getopt.
12 # Check for a POSIX compliant getopt function with GNU extensions (such as
13 # options with optional arguments) and the functions getopt_long,
15 AC_DEFUN([gl_FUNC_GETOPT_GNU],
17 AC_REQUIRE([gl_GETOPT_CHECK_HEADERS])
19 if test -n "$gl_replace_getopt"; then
24 AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
28 if test -z "$gl_replace_getopt"; then
29 AC_CHECK_HEADERS([getopt.h], [], [gl_replace_getopt=yes])
32 if test -z "$gl_replace_getopt"; then
33 AC_CHECK_FUNCS([getopt_long], [], [gl_replace_getopt=yes])
36 dnl BSD getopt_long uses a way to reset option processing, that is different
37 dnl from GNU and Solaris (which copied the GNU behavior). We support both
38 dnl GNU and BSD style resetting of getopt_long(), so there's no need to use
39 dnl GNU getopt_long() on BSD due to different resetting style.
40 if test -z "$gl_replace_getopt"; then
41 AC_CHECK_DECL([optreset],
42 [AC_DEFINE([HAVE_OPTRESET], 1,
43 [Define to 1 if getopt.h declares extern int optreset.])],
44 [], [#include <getopt.h>])
47 dnl POSIX 2008 does not specify leading '+' behavior, but see
48 dnl http://austingroupbugs.net/view.php?id=191 for a recommendation on
49 dnl the next version of POSIX. We don't use that feature, so this
50 dnl is not a problem for us. Thus, the respective test was removed here.
52 dnl Checks for getopt handling '-' as a leading character in an option
53 dnl string were removed, since we also don't use that feature.
57 AC_DEFUN([gl_GETOPT_SUBSTITUTE],
62 AC_CHECK_HEADERS_ONCE([sys/cdefs.h])
64 AC_DEFINE([__GETOPT_PREFIX], [[rpl_]],
65 [Define to rpl_ if the getopt replacement functions and variables
72 AC_DEFUN([gl_GETOPT], [gl_FUNC_GETOPT_GNU])