1# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
2# 2001, 2002, 2003 Free Software Foundation, Inc.
3#
4# This file is part of DejaGnu.
5#
6# DejaGnu is free software; you can redistribute it and/or modify it
7# under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# DejaGnu is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14# General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with DejaGnu; if not, write to the Free Software Foundation,
18# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20# This file was written by Rob Savoye. (rob@welcomehome.org)
21
22# this contains a list of gcc options and their respective directories.
23
24#
25# Find the pieces of libgloss for testing the GNU development tools
26# needed to link a set of object files into an executable.
27# This usually means setting the -L and -B paths correctly.
28#
29proc libgloss_link_flags { args } {
30    global target_cpu
31    global srcdir
32
33    # libgloss doesn't work native
34    if [isnative] {
35	return ""
36    }
37
38    # if we're on a remote host, we can't search for the file, so we can only
39    # use an installed compiler, so we don't add any paths here.
40    if [is_remote host] {
41	return ""
42    }
43
44    set gccpath "[get_multilibs]"
45
46    # map the target_cpu to the proper libgloss directory. unfortunately, these
47    # directory names are hardcoded into libgloss.
48    switch -glob -- $target_cpu {
49	"sparc86x" {
50	    set cpu sparc
51	}
52	"sparclite" {
53	    set cpu sparc
54	}
55	"sparclet" {
56	    set cpu sparc
57	}
58	"sparc64*" {
59	    set cpu sparc
60	}
61	"hppa*" {
62	    set cpu pa
63	}
64	"mips*" {
65	    set cpu mips
66	}
67	"powerpc*" {
68	    set cpu rs6000
69	}
70	"d10v*" {
71	    set cpu libnosys
72	}
73	"xscale*" {
74	    set cpu arm
75	}
76	default {
77	    set cpu $target_cpu
78	}
79    }
80
81    set gloss_srcdir ""
82    # look for the libgloss srcdir sp we can find the linker scripts
83    set gloss_srcdir [lookfor_file ${srcdir} libgloss/$cpu]
84
85    # set the proper paths for gcc if the target subdir exists, else assume we
86    # have no libgloss support for this target.
87    if { $gloss_srcdir == "" } {
88	return ""
89    }
90    if [file exists $gccpath/libgloss/$cpu] {
91	verbose "Libgloss path is $gccpath/libgloss/$cpu" 2
92	return "-B$gccpath/libgloss/$cpu/ -L$gccpath/libgloss/$cpu -L$gloss_srcdir"
93    } else {
94	verbose -log "No libgloss support for this target." 2
95	return ""
96    }
97}
98
99# There aren't any, but we'll be orthogonal here.
100
101proc libgloss_include_flags { args } {
102    return ""
103}
104
105#
106# Find the newlib libraries in the current source tree.
107#
108proc newlib_link_flags { args } {
109    global tool_root_dir
110
111    # libgloss doesn't work native
112    if [isnative] {
113	return ""
114    }
115
116    # if we're on a remote host, we can't search for the file, so we can only
117    # use an installed compiler, so we don't add any paths here.
118    if [is_remote host] {
119	return ""
120    }
121
122    set ld_script_path [lookfor_file ${tool_root_dir} "ld/ldscripts"]
123    if { $ld_script_path != "" } {
124	set result "-L[file dirname $ld_script_path]"
125    } else {
126	set result ""
127    }
128
129    set gccpath "[get_multilibs]"
130
131    verbose "Looking for $gccpath/newlib"
132    if [file exists $gccpath/newlib] {
133	verbose "Newlib path is $gccpath/newlib"
134	return "$result -B$gccpath/newlib/ -L$gccpath/newlib"
135    } else {
136	verbose "No newlib support for this target"
137	return "$result"
138    }
139}
140
141proc newlib_include_flags { args } {
142    global srcdir
143
144    if [isnative] {
145	return ""
146    }
147
148    if [is_remote host] {
149	return ""
150    }
151
152    set gccpath "[get_multilibs]"
153
154    if [file exists $gccpath/newlib] {
155	verbose "Newlib path is $gccpath/newlib"
156
157	set newlib_dir [lookfor_file ${srcdir} newlib/libc/include/assert.h]
158	if { ${newlib_dir} != "" } {
159	    set newlib_dir [file dirname ${newlib_dir}]
160	}
161	return " -isystem $gccpath/newlib/targ-include -isystem ${newlib_dir}"
162    } else {
163	verbose "No newlib support for this target"
164    }
165}
166
167proc libio_include_flags { args } {
168    global srcdir
169    global tool_root_dir
170
171    if [is_remote host] {
172	return ""
173    }
174
175    set gccpath "[get_multilibs]"
176
177    if { $gccpath == "" } {
178	set gccpath "$tool_root_dir"
179    }
180
181    set libio_bin_dir [lookfor_file ${gccpath} libio/_G_config.h]
182
183    # linux doesn't build _G_config.h and the test above fails, so
184    # we search for iostream.list too.
185    if { $libio_bin_dir == "" } {
186	set libio_bin_dir [lookfor_file ${gccpath} libio/iostream.list]
187    }
188
189    set libio_src_dir [lookfor_file ${srcdir} libio/Makefile.in]
190    if { $libio_bin_dir != "" && $libio_src_dir != "" } {
191	set libio_src_dir [file dirname ${libio_src_dir}]
192	set libio_bin_dir [file dirname ${libio_bin_dir}]
193	return " -isystem ${libio_src_dir} -isystem ${libio_bin_dir}"
194    } else {
195	return ""
196    }
197}
198
199proc libio_link_flags { args } {
200    if [is_remote host] {
201	return ""
202    }
203
204    set gccpath "[get_multilibs]"
205
206    set libio_dir [lookfor_file ${gccpath} libio/libio.a]
207    if { $libio_dir != "" } {
208	return "-L[file dirname ${libio_dir}]"
209    } else {
210	return ""
211    }
212}
213
214proc g++_include_flags { args } {
215    global srcdir
216    global target_alias
217
218    if [is_remote host] {
219	return ""
220    }
221
222    set gccpath [get_multilibs]
223    set libio_dir ""
224    set flags ""
225
226    set dir [lookfor_file ${srcdir} libg++]
227    if { ${dir} != "" } {
228	append flags " -isystem ${dir} -isystem ${dir}/src"
229    }
230
231    set dir [lookfor_file ${srcdir} libstdc++-v3]
232    if { ${dir} != "" } {
233	append flags " -isystem ${dir}/include -isystem ${dir}/include/std"
234	append flags " -isystem ${dir}/include/c_std -isystem ${dir}/libsupc++"
235    }
236
237    set dir [lookfor_file ${gccpath} libstdc++-v3]
238    if { ${dir} != "" } {
239	append flags " -isystem ${dir}/include -isystem ${dir}/include/${target_alias}"
240    }
241
242    set dir [lookfor_file ${srcdir} libstdc++]
243    if { ${dir} != "" } {
244	append flags " -isystem ${dir} -isystem ${dir}/stl"
245    }
246
247    return "$flags"
248}
249
250proc g++_link_flags { args } {
251    global srcdir
252    global ld_library_path
253
254    set gccpath [get_multilibs]
255    set libio_dir ""
256    set flags ""
257    set ld_library_path "."
258
259    if { $gccpath != "" } {
260	if [file exists "${gccpath}/lib/libstdc++.a"] {
261	    append ld_library_path ":${gccpath}/lib"
262	}
263	if [file exists "${gccpath}/libg++/libg++.a"] {
264	    append flags "-L${gccpath}/libg++ "
265	    append ld_library_path ":${gccpath}/libg++"
266	}
267	if [file exists "${gccpath}/libstdc++/libstdc++.a"] {
268	    append flags "-L${gccpath}/libstdc++ "
269	    append ld_library_path ":${gccpath}/libstdc++"
270	}
271	if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] {
272	    append flags "-L${gccpath}/libstdc++-v3/src/.libs "
273	    append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
274	}
275	if [file exists "${gccpath}/libiberty/libiberty.a"] {
276	    append flags "-L${gccpath}/libiberty "
277	}
278	if [file exists "${gccpath}/librx/librx.a"] {
279	    append flags "-L${gccpath}/librx "
280	}
281    } else {
282	global tool_root_dir
283
284	set libgpp [lookfor_file ${tool_root_dir} libg++]
285	if { $libgpp != "" } {
286	    append flags "-L${libgpp} "
287	    append ld_library_path ":${libgpp}"
288	}
289	set libstdcpp [lookfor_file ${tool_root_dir} libstdc++]
290	if { $libstdcpp != "" } {
291	    append flags "-L${libstdcpp} "
292	    append ld_library_path ":${libstdcpp}"
293	}
294	set libiberty [lookfor_file ${tool_root_dir} libiberty]
295	if { $libiberty != "" } {
296	    append flags "-L${libiberty} "
297	}
298	set librx [lookfor_file ${tool_root_dir} librx]
299	if { $librx != "" } {
300	    append flags "-L${librx} "
301	}
302    }
303    return "$flags"
304}
305
306proc libstdc++_include_flags { args } {
307    global srcdir
308    global target_alias
309
310    if [is_remote host] {
311	return ""
312    }
313
314    set gccpath [get_multilibs]
315    set libio_dir ""
316    set flags ""
317
318    set dir [lookfor_file ${srcdir} libstdc++-v3]
319    if { ${dir} != "" } {
320	append flags " -isystem ${dir}/include -isystem ${dir}/include/std"
321	append flags " -isystem ${dir}/include/c_std -isystem ${dir}/libsupc++"
322    }
323
324    set gccpath [get_multilibs]
325
326    set dir [lookfor_file ${gccpath} libstdc++-v3]
327    if { ${dir} != "" } {
328	append flags " -isystem ${dir}/include -isystem ${dir}/include/${target_alias}"
329    }
330
331    set dir [lookfor_file ${srcdir} libstdc++]
332    if { ${dir} != "" } {
333	append flags " -isystem ${dir} -isystem ${dir}/stl"
334    }
335
336    return "$flags"
337}
338
339proc libstdc++_link_flags { args } {
340    global srcdir
341    global ld_library_path
342
343    set gccpath [get_multilibs]
344    set libio_dir ""
345    set flags ""
346
347    if { $gccpath != "" } {
348	if [file exists "${gccpath}/libstdc++/libstdc++.a"] {
349	    append flags "-L${gccpath}/libstdc++ "
350	    append ld_library_path ":${gccpath}/libstdc++"
351	}
352	if [file exists "${gccpath}/libiberty/libiberty.a"] {
353	    append flags "-L${gccpath}/libiberty "
354	}
355	if [file exists "${gccpath}/librx/librx.a"] {
356	    append flags "-L${gccpath}/librx "
357	}
358    } else {
359	global tool_root_dir
360
361	set libstdcpp [lookfor_file ${tool_root_dir} libstdc++]
362	if { $libstdcpp != "" } {
363	    append flags "-L${libstdcpp} "
364	    append ld_library_path ":${libstdcpp}"
365	}
366	set libiberty [lookfor_file ${tool_root_dir} libiberty]
367	if { $libiberty != "" } {
368	    append flags "-L${libiberty} "
369	}
370	set librx [lookfor_file ${tool_root_dir} librx]
371	if { $librx != "" } {
372	    append flags "-L${librx} "
373	}
374    }
375    return "$flags"
376}
377
378#
379# Get the list of directories and -m options for gcc. This is kinda bogus that
380# generic testing software needs support for gcc hardwired in, but to make
381# testing the GNU tools work right, there didn't seem to be any other way.
382#
383
384proc get_multilibs { args } {
385    global target_alias
386    global board
387    global board_info
388
389    # if we're on a remote host, we can't search for the file, so we can only
390    # use an installed compiler, so we don't add any paths here.
391    if [is_remote host] {
392	return ""
393    }
394
395    if [info exists board] {
396	set target_board $board
397    } else {
398	set target_board [target_info name]
399    }
400
401    if { [llength $args] == 0 } {
402	if [board_info $target_board exists multitop] {
403	    return "[board_info $target_board multitop]"
404	}
405
406	set board_info($target_board,multitop) ""
407    }
408
409    if { [board_info $target_board exists compiler] } {
410	set compiler [board_info $target_board compiler]
411    } else {
412	set compiler [find_gcc]
413    }
414
415    if { $compiler == "" } {
416	return ""
417    }
418
419    foreach x "$compiler" {
420	if [regexp "^-B" "$x"] {
421	    regsub "^-B" "$x" "" comp_base_dir
422	    set comp_base_dir [file dirname $comp_base_dir]
423	    break
424	}
425    }
426
427    regexp "/.* " $compiler compiler
428    set compiler [string trimright $compiler " "]
429    verbose "compiler is $compiler"
430
431    if { [which $compiler] == 0 } {
432	return ""
433    }
434
435    if { [llength $args] > 0 } {
436	set mopts [lindex $args 0]
437    } else {
438	if { [board_info $target_board exists multilib_flags] } {
439	    set mopts [board_info $target_board multilib_flags]
440	} else {
441	    set mopts ""
442	}
443    }
444
445    set default_multilib [exec $compiler --print-multi-lib]
446    set default_multilib [lindex $default_multilib 0]
447    set extra [string trimleft $default_multilib ".;@@"]
448
449    # extract the options and their directory names as know by gcc
450    foreach i "[exec $compiler --print-multi-lib]" {
451    	if {$extra != ""} {
452	    # string trimright would do the wrong thing if we included
453	    # the leading @@ in $extra
454	    set i [string trimright $i $extra]
455	    set i [string trimright $i "@@"]
456	}
457	set opts ""
458	set dir ""
459	regexp -- "\[a-z0-9=/\.-\]*;" $i dir
460	set dir [string trimright $dir "\;@"]
461	regexp -- "\;@*\[\@a-zA-Z0-9=/\.-\]*" $i opts
462	set opts [split [string trimleft $opts "\;@@"] "@@"]
463	lappend multilibs "$dir {$opts }"
464
465	# If args contains arguments don't use the first one as
466	# multilib option unless it qualifies as a multilib option.
467	if { [llength $args] > 0 } {
468	    set override_opt [lindex $args 0]
469	    foreach j $opts {
470	        if {$j == $override_opt} {
471	    	    set mopts $override_opt
472	        }
473	    }
474	}
475    }
476
477    regsub "^-" $mopts "" moptions
478    regsub -all " -" $moptions " " dirty_moptions
479    set moptions ""
480    foreach x [split $dirty_moptions " "] {
481	if { $x != "" && [lsearch -exact $moptions $x] < 0 } {
482	    lappend moptions $x
483	}
484    }
485
486    if ![info exists comp_base_dir] {
487	set comp_base_dir [file dirname [file dirname [file dirname [file dirname [file dirname [exec $compiler --print-prog-name=cc1]]]]]]
488    }
489
490    # search for the top level multilib directory
491    set multitop [lookfor_file "${comp_base_dir}" "${target_alias}"]
492    if { $multitop == "" } {
493	set multitop [lookfor_file "${comp_base_dir}" "libraries"]
494	if { $multitop == "" } {
495	    set multitop "[lookfor_file ${comp_base_dir} gcc/xgcc]"
496	    if { $multitop != "" } {
497		set multitop [file dirname [file dirname $multitop]]
498	    } else {
499		return ""
500	    }
501	}
502    }
503
504    set gccpath [eval exec "$compiler" --print-multi-directory $mopts]
505    set gccpath [lindex $gccpath 0]
506    if { $gccpath != "" } {
507	verbose "GCC path is $gccpath"
508	if { [llength $args] == 0 } {
509	    set board_info($target_board,multitop) "$multitop/$gccpath"
510	}
511	return "$multitop/$gccpath"
512    }
513
514    # extract the MULTILIB_MATCHES from dumpspecs
515    set multimatches ""
516    set lines [split [exec $compiler -dumpspecs] "\n"]
517    for {set i 0} {$i <= [llength $lines] - 1} {incr i 1} {
518	if {"*multilib_matches:" == "[lindex $lines $i]"} {
519	    set multimatches [lindex $lines [expr $i + 1]]
520	    break
521	}
522    }
523    # if we find some
524    if {$multimatches != ""} {
525	# Split it into a list of pairs. If an moptions are the first
526	# of a pair, then replace it with the second.  If an moption
527	# is not in multimatches, we assume it's not a multilib option
528
529	set splitmatches [split $multimatches ";"]
530	set multimatches ""
531	foreach i $splitmatches {
532	    lappend multimatches [split $i " "]
533	}
534	verbose "multimatches: $multimatches" 3
535
536	verbose "options before multimatches: $moptions" 3
537	set toptions $moptions
538	set moptions ""
539	foreach i $toptions {
540	    foreach j $multimatches {
541		verbose "comparing [lindex $j 0] == $i" 3
542		if {[lindex $j 0] == $i} {
543		    lappend moptions [lindex $j 1]
544		}
545	    }
546	}
547	verbose "options after multimatches: $moptions" 3
548    }
549
550    # make a list of -m<foo> options from the various compiler config variables
551    set gccpath ""
552
553    # compare the lists of gcc options with the list of support multilibs
554    verbose "Supported multilibs are: $multilibs" 3
555    set best 0
556    foreach i "$multilibs" {
557	set hits 0
558	set opts [lindex $i 1]
559	if { [llength $opts] <= [llength $moptions] } {
560	    foreach j "$moptions" {
561		# see if all the -m<foo> options match any of the multilibs
562		verbose "Looking in $i for $j" 3
563		if { [lsearch -exact $opts $j] >= 0 } {
564		    incr hits
565		}
566	    }
567
568	    if { $hits > $best } {
569		verbose "[lindex $i 0] is better, using as gcc path" 2
570		set gccpath "[lindex $i 0]"
571		set best $hits
572	    }
573	}
574    }
575    if ![info exists multitop] {
576	return ""
577    }
578
579    verbose "gccpath is $gccpath" 3
580
581    if [file exists $multitop/$gccpath] {
582	verbose "GCC path is $multitop/$gccpath" 3
583	if { [llength $args] == 0 } {
584	    set board_info($target_board,multitop) "$multitop/$gccpath"
585	}
586	return "$multitop/$gccpath"
587    } else {
588	verbose "GCC path is $multitop" 3
589	if { [llength $args] == 0 } {
590	    set board_info($target_board,multitop) "$multitop"
591	}
592	return "$multitop"
593    }
594}
595
596proc find_binutils_prog { name } {
597    global tool_root_dir
598
599    if ![is_remote host] {
600
601	set file [lookfor_file $tool_root_dir $name]
602	if { $file == "" } {
603	    set file [lookfor_file $tool_root_dir ${name}-new]
604	}
605	if { $file == "" } {
606	    set file [lookfor_file $tool_root_dir binutils/$name]
607	}
608	if { $file == "" } {
609	    set file [lookfor_file $tool_root_dir binutils/${name}-new]
610	}
611	if { $file != "" } {
612	    set NAME "$file"
613	} else {
614	    set NAME [transform $name]
615	}
616    } else {
617	set NAME [transform $name]
618    }
619    return $NAME
620}
621
622proc find_gcc {} {
623    global tool_root_dir
624
625    if ![is_remote host] {
626	set file [lookfor_file $tool_root_dir xgcc]
627	if { $file == "" } {
628	    set file [lookfor_file $tool_root_dir gcc/xgcc]
629	}
630	if { $file != "" } {
631	    set CC "$file -B[file dirname $file]/"
632	} else {
633	    set CC [transform gcc]
634	}
635    } else {
636	set CC [transform gcc]
637    }
638    return $CC
639}
640
641proc find_gcj {} {
642    global tool_root_dir
643
644    if ![is_remote host] {
645	set file [lookfor_file $tool_root_dir gcj]
646	if { $file == "" } {
647	    set file [lookfor_file $tool_root_dir gcc/gcj]
648	}
649	if { $file != "" } {
650	    set CC "$file -B[file dirname $file]/"
651	} else {
652	    set CC [transform gcj]
653	}
654    } else {
655	set CC [transform gcj]
656    }
657    return $CC
658}
659
660proc find_g++ {} {
661    global tool_root_dir
662
663    if ![is_remote host] {
664	set file [lookfor_file $tool_root_dir g++]
665	if { $file == "" } {
666	    set file [lookfor_file $tool_root_dir gcc/g++]
667	}
668	if { $file != "" } {
669	    set CC "$file -B[file dirname $file]/"
670	} else {
671	    set CC [transform g++]
672	}
673    } else {
674	set CC [transform g++]
675    }
676    return $CC
677}
678
679proc find_g77 {} {
680    global tool_root_dir
681
682    if ![is_remote host] {
683	set file [lookfor_file $tool_root_dir g77]
684	if { $file == "" } {
685	    set file [lookfor_file $tool_root_dir gcc/g77]
686	}
687	if { $file != "" } {
688	    set CC "$file -B[file dirname $file]/"
689	} else {
690	    set CC [transform g77]
691	}
692    } else {
693	set CC [transform g77]
694    }
695    return $CC
696}
697
698proc find_nm {} {
699    global tool_root_dir
700
701    set NM ""
702    if ![is_remote host] {
703	set NM [lookfor_file $tool_root_dir nm-new]
704	if {$NM == ""} {
705 	    set NM [lookfor_file $tool_root_dir binutils/nm-new]
706	}
707    }
708    if { $NM == ""} {
709	set NM [transform nm]
710    }
711    return $NM
712}
713
714proc process_multilib_options { args } {
715    global board
716    global board_variant_list
717    global is_gdb_remote
718
719    set is_gdb_remote 0
720
721    if [board_info $board exists multilib_flags] {
722	return
723    }
724    eval add_multilib_option $args
725
726    set multilib_flags ""
727
728    foreach x $board_variant_list {
729	regsub -all "^\[ \t\]*" "$x" "" x
730	regsub -all "\[ \t\]*$" "$x" "" x
731
732	if { $x == "" } {
733	    continue
734	}
735	case $x in {
736	    { aout } {
737		set_board_info obj_format "a.out"
738	    }
739	    { elf } {
740		set_board_info obj_format "elf"
741	    }
742	    { pe } {
743		set_board_info obj_format "pe"
744	    }
745	    { ecoff } {
746		set_board_info obj_format "ecoff"
747	    }
748	    { stabs } {
749		set_board_info debug_flags "-gstabs"
750	    }
751	    { dwarf2 } {
752		set_board_info debug_flags "-gdwarf2"
753	    }
754	    { gdb:*=* } {
755		regsub "^gdb:\[^=\]*=(.*)$" "$x" "\\1" value
756		regsub "^gdb:(\[^=\]*)=.*$" "$x" "\\1" variable
757		set_board_info $variable "$value"
758	    }
759	    { gdb*remote } {
760		set is_gdb_remote 1
761	    }
762	    { little*endian el EL } {
763		append multilib_flags " -EL"
764	    }
765	    { big*endian eb EB } {
766		append multilib_flags " -EB"
767	    }
768	    { "soft*float" } {
769		append multilib_flags " -msoft-float"
770	    }
771	    { "-*" } {
772		append multilib_flags " $x"
773	    }
774	    default {
775		append multilib_flags " -m$x"
776	    }
777	}
778    }
779    set_board_info multilib_flags $multilib_flags
780}
781
782proc add_multilib_option { args } {
783    global board_variant_list
784
785    if ![info exists board_variant_list] {
786	set board_variant_list ""
787    }
788    set board_variant_list [concat $args $board_variant_list]
789}
790
791proc find_gas { } {
792    global tool_root_dir
793
794    set AS ""
795
796    if ![is_remote host] {
797	set AS [lookfor_file $tool_root_dir as-new]
798	if { $AS == "" } {
799	    set AS [lookfor_file $tool_root_dir gas/as-new]
800	}
801    }
802    if { $AS == "" } {
803	set AS [transform as]
804    }
805    return $AS
806}
807
808proc find_ld { } {
809    global tool_root_dir
810
811    set LD ""
812
813    if ![is_remote host] {
814	set LD [lookfor_file $tool_root_dir ld-new]
815	if { $LD == "" } {
816	    set LD [lookfor_file $tool_root_dir ld/ld-new]
817	}
818    }
819    if { $LD == "" } {
820	set LD [transform ld]
821    }
822    return $LD
823}
824
825proc build_wrapper { gluefile } {
826    global libdir
827    global tool
828
829    if [target_info exists wrap_m68k_aout] {
830	set flags "additional_flags=-DWRAP_M68K_AOUT"
831	set result ""
832    } elseif [target_info exists uses_underscores] {
833	set flags "additional_flags=-DUNDERSCORES"
834	set result "-Wl,-wrap,_exit -Wl,-wrap,__exit -Wl,-wrap,_main -Wl,-wrap,_abort"
835
836    } else {
837	set flags ""
838	if [target_info exists is_vxworks] {
839	    set flags "additional_flags=-DVXWORKS"
840	    set result "-Wl,-wrap,exit -Wl,-wrap,main -Wl,-wrap,abort"
841	    set result "-Wl,-wrap,exit -Wl,-wrap,_exit -Wl,-wrap,main -Wl,-wrap,abort"
842	} else {
843	    set result "-Wl,-wrap,exit -Wl,-wrap,_exit -Wl,-wrap,main -Wl,-wrap,abort"
844	}
845    }
846    if [target_info exists wrap_compile_flags] {
847	lappend flags "additional_flags=[target_info wrap_compile_flags]"
848    }
849    if { [target_compile ${libdir}/testglue.c ${gluefile} object $flags] == "" } {
850	set gluefile [remote_download host ${gluefile} ${tool}_tg.o]
851	return [list $gluefile $result]
852    } else {
853	return ""
854    }
855}
856
857
858proc winsup_include_flags { args } {
859    global srcdir
860
861    if [isnative] {
862	return ""
863    }
864
865    if [is_remote host] {
866	return ""
867    }
868
869    set gccpath "[get_multilibs]"
870
871    if [file exists $gccpath/winsup] {
872	verbose "Winsup path is $gccpath/winsup"
873
874	set winsup_dir [lookfor_file ${srcdir} winsup/include/windows.h]
875	if { ${winsup_dir} != "" } {
876	    set winsup_dir [file dirname ${winsup_dir}]
877	    return " -isystem ${winsup_dir}"
878	}
879    }
880    verbose "No winsup support for this target"
881
882}
883#
884# Find the winsup libraries in the current source tree.
885#
886proc winsup_link_flags { args } {
887    # libgloss doesn't work native
888    if [isnative] {
889	return ""
890    }
891
892    # if we're on a remote host, we can't search for the file, so we can only
893    # use an installed compiler, so we don't add any paths here.
894    if [is_remote host] {
895	return ""
896    }
897
898    set gccpath "[get_multilibs]"
899
900    verbose "Looking for $gccpath/winsup"
901    if [file exists $gccpath/winsup] {
902	verbose "Winsup path is $gccpath/newlib"
903	return "-B$gccpath/winsup/ -L$gccpath/winsup"
904    } else {
905	verbose "No winsup support for this target"
906	return ""
907    }
908}
909