From 7c5df228a04f7a655486bffee6f169f52b5edb35 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Thu, 21 Apr 2022 01:23:05 -0400 Subject: [PATCH] exported.sh: Restructure argument processing a bit. Adjust the script to iterate over arguments using a for loop instead of repeatedly checkind $# and shifting. More significantly, avoid calling expr on each filename where a case pattern can do the job. Additionally, add a new test case to verify the basic sanity of this script and its corresponding Autoconf macro. --- m4/exported.m4 | 19 ++++++------ snippet/exported.sh.in | 68 ++++++++++++++++++++---------------------- tests/macros.at | 58 +++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 45 deletions(-) diff --git a/m4/exported.m4 b/m4/exported.m4 index 7bb6e9e..6ac9217 100644 --- a/m4/exported.m4 +++ b/m4/exported.m4 @@ -1,4 +1,4 @@ -dnl Copyright © 2012 Nick Bowler +dnl Copyright © 2012, 2022 Nick Bowler dnl dnl Generate the exported.sh script used to determine the exported symbols of dnl a (libtool) object file. This is required by the glconfig Automake @@ -8,18 +8,17 @@ dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2. dnl This is free software: you are free to do what the fuck you want to. dnl There is NO WARRANTY, to the extent permitted by law. -AC_DEFUN([DX_EXPORTED_SH], [dnl -AC_REQUIRE([DX_INIT]) +AC_DEFUN([DX_EXPORTED_SH], +[AC_REQUIRE([DX_INIT])dnl +AC_REQUIRE([AC_PROG_SED])dnl -AC_CONFIG_COMMANDS_PRE([dnl - AC_PROVIDE_IFELSE([LT_INIT], , [m4_warn([syntax], +AC_CONFIG_COMMANDS_PRE( +[AC_PROVIDE_IFELSE([LT_INIT], , [m4_warn([syntax], [$0 requires libtool. Consider adding an invocation of LT_INIT to configure.ac.])]) - GLOBAL_SYMBOL_PIPE=$lt_cv_sys_global_symbol_pipe - AC_SUBST([GLOBAL_SYMBOL_PIPE]) -]) +GLOBAL_SYMBOL_PIPE=$lt_cv_sys_global_symbol_pipe +AC_SUBST([GLOBAL_SYMBOL_PIPE])]) AC_CONFIG_FILES([exported.sh:]DX_BASEDIR[/snippet/exported.sh.in], - [chmod +x exported.sh]) -]) + [chmod +x exported.sh])]) diff --git a/snippet/exported.sh.in b/snippet/exported.sh.in index ef875a5..f9d3c40 100644 --- a/snippet/exported.sh.in +++ b/snippet/exported.sh.in @@ -1,6 +1,6 @@ #!@SHELL@ # -# Copyright © 2011-2012 Nick Bowler +# Copyright © 2011-2012, 2022 Nick Bowler # # Determine the list of exported symbols from archives or (libtool) object # files. @@ -11,48 +11,46 @@ OBJS= -while test $# -gt 0 +for arg do - case $1 in - /*) arg=$1 ;; - *) arg=./$1 ;; - esac + case $arg in + *.lo) + case $arg in /*) :;; *) arg=./$arg ;; esac - if expr "$arg" : '.*\.lo' >/dev/null; then - non_pic_object= - pic_object= - . "$arg" + non_pic_object= + pic_object= + . "$arg" - dir=`expr "$arg" : '\(.*\)/'` - if test x"$pic_object" != x"none"; then - OBJS="$OBJS $dir/$pic_object" - fi - if test x"$non_pic_object" != x"none"; then - OBJS="$OBJS $dir/$non_pic_object" - fi - else - OBJS="$OBJS $arg" - fi - - shift + dir=`expr "$arg" : '\(.*\)/'` + if test x"$pic_object" != x"none"; then + OBJS="$OBJS $dir/$pic_object" + fi + if test x"$non_pic_object" != x"none"; then + OBJS="$OBJS $dir/$non_pic_object" + fi + ;; + *) + OBJS="$OBJS $arg" + ;; + esac done set x $OBJS; shift case $# in 0) : ;; *) - exec 4>&1 - eval_cmd=`exec 3>&1 - { @NM@ $OBJS 3>&- - echo "(exit $?) || exit $?" >&3 - } | { @GLOBAL_SYMBOL_PIPE@ 3>&- - echo "(exit $?) || exit $?" >&3 - } | { @SED@ 's/^.* //' 3>&- - echo "(exit $?) || exit $?" >&3 - } | { sort -u 3>&- - echo "(exit $?) || exit $?" >&3 - } >&4` - exec 4>&- - eval "$eval_cmd" + exec 4>&1 + eval_cmd=`exec 3>&1 + { @NM@ $OBJS 3>&- + echo "(exit $?) || exit $?" >&3 + } | { @GLOBAL_SYMBOL_PIPE@ 3>&- + echo "(exit $?) || exit $?" >&3 + } | { @SED@ 's/^.* //' 3>&- + echo "(exit $?) || exit $?" >&3 + } | { LC_ALL=C sort -u 3>&- + echo "(exit $?) || exit $?" >&3 + } >&4` + exec 4>&- + eval "$eval_cmd" ;; esac diff --git a/tests/macros.at b/tests/macros.at index a5efc23..99b9351 100644 --- a/tests/macros.at +++ b/tests/macros.at @@ -484,3 +484,61 @@ done exit 1]) AT_CLEANUP + +AT_SETUP([DX_EXPORTED_SH]) +AT_KEYWORDS([DX_EXPORTED_SH exported.sh macro]) + +AT_DATA([helpopt.nm], +[[0000000000000000 r .LC0 +000000000000001e r .LC1 +0000000000000025 r .LC2 + U __errno_location + U __printf_chk + U __stack_chk_fail +0000000000000000 T arg_to_int +0000000000000000 b dummy.0 + U help_print_optstring +0000000000000000 T main +00000000000000c0 T print_opt + U strchr + U strerror + U strtol + U tap_bail_out +]]) + +AT_DATA([helpopt-shared.lo], +[[pic_object=helpopt.nm +non_pic_object=none +]]) + +AT_DATA([helpopt-static.lo], +[[non_pic_object=helpopt.nm +pic_object=none +]]) + +AT_DATA([helpopt.lo], +[[non_pic_object=helpopt.nm +pic_object=helpopt.nm +]]) + +AT_DATA([expout], +[[arg_to_int +main +print_opt +]]) + +TEST_CONFIGURE_AC([[AC_PROVIDE([LT_INIT]) +AC_SUBST([NM], [cat]) +lt_cv_sys_global_symbol_pipe="sed -n -e '/ T /p'" +DX_EXPORTED_SH +]]) +TEST_AUTORECONF +TEST_CONFIGURE + +AT_CHECK([$SHELL exported.sh helpopt.nm], [0], [expout]) +AT_CHECK([$SHELL exported.sh helpopt-shared.lo], [0], [expout]) +AT_CHECK([$SHELL exported.sh helpopt-static.lo], [0], [expout]) +AT_CHECK([$SHELL exported.sh helpopt.lo], [0], [expout]) +AT_CHECK([$SHELL exported.sh nonexistent], [1], [], [ignore]) + +AT_CLEANUP -- 2.43.2