(AC_CHECK_PROG): Use it. Use ifval.
(AC_CHECK_PROGS): Use ifval. Fix the quoting.
* tests/semantics.m4: Test AC_CHECK_PROG.
* tests/Makefile.am (EGREP_EXCLUDE): Add /AC_CHECK_PROGS?/.
+2000-03-03 Akim Demaille <akim@epita.fr>
+
+ * acgeneral.m4 (_AC_WHICH_A): New macro.
+ (AC_CHECK_PROG): Use it. Use ifval.
+ (AC_CHECK_PROGS): Use ifval. Fix the quoting.
+ * tests/semantics.m4: Test AC_CHECK_PROG.
+ * tests/Makefile.am (EGREP_EXCLUDE): Add /AC_CHECK_PROGS?/.
+
2000-03-02 Russ Allbery <rra@stanford.edu>
* autoscan.pl (parse_args): Add support for -m <macrodir>.
## ----------------------- ##
+# _AC_WHICH_A(NAME, PATH)
+# -----------------------
+# Work like `which -a NAME' in PATH, even if NAME is not executable.
+# Can be used inside backquotes.
+define([_AC_WHICH_A],
+[IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
+dnl $ac_dummy forces splitting on constant user-supplied paths.
+dnl POSIX.2 word splitting is done only on the output of word expansions,
+dnl not every word. This closes a longstanding sh security hole.
+ac_dummy="$2"
+for ac_dir in $ac_dummy; do
+ test -z "$ac_dir" && ac_dir=.
+ if test -f $ac_dir/$1; then
+ echo "$ac_dir/$1"
+ fi
+done
+IFS="$ac_save_ifs"
+])
+
+
# AC_CHECK_PROG(VARIABLE, PROG-TO-CHECK-FOR,
# [VALUE-IF-FOUND], [VALUE-IF-NOT-FOUND],
# [PATH], [REJECT])
[if test -n "[$]$1"; then
ac_cv_prog_$1="[$]$1" # Let the user override the test.
else
- IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
-ifelse([$6], , , [ ac_prog_rejected=no
+ifval([$6], [ ac_prog_rejected=no
])dnl
-dnl $ac_dummy forces splitting on constant user-supplied paths.
-dnl POSIX.2 word splitting is done only on the output of word expansions,
-dnl not every word. This closes a longstanding sh security hole.
- ac_dummy="ifelse([$5], , $PATH, [$5])"
- for ac_dir in $ac_dummy; do
- test -z "$ac_dir" && ac_dir=.
- if test -f $ac_dir/$ac_word; then
-ifelse([$6], , , dnl
-[ if test "[$ac_dir/$ac_word]" = "$6"; then
- ac_prog_rejected=yes
- continue
- fi
-])dnl
- ac_cv_prog_$1="$3"
- break
+ for ac_path in `_AC_WHICH_A([$ac_word], [m4_default([$5], [$PATH])])`; do
+ifval([$6],
+[ if test "$ac_path" = "$6"; then
+ ac_prog_rejected=yes
+ continue
fi
+])dnl
+ ac_cv_prog_$1="$3"
+ break
done
- IFS="$ac_save_ifs"
-ifelse([$6], , , [if test $ac_prog_rejected = yes; then
+ifval([$6], [if test $ac_prog_rejected = yes; then
# We found a bogon in the path, so make sure we never use it.
set dummy [$]ac_cv_prog_$1
shift
# However, it has the same basename, so the bogon will be chosen
# first if we set $1 to just the basename; use the full file name.
shift
- set dummy "$ac_dir/$ac_word" "[$]@"
+ set dummy "$ac_path" "[$]@"
shift
ac_cv_prog_$1="[$]@"
-ifelse([$2], [$4], dnl
+ifelse([$2], [$4],
[ else
# Default is a loser.
AC_MSG_ERROR([$1=$6 unacceptable, but no other $4 found in dnl
])dnl
dnl If no 4th arg is given, leave the cache variable unset,
dnl so AC_CHECK_PROGS will keep looking.
-ifelse([$4], , , [ test -z "[$]ac_cv_prog_$1" && ac_cv_prog_$1="$4"
+ifval([$4], [ test -z "[$]ac_cv_prog_$1" && ac_cv_prog_$1="$4"
])dnl
fi])dnl
$1="$ac_cv_prog_$1"
AC_DEFUN(AC_CHECK_PROGS,
[for ac_prog in $2
do
-AC_CHECK_PROG($1, [$]ac_prog, [$]ac_prog, , $4)
+AC_CHECK_PROG([$1], [$]ac_prog, [$]ac_prog, , [$4])
test -n "[$]$1" && break
done
-ifelse([$3], , , [test -n "[$]$1" || $1="$3"
+ifval([$3], [test -n "[$]$1" || $1="$3"
])])
## ----------------------- ##
+# _AC_WHICH_A(NAME, PATH)
+# -----------------------
+# Work like `which -a NAME' in PATH, even if NAME is not executable.
+# Can be used inside backquotes.
+define([_AC_WHICH_A],
+[IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
+dnl $ac_dummy forces splitting on constant user-supplied paths.
+dnl POSIX.2 word splitting is done only on the output of word expansions,
+dnl not every word. This closes a longstanding sh security hole.
+ac_dummy="$2"
+for ac_dir in $ac_dummy; do
+ test -z "$ac_dir" && ac_dir=.
+ if test -f $ac_dir/$1; then
+ echo "$ac_dir/$1"
+ fi
+done
+IFS="$ac_save_ifs"
+])
+
+
# AC_CHECK_PROG(VARIABLE, PROG-TO-CHECK-FOR,
# [VALUE-IF-FOUND], [VALUE-IF-NOT-FOUND],
# [PATH], [REJECT])
[if test -n "[$]$1"; then
ac_cv_prog_$1="[$]$1" # Let the user override the test.
else
- IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
-ifelse([$6], , , [ ac_prog_rejected=no
+ifval([$6], [ ac_prog_rejected=no
])dnl
-dnl $ac_dummy forces splitting on constant user-supplied paths.
-dnl POSIX.2 word splitting is done only on the output of word expansions,
-dnl not every word. This closes a longstanding sh security hole.
- ac_dummy="ifelse([$5], , $PATH, [$5])"
- for ac_dir in $ac_dummy; do
- test -z "$ac_dir" && ac_dir=.
- if test -f $ac_dir/$ac_word; then
-ifelse([$6], , , dnl
-[ if test "[$ac_dir/$ac_word]" = "$6"; then
- ac_prog_rejected=yes
- continue
- fi
-])dnl
- ac_cv_prog_$1="$3"
- break
+ for ac_path in `_AC_WHICH_A([$ac_word], [m4_default([$5], [$PATH])])`; do
+ifval([$6],
+[ if test "$ac_path" = "$6"; then
+ ac_prog_rejected=yes
+ continue
fi
+])dnl
+ ac_cv_prog_$1="$3"
+ break
done
- IFS="$ac_save_ifs"
-ifelse([$6], , , [if test $ac_prog_rejected = yes; then
+ifval([$6], [if test $ac_prog_rejected = yes; then
# We found a bogon in the path, so make sure we never use it.
set dummy [$]ac_cv_prog_$1
shift
# However, it has the same basename, so the bogon will be chosen
# first if we set $1 to just the basename; use the full file name.
shift
- set dummy "$ac_dir/$ac_word" "[$]@"
+ set dummy "$ac_path" "[$]@"
shift
ac_cv_prog_$1="[$]@"
-ifelse([$2], [$4], dnl
+ifelse([$2], [$4],
[ else
# Default is a loser.
AC_MSG_ERROR([$1=$6 unacceptable, but no other $4 found in dnl
])dnl
dnl If no 4th arg is given, leave the cache variable unset,
dnl so AC_CHECK_PROGS will keep looking.
-ifelse([$4], , , [ test -z "[$]ac_cv_prog_$1" && ac_cv_prog_$1="$4"
+ifval([$4], [ test -z "[$]ac_cv_prog_$1" && ac_cv_prog_$1="$4"
])dnl
fi])dnl
$1="$ac_cv_prog_$1"
AC_DEFUN(AC_CHECK_PROGS,
[for ac_prog in $2
do
-AC_CHECK_PROG($1, [$]ac_prog, [$]ac_prog, , $4)
+AC_CHECK_PROG([$1], [$]ac_prog, [$]ac_prog, , [$4])
test -n "[$]$1" && break
done
-ifelse([$3], , , [test -n "[$]$1" || $1="$3"
+ifval([$3], [test -n "[$]$1" || $1="$3"
])])
# and some are already tested elsewhere. EGREP_EXCLUDE must filter out
# the macros we don't want to test in syntax.m4.
#
-# - AC_CHECK decls, files, funcs, members, types, headers
-# Already performed in the semantical tests.
+# - AC_CHECK decl, file, func, header, member, prog, sizeof, type
+# Performed in the semantics tests.
# - AC_CONFIG
# They fail when the source does not exist.
# - AC_INIT
# - AC_PROG_(CC|CXX|F77)_(GNU|WORKS)
# are used in AC_PROG_CC etc.
# - AC_PATH_PROGS?
-# They produce `= val' because $1 is empty.
+# They produce `= val' because $1, the variable used to store the result,
+# is empty.
# - AC_TRY
# Used in many places.
# - _AC_
# Internal macros are used elsewhere.
EGREP_EXCLUDE = egrep -v \
-e '^AC_ARG_VAR$$' \
- -e '^AC_CHECK_(DECL|FILE|FUNC|HEADER|MEMBER|SIZEOF|TYPE)S?$$' \
- -e '^AC_CHECK_PROGS$$' \
+ -e '^AC_CHECK_(DECL|FILE|FUNC|HEADER|MEMBER|PROG|SIZEOF|TYPE)S?$$' \
-e '^AC_CONFIG' \
-e '^AC_INIT' \
-e '^AC_LINKER_OPTION$$' \
# and some are already tested elsewhere. EGREP_EXCLUDE must filter out
# the macros we don't want to test in syntax.m4.
#
-# - AC_CHECK decls, files, funcs, members, types, headers
-# Already performed in the semantical tests.
+# - AC_CHECK decl, file, func, header, member, prog, sizeof, type
+# Performed in the semantics tests.
# - AC_CONFIG
# They fail when the source does not exist.
# - AC_INIT
# - AC_PROG_(CC|CXX|F77)_(GNU|WORKS)
# are used in AC_PROG_CC etc.
# - AC_PATH_PROGS?
-# They produce `= val' because $1 is empty.
+# They produce `= val' because $1, the variable use to store the result,
+# is empty.
# - AC_TRY
# Used in many places.
# - _AC_
# Internal macros are used elsewhere.
-EGREP_EXCLUDE = egrep -v -e '^AC_ARG_VAR$$' -e '^AC_CHECK_(DECL|FILE|FUNC|HEADER|MEMBER|SIZEOF|TYPE)S?$$' -e '^AC_CHECK_PROGS$$' -e '^AC_CONFIG' -e '^AC_INIT' -e '^AC_LINKER_OPTION$$' -e '^AC_LINK_FILES$$' -e '^AC_LIST_MEMBER_OF$$' -e '^AC_PATH_(TOOL|PROG)S?$$' -e '^AC_PROG_(CC|CXX|F77)_(GNU|WORKS)$$' -e '^AC_REPLACE_FUNCS$$' -e '^AC_SEARCH_LIBS$$' -e '^AC_TRY' -e '_AC_'
+EGREP_EXCLUDE = egrep -v -e '^AC_ARG_VAR$$' -e '^AC_CHECK_(DECL|FILE|FUNC|HEADER|MEMBER|PROG|SIZEOF|TYPE)S?$$' -e '^AC_CONFIG' -e '^AC_INIT' -e '^AC_LINKER_OPTION$$' -e '^AC_LINK_FILES$$' -e '^AC_LIST_MEMBER_OF$$' -e '^AC_PATH_(TOOL|PROG)S?$$' -e '^AC_PROG_(CC|CXX|F77)_(GNU|WORKS)$$' -e '^AC_REPLACE_FUNCS$$' -e '^AC_SEARCH_LIBS$$' -e '^AC_TRY' -e '_AC_'
CLEANFILES = debug-*.sh macro configure configure.in config.status config.cache config.log config.h.in config.h
[#define HAVE_AC_EXISTS1 1
/* #undef HAVE_AC_MISSING1 */
])])
+
+
+
+## --------------- ##
+## AC_CHECK_PROG. ##
+## --------------- ##
+
+AT_SETUP(AC_CHECK_PROG)
+
+# Create a sub directory `path' with 6 subdirs which all 7 contain
+# an executable `tool'. `6' contains a `better' tool.
+
+mkdir path
+
+cat >path/tool <<\EOF
+#! /bin/sh
+exit 0
+EOF
+chmod +x path/tool
+
+for i in 1 2 3 4 5 6
+do
+ mkdir path/$i
+ cp path/tool path/$i
+done
+cp path/tool path/6/better
+
+# Perform various tests of AC_CHECK_PROG and AC_CHECK_PROGS.
+AT_DATA(configure.in,
+[[AC_INIT
+path=`echo "1:2:3:4:5:6" | sed -e 's,\([[0-9]]\),'\`pwd\`'/path/\1,g'`
+fail=0
+
+AC_CHECK_PROG(TOOL1, tool, found, not-found, $path)
+test "$TOOL1" = found || fail=1
+
+# Yes, the semantics of this macro is weird.
+AC_CHECK_PROG(TOOL2, tool,, not-found, $path)
+test "$TOOL2" = not-found || fail=1
+
+AC_CHECK_PROG(TOOL3, tool, tool, not-found, $path, `pwd`/path/1/tool)
+test "$TOOL3" = `pwd`/path/2/tool || fail=1
+
+AC_CHECK_PROG(TOOL4, better, better, not-found, $path, `pwd`/path/1/tool)
+test "$TOOL4" = better || fail=1
+
+# When a tool is not found, and no value is given for not-found,
+# the variable is left empty.
+AC_CHECK_PROGS(TOOL5, missing,, $path)
+test -z "$TOOL5" || fail=1
+
+AC_CHECK_PROGS(TOOL6, missing tool better,, $path)
+test "$TOOL6" = tool || fail=1
+
+# no AC_OUTPUT, we don't need config.status.
+exit $fail
+]])
+
+AT_CHECK([../autoconf -m .. -l $at_srcdir], 0,, ignore)
+AT_CHECK([./configure], 0, ignore)
+
+AT_CLEANUP(path config.log config.cache configure)