From: Gary V. Vaughan Date: Sun, 27 Jun 2010 10:21:59 +0000 (+0700) Subject: Add an XSI replacement for func_split_short_opt, with test cases. X-Git-Tag: v2.4~130 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=448445c6f8767ca83d019c126fdf894b927792fe;p=thirdparty%2Flibtool.git 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. Signed-off-by: Gary V. Vaughan --- diff --git a/ChangeLog b/ChangeLog index 69117c9bb..cf3af83dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2010-06-28 Gary V. Vaughan + + 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 Add missing case branch terminators. diff --git a/Makefile.am b/Makefile.am index 58224286a..320a2a32c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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)" \ diff --git a/libltdl/config/getopt.m4sh b/libltdl/config/getopt.m4sh index 76f9d35d6..b3bf73882 100644 --- a/libltdl/config/getopt.m4sh +++ b/libltdl/config/getopt.m4sh @@ -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 diff --git a/libltdl/config/ltmain.m4sh b/libltdl/config/ltmain.m4sh index 93c3222a5..217643dde 100644 --- a/libltdl/config/ltmain.m4sh +++ b/libltdl/config/ltmain.m4sh @@ -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], [], [ diff --git a/libltdl/m4/libtool.m4 b/libltdl/m4/libtool.m4 index 8827d4a02..dcb2c437d 100644 --- a/libltdl/m4/libtool.m4 +++ b/libltdl/m4/libtool.m4 @@ -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 index 000000000..c55acfc8f --- /dev/null +++ b/tests/getopt-m4sh.at @@ -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