]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - binutils/testsuite/lib/utils-lib.exp
Fix typos in ChangeLogs and update copyright notices
[thirdparty/binutils-gdb.git] / binutils / testsuite / lib / utils-lib.exp
1 # Copyright 1993, 1994, 1995, 1996, 1997, 2000
2 # Free Software Foundation, Inc.
3
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.
17
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-dejagnu@prep.ai.mit.edu
20
21 # This file was written by Rob Savoye <rob@cygnus.com>
22 # and extended by Ian Lance Taylor <ian@cygnus.com>
23
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"
43 }
44
45 #
46 # default_binutils_run
47 # run a program, returning the output
48 # sets binutils_run_failed if the program does not exist
49 #
50 proc default_binutils_run { prog progargs } {
51 global binutils_run_failed
52 global host_triplet
53
54 set binutils_run_failed 0
55
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 }
63
64 send_log "$prog $progargs\n"
65 verbose "$prog $progargs"
66
67 # Gotta quote dollar-signs because they get mangled by the
68 # shell otherwise.
69 regsub -all "\\$" "$progargs" "\\$" progargs
70
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
78 }
79
80 #
81 # default_binutils_assemble
82 # assemble a file
83 #
84 proc default_binutils_assemble { source object } {
85 global srcdir
86 global host_triplet
87
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 }
101
102 set exec_output [target_assemble $source $object ""];
103 set exec_output [prune_warnings $exec_output]
104
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 }
113 }
114
115 if ![info exists target_assemble] {
116 #
117 # Stolen from dejagnu/lib/target.exp--please remove after 1/1/98.
118 #
119 uplevel #0 {
120 proc target_assemble { source destfile flags } {
121 return [default_target_assemble $source $destfile $flags];
122 }
123
124 proc default_target_assemble { source destfile flags } {
125 global AS_FOR_TARGET;
126 global ASFLAGS_FOR_TARGET;
127
128 if [info exists AS_FOR_TARGET] {
129 set AS "$AS_FOR_TARGET";
130 } else {
131 if ![board_info target exists assembler] {
132 set AS [find_gas];
133 } else {
134 set AS [board_info target assembler];
135 }
136 }
137
138 if [info exists ASFLAGS_FOR_TARGET] {
139 append flags " $ASFLAGS_FOR_TARGET";
140 }
141
142 if [is_remote host] {
143 set source [remote_download host $source];
144 set dest "a.out"
145 } else {
146 set dest $destfile
147 }
148 set status [remote_exec host "$AS $source $flags -o $dest"]
149 if [is_remote host] {
150 remote_upload host $dest $destfile
151 }
152
153 set comp_output [prune_warnings [lindex $status 1]];
154 if { [lindex $status 0] != 0 } {
155 verbose -log "assembler exited with status [lindex $status 0]";
156 }
157 if { [lindex $status 1] != "" } {
158 verbose -log "assembler output is:\n[lindex $status 1]" 2;
159 }
160 return ${comp_output};
161 }
162 }
163 }