aboutsummaryrefslogtreecommitdiff
path: root/binutils/testsuite/lib/utils-lib.exp
blob: 2ea9f83605b73cc675f571477f3329b6a322a3f6 (plain)
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
#   Copyright (C) 1993, 1994 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 {[which $prog] == 0} then {
	perror "$prog can't be run, file not found."
	return ""
    }
    catch "exec $prog --version" tmp
    # Should find a way to discard constant parts, keep whatever's
    # left, so the version string could be almost anything at all...
    regexp "version (cygnus-|)\[-0-9.a-zA-Z-\]+" $tmp version
    if ![info exists version] then {
        return "[which $prog] (no version number)\n"
    }
    set tmp $version
    return "[which $prog] $version\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

    set binutils_run_failed 0

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

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

    # This used to be
    # catch "exec $prog $progargs" exec_output
    # but that would evaluate $progargs twice, which would fail if
    # any arguments started with `$'.  This is a dismal hack to avoid
    # this problem.  I tried using
    # catch { exec $prog $progargs } exec_output
    # but that failed because $progargs was not split into words by
    # exec.  I don't know if this operation can be done correctly.  No
    # matter how hard I try, I can not convince myself that TCL is a
    # language.
    regsub -all "\\$" $progargs "\\$" progq
    catch "exec $prog $progq" exec_output
    if {![string match "" $exec_output]} then {
	send_log "$exec_output\n"
	verbose "$exec_output"
    }
    return $exec_output
}

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

    if {[which $as] == 0} then {
	perror "$as does not exist"
	return 0
    }

    if ![info exists ASFLAGS] { set ASFLAGS "" }

    # 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*-*-*" ] then {
	send_log "sed -f $srcdir/config/hppa.sed < $source | $as $ASFLAGS -o $object\n"
	verbose "sed -f $srcdir/config/hppa.sed < $source | $as $ASFLAGS -o $object"
	catch "exec sed -f $srcdir/config/hppa.sed < $source | $as $ASFLAGS -o $object" exec_output
    } else {
	send_log "$as $ASFLAGS -o $object $source\n"
	verbose "$as $ASFLAGS -o $object $source"
	catch "exec $as $ASFLAGS -o $object $source" exec_output
    }

    set exec_output [prune_system_crud $host_triplet $exec_output]

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

# This definition is taken from an unreleased version of DejaGnu.  Once
# that version gets released, and has been out in the world for a few
# months at least, it may be safe to delete this copy.
if ![string length [info proc prune_system_crud]] {
    #
    # prune_system_crud -- delete various system verbosities from TEXT on SYSTEM
    #
    # An example is:
    # ld.so: warning: /usr/lib/libc.so.1.8.1 has older revision than expected 9
    #
    # SYSTEM is typical $target_triplet or $host_triplet.
    #
    # This is useful when trying to do pattern matches on program output.
    # Sites with particular verbose os's may wish to override this in site.exp.
    #
    proc prune_system_crud { system text } {
	# This is from sun4's.  Do it for all machines for now.
	# The "\\1" is to try to preserve a "\n" but only if necessary.
	regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text

	# It might be tempting to get carried away and delete blank lines, etc.
	# Just delete *exactly* what we're ask to, and that's it.
	return $text
    }
}