future.exp revision 1.5
1# Copyright 2004-2015 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 3 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, see <http://www.gnu.org/licenses/>. 15 16load_lib libgloss.exp 17 18# FIXME:brobecker/2004-03-31: 19# The following functions should eventually be part of dejagnu. Even after 20# these functions becomes available in dejagnu, we will keep for a while 21# a copy here in order to avoid increasing the dejagnu version 22# requirement. 23 24proc gdb_find_gnatmake {} { 25 global tool_root_dir 26 27 set root "$tool_root_dir/gcc" 28 set GM "" 29 30 if ![is_remote host] { 31 set file [lookfor_file $root gnatmake] 32 if { $file != "" } { 33 set GM "$file -I$root/ada/rts --GCC=$root/xgcc --GNATBIND=$root/gnatbind --GNATLINK=$root/gnatlink -cargs -B$root -largs --GCC=$root/xgcc -margs"; 34 } 35 } 36 37 if {$GM == ""} { 38 set GM [transform gnatmake] 39 } 40 41 return $GM 42} 43 44proc gdb_find_gfortran {} { 45 global tool_root_dir 46 47 if {![is_remote host]} { 48 set file [lookfor_file $tool_root_dir gfortran] 49 if { $file == "" } { 50 set file [lookfor_file $tool_root_dir gcc/gfortran] 51 } 52 if { $file != "" } { 53 set CC "$file -B[file dirname $file]/" 54 } else { 55 set CC [transform gfortran] 56 } 57 } else { 58 set CC [transform gfortran] 59 } 60 return $CC 61} 62 63proc gdb_find_go {} { 64 global tool_root_dir 65 66 set GO "" 67 68 if {![is_remote host]} { 69 set file [lookfor_file $tool_root_dir gccgo] 70 if { $file != "" } { 71 set root [file dirname $file] 72 set GO "$file -B$root/gcc/" 73 } 74 } 75 76 if { $GO == "" } { 77 set GO [transform gccgo] 78 } 79 80 return $GO 81} 82 83proc gdb_find_go_linker {} { 84 return [find_go] 85} 86 87proc gdb_find_ldd {} { 88 global LDD_FOR_TARGET 89 if [info exists LDD_FOR_TARGET] { 90 set ldd $LDD_FOR_TARGET 91 } else { 92 set ldd "ldd" 93 } 94 return $ldd 95} 96 97proc gdb_find_objcopy {} { 98 global OBJCOPY_FOR_TARGET 99 if [info exists OBJCOPY_FOR_TARGET] { 100 set objcopy $OBJCOPY_FOR_TARGET 101 } else { 102 set objcopy [transform objcopy] 103 } 104 return $objcopy 105} 106 107# find target objdump 108proc gdb_find_objdump {} { 109 global OBJDUMP_FOR_TARGET 110 if [info exists OBJDUMP_FOR_TARGET] { 111 set objdump $OBJDUMP_FOR_TARGET 112 } else { 113 set objdump [transform objdump] 114 } 115 return $objdump 116} 117 118proc gdb_find_readelf {} { 119 global READELF_FOR_TARGET 120 if [info exists READELF_FOR_TARGET] { 121 set readelf $READELF_FOR_TARGET 122 } else { 123 set readelf [transform readelf] 124 } 125 return $readelf 126} 127 128proc gdb_default_target_compile {source destfile type options} { 129 global target_triplet 130 global tool_root_dir 131 global CFLAGS_FOR_TARGET 132 global compiler_flags 133 134 if { $destfile == "" && $type != "preprocess" && $type != "none" } { 135 error "Must supply an output filename for the compile to default_target_compile" 136 } 137 138 set add_flags "" 139 set libs "" 140 set compiler_type "c" 141 set compiler "" 142 set linker "" 143 # linker_opts_order is one of "sources-then-flags", "flags-then-sources". 144 # The order shouldn't matter. It's done this way to preserve 145 # existing behavior. 146 set linker_opts_order "sources-then-flags" 147 set ldflags "" 148 set dest [target_info name] 149 150 if {[info exists CFLAGS_FOR_TARGET]} { 151 append add_flags " $CFLAGS_FOR_TARGET" 152 } 153 154 if {[info exists target_info(host,name)]} { 155 set host [host_info name] 156 } else { 157 set host "unix" 158 } 159 160 foreach i $options { 161 162 if { $i == "ada" } { 163 set compiler_type "ada" 164 if {[board_info $dest exists adaflags]} { 165 append add_flags " [target_info adaflags]" 166 } 167 if {[board_info $dest exists gnatmake]} { 168 set compiler [target_info gnatmake] 169 } else { 170 set compiler [find_gnatmake] 171 } 172 } 173 174 if { $i == "c++" } { 175 set compiler_type "c++" 176 if {[board_info $dest exists cxxflags]} { 177 append add_flags " [target_info cxxflags]" 178 } 179 append add_flags " [g++_include_flags]" 180 if {[board_info $dest exists c++compiler]} { 181 set compiler [target_info c++compiler] 182 } else { 183 set compiler [find_g++] 184 } 185 } 186 187 if { $i == "f77" } { 188 set compiler_type "f77" 189 if {[board_info $dest exists f77flags]} { 190 append add_flags " [target_info f77flags]" 191 } 192 if {[board_info $dest exists f77compiler]} { 193 set compiler [target_info f77compiler] 194 } else { 195 set compiler [find_g77] 196 } 197 } 198 199 if { $i == "f90" } { 200 set compiler_type "f90" 201 if {[board_info $dest exists f90flags]} { 202 append add_flags " [target_info f90flags]" 203 } 204 if {[board_info $dest exists f90compiler]} { 205 set compiler [target_info f90compiler] 206 } else { 207 set compiler [find_gfortran] 208 } 209 } 210 211 if { $i == "go" } { 212 set compiler_type "go" 213 if {[board_info $dest exists goflags]} { 214 append add_flags " [target_info goflags]" 215 } 216 if {[board_info $dest exists gocompiler]} { 217 set compiler [target_info gocompiler] 218 } else { 219 set compiler [find_go] 220 } 221 if {[board_info $dest exists golinker]} { 222 set linker [target_info golinker] 223 } else { 224 set linker [find_go_linker] 225 } 226 if {[board_info $dest exists golinker_opts_order]} { 227 set linker_opts_order [target_info golinker_opts_order] 228 } 229 } 230 231 if {[regexp "^dest=" $i]} { 232 regsub "^dest=" $i "" tmp 233 if {[board_info $tmp exists name]} { 234 set dest [board_info $tmp name] 235 } else { 236 set dest $tmp 237 } 238 } 239 if {[regexp "^compiler=" $i]} { 240 regsub "^compiler=" $i "" tmp 241 set compiler $tmp 242 } 243 if {[regexp "^additional_flags=" $i]} { 244 regsub "^additional_flags=" $i "" tmp 245 append add_flags " $tmp" 246 } 247 if {[regexp "^ldflags=" $i]} { 248 regsub "^ldflags=" $i "" tmp 249 append ldflags " $tmp" 250 } 251 if {[regexp "^libs=" $i]} { 252 regsub "^libs=" $i "" tmp 253 append libs " $tmp" 254 } 255 if {[regexp "^incdir=" $i]} { 256 regsub "^incdir=" $i "-I" tmp 257 append add_flags " $tmp" 258 } 259 if {[regexp "^libdir=" $i]} { 260 regsub "^libdir=" $i "-L" tmp 261 append add_flags " $tmp" 262 } 263 if {[regexp "^ldscript=" $i]} { 264 regsub "^ldscript=" $i "" ldscript 265 } 266 if {[regexp "^redirect=" $i]} { 267 regsub "^redirect=" $i "" redirect 268 } 269 if {[regexp "^optimize=" $i]} { 270 regsub "^optimize=" $i "" optimize 271 } 272 if {[regexp "^timeout=" $i]} { 273 regsub "^timeout=" $i "" timeout 274 } 275 } 276 277 if {[board_info $host exists cflags_for_target]} { 278 append add_flags " [board_info $host cflags_for_target]" 279 } 280 281 global CC_FOR_TARGET 282 global CXX_FOR_TARGET 283 global F77_FOR_TARGET 284 global F90_FOR_TARGET 285 global GNATMAKE_FOR_TARGET 286 global GO_FOR_TARGET 287 global GO_LD_FOR_TARGET 288 289 if {[info exists GNATMAKE_FOR_TARGET]} { 290 if { $compiler_type == "ada" } { 291 set compiler $GNATMAKE_FOR_TARGET 292 } 293 } 294 295 if {[info exists CC_FOR_TARGET]} { 296 if { $compiler == "" } { 297 set compiler $CC_FOR_TARGET 298 } 299 } 300 301 if {[info exists CXX_FOR_TARGET]} { 302 if { $compiler_type == "c++" } { 303 set compiler $CXX_FOR_TARGET 304 } 305 } 306 307 if {[info exists F77_FOR_TARGET]} { 308 if { $compiler_type == "f77" } { 309 set compiler $F77_FOR_TARGET 310 } 311 } 312 313 if {[info exists F90_FOR_TARGET]} { 314 if { $compiler_type == "f90" } { 315 set compiler $F90_FOR_TARGET 316 } 317 } 318 319 if { $compiler_type == "go" } { 320 if {[info exists GO_FOR_TARGET]} { 321 set compiler $GO_FOR_TARGET 322 } 323 if {[info exists GO_LD_FOR_TARGET]} { 324 set linker $GO_LD_FOR_TARGET 325 } 326 } 327 328 if { $type == "executable" && $linker != "" } { 329 set compiler $linker 330 } 331 332 if { $compiler == "" } { 333 set compiler [board_info $dest compiler] 334 if { $compiler == "" } { 335 return "default_target_compile: No compiler to compile with" 336 } 337 } 338 339 if {![is_remote host]} { 340 if { [which $compiler] == 0 } { 341 return "default_target_compile: Can't find $compiler." 342 } 343 } 344 345 if {$type == "object"} { 346 append add_flags " -c" 347 } 348 349 if { $type == "preprocess" } { 350 append add_flags " -E" 351 } 352 353 if { $type == "assembly" } { 354 append add_flags " -S" 355 } 356 357 if {[board_info $dest exists cflags]} { 358 append add_flags " [board_info $dest cflags]" 359 } 360 361 if { $type == "executable" } { 362 if {[board_info $dest exists ldflags]} { 363 append add_flags " [board_info $dest ldflags]" 364 } 365 if { $compiler_type == "c++" } { 366 append add_flags " [g++_link_flags]" 367 } 368 if {[isnative]} { 369 # This is a lose. 370 catch "glob -nocomplain $tool_root_dir/libstdc++/libstdc++.so* $tool_root_dir/libstdc++/libstdc++.sl" tmp 371 if { ${tmp} != "" } { 372 if {[regexp ".*solaris2.*" $target_triplet]} { 373 # Solaris 2 374 append add_flags " -R$tool_root_dir/libstdc++" 375 } elseif {[regexp ".*(osf|irix5|linux).*" $target_triplet]} { 376 # OSF/1 or IRIX 5 377 append add_flags " -Wl,-rpath,$tool_root_dir/libstdc++" 378 } elseif {[regexp ".*hppa.*" $target_triplet]} { 379 # HP-UX 380 append add_flags " -Wl,-a,shared_archive" 381 } 382 } 383 } 384 } 385 386 if {![info exists ldscript]} { 387 set ldscript [board_info $dest ldscript] 388 } 389 390 foreach i $options { 391 if { $i == "debug" } { 392 if {[board_info $dest exists debug_flags]} { 393 append add_flags " [board_info $dest debug_flags]" 394 } else { 395 append add_flags " -g" 396 } 397 } 398 } 399 400 if {[info exists optimize]} { 401 append add_flags " $optimize" 402 } 403 404 if { $type == "executable" } { 405 append add_flags " $ldflags" 406 foreach x $libs { 407 if {[file exists $x]} { 408 append source " $x" 409 } else { 410 append add_flags " $x" 411 } 412 } 413 414 if {[board_info $dest exists libs]} { 415 append add_flags " [board_info $dest libs]" 416 } 417 418 # This probably isn't such a good idea, but it avoids nasty 419 # hackiness in the testsuites. 420 # The math library must be linked in before the C library. The C 421 # library is linked in by the linker script, so this must be before 422 # the linker script. 423 if {[board_info $dest exists mathlib]} { 424 append add_flags " [board_info $dest mathlib]" 425 } else { 426 append add_flags " -lm" 427 } 428 429 # This must be added here. 430 append add_flags " $ldscript" 431 432 if {[board_info $dest exists remote_link]} { 433 # Relink option. 434 append add_flags " -Wl,-r" 435 } 436 if {[board_info $dest exists output_format]} { 437 append add_flags " -Wl,-oformat,[board_info $dest output_format]" 438 } 439 } 440 441 if {[board_info $dest exists multilib_flags]} { 442 append add_flags " [board_info $dest multilib_flags]" 443 } 444 445 verbose "doing compile" 446 447 set sources "" 448 if {[is_remote host]} { 449 foreach x $source { 450 set file [remote_download host $x] 451 if { $file == "" } { 452 warning "Unable to download $x to host." 453 return "Unable to download $x to host." 454 } else { 455 append sources " $file" 456 } 457 } 458 } else { 459 set sources $source 460 } 461 462 if {[is_remote host]} { 463 append add_flags " -o " [file tail $destfile] 464 remote_file host delete [file tail $destfile] 465 } else { 466 if { $destfile != "" } { 467 append add_flags " -o $destfile" 468 } 469 } 470 471 # This is obscure: we put SOURCES at the end when building an 472 # object, because otherwise, in some situations, libtool will 473 # become confused about the name of the actual source file. 474 switch $type { 475 "object" { 476 set opts "$add_flags $sources" 477 } 478 "executable" { 479 switch $linker_opts_order { 480 "flags-then-sources" { 481 set opts "$add_flags $sources" 482 } 483 "sources-then-flags" { 484 set opts "$sources $add_flags" 485 } 486 default { 487 error "Invalid value for board_info linker_opts_order" 488 } 489 } 490 } 491 default { 492 set opts "$sources $add_flags" 493 } 494 } 495 496 if {[is_remote host]} { 497 if {[host_info exists use_at]} { 498 set fid [open "atfile" "w"] 499 puts $fid "$opts" 500 close $fid 501 set opts "@[remote_download host atfile]" 502 remote_file build delete atfile 503 } 504 } 505 506 verbose "Invoking the compiler as $compiler $opts" 2 507 508 if {[info exists redirect]} { 509 verbose "Redirecting output to $redirect" 2 510 set status [remote_exec host "$compiler $opts" "" "" $redirect] 511 } else { 512 if {[info exists timeout]} { 513 verbose "Setting timeout to $timeout" 2 514 set status [remote_exec host "$compiler $opts" "" "" "" $timeout] 515 } else { 516 set status [remote_exec host "$compiler $opts"] 517 } 518 } 519 520 set compiler_flags $opts 521 if {[is_remote host]} { 522 remote_upload host [file tail $destfile] $destfile 523 remote_file host delete [file tail $destfile] 524 } 525 set comp_output [prune_warnings [lindex $status 1]] 526 regsub "^\[\r\n\]+" $comp_output "" comp_output 527 if { [lindex $status 0] != 0 } { 528 verbose -log "compiler exited with status [lindex $status 0]" 529 } 530 if { [lindex $status 1] != "" } { 531 verbose -log "output is:\n[lindex $status 1]" 2 532 } 533 if { [lindex $status 0] != 0 && "${comp_output}" == "" } { 534 set comp_output "exit status is [lindex $status 0]" 535 } 536 return ${comp_output} 537} 538 539# See if the version of dejaGNU being used to run the testsuite is 540# recent enough to contain support for building Ada programs or not. 541# If not, then use the functions above in place of the ones provided 542# by dejaGNU. This is only temporary (brobecker/2004-03-31). 543 544set use_gdb_compile 0 545if {[info procs find_gnatmake] == ""} { 546 rename gdb_find_gnatmake find_gnatmake 547 set use_gdb_compile 1 548} 549 550if {[info procs find_gfortran] == ""} { 551 rename gdb_find_gfortran find_gfortran 552 set use_gdb_compile 1 553} 554 555if {[info procs find_go_linker] == ""} { 556 rename gdb_find_go find_go 557 rename gdb_find_go_linker find_go_linker 558 set use_gdb_compile 1 559} 560 561if {$use_gdb_compile} { 562 catch {rename default_target_compile {}} 563 rename gdb_default_target_compile default_target_compile 564} 565 566 567# Provide 'lreverse' missing in Tcl before 7.5. 568 569if {[info procs lreverse] == ""} { 570 proc lreverse { arg } { 571 set retval {} 572 while { [llength $retval] < [llength $arg] } { 573 lappend retval [lindex $arg end-[llength $retval]] 574 } 575 return $retval 576 } 577} 578