3 # Copyright (C) 2018 Free Software Foundation, Inc.
5 # This file is part of DejaGnu.
7 # DejaGnu is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # DejaGnu is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with DejaGnu; if not, write to the Free Software Foundation,
19 # Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
21 # Portions from runtest Copyright (C) 1992-2016 Free Software Foundation, Inc.
23 # This script was written by Jacob Bachmeyer. Portions of this script are
24 # adapted from the existing runtest script originally written by Rob Savoye.
26 # This script finds an implementation for the command given, finds the
27 # proper interpreter, and then dispatches the command. This script can
28 # either be run with a command name as the first (few) argument(s), via a
29 # link from the command name, or some combination of those.
31 # shellcheck disable=SC2209
32 # The shellcheck tool complains about assigning certain constant strings to
33 # variables. In this script, the intended meaning is obvious in context.
36 # #Usage: dejagnu <command> [--help|options...]
37 # #Usage: dejagnu --help
38 # #Usage: dejagnu --version
39 # # --help Print help text
40 # # --version Print DejaGnu version
43 # list of extensions supported for commands in priority order
44 readonly Variants
="gawk awk tcl exp bash sh"
48 # For testing and development
50 if test x
"$1" = x--DGTimpl
; then
60 --help) want_help
=true
;;
61 -v|
--v|
-verbose|
--verbose) verbose
=$
((verbose
+ 1)) ;;
62 -V|
--V|
-version|
--version) want_version
=true
;;
66 if expr "$verbose" \
> 0 > /dev
/null
; then
67 echo Verbose level is
$verbose
70 ## Get the file name of this script and deduce @bindir@.
72 bindir
="$(echo "$0" | sed -e 's@/[^/]*$@@')"
73 if expr "$verbose" \
> 0 > /dev
/null
; then
74 echo Running launcher from
"$bindir"
79 # If running from source tree, they are in ./commands/ relative to this script.
80 # If installed, they are in @datadir@/dejagnu/commands/ on the system.
82 # This makes the same assumption as in runtest that one of these holds:
84 # @datadir@ == @bindir@/../share
85 # @datadir@ == @bindir@/../../share
86 # @datadir@ == /usr/share
87 # @datadir@ == /usr/local/share
89 if test -n "$DEJAGNULIBS" ; then
90 commdir
="${DEJAGNULIBS}/commands"
91 datadir
="${DEJAGNULIBS}"
92 elif test -d "${bindir}/commands" && test -f "${bindir}/runtest.exp" ; then
93 if expr "$verbose" \
> 1 > /dev
/null
; then
94 echo Running from
source directory
96 commdir
="${bindir}/commands"
101 "$(echo "$bindir" | sed -e 's@/[^/]*$@/share/dejagnu@')" \
102 "$(echo "$bindir" | sed -e 's@/[^/]*/[^/]*$@/share/dejagnu@')" \
103 /usr
/share
/dejagnu
/usr
/local
/share
/dejagnu
105 if expr "$verbose" \
> 1 > /dev
/null
; then
106 echo Probing directory
"$i"/commands
108 if test -d "$i"/commands
; then
109 commdir
="$i"/commands
116 if test -z "${commdir}" ; then
117 echo ERROR
: could not
find command directory.
121 if expr "$verbose" \
> 0 > /dev
/null
; then
122 echo Looking
for commands
in "$commdir"
125 ## Get the name of the requested command.
127 # Are we just looking for version information?
128 if $want_version ; then
129 frame_version
=$
(grep '^set frame_version' "${datadir}/runtest.exp" \
130 |
sed 's/^[^0-9]*//')
131 echo 'dejagnu auxiliary launcher (DejaGnu)' "$frame_version"
135 # Remove any leading autoconf platform prefix and the "dejagnu" prefix.
136 command="$(basename "$0" | sed -e 's/^.*-\?dejagnu-\?//')"
138 while expr $# \
> 0 > /dev
/null
140 if test -z "${command}" ; then
141 if expr "$1" : - > /dev
/null
; then
147 if expr "$verbose" \
> 2 > /dev
/null
; then
148 echo Looking
for "${commdir}/${command}.*"
150 for ext
in ${Variants}
152 if test -f "${commdir}/${command}.$ext" ; then
156 if expr "$1" : - > /dev
/null
; then
159 if test -n "$1" ; then
160 command="${command}-$1"
168 for ext
in ${Variants}
170 if test -f "${commdir}/${command}.$ext" ; then
171 commext
="$commext $ext"
175 if test -z "$commext" && test -n "$command" ; then
176 echo ERROR
: could not resolve
command "$command"
180 if expr "$verbose" \
> 0 > /dev
/null
; then
181 if test -n "$command"; then
182 if expr "$verbose" \
> 1 > /dev
/null
; then
183 echo Found subcommand
"$command" with variants
: "$commext"
185 echo Found subcommand
"$command"
188 echo Running nothing.
192 ## Find interpreters.
195 if test -n "$AWK" ; then
197 elif test -x "${bindir}/awk" ; then
198 awkbin
="${bindir}/awk"
202 if test -n "$GAWK" ; then
204 elif test -x "${bindir}/gawk" ; then
205 gawkbin
="${bindir}/gawk"
209 if command -v "$awkbin" > /dev
/null
2>&1 ; then
214 if command -v "$gawkbin" > /dev
/null
2>&1 ; then
219 # substitute GNU awk for awk if needed
221 if $have_awk ; then : ; else
226 # is "awk" actually GNU Awk?
228 if "$awkbin" --version |
sed 1q |
grep -qi 'GNU Awk' ; then
229 have_gawk_as_awk
=true
231 have_gawk_as_awk
=false
234 if expr "$verbose" \
> 2 > /dev
/null
; then
236 echo Awk interpreter is
"$awkbin"
238 echo Awk interpreter was not found
241 echo GNU Awk interpreter is
"$gawkbin"
243 echo GNU Awk interpreter was not found
249 if test -n "$BASH" ; then
251 elif test -x "${bindir}/bash" ; then
252 bashbin
="${bindir}/bash"
253 elif test -x /bin
/bash
; then
258 if command -v "$bashbin" > /dev
/null
2>&1 ; then
263 if expr "$verbose" \
> 2 > /dev
/null
; then
265 echo Bash interpreter is
"$bashbin"
267 echo Bash interpreter was not found
272 # This script is running, therefore we have a Bourne shell.
276 # DejaGnu configure bails out if Expect is not available, but this script
277 # can be run from the source directory without first running configure.
278 if test -n "$EXPECT" ; then
280 elif test -x "${bindir}/expect" ; then
281 expectbin
="${bindir}/expect"
285 if command -v "$expectbin" > /dev
/null
2>&1 ; then
290 if expr "$verbose" \
> 2 > /dev
/null
; then
291 if $have_expect ; then
292 echo Expect interpreter is
"$expectbin"
294 echo Expect interpreter was not found
299 if test -n "$TCLSH" ; then
301 elif test -x "${bindir}/tclsh" ; then
302 tclbin
="${bindir}/tclsh"
306 # substitute expect if needed
307 if command -v "$tclbin" > /dev
/null
2>&1 ; then :
308 elif command -v "$expectbin" > /dev
/null
2>&1 ; then tclbin
="$expectbin"
310 if command -v "$tclbin" > /dev
/null
2>&1 ; then
315 if expr "$verbose" \
> 2 > /dev
/null
; then
317 echo Tcl interpreter is
"$tclbin"
319 echo Tcl interpreter was not found
325 if test -n "$override_ext" ; then
326 selected_ext
="$override_ext"
345 if $have_expect ; then
367 echo ERROR
: '(select-variant)' unrecognized variant
"$v"
371 if test -z "$selected_ext" && test -n "$command" ; then
372 echo ERROR
: no variant of
"$command" was selected
377 if test -n "$command" && expr "$verbose" \
> 0 > /dev
/null
; then
378 if test -n "$override_ext" ; then
379 echo Selected variant
"$selected_ext" by override
381 echo Selected variant
"$selected_ext"
385 ## Dispatch to the selected command.
387 # Are we just looking for a usage message?
389 if test -z "$command" ; then
390 # want help on the launcher itself
393 help_file
="${commdir}/${command}.${selected_ext}"
395 if test ! -r "$help_file" ; then
396 echo ERROR
: file "'$help_file'" is not readable
399 if grep -q '#help' "$help_file" \
400 && grep -q '#end' "$help_file"; then : ; else
401 echo ERROR
: file "'$help_file'" does not contain a
help message
404 help_prefix_pat
=$
(grep '#help' "$help_file" \
405 |
sed -e 's/#help.*$//' -e '1q' |
tr '[:print:][:blank:]' .
)
406 if expr "$verbose" \
> 1 > /dev
/null
; then
407 echo Extracting
help from
"'$help_file'" with prefix
"'$help_prefix_pat'"
409 sed -n < "$help_file" \
411 -e '/^'"$help_prefix_pat"'#end/q' \
412 -e 's/^'"$help_prefix_pat"'//;p'
416 if test -z "$command" ; then
417 if test -n "$override_ext" ; then
418 case $selected_ext in
419 awk) $have_awk; exit $?
;;
420 bash
) $have_bash; exit $?
;;
421 exp
) $have_expect; exit $?
;;
422 gawk
) $have_gawk; exit $?
;;
423 tcl
) $have_tcl; exit $?
;;
424 sh
) $have_sh; exit $?
;;
428 echo ERROR
: no
command given
433 case $selected_ext in
435 if $have_gawk_as_awk ; then
436 exec "$awkbin" --posix -f "${commdir}/${command}.awk" -- ${1+"$@"}
438 exec "$awkbin" -f "${commdir}/${command}.awk" -- ${1+"$@"}
441 bash
) exec "$bashbin" -- "${commdir}/${command}.bash" ${1+"$@"} ;;
442 exp) exec "$expectbin" -- "${commdir}/${command}.exp" ${1+"$@"} ;;
443 gawk
) exec "$gawkbin" -f "${commdir}/${command}.gawk" -- ${1+"$@"} ;;
444 tcl) exec "$tclbin" "${commdir}/${command}.tcl" ${1+"$@"} ;;
445 sh
) exec /bin
/sh
"${commdir}/${command}.sh" ${1+"$@"} ;;
447 echo command: "${command}"
452 echo ERROR: '(run-variant)' unrecognized variant "$selected_ext"