1# getopt.m4 serial 14 (modified version) 2dnl Copyright (C) 2002-2006, 2008 Free Software Foundation, Inc. 3dnl This file is free software; the Free Software Foundation 4dnl gives unlimited permission to copy and/or distribute it, 5dnl with or without modifications, as long as this notice is preserved. 6 7# The getopt module assume you want GNU getopt, with getopt_long etc, 8# rather than vanilla POSIX getopt. This means your code should 9# always include <getopt.h> for the getopt prototypes. 10 11AC_DEFUN([gl_GETOPT_SUBSTITUTE], 12[ 13 AC_LIBOBJ([getopt]) 14 AC_LIBOBJ([getopt1]) 15 gl_GETOPT_SUBSTITUTE_HEADER 16]) 17 18AC_DEFUN([gl_GETOPT_SUBSTITUTE_HEADER], 19[ 20 GETOPT_H=getopt.h 21 AC_DEFINE([__GETOPT_PREFIX], [[rpl_]], 22 [Define to rpl_ if the getopt replacement functions and variables 23 should be used.]) 24 AC_SUBST([GETOPT_H]) 25]) 26 27AC_DEFUN([gl_GETOPT_CHECK_HEADERS], 28[ 29 if test -z "$GETOPT_H"; then 30 AC_CHECK_HEADERS([getopt.h], [], [GETOPT_H=getopt.h]) 31 fi 32 33 if test -z "$GETOPT_H"; then 34 AC_CHECK_FUNCS([getopt_long], [], [GETOPT_H=getopt.h]) 35 fi 36 37 dnl BSD getopt_long uses a way to reset option processing, that is different 38 dnl from GNU and Solaris (which copied the GNU behavior). We support both 39 dnl GNU and BSD style resetting of getopt_long(), so there's no need to use 40 dnl GNU getopt_long() on BSD due to different resetting style. 41 dnl 42 dnl With getopt_long(), some BSD versions have a bug in handling optional 43 dnl arguments. This bug appears only if the environment variable 44 dnl POSIXLY_CORRECT has been set, so it shouldn't be too bad in most 45 dnl cases; probably most don't have that variable set. But if we actually 46 dnl hit this bug, it is a real problem due to our heavy use of optional 47 dnl arguments. 48 dnl 49 dnl According to CVS logs, the bug was introduced in OpenBSD in 2003-09-22 50 dnl and copied to FreeBSD in 2004-02-24. It was fixed in both in 2006-09-22, 51 dnl so the affected versions shouldn't be popular anymore anyway. NetBSD 52 dnl never had this bug. TODO: What about Darwin and others? 53 if test -z "$GETOPT_H"; then 54 AC_CHECK_DECL([optreset], 55 [AC_DEFINE([HAVE_OPTRESET], 1, 56 [Define to 1 if getopt.h declares extern int optreset.])], 57 [], [#include <getopt.h>]) 58 fi 59 60 dnl Solaris 10 getopt doesn't handle `+' as a leading character in an 61 dnl option string (as of 2005-05-05). We don't use that feature, so this 62 dnl is not a problem for us. Thus, the respective test was removed here. 63]) 64 65AC_DEFUN([gl_GETOPT_IFELSE], 66[ 67 AC_REQUIRE([gl_GETOPT_CHECK_HEADERS]) 68 AS_IF([test -n "$GETOPT_H"], [$1], [$2]) 69]) 70 71AC_DEFUN([gl_GETOPT], [gl_GETOPT_IFELSE([gl_GETOPT_SUBSTITUTE])]) 72