]> git.draconx.ca Git - dxcommon.git/commitdiff
exported.sh: Restructure argument processing a bit.
authorNick Bowler <nbowler@draconx.ca>
Thu, 21 Apr 2022 05:23:05 +0000 (01:23 -0400)
committerNick Bowler <nbowler@draconx.ca>
Thu, 21 Apr 2022 05:28:39 +0000 (01:28 -0400)
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
snippet/exported.sh.in
tests/macros.at

index 7bb6e9e5821e3753abd901adea89284e436c7fea..6ac92171bd4fd8a2b60a26419b19f78ca8acef09 100644 (file)
@@ -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])])
index ef875a55f3ddd500be41a9a5db4beef24a712afc..f9d3c4043511767cded4010d9578154b54079fdb 100644 (file)
@@ -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.
 
 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
index a5efc2388189ed98f2997e933374d518220433fe..99b93515b04ab5e882e5c76060dabd99dcc961ad 100644 (file)
@@ -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