changeset 14968:87792dbdedee

getopt, argp: Respect rules for use of AC_LIBOBJ. * m4/argp.m4 (gl_ARGP): Don't invoke gl_REPLACE_GETOPT. (gl_REPLACE_GETOPT_ALWAYS): New macro. * m4/getopt.m4 (gl_FUNC_GETOPT_POSIX): Test whether gl_REPLACE_GETOPT_ALWAYS is defined. Set REPLACE_GETOPT.
author Bruno Haible <bruno@clisp.org>
date Sun, 08 May 2011 13:00:10 +0200
parents f5c94f32d08b
children 9ac32f9b5582
files ChangeLog m4/argp.m4 m4/getopt.m4
diffstat 3 files changed, 29 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-05-08  Bruno Haible  <bruno@clisp.org>
+
+	getopt, argp: Respect rules for use of AC_LIBOBJ.
+	* m4/argp.m4 (gl_ARGP): Don't invoke gl_REPLACE_GETOPT.
+	(gl_REPLACE_GETOPT_ALWAYS): New macro.
+	* m4/getopt.m4 (gl_FUNC_GETOPT_POSIX): Test whether
+	gl_REPLACE_GETOPT_ALWAYS is defined. Set REPLACE_GETOPT.
+
 2011-05-08  Bruno Haible  <bruno@clisp.org>
 
 	getlogin_r: Move AC_LIBOBJ invocations to module description.
--- a/m4/argp.m4
+++ b/m4/argp.m4
@@ -1,4 +1,4 @@
-# argp.m4 serial 11
+# argp.m4 serial 12
 dnl Copyright (C) 2003-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -9,10 +9,6 @@
   AC_REQUIRE([AC_C_INLINE])
   AC_REQUIRE([AC_C_RESTRICT])
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
-  dnl argp-parse.c depends on GNU getopt internals, therefore use GNU getopt
-  dnl always.
-  gl_REPLACE_GETOPT
-  dnl Note: gl_REPLACE_GETOPT does AC_LIBOBJ([getopt]), AC_LIBOBJ([getopt1]).
 
   AC_CHECK_DECL([program_invocation_name],
                 [AC_DEFINE([HAVE_DECL_PROGRAM_INVOCATION_NAME], [1],
@@ -63,3 +59,7 @@
   AC_CHECK_FUNCS_ONCE([flockfile funlockfile])
   AC_CHECK_HEADERS_ONCE([features.h linewrap.h])
 ])
+
+dnl argp-parse.c depends on GNU getopt internals, therefore use GNU getopt
+dnl always.
+AC_DEFUN([gl_REPLACE_GETOPT_ALWAYS], [])
--- a/m4/getopt.m4
+++ b/m4/getopt.m4
@@ -1,4 +1,4 @@
-# getopt.m4 serial 34
+# getopt.m4 serial 35
 dnl Copyright (C) 2002-2006, 2008-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -9,10 +9,22 @@
 [
   m4_divert_text([DEFAULTS], [gl_getopt_required=POSIX])
   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
-  gl_GETOPT_IFELSE([
+  dnl Other modules can request the gnulib implementation of the getopt
+  dnl functions unconditionally, by defining gl_REPLACE_GETOPT_ALWAYS.
+  dnl argp.m4 does this.
+  m4_ifdef([gl_REPLACE_GETOPT_ALWAYS], [
+    gl_GETOPT_IFELSE([], [])
+    REPLACE_GETOPT=1
+  ], [
+    REPLACE_GETOPT=0
+    gl_GETOPT_IFELSE([
+      REPLACE_GETOPT=1
+    ],
+    [])
+  ])
+  if test $REPLACE_GETOPT = 1; then
     gl_REPLACE_GETOPT
-  ],
-  [])
+  fi
 ])
 
 # Request a POSIX compliant getopt function with GNU extensions (such as
@@ -26,7 +38,6 @@
 ])
 
 # Request the gnulib implementation of the getopt functions unconditionally.
-# argp.m4 uses this.
 AC_DEFUN([gl_REPLACE_GETOPT],
 [
   dnl Arrange for getopt.h to be created.