2eb68210b2ee9b95cc46a8c23a4ad66e84e65fbb
[external/binutils.git] / binutils / testsuite / lib / utils-lib.exp
1 #   Copyright (C) 1993, 1994 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-dejagnu@prep.ai.mit.edu
19
20 # This file was written by Rob Savoye <rob@cygnus.com>
21 # and extended by Ian Lance Taylor <ian@cygnus.com>
22
23 proc binutil_version { prog } {
24     if {[which $prog] == 0} then {
25         perror "$prog can't be run, file not found."
26         return ""
27     }
28     catch "exec $prog --version" tmp
29     # Should find a way to discard constant parts, keep whatever's
30     # left, so the version string could be almost anything at all...
31     regexp "version (cygnus-|)\[-0-9.a-zA-Z-\]+" $tmp version
32     if ![info exists version] then {
33         return "[which $prog] (no version number)\n"
34     }
35     set tmp $version
36     return "[which $prog] $version\n"
37 }
38
39 #
40 # default_binutils_run
41 #       run a program, returning the output
42 #       sets binutils_run_failed if the program does not exist
43 #
44 proc default_binutils_run { prog progargs } {
45     global binutils_run_failed
46
47     set binutils_run_failed 0
48
49     if {[which $prog] == 0} then {
50         perror "$prog does not exist"
51         set binutils_run_failed 1
52         return ""
53     }
54
55     send_log "$prog $progargs\n"
56     verbose "$prog $progargs"
57
58     # This used to be
59     # catch "exec $prog $progargs" exec_output
60     # but that would evaluate $progargs twice, which would fail if
61     # any arguments started with `$'.  This is a dismal hack to avoid
62     # this problem.  I tried using
63     # catch { exec $prog $progargs } exec_output
64     # but that failed because $progargs was not split into words by
65     # exec.  I don't know if this operation can be done correctly.  No
66     # matter how hard I try, I can not convince myself that TCL is a
67     # language.
68     regsub -all "\\$" $progargs "\\$" progq
69     catch "exec $prog $progq" exec_output
70     if {![string match "" $exec_output]} then {
71         send_log "$exec_output\n"
72         verbose "$exec_output"
73     }
74     return $exec_output
75 }
76
77 #
78 # default_binutils_assemble
79 #       assemble a file
80 #
81 proc default_binutils_assemble { as source object } {
82     global ASFLAGS
83     global srcdir
84
85     if {[which $as] == 0} then {
86         perror "$as does not exist"
87         return 0
88     }
89
90     if ![info exists ASFLAGS] { set ASFLAGS "" }
91
92     # The HPPA assembler syntax is a little different than most, to make
93     # the test source file assemble we need to run it through sed.
94     #
95     # This is a hack in that it won't scale well if other targets need
96     # similar transformations to assemble.  We'll generalize the hack
97     # if/when other targets need similar handling.
98     if [istarget "hppa*-*-*" ] then {
99         send_log "sed -f $srcdir/config/hppa.sed < $source | $as $ASFLAGS -o $object\n"
100         verbose "sed -f $srcdir/config/hppa.sed < $source | $as $ASFLAGS -o $object"
101         catch "exec sed -f $srcdir/config/hppa.sed < $source | $as $ASFLAGS -o $object" exec_output
102     } else {
103         send_log "$as $ASFLAGS -o $object $source\n"
104         verbose "$as $ASFLAGS -o $object $source"
105         catch "exec $as $ASFLAGS -o $object $source" exec_output
106     }
107
108     if [string match "" $exec_output] then {
109         return 1
110     } else {
111         send_log "$exec_output\n"
112         verbose "$exec_output"
113         perror "$source: assembly failed"
114         return 0
115     }
116 }