lördag den 10 mars 2012 klockan 10:28 skrev Alfred M. Szmidt detta:
> Yes, please! I have begun thinking how I could let the user
> override grep and sed, in particular, so your sketch does exactly
> what I want.
>
> I was really just thinking of something silly like this and have each
> test source tools.sh, the tools.sh.in file could be better of course,
> i.e. letting the user overide GREP etc. The checks for programs can
> be more exact as well, providing wrappers and what not. If GREP is
> missing, we and FOO test requires it, we can have something like,
>
> +AM_MISSING_PROG(GREP, grep, $missing_dir)
> ...
I have had success with the following base construct, so I volonteer
to go ahead along these lines. AC_PATH_PROG and AC_VAR_ARG are the key
ingredients for searching and overriding. The test run gave me a good
way of testing "func_id_uid" and "func_id_user" which were needed as
work around for a troublesome early Belenix, i.e., OpenSolaris version.
Regards,
Mats
diff --git a/configure.ac b/configure.ac
index 017d0ac..14dd6e3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -129,6 +129,9 @@ AC_ISC_POSIX
AC_PROG_CC
gl_EARLY
AC_CHECK_TOOL(AR, ar)
+AC_PATH_PROG(DD, dd, dd)
+AC_PATH_PROG(MKTEMP, mktemp, mktemp)
+AC_PATH_PROG(NETSTAT, netstat, netstat)
AC_PATH_PROG(RM, rm, rm)
AC_PROG_CPP
AC_PROG_INSTALL
@@ -136,8 +139,13 @@ AC_PROG_MAKE_SET
AC_PROG_RANLIB
AC_PROG_YACC
AC_PROG_LN_S
+AC_PROG_SED
AM_MISSING_PROG(HELP2MAN, help2man, $missing_dir)
-
+AC_ARG_VAR(GREP, [Preferred grep(1) utility.])
+AC_ARG_VAR(SED, [Preferred sed(1) utility.])
+AC_ARG_VAR(DD, [Path to dd(1).])
+AC_ARG_VAR(MKTEMP, [Path to mktemp(1).])
+AC_ARG_VAR(NETSTAT, [Path to netstat(8).])
gl_INIT
### Checks for libraries.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 043e790..8d20c11 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -67,3 +67,14 @@ endif
TESTS = $(check_PROGRAMS) $(dist_check_SCRIPTS)
TESTS_ENVIRONMENT = EXEEXT=$(EXEEXT)
+
+BUILT_SOURCES = tools.sh
+
+tools_subst = sed -e 's,[@]GREP[@],$(GREP),g' \
+ -e 's,[@]SED[@],$(SED),g' \
+ -e 's,[@]DD[@],$(DD),g' \
+ -e 's,[@]MKTEMP[@],$(MKTEMP),g' \
+ -e 's,[@]NETSTAT[@],$(NETSTAT),g'
+
+tools.sh: tools.sh.in Makefile
+ $(tools_subst) < $(srcdir)/tools.sh.in > $@
diff --git a/tests/tools.sh.in b/tests/tools.sh.in
new file mode 100644
index 0000000..a18a16d
--- /dev/null
+++ b/tests/tools.sh.in
@@ -0,0 +1,16 @@
+GREP=@GREP@
+SED=@SED@
+DD=@DD@
+MKTEMP=@MKTEMP@
+NETSTAT=@NETSTAT@
+
+# Some Solaris variants provide id(1) lacking `-u' switch.
+# Work around this by some computation.
+
+func_id_uid () {
+ id $1 | $SED -n 's,.*uid=\([0-9]*\).*,\1,p'
+}
+
+func_id_user () {
+ id $1 | $SED -n 's,.*uid=[0-9]*(\([^)]*\).*,\1,p'
+}