1# Copyright (C) 1999 Free Software Foundation, Inc. 2 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. 12# 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. 16 17# Please email any bugs, comments, and/or additions to this file to: 18# gcc-bugs@gcc.gnu.org 19 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. 24 25proc gcc_target_object_format { } { 26 global gcc_target_object_format_saved 27 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 35 36 gcc_target_compile objfmtst.c objfmtst.o object "" 37 38 catch { 39 set output [exec $objdump_name --file-headers objfmtst.o ] 40 } output 41 42 file delete objfmtst.o 43 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 51 } 52 ecoff { 53 set gcc_target_object_format_saved ecoff 54 } 55 coff { 56 set gcc_target_object_format_saved coff 57 } 58 a\.out { 59 set gcc_target_object_format_saved a.out 60 } 61 pe { 62 set gcc_target_object_format_saved pe 63 } 64 default { 65 verbose "Unknown file format: $objformat" 3 66 set gcc_target_object_format_saved unknown 67 } 68 } 69 70 verbose "gcc_target_object_format returning $gcc_target_object_format_saved" 2 71 } 72 } 73 74 return $gcc_target_object_format_saved 75} 76