Move proc gcc_target_object_format from ecos.exp to file-format.exp
[official-gcc.git] / gcc / testsuite / lib / file-format.exp
blob2d53faf5d0db60ca0ced0e5efa64ed24c0323070
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 # egcs-bugs@egcs.cygnus.com
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 seperate 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 set output [exec $objdump_name --file-headers objfmtst.o ]
40 file delete objfmtst.o
42 if ![ regexp "file format (.*)arch" $output dummy objformat ] {
43 verbose "Could not parse objdump output" 2
44 set gcc_target_object_format_saved unknown
45 } else {
46 switch -regexp $objformat {
47 elf {
48 set gcc_target_object_format_saved elf
50 ecoff {
51 set gcc_target_object_format_saved ecoff
53 coff {
54 set gcc_target_object_format_saved coff
56 a\.out {
57 set gcc_target_object_format_saved a.out
59 pe {
60 set gcc_target_object_format_saved pe
62 default {
63 verbose "Unknown file format: $objformat" 3
64 set gcc_target_object_format_saved unknown
68 verbose "gcc_target_object_format returning $gcc_target_object_format_saved" 2
72 return $gcc_target_object_format_saved