--- /dev/null
+dnl Copyright © 2021 Nick Bowler
+dnl
+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.
+
+dnl DX_BASENAME(variable, string)
+dnl
+dnl If string, which must be a single shell word, contains a / character,
+dnl variable is assigned to the portion of string that follows the last
+dnl such character. Otherwise, variable is set to string.
+AC_DEFUN([DX_BASENAME],
+[AC_REQUIRE([_DX_BASENAME_SETUP])dnl
+dx_fn_basename $1 $2])
+
+AC_DEFUN_ONCE([_DX_BASENAME_SETUP], [m4_divert_push([INIT_PREPARE])dnl
+dx_fn_basename () {
+ _dx_tmp=; { _dx_tmp=${2##*/}; } 2>/dev/null
+ AS_CASE([$_dx_tmp], [""], [_dx_save_IFS=$IFS; IFS=/
+ for _dx_tmp in $][2; do :; done
+ IFS=$_dx_save_IFS])
+ AS_VAR_SET([$][1], [$_dx_tmp])
+}
+m4_divert_pop()])
[dx_cv_bison_found=:
AC_PATH_PROGS_FEATURE_CHECK([BISON], [bison],
[_DX_BISON_DO_TEST([$ac_path_BISON],
-[bison_relcmd=${ac_path_BISON##*/}
-bison_bypath=`command -v "$bison_relcmd"` #''
+[DX_BASENAME([bison_relcmd], ["$ac_path_BISON"])
+bison_bypath=`{ command -v "$bison_relcmd"; } 2>/dev/null` #''
ac_cv_path_BISON=$ac_path_BISON
test x"$bison_bypath" = x"$ac_path_BISON" && ac_cv_path_BISON=$bison_relcmd
ac_path_BISON_found=:
[dx_cv_flex_found=:
AC_PATH_PROGS_FEATURE_CHECK([FLEX], [flex lex],
[_DX_FLEX_DO_TEST([$ac_path_FLEX],
-[flex_relcmd=${ac_path_FLEX##*/}
-flex_bypath=`command -v "$flex_relcmd"` #''
+[DX_BASENAME([flex_relcmd], ["$ac_path_FLEX"])
+flex_bypath=`{ command -v "$flex_relcmd"; } 2>/dev/null` #''
ac_cv_path_FLEX=$ac_path_FLEX
test x"$flex_bypath" = x"$ac_path_FLEX" && ac_cv_path_FLEX=$flex_relcmd
ac_path_FLEX_found=:
AC_PATH_PROGS_FEATURE_CHECK([GOB2], [gob2],
[rm -f conftest.c
$ac_path_GOB2 conftest.gob >&AS_MESSAGE_LOG_FD 2>&1 && test -f conftest.c && {
- gob_relcmd=${ac_path_GOB2##*/}
- gob_bypath=`command -v "$gob_relcmd"` # ''
+ DX_BASENAME([gob_relcmd], ["$ac_path_GOB2"])
+ gob_bypath=`{ command -v "$gob_relcmd"; } 2>/dev/null` # ''
ac_cv_path_GOB2=$ac_path_GOB2
test x"$gob_bypath" = x"$ac_path_GOB2" && ac_cv_path_GOB2=$gob_relcmd
ac_path_GOB2_found=:
]])
AT_CLEANUP
+
+AT_SETUP([DX_BASENAME])
+AT_KEYWORDS([DX_BASENAME macro])
+
+AT_DATA([test.in], [[@base0@
+@base1@
+@base2@
+@base3@
+]])
+
+TEST_CONFIGURE_AC(
+[[DX_BASENAME([base0], ["hello"])
+DX_BASENAME([base1], ["foo/bar"])
+DX_BASENAME([base2], ["/foo/bar/baz"])
+DX_BASENAME([base3], ["hello world"])
+AC_SUBST([base0])
+AC_SUBST([base1])
+AC_SUBST([base2])
+AC_SUBST([base3])
+AC_CONFIG_FILES([test])
+]])
+TEST_AUTORECONF
+
+TEST_CONFIGURE
+AT_CHECK([cat test], [0], [hello
+bar
+baz
+hello world
+])
+
+AT_CLEANUP
# Check the search via path lookup
save_PATH=$PATH
-PATH=$PWD/bin${PATH:+":$PATH"}
+PATH=`pwd`/bin${PATH:+":$PATH"}
-# Sanity test on PATH lookup
-AT_CHECK([test x"`command -v $1`" = x"$PWD/bin/$1" || exit 99 #''])
+# Sanity test on PATH lookup; configure will substitute absolute path if
+# "command" does not work (e.g., heirloom-sh).
+expected=$1
+val=`$TEST_SHELL -c 'command -v $1'`
+test x"$val" = x"`pwd`/bin/$1" || expected=`pwd`/bin/$1
TEST_CONFIGURE
AT_CHECK_UNQUOTED([cat test], [0], [yes
-$1
+$expected
])
PATH=$save_PATH