From 37723302e73ab8dce05a5291d6c9278f09720eda Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Sun, 8 May 2011 13:05:47 +0200
Subject: [PATCH] getopt: Move AC_LIBOBJ invocations to module description.

* m4/getopt.m4 (gl_REPLACE_GETOPT): Remove macro.
(gl_FUNC_GETOPT): Inline it here. Move AC_LIBOBJ and gl_PREREQ_GETOPT
invocations from here...
* modules/getopt-gnu (configure.ac): ... to here.
* modules/getopt-posix (configure.ac): ... and here.
(Depends-on): Update condition.
---
 ChangeLog            | 10 ++++++++++
 m4/getopt.m4         | 18 ++++--------------
 modules/getopt-gnu   |  5 +++++
 modules/getopt-posix |  7 ++++++-
 4 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5db6ffe3ed..b1c66fd170 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-05-08  Bruno Haible  <bruno@clisp.org>
+
+	getopt: Move AC_LIBOBJ invocations to module description.
+	* m4/getopt.m4 (gl_REPLACE_GETOPT): Remove macro.
+	(gl_FUNC_GETOPT): Inline it here. Move AC_LIBOBJ and gl_PREREQ_GETOPT
+	invocations from here...
+	* modules/getopt-gnu (configure.ac): ... to here.
+	* modules/getopt-posix (configure.ac): ... and here.
+	(Depends-on): Update condition.
+
 2011-05-08  Bruno Haible  <bruno@clisp.org>
 
 	getopt, argp: Respect rules for use of AC_LIBOBJ.
diff --git a/m4/getopt.m4 b/m4/getopt.m4
index 4ad52fd54b..4d8450ff90 100644
--- a/m4/getopt.m4
+++ b/m4/getopt.m4
@@ -23,7 +23,10 @@ AC_DEFUN([gl_FUNC_GETOPT_POSIX],
     [])
   ])
   if test $REPLACE_GETOPT = 1; then
-    gl_REPLACE_GETOPT
+    dnl Arrange for getopt.h to be created.
+    gl_GETOPT_SUBSTITUTE_HEADER
+    dnl Arrange for unistd.h to include getopt.h.
+    GNULIB_UNISTD_H_GETOPT=1
   fi
 ])
 
@@ -37,19 +40,6 @@ AC_DEFUN([gl_FUNC_GETOPT_GNU],
   AC_REQUIRE([gl_FUNC_GETOPT_POSIX])
 ])
 
-# Request the gnulib implementation of the getopt functions unconditionally.
-AC_DEFUN([gl_REPLACE_GETOPT],
-[
-  dnl Arrange for getopt.h to be created.
-  gl_GETOPT_SUBSTITUTE_HEADER
-  dnl Arrange for unistd.h to include getopt.h.
-  GNULIB_UNISTD_H_GETOPT=1
-  dnl Arrange to compile the getopt implementation.
-  AC_LIBOBJ([getopt])
-  AC_LIBOBJ([getopt1])
-  gl_PREREQ_GETOPT
-])
-
 # emacs' configure.in uses this.
 AC_DEFUN([gl_GETOPT_IFELSE],
 [
diff --git a/modules/getopt-gnu b/modules/getopt-gnu
index 92b37ddbed..3e5876a1b9 100644
--- a/modules/getopt-gnu
+++ b/modules/getopt-gnu
@@ -9,6 +9,11 @@ getopt-posix
 
 configure.ac:
 gl_FUNC_GETOPT_GNU
+if test $REPLACE_GETOPT = 1; then
+  AC_LIBOBJ([getopt])
+  AC_LIBOBJ([getopt1])
+  gl_PREREQ_GETOPT
+fi
 gl_MODULE_INDICATOR_FOR_TESTS([getopt-gnu])
 
 Makefile.am:
diff --git a/modules/getopt-posix b/modules/getopt-posix
index c99f8a4feb..5da0b472ea 100644
--- a/modules/getopt-posix
+++ b/modules/getopt-posix
@@ -13,10 +13,15 @@ unistd
 extensions
 include_next
 arg-nonnull
-gettext-h       [test $GNULIB_UNISTD_H_GETOPT = 1]
+gettext-h       [test $REPLACE_GETOPT = 1]
 
 configure.ac:
 gl_FUNC_GETOPT_POSIX
+if test $REPLACE_GETOPT = 1; then
+  AC_LIBOBJ([getopt])
+  AC_LIBOBJ([getopt1])
+  gl_PREREQ_GETOPT
+fi
 
 Makefile.am:
 BUILT_SOURCES += $(GETOPT_H)
-- 
2.39.5