daily update
[binutils.git] / binutils / testsuite / lib / utils-lib.exp
blob54c59dee0c095db5c9a8dd96d8ca47e3937a6adf
1 # Copyright 1993, 1994, 1995, 1996, 1997, 2000, 2001
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-dejagnu@prep.ai.mit.edu
21 # This file was written by Rob Savoye <rob@cygnus.com>
22 # and extended by Ian Lance Taylor <ian@cygnus.com>
24 proc binutil_version { prog } {
25     if ![is_remote host] {
26         set path [which $prog];
27         if {$path == 0} then {
28             perror "$prog can't be run, file not found."
29             return ""
30         }
31     } else {
32         set path $prog
33     }
34     set state [remote_exec host $prog --version];
35     set tmp "[lindex $state 1]\n";
36     # Should find a way to discard constant parts, keep whatever's
37     # left, so the version string could be almost anything at all...
38     regexp "\[^\n\]* (cygnus-|)(\[-0-9.a-zA-Z-\]+)\[\r\n\].*" "$tmp" version cyg number
39     if ![info exists number] then {
40         return "$path (no version number)\n"
41     }
42     return "$path $number\n"
46 # default_binutils_run
47 #       run a program, returning the output
48 #       sets binutils_run_failed if the program does not exist
50 proc default_binutils_run { prog progargs } {
51     global binutils_run_failed
52     global host_triplet
54     set binutils_run_failed 0
56     if ![is_remote host] {
57         if {[which $prog] == 0} then {
58             perror "$prog does not exist"
59             set binutils_run_failed 1
60             return ""
61         }
62     }
64     send_log "$prog $progargs\n"
65     verbose "$prog $progargs"
67     # Gotta quote dollar-signs because they get mangled by the
68     # shell otherwise.
69     regsub -all "\\$" "$progargs" "\\$" progargs
71     set state [remote_exec host $prog $progargs]
72     set exec_output [prune_warnings [lindex $state 1]];
73     if {![string match "" $exec_output]} then {
74         send_log "$exec_output\n"
75         verbose "$exec_output"
76     }
77     return $exec_output
81 # default_binutils_assemble
82 #       assemble a file
84 proc default_binutils_assemble { source object } {
85     global srcdir
86     global host_triplet
88     # The HPPA assembler syntax is a little different than most, to make
89     # the test source file assemble we need to run it through sed.
90     #
91     # This is a hack in that it won't scale well if other targets need
92     # similar transformations to assemble.  We'll generalize the hack
93     # if/when other targets need similar handling.
94     if { [istarget "hppa*-*-*"] && ![istarget "*-*-linux*" ] } then {
95         set sed_file $srcdir/config/hppa.sed
96         send_log "sed -f $sed_file < $source > asm.s\n"
97         verbose "sed -f $sed_file < $source > asm.s"
98         catch "exec sed -f $sed_file < $source > asm.s";
99         set source asm.s
100     }
102     set exec_output [target_assemble $source $object ""];
103     set exec_output [prune_warnings $exec_output]
105     if [string match "" $exec_output] {
106         return 1
107     } else {
108         send_log "$exec_output\n"
109         verbose "$exec_output"
110         perror "$source: assembly failed"
111         return 0
112     }