]> git.ipfire.org Git - thirdparty/libtool.git/commitdiff
Add an XSI replacement for func_split_short_opt, with test cases.
authorGary V. Vaughan <gary@gnu.org>
Sun, 27 Jun 2010 10:21:59 +0000 (17:21 +0700)
committerGary V. Vaughan <gary@gnu.org>
Sun, 27 Jun 2010 22:41:36 +0000 (05:41 +0700)
* libltdl/config/getopt.m4sh (m4go_shortnoargs): Remove 'v' now
that getopt.m4sh doesn't steal that letter for the --version
short option.
* libltdl/config/ltmain.m4sh (M4SH_GETOPTS): We can now use 'v'
as a short option for '--verbose'.
* libltdl/config/getopt.m4sh (m4go_printopts): Add back in the
leading '-' for remaining non-argument short options.
(func_split_short_opt): Use the correct sed script variable.
* libltdl/m4/libtool.m4 (_LT_CHECK_SHELL_FEATURES): Also ensure
that XSI substring extraction is supported.
(_LT_PROG_XSI_SHELLFNS): Use XSI substring extraction to split
short options to avoid unnecessary forks if the host shell
supports that.
* tests/getopt-m4sh.at: New tests for getopt.m4sh coverage.
* Makefile.am (TESTSUITE_AT): Add getopt-m4sh.at.
(TESTS_ENVIRONMENT): Pass M4SH and SED for substition into the
m4sh expansion performed in tests/getopt-m4sh.at.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
ChangeLog
Makefile.am
libltdl/config/getopt.m4sh
libltdl/config/ltmain.m4sh
libltdl/m4/libtool.m4
tests/getopt-m4sh.at [new file with mode: 0644]

index 69117c9bb96a9c96ada401b62d000df6c3b31d89..cf3af83dc86628c4792979b7e7975297d321a14e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2010-06-28  Gary V. Vaughan  <gary@gnu.org>
+
+       Add an XSI replacement for func_split_short_opt, with test cases.
+       * libltdl/config/getopt.m4sh (m4go_shortnoargs): Remove 'v' now
+       that getopt.m4sh doesn't steal that letter for the --version
+       short option.
+       * libltdl/config/ltmain.m4sh (M4SH_GETOPTS): We can now use 'v'
+       as a short option for '--verbose'.
+       * libltdl/config/getopt.m4sh (m4go_printopts): Add back in the
+       leading '-' for remaining non-argument short options.
+       (func_split_short_opt): Use the correct sed script variable.
+       * libltdl/m4/libtool.m4 (_LT_CHECK_SHELL_FEATURES): Also ensure
+       that XSI substring extraction is supported.
+       (_LT_PROG_XSI_SHELLFNS): Use XSI substring extraction to split
+       short options to avoid unnecessary forks if the host shell
+       supports that.
+       * tests/getopt-m4sh.at: New tests for getopt.m4sh coverage.
+       * Makefile.am (TESTSUITE_AT): Add getopt-m4sh.at.
+       (TESTS_ENVIRONMENT): Pass M4SH and SED for substition into the
+       m4sh expansion performed in tests/getopt-m4sh.at.
+
 2010-06-27  Gary V. Vaughan  <gary@gnu.org>
 
        Add missing case branch terminators.
index 58224286ac3310df54ad3a842a3f88c47b92ae42..320a2a32cdaec998b86225440318e40647e97a04 100644 (file)
@@ -453,6 +453,7 @@ dist-hook:
 # The testsuite files are evaluated in the order given here.
 TESTSUITE      = tests/testsuite
 TESTSUITE_AT   = tests/testsuite.at \
+                 tests/getopt-m4sh.at \
                  tests/libtoolize.at \
                  tests/help.at \
                  tests/duplicate_members.at \
@@ -519,7 +520,7 @@ EXTRA_DIST     += $(srcdir)/$(TESTSUITE) $(TESTSUITE_AT) $(srcdir)/tests/package
 TESTS_ENVIRONMENT = MAKE="$(MAKE)" CC="$(CC)" CFLAGS="$(CFLAGS)" \
        CPP="$(CPP)" CPPFLAGS="$(CPPFLAGS)" LD="$(LD)" LDFLAGS="$(LDFLAGS)" \
        LIBS="$(LIBS)" LN_S="$(LN_S)" NM="$(NM)" RANLIB="$(RANLIB)" \
-       STRIP="$(STRIP)" lt_INSTALL="$(INSTALL)" \
+       M4SH="$(M4SH)" SED="$(SED)" STRIP="$(STRIP)" lt_INSTALL="$(INSTALL)" \
        OBJEXT="$(OBJEXT)" EXEEXT="$(EXEEXT)" \
        SHELL="$(SHELL)" CONFIG_SHELL="$(SHELL)" \
        CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS)" CXXCPP="$(CXXCPP)" \
index 76f9d35d63541e6fca69286cb4f8184aa657823a..b3bf73882973a7b52d895adcbc029773001f1866 100644 (file)
@@ -181,7 +181,7 @@ m4_define([m4go_branches], [])      # case branches to process options
 # OPTION, [|])' to insert the separator pipe symbols - which requires
 # that `m4go_shortargs' be undefined if the first option appended is not
 # prefixed by a leading `|'.
-m4_define([m4go_shortnoargs], [-\?*|-h*|-v*])
+m4_define([m4go_shortnoargs], [-\?*|-h*])
 
 
 # M4SH_GETOPTS(SHORT-SPEC1, LONG-MATCH1, DEF1, INIT1,
@@ -504,7 +504,7 @@ m4_ifset([m4go_shortargs], dnl (
 [      # Separate non-argument short options:
       ]m4go_shortnoargs[)
                        func_split_short_opt "$opt"
-                       set dummy "$func_split_short_opt_name" "$func_split_short_opt_arg" ${1+"[$]@"}
+                       set dummy "$func_split_short_opt_name" "-$func_split_short_opt_arg" ${1+"[$]@"}
                        shift
                        ;;
 
@@ -627,7 +627,7 @@ func_split_short_opt ()
     my_sed_short_rest='1s/^..\(.*\)$/\1/;q'
 
     func_split_short_opt_name=`$ECHO "$1" | $SED "$my_sed_short_opt"`
-    func_split_short_opt_arg=`$ECHO "$1" | $SED "$my_sed_short_arg"`
+    func_split_short_opt_arg=`$ECHO "$1" | $SED "$my_sed_short_rest"`
 } # func_split_short_opt may be replaced by XSI optimised implementation
 
 
index 93c3222a5e246da6b90950f1d87147d61be62836..217643dde59d5f3b0a9b2e9c6a5776f272779c4b 100644 (file)
@@ -370,7 +370,7 @@ M4SH_GETOPTS(
   [],          [--silent|--quiet],             [],                     [
        preserve_args="$preserve_args $opt"
         opt_verbose=false],
-  [],          [--verbose],                    [],                     [
+  [v],         [--verbose],                    [],                     [
        preserve_args="$preserve_args $opt"
        opt_silent=false],
   [!],         [--tag],                        [],                     [
index 8827d4a022a64982297800c44ce0aa921ed99142..dcb2c437dde586f60c6b0aaf88a66b9cdc3ec454 100644 (file)
@@ -7227,6 +7227,14 @@ lt_shell_append=no
 AC_MSG_RESULT([$lt_shell_append])
 _LT_CONFIG_LIBTOOL_INIT([lt_shell_append='$lt_shell_append'])
 
+AC_MSG_CHECKING([whether the shell understands variable substring :-syntax])
+lt_shell_substring=no
+( _lt_dummy="-bar"
+  test "${_lt_dummy:0:2},${_lt_dummy:2}" = -b,ar ) >/dev/null 2>&1 \
+&& lt_shell_substring=yes
+AC_MSG_RESULT([$lt_shell_substring])
+_LT_CONFIG_LIBTOOL_INIT([lt_shell_substring='$lt_shell_substring'])
+
 if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
   lt_unset=unset
 else
@@ -7318,6 +7326,12 @@ if test x"$lt_shell_append" = xyes; then
   _LT_PROG_XSI_REPLACE([func_append], [    eval "${1}+=\\${2}"])
 fi
 
+if test x"$lt_shell_substring" = xyes; then
+  _LT_PROG_XSI_REPLACE([func_split_short_opt], [dnl
+    func_split_short_opt_name=${1:0:2}
+    func_split_short_opt_arg=${1:2}])
+fi
+
 if test x"$_lt_xsi_replace_fail" = x":"; then
   AC_MSG_WARN([Unable to substitute faster XSI functions in $ofile]) 
 fi
diff --git a/tests/getopt-m4sh.at b/tests/getopt-m4sh.at
new file mode 100644 (file)
index 0000000..c55acfc
--- /dev/null
@@ -0,0 +1,132 @@
+# getopts-m4sh.at -- test getopts.m4sh option parsers       -*- Autotest -*-
+#
+#   Copyright (C) 2010 Free Software Foundation, Inc.
+#   Written by Gary V. Vaughan, 2010
+#
+#   This file is part of GNU Libtool.
+#
+# GNU Libtool is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# GNU Libtool is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Libtool; see the file COPYING.  If not, a copy
+# can be downloaded from  http://www.gnu.org/licenses/gpl.html,
+# or obtained by writing to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+####
+
+AT_BANNER([Shell option parser generator.])
+
+auxdir="$abs_top_srcdir/libltdl/config"
+
+
+# _LT_AT_GETOPT_M4SH_SETUP
+# ------------------------
+m4_define([_LT_AT_GETOPT_M4SH_SETUP],
+[m4_pattern_allow([AS_INIT])
+m4_pattern_allow([m4_include])
+AT_DATA([options.m4sh],
+[[AS_INIT[]m4_include([getopt.m4sh])
+options=
+M4SH_GETOPTS(
+  [f], [--force],      [],     [options="$options force"],
+  [i], [--install],    [],     [options="$options install"],
+  [v], [--verbose],    [],     [options="$options verbose"],
+  [!], [--ltdl],       [false],[options="$options ltdl=$optarg"],
+[echo $options])
+]])
+m4_pattern_forbid([m4_include])
+m4_pattern_forbid([AS_INIT])
+
+$M4SH -B $abs_top_srcdir/libltdl/config options.m4sh \
+    | $SED \
+       -e "s,@LN_S\@,$LN_S,g" \
+       -e "s,@SED\@,$SED,g" \
+    > options
+])# _LT_AT_GETOPT_M4SH_SETUP
+
+
+# _LT_AT_XSI_FUNC_EXTRACT(FUNC-NAME)
+# ----------------------------------
+# Extract the XSI decorated function FUNC-NAME from libtool
+m4_define([_LT_AT_XSI_FUNC_EXTRACT],
+[dnl {{
+$SED '/^# $1/q' options > options.tmp
+$SED -n '/^$1/,/^} # XSI $1 /p' $abs_top_builddir/libtool >> options.tmp
+$SED '1,/^} # $1 /d' options >> options.tmp
+rm -f options && mv options.tmp options])
+
+
+## ----------------------- ##
+## Short option splitting. ##
+## ----------------------- ##
+
+AT_SETUP([short option splitting])
+
+AT_DATA(expout,
+[[force verbose install
+]])
+
+_LT_AT_GETOPT_M4SH_SETUP
+
+AT_CHECK([$SHELL ./options -fvi], 0, [expout])
+
+AT_CLEANUP
+
+
+AT_SETUP([enhanced shell short option splitting])
+
+# Don't bother with additional XSI checks unless functions were substituted
+AT_CHECK([fgrep '# XSI func_split_short_opt' $abs_top_builddir/libtool >/dev/null 2>&1 || (exit 77)])
+
+AT_DATA(expout,
+[[force verbose install
+]])
+
+_LT_AT_GETOPT_M4SH_SETUP
+_LT_AT_XSI_FUNC_EXTRACT(func_split_short_opt)
+
+AT_CHECK([$SHELL ./options -fvi], 0, [expout])
+
+AT_CLEANUP
+
+
+## ---------------------- ##
+## Long option splitting. ##
+## ---------------------- ##
+
+AT_SETUP([long option splitting])
+
+AT_DATA(expout,
+[[ltdl=long
+]])
+
+_LT_AT_GETOPT_M4SH_SETUP
+
+AT_CHECK([$SHELL ./options --ltdl=long], 0, [expout])
+
+AT_CLEANUP
+
+
+AT_SETUP([XSI long option splitting])
+
+# Don't bother with additional XSI checks unless functions were substituted
+AT_CHECK([fgrep '# XSI func_split_long_opt' $abs_top_builddir/libtool >/dev/null 2>&1 || (exit 77)])
+
+AT_DATA(expout,
+[[ltdl=long
+]])
+
+_LT_AT_GETOPT_M4SH_SETUP
+_LT_AT_XSI_FUNC_EXTRACT(func_split_long_opt)
+
+AT_CHECK([$SHELL ./options --ltdl=long], 0, [expout])
+
+AT_CLEANUP