gnat.exp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. # Copyright (C) 2006-2015 Free Software Foundation, Inc.
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 3 of the License, or
  5. # (at your option) any later version.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with GCC; see the file COPYING3. If not see
  14. # <http://www.gnu.org/licenses/>.
  15. # This file was written by James A. Morrison (ja2morri@uwaterloo.ca)
  16. # based on gcc.exp written by Rob Savoye (rob@cygnus.com).
  17. # This file is loaded by the tool init file (eg: unix.exp). It provides
  18. # default definitions for gnat_start, etc. and other supporting cast members.
  19. load_lib prune.exp
  20. load_lib gcc-defs.exp
  21. load_lib gcc.exp
  22. load_lib timeout.exp
  23. #
  24. # GNAT_UNDER_TEST is the compiler under test.
  25. #
  26. #
  27. # default_gnat_version -- extract and print the version number of the compiler
  28. #
  29. proc default_gnat_version { } {
  30. global GNAT_UNDER_TEST
  31. gnat_init
  32. # ignore any arguments after the command
  33. set compiler [lindex $GNAT_UNDER_TEST 0]
  34. if ![is_remote host] {
  35. set compiler_name [which $compiler]
  36. } else {
  37. set compiler_name $compiler
  38. }
  39. # verify that the compiler exists
  40. if { $compiler_name != 0 } then {
  41. set tmp [remote_exec host "$compiler --version"]
  42. set status [lindex $tmp 0]
  43. set output [lindex $tmp 1]
  44. regexp "^GNATMAKE (\[^\n\r\]*)" $output verline version
  45. if { $status == 0 && [info exists version] } then {
  46. # test_summary expects "version" as second field.
  47. clone_output "$compiler_name version $version\n"
  48. } else {
  49. clone_output "Couldn't determine version of $compiler_name: $output\n"
  50. }
  51. } else {
  52. # compiler does not exist (this should have already been detected)
  53. warning "$compiler does not exist"
  54. }
  55. }
  56. #
  57. # gnat_version -- Call default_gnat_version, so we can override it if needed.
  58. #
  59. proc gnat_version { } {
  60. default_gnat_version
  61. }
  62. #
  63. # gnat_init -- called at the start of each .exp script.
  64. #
  65. set gnat_initialized 0
  66. proc gnat_init { args } {
  67. global rootme
  68. global tmpdir
  69. global libdir
  70. global gluefile wrap_flags
  71. global gnat_initialized
  72. global GNAT_UNDER_TEST
  73. global TOOL_EXECUTABLE
  74. global gnat_target_current
  75. set gnat_target_current ""
  76. if { $gnat_initialized == 1 } { return }
  77. if ![info exists GNAT_UNDER_TEST] then {
  78. if [info exists TOOL_EXECUTABLE] {
  79. set GNAT_UNDER_TEST "$TOOL_EXECUTABLE"
  80. } else {
  81. set GNAT_UNDER_TEST "[local_find_gnatmake]"
  82. }
  83. }
  84. if ![info exists tmpdir] then {
  85. set tmpdir /tmp
  86. }
  87. }
  88. proc gnat_target_compile { source dest type options } {
  89. global rootme
  90. global tmpdir
  91. global gluefile wrap_flags
  92. global srcdir
  93. global GNAT_UNDER_TEST
  94. global TOOL_OPTIONS
  95. global gnat_target_current
  96. global TEST_ALWAYS_FLAGS
  97. # dg-require-effective-target tests must be compiled as C.
  98. if [ string match "*.c" $source ] then {
  99. return [gcc_target_compile $source $dest $type $options]
  100. }
  101. # If we detect a change of target, we need to recompute both
  102. # GNAT_UNDER_TEST and the appropriate RTS.
  103. if { $gnat_target_current!="[current_target_name]" } {
  104. set gnat_target_current "[current_target_name]"
  105. if [info exists TOOL_OPTIONS] {
  106. set rtsdir "[get_multilibs ${TOOL_OPTIONS}]/libada"
  107. } else {
  108. set rtsdir "[get_multilibs]/libada"
  109. }
  110. if [info exists TOOL_EXECUTABLE] {
  111. set GNAT_UNDER_TEST "$TOOL_EXECUTABLE"
  112. } else {
  113. set GNAT_UNDER_TEST "[local_find_gnatmake]"
  114. }
  115. set GNAT_UNDER_TEST "$GNAT_UNDER_TEST --RTS=$rtsdir"
  116. # gnatlink looks for system.ads itself and has no --RTS option, so
  117. # specify via environment
  118. setenv ADA_INCLUDE_PATH "$rtsdir/adainclude"
  119. setenv ADA_OBJECTS_PATH "$rtsdir/adainclude"
  120. # Always log so compilations can be repeated manually.
  121. verbose -log "ADA_INCLUDE_PATH=$rtsdir/adainclude"
  122. verbose -log "ADA_OBJECTS_PATH=$rtsdir/adainclude"
  123. }
  124. lappend options "compiler=$GNAT_UNDER_TEST -q -f"
  125. lappend options "timeout=[timeout_value]"
  126. if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
  127. lappend options "libs=${gluefile}"
  128. lappend options "ldflags=$wrap_flags"
  129. }
  130. # TEST_ALWAYS_FLAGS are flags that should be passed to every
  131. # compilation. They are passed first to allow individual
  132. # tests to override them.
  133. if [info exists TEST_ALWAYS_FLAGS] {
  134. set options [concat "{additional_flags=$TEST_ALWAYS_FLAGS}" $options]
  135. }
  136. # TOOL_OPTIONS must come first, so that it doesn't override testcase
  137. # specific options.
  138. if [info exists TOOL_OPTIONS] {
  139. set options [concat "additional_flags=$TOOL_OPTIONS" $options]
  140. }
  141. return [target_compile $source $dest $type $options]
  142. }
  143. # Prune messages from GNAT that aren't useful.
  144. proc prune_gnat_output { text } {
  145. #send_user "Before:$text\n"
  146. regsub -all "(^|\n)\[^\n\]*: In (function|method) \[^\n\]*" $text "" text
  147. regsub -all "(^|\n)\[^\n\]*: At top level:\[^\n\]*" $text "" text
  148. # prune the output from gnatmake.
  149. regsub -all "(^|\n)\[^\n\]*gnatmake: [^\n\]*" $text "" text
  150. # It would be nice to avoid passing anything to gnat that would cause it to
  151. # issue these messages (since ignoring them seems like a hack on our part),
  152. # but that's too difficult in the general case. For example, sometimes
  153. # you need to use -B to point gnat at crt0.o, but there are some targets
  154. # that don't have crt0.o.
  155. regsub -all "(^|\n)\[^\n\]*file path prefix \[^\n\]* never used" $text "" text
  156. regsub -all "(^|\n)\[^\n\]*linker input file unused since linking not done" $text "" text
  157. #send_user "After:$text\n"
  158. return $text
  159. }
  160. # find_gnatmake for some version of DejaGnu will hardcode a -I...rts/ada flag
  161. # which prevent multilib from working, so define a new one.
  162. proc local_find_gnatmake {} {
  163. global tool_root_dir
  164. if ![is_remote host] {
  165. set file [lookfor_file $tool_root_dir gnatmake]
  166. if { $file == "" } {
  167. set file [lookfor_file $tool_root_dir gcc/gnatmake]
  168. }
  169. if { $file != "" } {
  170. set root [file dirname $file]
  171. # Need to pass full --GCC, including multilib flags, to gnatlink,
  172. # otherwise gcc from PATH is invoked.
  173. set dest [target_info name]
  174. set gnatlink_gcc "--GCC=$root/xgcc -B$root [board_info $dest multilib_flags]"
  175. # Escape blanks to get them through DejaGnu's exec machinery.
  176. regsub -all {\s} "$gnatlink_gcc" {\\&} gnatlink_gcc
  177. set CC "$file --GCC=$root/xgcc --GNATBIND=$root/gnatbind --GNATLINK=$root/gnatlink -cargs -B$root -largs $gnatlink_gcc -margs";
  178. } else {
  179. set CC [transform gnatmake]
  180. }
  181. } else {
  182. set CC [transform gnatmake]
  183. }
  184. return $CC
  185. }
  186. proc find_gnatclean {} {
  187. global tool_root_dir
  188. if ![is_remote host] {
  189. set file [lookfor_file $tool_root_dir gnatclean]
  190. if { $file == "" } {
  191. set file [lookfor_file $tool_root_dir gcc/gnatclean]
  192. }
  193. if { $file != "" } {
  194. set gnatclean $file;
  195. } else {
  196. set gnatclean [transform gnatclean]
  197. }
  198. } else {
  199. set gnatclean [transform gnatclean]
  200. }
  201. return $gnatclean
  202. }
  203. # Local Variables:
  204. # tcl-indent-level:4
  205. # End: