PageRenderTime 61ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/src/netbsd/src/gnu/dist/gdb6/gdb/testsuite/lib/ada.exp

https://bitbucket.org/killerpenguinassassins/open_distrib_devel
Expect | 433 lines | 339 code | 45 blank | 49 comment | 98 complexity | fec100031cab7eec4ab063ad0b3277c4 MD5 | raw file
Possible License(s): CC0-1.0, MIT, LGPL-2.0, LGPL-3.0, WTFPL, GPL-2.0, BSD-2-Clause, AGPL-3.0, CC-BY-SA-3.0, MPL-2.0, JSON, BSD-3-Clause-No-Nuclear-License-2014, LGPL-2.1, CPL-1.0, AGPL-1.0, 0BSD, ISC, Apache-2.0, GPL-3.0, IPL-1.0, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. # Copyright 2004 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 2 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, write to the Free Software
  15. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. # USA.
  17. load_lib libgloss.exp
  18. # FIXME:brobecker/2004-03-31:
  19. # The following function should eventually be part of dejagnu. Even after
  20. # this function becomes available in dejagnu, we will keep for a while
  21. # a copy of this function here in order to avoid increasing the dejagnu
  22. # version requirement.
  23. proc gdb_find_gnatmake {} {
  24. global tool_root_dir
  25. set root "$tool_root_dir/gcc"
  26. set GM ""
  27. if ![is_remote host] {
  28. set file [lookfor_file $root gnatmake]
  29. if { $file != "" } {
  30. set GM "$file -I$root/ada/rts --GCC=$root/xgcc --GNATBIND=$root/gnatbind --GNATLINK=$root/gnatlink -cargs -B$root -largs --GCC=$root/xgcc -margs";
  31. }
  32. }
  33. if {$GM == ""} {
  34. set GM [transform gnatmake]
  35. }
  36. return $GM
  37. }
  38. # FIXME:brobecker/2004-03-31:
  39. # The following function is a copy of the function of the same name provided
  40. # by dejagnu, except that it has been modified to add support for building
  41. # Ada programs. This copy is temporarily placed here until the changes
  42. # are merged into the dejagnu official release. Once the changes are merged,
  43. # we will likely keep this local copy for a while to avoid increasing the
  44. # dejagnu version requirement.
  45. proc gdb_default_target_compile {source destfile type options} {
  46. global target_triplet
  47. global tool_root_dir
  48. global CFLAGS_FOR_TARGET
  49. global compiler_flags
  50. if { $destfile == "" && $type != "preprocess" && $type != "none" } {
  51. error "Must supply an output filename for the compile to default_target_compile"
  52. }
  53. set add_flags ""
  54. set libs ""
  55. set compiler_type "c"
  56. set compiler ""
  57. set ldflags ""
  58. set dest [target_info name]
  59. if [info exists CFLAGS_FOR_TARGET] {
  60. append add_flags " $CFLAGS_FOR_TARGET"
  61. }
  62. if [info exists target_info(host,name)] {
  63. set host [host_info name];
  64. } else {
  65. set host "unix";
  66. }
  67. foreach i $options {
  68. if { $i == "ada" } {
  69. set compiler_type "ada"
  70. if [board_info $dest exists adaflags] {
  71. append add_flags " [target_info adaflags]"
  72. }
  73. # append add_flags " [gnatmake_include_flags]";
  74. if [board_info $dest exists gnatmake] {
  75. set compiler [target_info gnatmake];
  76. } else {
  77. set compiler [find_gnatmake];
  78. }
  79. }
  80. if { $i == "c++" } {
  81. set compiler_type "c++"
  82. if [board_info $dest exists cxxflags] {
  83. append add_flags " [target_info cxxflags]"
  84. }
  85. append add_flags " [g++_include_flags]";
  86. if [board_info $dest exists c++compiler] {
  87. set compiler [target_info c++compiler];
  88. } else {
  89. set compiler [find_g++];
  90. }
  91. }
  92. if { $i == "f77" } {
  93. set compiler_type "f77"
  94. if [board_info $dest exists f77flags] {
  95. append add_flags " [target_info f77flags]"
  96. }
  97. # append add_flags " [f77_include_flags]"
  98. if [board_info $dest exists f77compiler] {
  99. set compiler [target_info f77compiler]
  100. } else {
  101. set compiler [find_g77]
  102. }
  103. }
  104. if [regexp "^dest=" $i] {
  105. regsub "^dest=" $i "" tmp
  106. if [board_info $tmp exists name] {
  107. set dest [board_info $tmp name];
  108. } else {
  109. set dest $tmp;
  110. }
  111. }
  112. if [regexp "^compiler=" $i] {
  113. regsub "^compiler=" $i "" tmp
  114. set compiler $tmp
  115. }
  116. if [regexp "^additional_flags=" $i] {
  117. regsub "^additional_flags=" $i "" tmp
  118. append add_flags " $tmp"
  119. }
  120. if [regexp "^ldflags=" $i] {
  121. regsub "^ldflags=" $i "" tmp
  122. append ldflags " $tmp"
  123. }
  124. if [regexp "^libs=" $i] {
  125. regsub "^libs=" $i "" tmp
  126. append libs " $tmp"
  127. }
  128. if [regexp "^incdir=" $i] {
  129. regsub "^incdir=" $i "-I" tmp
  130. append add_flags " $tmp"
  131. }
  132. if [regexp "^libdir=" $i] {
  133. regsub "^libdir=" $i "-L" tmp
  134. append add_flags " $tmp"
  135. }
  136. if [regexp "^ldscript=" $i] {
  137. regsub "^ldscript=" $i "" ldscript
  138. }
  139. if [regexp "^redirect=" $i] {
  140. regsub "^redirect=" $i "" redirect
  141. }
  142. if [regexp "^optimize=" $i] {
  143. regsub "^optimize=" $i "" optimize
  144. }
  145. if [regexp "^timeout=" $i] {
  146. regsub "^timeout=" $i "" timeout
  147. }
  148. }
  149. if [board_info $host exists cflags_for_target] {
  150. append add_flags " [board_info $host cflags_for_target]";
  151. }
  152. global CC_FOR_TARGET
  153. global CXX_FOR_TARGET
  154. global F77_FOR_TARGET
  155. global GNATMAKE_FOR_TARGET
  156. if [info exists CC_FOR_TARGET] {
  157. if { $compiler == "" } {
  158. set compiler $CC_FOR_TARGET
  159. }
  160. }
  161. if [info exists CXX_FOR_TARGET] {
  162. if { $compiler_type == "c++" } {
  163. set compiler $CXX_FOR_TARGET
  164. }
  165. }
  166. if [info exists F77_FOR_TARGET] {
  167. if { $compiler_type == "f77" } {
  168. set compiler $F77_FOR_TARGET
  169. }
  170. }
  171. if [info exists GNATMAKE_FOR_TARGET] {
  172. if { $compiler_type == "ada" } {
  173. set compiler $GNATMAKE_FOR_TARGET
  174. }
  175. }
  176. if { $compiler == "" } {
  177. set compiler [board_info $dest compiler];
  178. if { $compiler == "" } {
  179. return "default_target_compile: No compiler to compile with";
  180. }
  181. }
  182. if ![is_remote host] {
  183. if { [which $compiler] == 0 } {
  184. return "default_target_compile: Can't find $compiler."
  185. }
  186. }
  187. if {$type == "object"} {
  188. append add_flags " -c"
  189. }
  190. if { $type == "preprocess" } {
  191. append add_flags " -E"
  192. }
  193. if { $type == "assembly" } {
  194. append add_flags " -S"
  195. }
  196. if [board_info $dest exists cflags] {
  197. append add_flags " [board_info $dest cflags]"
  198. }
  199. if { $type == "executable" } {
  200. # This must be added here.
  201. # if [board_info $dest exists ldscript] {
  202. # append add_flags " [board_info $dest ldscript]"
  203. # }
  204. if [board_info $dest exists ldflags] {
  205. append add_flags " [board_info $dest ldflags]"
  206. }
  207. if { $compiler_type == "c++" } {
  208. append add_flags " [g++_link_flags]";
  209. }
  210. if [isnative] {
  211. # This is a lose.
  212. catch "glob -nocomplain $tool_root_dir/libstdc++/libstdc++.so* $tool_root_dir/libstdc++/libstdc++.sl" tmp
  213. if { ${tmp} != "" } {
  214. if [regexp ".*solaris2.*" $target_triplet] {
  215. # Solaris 2
  216. append add_flags " -R$tool_root_dir/libstdc++"
  217. } elseif [regexp ".*(osf|irix5|linux).*" $target_triplet] {
  218. # OSF/1 or Irix5
  219. append add_flags " -Wl,-rpath,$tool_root_dir/libstdc++"
  220. } elseif [regexp ".*hppa.*" $target_triplet] {
  221. # HP/UX
  222. append add_flags " -Wl,-a,shared_archive"
  223. }
  224. }
  225. }
  226. }
  227. if ![info exists ldscript] {
  228. set ldscript [board_info $dest ldscript]
  229. }
  230. foreach i $options {
  231. if { $i == "debug" } {
  232. if [board_info $dest exists debug_flags] {
  233. append add_flags " [board_info $dest debug_flags]";
  234. } else {
  235. append add_flags " -g"
  236. }
  237. }
  238. }
  239. if [info exists optimize] {
  240. append add_flags " $optimize";
  241. }
  242. if { $type == "executable" } {
  243. append add_flags " $ldflags"
  244. foreach x $libs {
  245. if [file exists $x] {
  246. append source " $x"
  247. } else {
  248. append add_flags " $x";
  249. }
  250. }
  251. if [board_info $dest exists libs] {
  252. append add_flags " [board_info $dest libs]"
  253. }
  254. # This probably isn't such a good idea, but it avoids nasty
  255. # hackiness in the testsuites.
  256. # The math library must be linked in before the C library. The C
  257. # library is linked in by the linker script, so this must be before
  258. # the linker script.
  259. if [board_info $dest exists mathlib] {
  260. append add_flags " [board_info $dest mathlib]"
  261. } else {
  262. append add_flags " -lm"
  263. }
  264. # This must be added here.
  265. append add_flags " $ldscript";
  266. if [board_info $dest exists remote_link] {
  267. # Relink option.
  268. append add_flags " -Wl,-r"
  269. }
  270. if [board_info $dest exists output_format] {
  271. append add_flags " -Wl,-oformat,[board_info $dest output_format]";
  272. }
  273. }
  274. if [board_info $dest exists multilib_flags] {
  275. append add_flags " [board_info $dest multilib_flags]";
  276. }
  277. verbose "doing compile"
  278. set sources ""
  279. if [is_remote host] {
  280. foreach x $source {
  281. set file [remote_download host $x];
  282. if { $file == "" } {
  283. warning "Unable to download $x to host."
  284. return "Unable to download $x to host."
  285. } else {
  286. append sources " $file";
  287. }
  288. }
  289. } else {
  290. set sources $source
  291. }
  292. if [is_remote host] {
  293. append add_flags " -o a.out"
  294. remote_file host delete a.out;
  295. } else {
  296. if { $destfile != "" } {
  297. append add_flags " -o $destfile";
  298. }
  299. }
  300. # This is obscure: we put SOURCES at the end when building an
  301. # object, because otherwise, in some situations, libtool will
  302. # become confused about the name of the actual source file.
  303. if {$type == "object"} {
  304. set opts "$add_flags $sources"
  305. } else {
  306. set opts "$sources $add_flags"
  307. }
  308. if [is_remote host] {
  309. if [host_info exists use_at] {
  310. set fid [open "atfile" "w"];
  311. puts $fid "$opts";
  312. close $fid;
  313. set opts "@[remote_download host atfile]"
  314. remote_file build delete atfile
  315. }
  316. }
  317. verbose "Invoking the compiler as $compiler $opts" 2
  318. if [info exists redirect] {
  319. verbose "Redirecting output to $redirect" 2
  320. set status [remote_exec host "$compiler $opts" "" "" $redirect];
  321. } else {
  322. if [info exists timeout] {
  323. verbose "Setting timeout to $timeout" 2
  324. set status [remote_exec host "$compiler $opts" "" "" "" $timeout];
  325. } else {
  326. set status [remote_exec host "$compiler $opts"];
  327. }
  328. }
  329. set compiler_flags $opts
  330. if [is_remote host] {
  331. remote_upload host a.out $destfile;
  332. remote_file host delete a.out;
  333. }
  334. set comp_output [prune_warnings [lindex $status 1]];
  335. regsub "^\[\r\n\]+" $comp_output "" comp_output;
  336. if { [lindex $status 0] != 0 } {
  337. verbose -log "compiler exited with status [lindex $status 0]";
  338. }
  339. if { [lindex $status 1] != "" } {
  340. verbose -log "output is:\n[lindex $status 1]" 2;
  341. }
  342. if { [lindex $status 0] != 0 && "${comp_output}" == "" } {
  343. set comp_output "exit status is [lindex $status 0]";
  344. }
  345. return ${comp_output};
  346. }
  347. # See if the version of dejaGNU being used to run the testsuite is
  348. # recent enough to contain support for building Ada programs or not.
  349. # If not, then use the functions above in place of the ones provided
  350. # by dejaGNU. This is only temporary (brobecker/2004-03-31).
  351. if {[info procs find_gnatmake] == ""} {
  352. proc find_gnatmake { } { return [gdb_find_gnatmake] }
  353. proc default_target_compile { source destfile type options } {
  354. return [gdb_default_target_compile $source $destfile $type $options]
  355. }
  356. }
  357. # Compile some Ada code.
  358. proc gdb_compile_ada {source dest type options} {
  359. set srcdir [file dirname $source]
  360. set gprdir [file dirname $srcdir]
  361. set objdir [file dirname $dest]
  362. append options " ada"
  363. append options " additional_flags=-P$gprdir/gnat_ada"
  364. append options " additional_flags=-XSRC=[file tail $srcdir]"
  365. append options " additional_flags=-XOBJ=$objdir"
  366. set result [target_compile [file tail $source] $dest $type $options]
  367. # The Ada build always produces some output, even when the build
  368. # succeeds. Thus, we can not use the output the same way we do in
  369. # gdb_compile to determine whether the build has succeeded or not.
  370. # We therefore simply check whether the dest file has been created
  371. # or not. Unless not present, the build has succeeded.
  372. if ![file exists $dest] {
  373. unsupported "Ada compilation failed: $result"
  374. return "Ada compilation failed."
  375. }
  376. }