]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
2003-11-24 Paolo Bonzini <bonzini@gnu.org>
authorPaolo Bonzini <bonzini@gnu.org>
Mon, 24 Nov 2003 10:44:52 +0000 (10:44 +0000)
committerPaolo Bonzini <bonzini@gnu.org>
Mon, 24 Nov 2003 10:44:52 +0000 (10:44 +0000)
        * lib/m4sugar/m4sh.m4 (AS_REQUIRE_SHELL_FN): New macro.
        * tests/m4sh.at (AS_REQUIRE_SHELL_FN and m4_require): New test.

Approved by Paul Eggert.

lib/m4sugar/m4sh.m4
tests/m4sh.at

index 3868939d31770d3255f6a9d2321d590d7a02c2e8..9fa642a9db9b89e380fdb73ff9c0a7264b10e2cb 100644 (file)
@@ -134,6 +134,19 @@ m4_define([AS_REQUIRE],
               [m4_divert_text([M4SH-INIT], [m4_default([$2], [$1])])])])
 
 
+# AS_REQUIRE_SHELL_FN(NAME-TO-CHECK, BODY-TO-EXPAND)
+# --------------------------------------------------
+# BODY-TO-EXPAND is the body of a shell function to be emitted in the
+# M4SH-INIT section when expanded (required or not).  Unlike other
+# xx_REQUIRE macros, BODY-TO-EXPAND is mandatory.
+#
+m4_define([AS_REQUIRE_SHELL_FN],
+[m4_provide_if([AS_SHELL_FN_$1], [],
+               [m4_provide([AS_SHELL_FN_$1])m4_divert_text([M4SH-INIT], [$1() {
+$2
+}])])])
+
+
 # AS_SHELL_SANITIZE
 # -----------------
 # Try to be as Bourne and/or POSIX as possible.
index fd578d0399fdd33e6588820b3a6fc89789f59b6d..e924d62b398ff099853d9d53377e55ab5539d19f 100644 (file)
@@ -350,6 +350,50 @@ AT_CHECK([./script])
 
 AT_CLEANUP
 
+
+## ------------------------------------ ##
+## AS_REQUIRE_SHELL_FN and m4_require.  ##
+## ------------------------------------ ##
+
+# Hypothesis: M4sh expands the requirements of AS_REQUIRE_SHELL_FN
+# in the main diversion, and not in M4SH-INIT.
+
+AT_SETUP([AS@&t@_REQUIRE_SHELL_FN and m4@&t@_require])
+
+AT_DATA_M4SH([script.as], [[dnl
+AS_INIT
+
+m4_defun([in_m4_sh_init], still_in_m4sh_init=yes)
+m4_defun([not_in_m4_sh_init], still_in_m4sh_init=no)
+
+m4_defun([error_if_emitted_in_m4sh_init], [
+  if test x$still_in_m4sh_init = xyes; then
+    AS_ERROR([requirement emitted in M4SH-INIT])
+  fi
+])
+
+m4_defun([TEST_FUNC_BODY], [
+m4_require([error_if_emitted_in_m4sh_init])
+: echo in shell function, with parameter = [$]1
+])
+
+
+m4_defun([test_init], [
+AS_REQUIRE([in_m4_sh_init])
+AS_REQUIRE_SHELL_FN([test_func], [TEST_FUNC_BODY])
+AS_REQUIRE([not_in_m4_sh_init])
+])
+
+test_init
+test_func parameter1
+]])
+
+AT_CHECK_M4SH
+AT_CHECK([./script])
+
+AT_CLEANUP
+
+
 ## -------------- ##
 ## AS_HELP_STRING ##
 ## -------------- ##