aboutsummaryrefslogtreecommitdiff
path: root/binutils/testsuite/lib/utils-lib.exp
blob: f7970b29269171d4b287d252f9ae9eafcd87157e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# Copyright 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2003, 2004
# Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.

# Please email any bugs, comments, and/or additions to this file to:
# bug-dejagnu@prep.ai.mit.edu

# This file was written by Rob Savoye <rob@cygnus.com>
# and extended by Ian Lance Taylor <ian@cygnus.com>

proc binutil_version { prog } {
    if ![is_remote host] {
	set path [which $prog]
	if {$path == 0} then {
	    perror "$prog can't be run, file not found."
	    return ""
	}
    } else {
	set path $prog
    }
    set state [remote_exec host $prog --version]
    set tmp "[lindex $state 1]\n"
    # Should find a way to discard constant parts, keep whatever's
    # left, so the version string could be almost anything at all...
    regexp "\[^\n\]* (cygnus-|)(\[-0-9.a-zA-Z-\]+)\[\r\n\].*" "$tmp" version cyg number
    if ![info exists number] then {
        return "$path (no version number)\n"
    }
    return "$path $number\n"
}

#
# default_binutils_run
#	run a program, returning the output
#	sets binutils_run_failed if the program does not exist
#
proc default_binutils_run { prog progargs } {
    global binutils_run_failed
    global host_triplet

    set binutils_run_failed 0

    if ![is_remote host] {
	if {[which $prog] == 0} then {
	    perror "$prog does not exist"
	    set binutils_run_failed 1
	    return ""
	}
    }

    send_log "$prog $progargs\n"
    verbose "$prog $progargs"

    # Gotta quote dollar-signs because they get mangled by the
    # shell otherwise.
    regsub -all "\\$" "$progargs" "\\$" progargs

    set state [remote_exec host $prog $progargs]
    set exec_output [prune_warnings [lindex $state 1]]
    if {![string match "" $exec_output]} then {
	send_log "$exec_output\n"
	verbose "$exec_output"
    } else {
	if { [lindex $state 0] != 0 } {
	    set exec_output "$prog exited with status [lindex $state 0]"
	    send_log "$exec_output\n"
	    verbose "$exec_output"
	}
    }
    return $exec_output
}

#
# default_binutils_assemble
#	assemble a file
#
proc default_binutils_assemble { source object } {
    global srcdir
    global host_triplet

    # The HPPA assembler syntax is a little different than most, to make
    # the test source file assemble we need to run it through sed.
    #
    # This is a hack in that it won't scale well if other targets need
    # similar transformations to assemble.  We'll generalize the hack
    # if/when other targets need similar handling.
    if { [istarget "hppa*-*-*"] && ![istarget "*-*-linux*" ] } then {
        set sed_file $srcdir/config/hppa.sed
	send_log "sed -f $sed_file < $source > asm.s\n"
	verbose "sed -f $sed_file < $source > asm.s"
	catch "exec sed -f $sed_file < $source > asm.s"
	set source asm.s
    }

    set exec_output [target_assemble $source $object ""]
    set exec_output [prune_warnings $exec_output]

    if [string match "" $exec_output] {
	return 1
    } else {
	send_log "$exec_output\n"
	verbose "$exec_output"
	perror "$source: assembly failed"
	return 0
    }
}

#
# is_elf_format
#	true if the object format is known to be ELF
#
proc is_elf_format {} {
    if { ![istarget *-*-sysv4*] \
	 && ![istarget *-*-unixware*] \
	 && ![istarget *-*-elf*] \
	 && ![istarget *-*-eabi*] \
	 && ![istarget hppa*64*-*-hpux*] \
	 && ![istarget ia64-*-hpux*] \
	 && ![istarget *-*-linux*] \
	 && ![istarget *-*-irix5*] \
	 && ![istarget *-*-irix6*] \
	 && ![istarget *-*-netbsd*] \
	 && ![istarget *-*-solaris2*] } {
	return 0
    }

    if { [istarget *-*-linux*aout*] \
	 || [istarget *-*-linux*oldld*] } {
	return 0
    }

    if { ![istarget *-*-netbsdelf*] \
	 && ([istarget *-*-netbsd*aout*] \
	     || [istarget *-*-netbsdpe*] \
	     || [istarget arm*-*-netbsd*] \
	     || [istarget sparc-*-netbsd*] \
	     || [istarget i*86-*-netbsd*] \
	     || [istarget m68*-*-netbsd*] \
	     || [istarget vax-*-netbsd*] \
	     || [istarget ns32k-*-netbsd*]) } {
    	return 0
    }
    return 1
}

#
# exe_ext
#	Returns target executable extension, if any.
#
proc exe_ext {} {
    if { [istarget *-*-mingw32] || [istarget *-*-cygwin*] } {
        return ".exe"
    } else {
        return ""
    }
}