-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
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])])
#!@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
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