1# This program is free software; you can redistribute it and/or modify
2# it under the terms of the GNU General Public License as published by
3# the Free Software Foundation; either version 2 of the License, or
4# (at your option) any later version.
5#
6# This program is distributed in the hope that it will be useful,
7# but WITHOUT ANY WARRANTY; without even the implied warranty of
8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9# GNU General Public License for more details.
10#
11# You should have received a copy of the GNU General Public License
12# along with this program; if not, write to the Free Software
13# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
14
15# Damn dejagnu for not having proper library search paths for load_lib.
16# We have to explicitly load everything that gcc-dg.exp wants to load.
17
18proc load_gcc_lib { filename } {
19    global srcdir loaded_libs
20
21    load_file $srcdir/../../gcc/testsuite/lib/$filename
22    set loaded_libs($filename) ""
23}
24
25load_lib dg.exp
26load_gcc_lib file-format.exp
27load_gcc_lib target-supports.exp
28load_gcc_lib target-supports-dg.exp
29load_gcc_lib target-utils.exp
30load_gcc_lib scanasm.exp
31load_gcc_lib scandump.exp
32load_gcc_lib scanrtl.exp
33load_gcc_lib scantree.exp
34load_gcc_lib scanipa.exp
35load_gcc_lib prune.exp
36load_gcc_lib target-libpath.exp
37load_gcc_lib wrapper.exp
38load_gcc_lib gcc-defs.exp
39load_gcc_lib torture-options.exp
40load_gcc_lib timeout.exp
41load_gcc_lib timeout-dg.exp
42load_gcc_lib fortran-modules.exp
43load_gcc_lib gcc-dg.exp
44
45set dg-do-what-default run
46
47#
48# GCC_UNDER_TEST is the compiler under test.
49#
50
51set libvtv_compile_options ""
52
53#
54# libvtv_init
55#
56
57if [info exists TOOL_OPTIONS] {
58    set multilibs [get_multilibs $TOOL_OPTIONS]
59} else {
60    set multilibs [get_multilibs]
61}
62
63proc libvtv_init { args } {
64    global srcdir blddir objdir tool_root_dir
65    global libvtv_initialized
66    global tmpdir
67    global blddir
68    global gluefile wrap_flags
69    global ALWAYS_CFLAGS
70    global CFLAGS
71    global TOOL_EXECUTABLE TOOL_OPTIONS
72    global GCC_UNDER_TEST
73    global TESTING_IN_BUILD_TREE
74    global target_triplet
75    global always_ld_library_path
76
77    set blddir [lookfor_file [get_multilibs] libvtv]
78
79    # We set LC_ALL and LANG to C so that we get the same error
80    # messages as expected.
81    setenv LC_ALL C
82    setenv LANG C
83
84    if ![info exists GCC_UNDER_TEST] then {
85	if [info exists TOOL_EXECUTABLE] {
86	    set GCC_UNDER_TEST $TOOL_EXECUTABLE
87	} else {
88	    set GCC_UNDER_TEST "[find_gcc]"
89	}
90    }
91
92    if ![info exists tmpdir] {
93	set tmpdir "/tmp"
94    }
95
96    if [info exists gluefile] {
97	unset gluefile
98    }
99
100    if {![info exists CFLAGS]} {
101	set CFLAGS ""
102    }
103
104    # Locate libgcc.a so we don't need to account for different values of
105    # SHLIB_EXT on different platforms
106    set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
107    if {$gccdir != ""} {
108	set gccdir [file dirname $gccdir]
109    }
110
111    # Compute what needs to be put into LD_LIBRARY_PATH
112    set always_ld_library_path ".:${blddir}/.libs"
113
114    # Compute what needs to be added to the existing LD_LIBRARY_PATH.
115    if {$gccdir != ""} {
116	# Add AIX pthread directory first.
117	if { [llength [glob -nocomplain ${gccdir}/pthread/libgcc_s*.a]] >= 1 } {
118	    append always_ld_library_path ":${gccdir}/pthread"
119	}
120	append always_ld_library_path ":${gccdir}"
121	set compiler [lindex $GCC_UNDER_TEST 0]
122
123	if { [is_remote host] == 0 && [which $compiler] != 0 } {
124	  foreach i "[exec $compiler --print-multi-lib]" {
125	    set mldir ""
126	    regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
127	    set mldir [string trimright $mldir "\;@"]
128	    if { "$mldir" == "." } {
129	      continue
130	    }
131	    if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
132	      append always_ld_library_path ":${gccdir}/${mldir}"
133	    }
134	  }
135	}
136    }
137
138    set ALWAYS_CFLAGS ""
139    if { $blddir != "" } {
140	lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/"
141	lappend ALWAYS_CFLAGS "additional_flags=-I${blddir}"
142	lappend ALWAYS_CFLAGS "ldflags=-L${blddir}/.libs"
143    }
144    lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/.."
145
146    if [istarget *-*-darwin*] {
147	lappend ALWAYS_CFLAGS "additional_flags=-shared-libgcc"
148    }
149
150    if [info exists TOOL_OPTIONS] {
151	lappend ALWAYS_CFLAGS "additional_flags=$TOOL_OPTIONS"
152    }
153
154    # Make sure that lines are not wrapped.  That can confuse the
155    # error-message parsing machinery.
156    lappend ALWAYS_CFLAGS "additional_flags=-fmessage-length=0"
157
158    # Turn on vtable verification
159    lappend ALWAYS_CFLAGS "-fvtable-verify=std"
160    # lappend ALWAYS_CFLAGS "ldflags=-lvtv"
161}
162
163#
164# libvtv_target_compile -- compile a source file
165#
166
167proc libvtv_target_compile { source dest type options } {
168    global blddir
169    global libvtv_compile_options
170    global gluefile wrap_flags
171    global ALWAYS_CFLAGS
172    global GCC_UNDER_TEST
173    global lang_test_file
174    global lang_library_path
175    global lang_link_flags
176
177    if { [info exists lang_test_file] } {
178	if { $blddir != "" } {
179	    lappend options "ldflags=-L${blddir}/${lang_library_path}"
180	}
181	lappend options "ldflags=${lang_link_flags}"
182    }
183
184    if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
185	lappend options "libs=${gluefile}"
186	lappend options "ldflags=${wrap_flags}"
187    }
188
189    lappend options "additional_flags=[libio_include_flags]"
190    lappend options "timeout=[timeout_value]"
191    lappend options "compiler=$GCC_UNDER_TEST"
192
193    set options [concat $libvtv_compile_options $options]
194
195    if [info exists ALWAYS_CFLAGS] {
196	set options [concat "$ALWAYS_CFLAGS" $options]
197    }
198
199    set options [dg-additional-files-options $options $source]
200
201    set result [target_compile $source $dest $type $options]
202
203    return $result
204}
205
206proc libvtv_option_help { } {
207    send_user " --additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
208}
209
210proc libvtv_option_proc { option } {
211    if [regexp "^--additional_options," $option] {
212	global libvtv_compile_options
213	regsub "--additional_options," $option "" option
214	foreach x [split $option ","] {
215	    lappend libvtv_compile_options "additional_flags=$x"
216	}
217	return 1
218    } else {
219	return 0
220    }
221}
222