2006-04-10 H.J. Lu <hongjiu.lu@intel.com>
[deliverable/binutils-gdb.git] / binutils / testsuite / lib / utils-lib.exp
1 # Copyright 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2003, 2004
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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, 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 } else {
77 if { [lindex $state 0] != 0 } {
78 set exec_output "$prog exited with status [lindex $state 0]"
79 send_log "$exec_output\n"
80 verbose "$exec_output"
81 }
82 }
83 return $exec_output
84 }
85
86 #
87 # default_binutils_assemble
88 # assemble a file
89 #
90 proc default_binutils_assemble { source object } {
91 global srcdir
92 global host_triplet
93
94 # The HPPA assembler syntax is a little different than most, to make
95 # the test source file assemble we need to run it through sed.
96 #
97 # This is a hack in that it won't scale well if other targets need
98 # similar transformations to assemble. We'll generalize the hack
99 # if/when other targets need similar handling.
100 if { [istarget "hppa*-*-*"] && ![istarget "*-*-linux*" ] } then {
101 set sed_file $srcdir/config/hppa.sed
102 send_log "sed -f $sed_file < $source > asm.s\n"
103 verbose "sed -f $sed_file < $source > asm.s"
104 catch "exec sed -f $sed_file < $source > asm.s"
105 set source asm.s
106 }
107
108 set exec_output [target_assemble $source $object ""]
109 set exec_output [prune_warnings $exec_output]
110
111 if [string match "" $exec_output] {
112 return 1
113 } else {
114 send_log "$exec_output\n"
115 verbose "$exec_output"
116 perror "$source: assembly failed"
117 return 0
118 }
119 }
120
121 #
122 # is_elf_format
123 # true if the object format is known to be ELF
124 #
125 proc is_elf_format {} {
126 if { ![istarget *-*-sysv4*] \
127 && ![istarget *-*-unixware*] \
128 && ![istarget *-*-elf*] \
129 && ![istarget *-*-eabi*] \
130 && ![istarget hppa*64*-*-hpux*] \
131 && ![istarget ia64-*-hpux*] \
132 && ![istarget *-*-linux*] \
133 && ![istarget *-*-irix5*] \
134 && ![istarget *-*-irix6*] \
135 && ![istarget *-*-netbsd*] \
136 && ![istarget *-*-solaris2*] } {
137 return 0
138 }
139
140 if { [istarget *-*-linux*aout*] \
141 || [istarget *-*-linux*oldld*] } {
142 return 0
143 }
144
145 if { ![istarget *-*-netbsdelf*] \
146 && ([istarget *-*-netbsd*aout*] \
147 || [istarget *-*-netbsdpe*] \
148 || [istarget arm*-*-netbsd*] \
149 || [istarget sparc-*-netbsd*] \
150 || [istarget i*86-*-netbsd*] \
151 || [istarget m68*-*-netbsd*] \
152 || [istarget vax-*-netbsd*] \
153 || [istarget ns32k-*-netbsd*]) } {
154 return 0
155 }
156 return 1
157 }
158
159 #
160 # exe_ext
161 # Returns target executable extension, if any.
162 #
163 proc exe_ext {} {
164 if { [istarget *-*-mingw32] || [istarget *-*-cygwin*] } {
165 return ".exe"
166 } else {
167 return ""
168 }
169 }
This page took 0.034044 seconds and 4 git commands to generate.