xref: /openbsd/gnu/usr.bin/gcc/gcc/testsuite/lib/gcc.exp (revision 4e43c760)
1# Copyright (C) 1992, 1993, 1994, 1996, 1997, 1999, 2000, 2001 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17# This file was written by Rob Savoye (rob@cygnus.com)
18# Currently maintained by Doug Evans (dje@cygnus.com)
19
20# This file is loaded by the tool init file (eg: unix.exp).  It provides
21# default definitions for gcc_start, etc. and other supporting cast members.
22
23# These globals are used by gcc_start if no compiler arguments are provided.
24# They are also used by the various testsuites to define the environment:
25# where to find stdio.h, libc.a, etc.
26
27# we want to use libgloss so we can get find_gcc.
28load_lib libgloss.exp
29load_lib prune.exp
30load_lib gcc-defs.exp
31
32#
33# GCC_UNDER_TEST is the compiler under test.
34#
35
36#
37# default_gcc_version -- extract and print the version number of the compiler
38#
39
40proc default_gcc_version { } {
41    global GCC_UNDER_TEST
42
43    gcc_init;
44
45    # ignore any arguments after the command
46    set compiler [lindex $GCC_UNDER_TEST 0]
47
48    if ![is_remote host] {
49	set compiler_name [which $compiler];
50    } else {
51	set compiler_name $compiler;
52    }
53
54    # verify that the compiler exists
55    if { $compiler_name != 0 } then {
56	set tmp [remote_exec host "$compiler -v"]
57	set status [lindex $tmp 0];
58	set output [lindex $tmp 1];
59	regexp "version\[^\n\r\]*" $output version
60	if { $status == 0 && [info exists version] } then {
61	    clone_output "$compiler_name $version\n"
62	} else {
63	    clone_output "Couldn't determine version of $compiler_name: $output\n"
64	}
65    } else {
66	# compiler does not exist (this should have already been detected)
67	warning "$compiler does not exist"
68    }
69}
70
71#
72# gcc_version -- Call default_gcc_version, so we can override it if needed.
73#
74
75proc gcc_version { } {
76    default_gcc_version;
77}
78
79#
80# gcc_init -- called at the start of each .exp script.
81#
82# There currently isn't much to do, but always using it allows us to
83# make some enhancements without having to go back and rewrite the scripts.
84#
85
86set gcc_initialized 0
87
88proc gcc_init { args } {
89    global tmpdir
90    global libdir
91    global gluefile wrap_flags
92    global gcc_initialized
93    global GCC_UNDER_TEST
94    global TOOL_EXECUTABLE
95
96    if { $gcc_initialized == 1 } { return; }
97
98    if ![info exists GCC_UNDER_TEST] {
99	if [info exists TOOL_EXECUTABLE] {
100	    set GCC_UNDER_TEST $TOOL_EXECUTABLE;
101	} else {
102	    set GCC_UNDER_TEST "[find_gcc]"
103	}
104    }
105
106    if ![info exists tmpdir] then {
107	set tmpdir /tmp
108    }
109    if {[target_info needs_status_wrapper] != "" && \
110	    [target_info needs_status_wrapper] != "0" && \
111	    ![info exists gluefile]} {
112	set gluefile ${tmpdir}/gcc-testglue.o;
113	set result [build_wrapper $gluefile];
114	if { $result != "" } {
115	    set gluefile [lindex $result 0];
116	    set wrap_flags [lindex $result 1];
117	} else {
118	    unset gluefile
119	}
120    }
121}
122
123#
124# gcc_target_compile -- compile a source file
125#
126
127proc gcc_target_compile { source dest type options } {
128    global tmpdir;
129    global gluefile wrap_flags;
130    global GCC_UNDER_TEST
131    global TOOL_OPTIONS
132
133    if {[target_info needs_status_wrapper] != "" && \
134	    [target_info needs_status_wrapper] != "0" && \
135	    [info exists gluefile] } {
136	lappend options "libs=${gluefile}"
137	lappend options "ldflags=$wrap_flags"
138    }
139
140    if [target_info exists gcc,stack_size] {
141	lappend options "additional_flags=-DSTACK_SIZE=[target_info gcc,stack_size]"
142    }
143    if [target_info exists gcc,no_trampolines] {
144	lappend options "additional_flags=-DNO_TRAMPOLINES"
145    }
146    if [target_info exists gcc,no_label_values] {
147	lappend options "additional_flags=-DNO_LABEL_VALUES"
148    }
149    if [info exists TOOL_OPTIONS] {
150	lappend options "additional_flags=$TOOL_OPTIONS"
151    }
152    if [target_info exists gcc,timeout] {
153	lappend options "timeout=[target_info gcc,timeout]"
154    }
155    lappend options "compiler=$GCC_UNDER_TEST"
156    return [target_compile $source $dest $type $options]
157}
158