2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / lib / file-format.exp
bloba4168b6d61499cd8a2a56da6e80042ae06ab5d53
1 # Copyright (C) 1999 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # gcc-bugs@gcc.gnu.org
20 # This file defines a proc for determining the file format in use by the
21 # target. This is useful for tests that are only supported by certain file
22 # formats. This procedure is defined in a separate file so that it can be
23 # included by other expect library files.
25 proc gcc_target_object_format { } {
26 global gcc_target_object_format_saved
28 if [info exists gcc_target_object_format_saved] {
29 verbose "gcc_target_object_format returning saved $gcc_target_object_format_saved" 2
30 } else {
31 set objdump_name [find_binutils_prog objdump]
32 set open_file [open objfmtst.c w]
33 puts $open_file "void foo(void) { }"
34 close $open_file
36 gcc_target_compile objfmtst.c objfmtst.o object ""
38 catch {
39 set output [exec $objdump_name --file-headers objfmtst.o ]
40 } output
42 file delete objfmtst.o
44 if ![ regexp "file format (.*)arch" $output dummy objformat ] {
45 verbose "Could not parse objdump output" 2
46 set gcc_target_object_format_saved unknown
47 } else {
48 switch -regexp $objformat {
49 elf {
50 set gcc_target_object_format_saved elf
52 ecoff {
53 set gcc_target_object_format_saved ecoff
55 coff {
56 set gcc_target_object_format_saved coff
58 a\.out {
59 set gcc_target_object_format_saved a.out
61 pe {
62 set gcc_target_object_format_saved pe
64 default {
65 verbose "Unknown file format: $objformat" 3
66 set gcc_target_object_format_saved unknown
70 verbose "gcc_target_object_format returning $gcc_target_object_format_saved" 2
74 return $gcc_target_object_format_saved