merge from gcc
[binutils.git] / binutils / testsuite / lib / utils-lib.exp
blobbb819a3766fbaba58e7c47a30dbc74d41870f6bd
1 # Copyright 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2003, 2004
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.
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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, 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 ""
31 } else {
32 set path $prog
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"
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 ""
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"
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.
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
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
116 # is_elf_format
117 # true if the object format is known to be ELF
119 proc is_elf_format {} {
120 if { ![istarget *-*-sysv4*] \
121 && ![istarget *-*-unixware*] \
122 && ![istarget *-*-elf*] \
123 && ![istarget *-*-eabi*] \
124 && ![istarget hppa*64*-*-hpux*] \
125 && ![istarget ia64-*-hpux*] \
126 && ![istarget *-*-linux*] \
127 && ![istarget *-*-irix5*] \
128 && ![istarget *-*-irix6*] \
129 && ![istarget *-*-netbsd*] \
130 && ![istarget *-*-solaris2*] } {
131 return 0
134 if { [istarget *-*-linux*aout*] \
135 || [istarget *-*-linux*oldld*] } {
136 return 0
139 if { ![istarget *-*-netbsdelf*] \
140 && ([istarget *-*-netbsd*aout*] \
141 || [istarget *-*-netbsdpe*] \
142 || [istarget arm*-*-netbsd*] \
143 || [istarget sparc-*-netbsd*] \
144 || [istarget i*86-*-netbsd*] \
145 || [istarget m68*-*-netbsd*] \
146 || [istarget vax-*-netbsd*] \
147 || [istarget ns32k-*-netbsd*]) } {
148 return 0
150 return 1
154 # exe_ext
155 # Returns target executable extension, if any.
157 proc exe_ext {} {
158 if { [istarget *-*-mingw32] || [istarget *-*-cygwin*] } {
159 return ".exe"
160 } else {
161 return ""