Initial revision
[binutils.git] / binutils / testsuite / lib / utils-lib.exp
blobe27f21710c9e8d67f44c42bdb1d1565dd1ce12be
1 # Copyright (C) 1993, 1994, 1997 Free Software Foundation, Inc.
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.
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.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-dejagnu@prep.ai.mit.edu
20 # This file was written by Rob Savoye <rob@cygnus.com>
21 # and extended by Ian Lance Taylor <ian@cygnus.com>
23 proc binutil_version { prog } {
24 if ![is_remote host] {
25 set path [which $prog];
26 if {$path == 0} then {
27 perror "$prog can't be run, file not found."
28 return ""
30 } else {
31 set path $prog
33 set state [remote_exec host $prog --version];
34 set tmp "[lindex $state 1]\n";
35 # Should find a way to discard constant parts, keep whatever's
36 # left, so the version string could be almost anything at all...
37 regexp "\[^\n\]* (cygnus-|)(\[-0-9.a-zA-Z-\]+)\[\r\n\].*" "$tmp" version cyg number
38 if ![info exists number] then {
39 return "$path (no version number)\n"
41 return "$path $number\n"
45 # default_binutils_run
46 # run a program, returning the output
47 # sets binutils_run_failed if the program does not exist
49 proc default_binutils_run { prog progargs } {
50 global binutils_run_failed
51 global host_triplet
53 set binutils_run_failed 0
55 if ![is_remote host] {
56 if {[which $prog] == 0} then {
57 perror "$prog does not exist"
58 set binutils_run_failed 1
59 return ""
63 send_log "$prog $progargs\n"
64 verbose "$prog $progargs"
66 # Gotta quote dollar-signs because they get mangled by the
67 # shell otherwise.
68 regsub -all "\\$" "$progargs" "\\$" progargs
70 set state [remote_exec host $prog $progargs]
71 set exec_output [prune_warnings [lindex $state 1]];
72 if {![string match "" $exec_output]} then {
73 send_log "$exec_output\n"
74 verbose "$exec_output"
76 return $exec_output
80 # default_binutils_assemble
81 # assemble a file
83 proc default_binutils_assemble { source object } {
84 global srcdir
85 global host_triplet
87 # The HPPA assembler syntax is a little different than most, to make
88 # the test source file assemble we need to run it through sed.
90 # This is a hack in that it won't scale well if other targets need
91 # similar transformations to assemble. We'll generalize the hack
92 # if/when other targets need similar handling.
93 if [istarget "hppa*-*-*" ] then {
94 send_log "sed -f $srcdir/config/hppa.sed < $source > asm.s\n"
95 verbose "sed -f $srcdir/config/hppa.sed < $source > asm.s"
96 catch "exec sed -f $srcdir/config/hppa.sed < $source > asm.s";
97 set source asm.s
100 set exec_output [target_assemble $source $object ""];
101 set exec_output [prune_warnings $exec_output]
103 if [string match "" $exec_output] {
104 return 1
105 } else {
106 send_log "$exec_output\n"
107 verbose "$exec_output"
108 perror "$source: assembly failed"
109 return 0
113 if ![info exists target_assemble] {
115 # Stolen from dejagnu/lib/target.exp--please remove after 1/1/98.
117 uplevel #0 {
118 proc target_assemble { source destfile flags } {
119 return [default_target_assemble $source $destfile $flags];
122 proc default_target_assemble { source destfile flags } {
123 global AS_FOR_TARGET;
124 global ASFLAGS_FOR_TARGET;
126 if [info exists AS_FOR_TARGET] {
127 set AS "$AS_FOR_TARGET";
128 } else {
129 if ![board_info target exists assembler] {
130 set AS [find_gas];
131 } else {
132 set AS [board_info target assembler];
136 if [info exists ASFLAGS_FOR_TARGET] {
137 append flags " $ASFLAGS_FOR_TARGET";
140 if [is_remote host] {
141 set source [remote_download host $source];
142 set dest "a.out"
143 } else {
144 set dest $destfile
146 set status [remote_exec host "$AS $source $flags -o $dest"]
147 if [is_remote host] {
148 remote_upload host $dest $destfile
151 set comp_output [prune_warnings [lindex $status 1]];
152 if { [lindex $status 0] != 0 } {
153 verbose -log "assembler exited with status [lindex $status 0]";
155 if { [lindex $status 1] != "" } {
156 verbose -log "assembler output is:\n[lindex $status 1]" 2;
158 return ${comp_output};