1 # Copyright
(C
) 1992-2019, 2020 Free Software Foundation
, Inc.
3 # This file is part of DejaGnu.
5 # DejaGnu is free software
; you can redistribute it and
/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation
; either version
3 of the License
, or
8 #
(at your option
) any later version.
10 # DejaGnu is distributed in the hope that it will be useful
, but
11 # WITHOUT
ANY WARRANTY
; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License
for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with DejaGnu
; if not
, write to the Free Software Foundation
,
17 # Inc.
, 51 Franklin Street
- Fifth Floor
, Boston
, MA
02110-1301, USA.
19 # This file was written by Rob Savoye
<rob@welcomehome.org
>.
21 # this contains a list of gcc options and their respective directories.
23 # Find the pieces of libgloss
for testing the GNU development tools
24 # needed to link a
set of object files into an executable.
25 # This usually means setting the
-L and
-B paths correctly.
27 proc libgloss_link_flags
{ args } {
31 # libgloss doesn
't work native
36 # if we're
on a remote host
, we can
't search for the file, so we can only
37 # use an installed compiler, so we don't add
any paths here.
38 if {[isremote host
]} {
42 set gccpath
"[get_multilibs]"
44 # map the target_cpu to the proper libgloss directory. unfortunately
, these
45 # directory names are hardcoded into libgloss.
46 switch -glob
-- $target_cpu
{
83 # look
for the libgloss srcdir sp we can find the linker scripts
84 set gloss_srcdir
[lookfor_file $srcdir libgloss
/$cpu
]
86 #
set the proper paths
for gcc
if the target subdir
exists, else assume we
87 # have no libgloss support
for this target.
88 if { $gloss_srcdir eq
"" } {
91 if {[file
exists [file join $gccpath libgloss $cpu
]]} {
92 verbose
"Libgloss path is $gccpath/libgloss/$cpu" 2
93 return "-B$gccpath/libgloss/$cpu/ -L$gccpath/libgloss/$cpu -L$gloss_srcdir"
95 verbose
-log "No libgloss support for this target." 2
100 # There aren
't any, but we'll be orthogonal here.
102 proc libgloss_include_flags
{ args } {
106 # Find the newlib libraries in the current source tree.
108 proc newlib_link_flags
{ args } {
111 # libgloss doesn
't work native
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 {[isremote host
]} {
122 set ld_script_path
[lookfor_file $tool_root_dir
"ld/ldscripts"]
123 if { $ld_script_path ne
"" } {
124 set result
"-L[file dirname $ld_script_path]"
129 set gccpath
"[get_multilibs]"
131 verbose
"Looking for $gccpath/newlib"
132 if {[file
exists [file join $gccpath newlib
]]} {
133 verbose
"Newlib path is $gccpath/newlib"
134 return "$result -B$gccpath/newlib/ -L$gccpath/newlib"
136 verbose
"No newlib support for this target"
141 proc newlib_include_flags
{ args } {
148 if {[isremote host
]} {
152 set gccpath
"[get_multilibs]"
154 if {[file
exists [file join $gccpath newlib
]]} {
155 verbose
"Newlib path is $gccpath/newlib"
157 set newlib_dir
[lookfor_file $srcdir newlib
/libc
/include/assert.h
]
158 if { $newlib_dir ne
"" } {
159 set newlib_dir
[file dirname $newlib_dir
]
161 # Note
- we use
-isystem rather than
-I because newlib contains
162 #
system header files. This is especially important
for the
163 # limits.h header which makes use of the #include_next directive.
164 # #include_next will generate error messages from GCC
if compiling
165 # in strict ANSI
mode or
if another limits.h header cannot be found.
166 # When it is included via
-isystem these things
do not happen.
167 return " -isystem $gccpath/newlib/targ-include -isystem $newlib_dir"
169 verbose
"No newlib support for this target"
173 proc libio_include_flags
{ args } {
177 if {[isremote host
]} {
181 set gccpath
"[get_multilibs]"
183 if { $gccpath eq
"" } {
184 set gccpath $tool_root_dir
187 set libio_bin_dir
[lookfor_file $gccpath libio
/_G_config.h
]
189 # linux doesn
't build _G_config.h and the test above fails, so
190 # we search for iostream.list too.
191 if { $libio_bin_dir eq "" } {
192 set libio_bin_dir [lookfor_file $gccpath libio/iostream.list]
195 set libio_src_dir [lookfor_file $srcdir libio/Makefile.in]
196 if { $libio_bin_dir ne "" && $libio_src_dir ne "" } {
197 set libio_src_dir [file dirname $libio_src_dir]
198 set libio_bin_dir [file dirname $libio_bin_dir]
199 # Note - unlike the newlib_include_flags proc above we use the -I
200 # switch to specify the include paths. This is because these headers
201 # are not system headers, and if -isystem were to be used GCC would
202 # generate an implicit extern "C" { ... } surrounding them. This
203 # will break targets which do not define NO_IMPLICIT_EXTERN_C.
204 return " -I$libio_src_dir -I$libio_bin_dir"
210 proc libio_link_flags { args } {
211 if {[isremote host]} {
215 set gccpath "[get_multilibs]"
217 set libio_dir [lookfor_file $gccpath libio/libio.a]
218 if { $libio_dir ne "" } {
219 return "-L[file dirname $libio_dir]"
225 proc g++_include_flags { args } {
229 if {[isremote host]} {
233 set gccpath [get_multilibs]
237 set dir [lookfor_file $srcdir libg++]
239 # See comment in libio_include_flags about using -I.
240 append flags " -I$dir -I$dir/src"
243 set dir [lookfor_file $srcdir libstdc++-v3]
245 append flags " -I$dir/include -I$dir/include/std -I$dir/include/c_std -I$dir/libsupc++"
248 set dir [lookfor_file $gccpath libstdc++-v3]
250 append flags " -I$dir/include -I$dir/include/$target_alias"
253 set dir [lookfor_file $srcdir libstdc++]
255 append flags " -I$dir -I$dir/stl"
261 proc g++_link_flags { args } {
263 global ld_library_path
265 set gccpath [get_multilibs]
268 set ld_library_path "."
270 if { $gccpath ne "" } {
271 if {[file exists [file join $gccpath lib libstdc++.a]]} {
272 append ld_library_path ":$gccpath/lib"
274 if {[file exists [file join $gccpath libg++ libg++.a]]} {
275 append flags "-L$gccpath/libg++ "
276 append ld_library_path ":$gccpath/libg++"
278 if {[file exists [file join $gccpath libstdc++ libstdc++.a]]} {
279 append flags "-L$gccpath/libstdc++ "
280 append ld_library_path ":$gccpath/libstdc++"
282 if {[file exists [file join $gccpath libstdc++-v3 src .libs libstdc++.a]]} {
283 append flags "-L$gccpath/libstdc++-v3/src/.libs "
284 append ld_library_path ":$gccpath/libstdc++-v3/src/.libs"
286 if {[file exists [file join $gccpath libiberty libiberty.a]]} {
287 append flags "-L$gccpath/libiberty "
289 if {[file exists [file join $gccpath librx librx.a]]} {
290 append flags "-L$gccpath/librx "
295 set libgpp [lookfor_file $tool_root_dir libg++]
296 if { $libgpp ne "" } {
297 append flags "-L$libgpp "
298 append ld_library_path ":$libgpp"
300 set libstdcpp [lookfor_file $tool_root_dir libstdc++]
301 if { $libstdcpp ne "" } {
302 append flags "-L$libstdcpp "
303 append ld_library_path ":$libstdcpp"
305 set libiberty [lookfor_file $tool_root_dir libiberty]
306 if { $libiberty ne "" } {
307 append flags "-L$libiberty "
309 set librx [lookfor_file $tool_root_dir librx]
310 if { $librx ne "" } {
311 append flags "-L$librx "
317 proc libstdc++_include_flags { args } {
321 if {[isremote host]} {
325 set gccpath [get_multilibs]
329 set dir [lookfor_file $srcdir libstdc++-v3]
331 # See comment in libio_include_flags about using -I.
332 append flags " -I$dir/include -I$dir/include/std -I$dir/include/c_std -I$dir/libsupc++"
335 set gccpath [get_multilibs]
337 set dir [lookfor_file $gccpath libstdc++-v3]
339 append flags " -I$dir/include -I$dir/include/$target_alias"
342 set dir [lookfor_file $srcdir libstdc++]
344 append flags " -I$dir -I$dir/stl"
350 proc libstdc++_link_flags { args } {
352 global ld_library_path
354 set gccpath [get_multilibs]
358 if { $gccpath ne "" } {
359 if {[file exists [file join $gccpath libstdc++ libstdc++.a]]} {
360 append flags "-L$gccpath/libstdc++ "
361 append ld_library_path ":$gccpath/libstdc++"
363 if {[file exists [file join $gccpath libiberty libiberty.a]]} {
364 append flags "-L$gccpath/libiberty "
366 if {[file exists [file join $gccpath librx librx.a]]} {
367 append flags "-L$gccpath/librx "
372 set libstdcpp [lookfor_file $tool_root_dir libstdc++]
373 if { $libstdcpp ne "" } {
374 append flags "-L$libstdcpp "
375 append ld_library_path ":$libstdcpp"
377 set libiberty [lookfor_file $tool_root_dir libiberty]
378 if { $libiberty ne "" } {
379 append flags "-L$libiberty "
381 set librx [lookfor_file $tool_root_dir librx]
382 if { $librx ne "" } {
383 append flags "-L$librx "
389 # Get the list of directories and -m options for gcc. This is kinda bogus that
390 # generic testing software needs support for gcc hardwired in, but to make
391 # testing the GNU tools work right, there didn't seem to be
any other way.
393 proc get_multilibs
{ args } {
398 #
if we
're on a remote host, we can't search
for the file
, so we can only
399 # use an installed compiler
, so we don
't add any paths here.
400 if {[isremote host]} {
404 if {[info exists board]} {
405 set target_board $board
407 set target_board [target_info name]
410 if { [llength $args] == 0 } {
411 if {[board_info $target_board exists multitop]} {
412 return "[board_info $target_board multitop]"
415 set board_info($target_board,multitop) ""
418 if { [board_info $target_board exists compiler] } {
419 set compiler [board_info $target_board compiler]
421 set compiler [find_gcc]
424 if { $compiler eq "" } {
428 foreach x $compiler {
429 if {[regexp "^-B" $x]} {
430 regsub "^-B" $x "" comp_base_dir
431 set comp_base_dir [file dirname $comp_base_dir]
436 regexp "/.* " $compiler compiler
437 set compiler [string trimright $compiler " "]
438 verbose "compiler is $compiler"
440 if { [which $compiler] == 0 } {
444 if { [llength $args] > 0 } {
445 set mopts [lindex $args 0]
447 if { [board_info $target_board exists multilib_flags] } {
448 set mopts [board_info $target_board multilib_flags]
454 set default_multilib [exec $compiler --print-multi-lib]
455 set default_multilib [lindex $default_multilib 0]
456 set extra [string trimleft $default_multilib ".;@@"]
458 # extract the options and their directory names as know by gcc
459 foreach i "[exec $compiler --print-multi-lib]" {
461 # string trimright would do the wrong thing if we included
462 # the leading @@ in $extra
463 set i [string trimright $i $extra]
464 set i [string trimright $i "@@"]
468 regexp -- "\[a-z0-9=/\.-\]*;" $i dir
469 set dir [string trimright $dir "\;@"]
470 regexp -- "\;@*\[\@a-zA-Z0-9=/\.-\]*" $i opts
471 set opts [split [string trimleft $opts "\;@@"] "@@"]
472 lappend multilibs "$dir {$opts }"
474 # If args contains arguments don't use the first one as
475 # multilib option unless it qualifies as a multilib option.
476 if { [llength $
args] > 0 } {
477 set override_opt
[lindex $
args 0]
479 if {$j
== $override_opt
} {
480 set mopts $override_opt
486 regsub
"^-" $mopts "" moptions
487 regsub
-all
" -" $moptions " " dirty_moptions
489 foreach x
[split $dirty_moptions
" "] {
490 if { $x ne
"" && [lsearch -exact $moptions $x] < 0 } {
495 if {![info exists comp_base_dir
]} {
496 set comp_base_dir
[file dirname
[file dirname
[file dirname
[file dirname
[file dirname
[exec $compiler
--print
-prog
-name=cc1
]]]]]]
499 # search
for the top level multilib directory
500 set multitop
[lookfor_file $comp_base_dir $target_alias
]
501 if { $multitop eq
"" } {
502 set multitop
[lookfor_file $comp_base_dir
"libraries"]
503 if { $multitop eq
"" } {
504 set multitop
"[lookfor_file $comp_base_dir gcc/xgcc]"
505 if { $multitop ne
"" } {
506 set multitop
[file dirname
[file dirname $multitop
]]
513 set gccpath
[eval exec $compiler
--print
-multi
-directory $mopts
]
514 set gccpath
[lindex $gccpath
0]
515 if { $gccpath ne
"" } {
516 verbose
"GCC path is $gccpath"
517 if { [llength $
args] == 0 } {
518 set board_info
($target_board
,multitop
) $multitop
/$gccpath
520 return $multitop
/$gccpath
523 # extract the MULTILIB_MATCHES from dumpspecs
525 set lines
[split
[exec $compiler
-dumpspecs
] "\n"]
526 for {set i
0} {$i
<= [llength $lines
] - 1} {incr i
1} {
527 if {"*multilib_matches:" eq "[lindex $lines $i]"} {
528 set multimatches
[lindex $lines
[expr
{$i
+ 1}]]
533 if {$multimatches ne
""} {
534 # Split it into a list of pairs.
If an moptions are the first
535 # of a pair
, then replace it with the second.
If an moption
536 # is not in multimatches
, we assume it
's not a multilib option
538 set splitmatches [split $multimatches ";"]
540 foreach i $splitmatches {
541 lappend multimatches [split $i " "]
543 verbose "multimatches: $multimatches" 3
545 verbose "options before multimatches: $moptions" 3
546 set toptions $moptions
548 foreach i $toptions {
549 foreach j $multimatches {
550 verbose "comparing [lindex $j 0] == $i" 3
551 if {[lindex $j 0] == $i} {
552 lappend moptions [lindex $j 1]
556 verbose "options after multimatches: $moptions" 3
559 # make a list of -m<foo> options from the various compiler config variables
562 # compare the lists of gcc options with the list of support multilibs
563 verbose "Supported multilibs are: $multilibs" 3
565 foreach i $multilibs {
567 set opts [lindex $i 1]
568 if { [llength $opts] <= [llength $moptions] } {
569 foreach j $moptions {
570 # see if all the -m<foo> options match any of the multilibs
571 verbose "Looking in $i for $j" 3
572 if { [lsearch -exact $opts $j] >= 0 } {
577 if { $hits > $best } {
578 verbose "[lindex $i 0] is better, using as gcc path" 2
579 set gccpath "[lindex $i 0]"
584 if {![info exists multitop]} {
588 verbose "gccpath is $gccpath" 3
590 if {[file exists [file join $multitop $gccpath]]} {
591 verbose "GCC path is $multitop/$gccpath" 3
592 if { [llength $args] == 0 } {
593 set board_info($target_board,multitop) $multitop/$gccpath
595 return $multitop/$gccpath
597 verbose "GCC path is $multitop" 3
598 if { [llength $args] == 0 } {
599 set board_info($target_board,multitop) $multitop
605 proc find_binutils_prog { name } {
608 if {![isremote host]} {
610 set file [lookfor_file $tool_root_dir $name]
612 set file [lookfor_file $tool_root_dir $name-new]
615 set file [lookfor_file $tool_root_dir binutils/$name]
618 set file [lookfor_file $tool_root_dir binutils/$name-new]
623 set NAME [transform $name]
626 set NAME [transform $name]
634 if {![isremote host]} {
635 set file [lookfor_file $tool_root_dir xgcc]
637 set file [lookfor_file $tool_root_dir gcc/xgcc]
640 set CC "$file -B[file dirname $file]/"
642 set CC [transform gcc]
645 set CC [transform gcc]
653 if {![isremote host]} {
654 set file [lookfor_file $tool_root_dir gcj]
656 set file [lookfor_file $tool_root_dir gcc/gcj]
659 set CC "$file -B[file dirname $file]/"
661 set CC [transform gcj]
664 set CC [transform gcj]
672 if {![isremote host]} {
673 set file [lookfor_file $tool_root_dir xg++]
675 set file [lookfor_file $tool_root_dir gcc/xg++]
678 set file [lookfor_file $tool_root_dir g++]
681 set CC "$file -B[file dirname $file]/"
683 set CC [transform g++]
686 set CC [transform g++]
694 if {![isremote host]} {
695 set file [lookfor_file $tool_root_dir gdc]
697 set file [lookfor_file $tool_root_dir gcc/gdc]
700 set CC "$file -B[file dirname $file]/"
702 set CC [transform gdc]
705 set CC [transform gdc]
713 if {![isremote host]} {
714 set file [lookfor_file $tool_root_dir g77]
716 set file [lookfor_file $tool_root_dir gcc/g77]
719 set CC "$file -B[file dirname $file]/"
721 set CC [transform g77]
724 set CC [transform g77]
729 proc find_gfortran {} {
732 if {![isremote host]} {
733 set file [lookfor_file $tool_root_dir gfortran]
735 set file [lookfor_file $tool_root_dir gcc/gfortran]
738 set CC "$file -B[file dirname $file]/"
740 set CC [transform gfortran]
743 set CC [transform gfortran]
748 proc find_gnatmake {} {
751 if {![isremote host]} {
752 set file [lookfor_file $tool_root_dir gnatmake]
754 set file [lookfor_file $tool_root_dir gcc/gnatmake]
757 set root [file dirname $file]
758 set CC "$file -I$root/ada/rts --GCC=$root/xgcc --GNATBIND=$root/gnatbind --GNATLINK=$root/gnatlink -cargs -B$root -largs --GCC=$root/xgcc -B$root -margs"
760 set CC [transform gnatmake]
763 set CC [transform gnatmake]
773 if {![is_remote host]} {
774 set file [lookfor_file $tool_root_dir gccgo]
776 set root [file dirname $file]
777 set GO "$file -B$root/gcc/"
782 set GO [transform gccgo]
788 proc find_go_linker {} {
794 if {![is_remote host]} {
795 set rustc [lookfor_file $tool_root_dir rustc]
803 append rustc " --color never"
812 if {![isremote host]} {
813 set NM [lookfor_file $tool_root_dir nm-new]
815 set NM [lookfor_file $tool_root_dir binutils/nm-new]
819 set NM [transform nm]
824 proc process_multilib_options { args } {
826 global board_variant_list
831 if {[board_info $board exists multilib_flags]} {
834 eval add_multilib_option $args
836 set multilib_flags ""
838 foreach x $board_variant_list {
839 regsub -all "^\[ \t\]*" $x "" x
840 regsub -all "\[ \t\]*$" $x "" x
847 set_board_info obj_format "a.out"
850 set_board_info obj_format "elf"
853 set_board_info obj_format "pe"
856 set_board_info obj_format "ecoff"
859 set_board_info debug_flags "-gstabs"
862 set_board_info debug_flags "-gdwarf2"
865 regsub "^gdb:\[^=\]*=(.*)$" $x "\\1" value
866 regsub "^gdb:(\[^=\]*)=.*$" $x "\\1" variable
867 set_board_info $variable $value
875 append multilib_flags " -EL"
880 append multilib_flags " -EB"
883 append multilib_flags " -msoft-float"
886 append multilib_flags " $x"
889 append multilib_flags " -m$x"
893 set_board_info multilib_flags $multilib_flags
896 proc add_multilib_option { args } {
897 global board_variant_list
899 if {![info exists board_variant_list]} {
900 set board_variant_list ""
902 set board_variant_list [concat $args $board_variant_list]
910 if {![isremote host]} {
911 set AS [lookfor_file $tool_root_dir as-new]
913 set AS [lookfor_file $tool_root_dir gas/as-new]
917 set AS [transform as]
927 if {![isremote host]} {
928 set LD [lookfor_file $tool_root_dir ld-new]
930 set LD [lookfor_file $tool_root_dir ld/ld-new]
934 set LD [transform ld]
939 proc build_wrapper { gluefile } {
943 if {[target_info exists wrap_m68k_aout]} {
944 set flags "additional_flags=-DWRAP_M68K_AOUT"
946 } elseif {[target_info exists uses_underscores]} {
947 set flags "additional_flags=-DUNDERSCORES"
948 set result "-Wl,-wrap,_exit -Wl,-wrap,__exit -Wl,-wrap,_main -Wl,-wrap,_abort"
952 if {[target_info exists is_vxworks]} {
953 set flags "additional_flags=-DVXWORKS"
954 set result "-Wl,-wrap,exit -Wl,-wrap,_exit -Wl,-wrap,main -Wl,-wrap,abort"
956 set result "-Wl,-wrap,exit -Wl,-wrap,_exit -Wl,-wrap,main -Wl,-wrap,abort"
959 if {[target_info exists wrap_compile_flags]} {
960 lappend flags "additional_flags=[target_info wrap_compile_flags]"
962 if { [target_compile $libdir/testglue.c $gluefile object $flags] eq "" } {
963 set gluefile [remote_download host $gluefile ${tool}_tg.o]
964 return [list $gluefile $result]
971 proc winsup_include_flags { args } {
978 if {[isremote host]} {
982 set gccpath "[get_multilibs]"
984 if {[file exists [file join $gccpath winsup]]} {
985 verbose "Winsup path is $gccpath/winsup"
987 set winsup_dir [lookfor_file $srcdir winsup/include/windows.h]
988 if { $winsup_dir ne "" } {
989 set winsup_dir [file dirname $winsup_dir]
990 # See comment in libio_include_flags about using -I.
991 return " -I$winsup_dir"
994 verbose "No winsup support for this target"
998 # Find the winsup libraries in the current source tree.
1000 proc winsup_link_flags { args } {
1001 # libgloss doesn't work native
1006 #
if we
're on a remote host, we can't search
for the file
, so we can only
1007 # use an installed compiler
, so we don
't add any paths here.
1008 if {[isremote host]} {
1012 set gccpath "[get_multilibs]"
1014 verbose "Looking for $gccpath/winsup"
1015 if {[file exists [file join $gccpath winsup]]} {
1016 verbose "Winsup path is $gccpath/newlib"
1017 return "-B$gccpath/winsup/ -L$gccpath/winsup"
1019 verbose "No winsup support for this target"