gfortran.exp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. # Copyright (C) 2003-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 is just 'sed -e 's/77/fortran/g' \
  16. # -e 's/f2c/gfortran' g77.exp > gfortran.exp'
  17. #
  18. # with some minor modifications to make it work.
  19. #
  20. # gfortran support library routines
  21. #
  22. load_lib prune.exp
  23. load_lib gcc-defs.exp
  24. load_lib timeout.exp
  25. load_lib target-libpath.exp
  26. load_lib target-supports.exp
  27. #
  28. # GFORTRAN_UNDER_TEST is the compiler under test.
  29. #
  30. set gpp_compile_options ""
  31. #
  32. # gfortran_version -- extract and print the version number of the compiler
  33. #
  34. proc gfortran_version { } {
  35. global GFORTRAN_UNDER_TEST
  36. gfortran_init
  37. # ignore any arguments after the command
  38. set compiler [lindex $GFORTRAN_UNDER_TEST 0]
  39. # verify that the compiler exists
  40. if { [is_remote host] || [which $compiler] != 0 } then {
  41. set tmp [remote_exec host "$compiler -v"]
  42. set status [lindex $tmp 0]
  43. set output [lindex $tmp 1]
  44. regexp " version \[^\n\r\]*" $output version
  45. if { $status == 0 && [info exists version] } then {
  46. if [is_remote host] {
  47. clone_output "$compiler $version\n"
  48. } else {
  49. clone_output "[which $compiler] $version\n"
  50. }
  51. } else {
  52. clone_output "Couldn't determine version of [which $compiler]\n"
  53. }
  54. } else {
  55. # compiler does not exist (this should have already been detected)
  56. warning "$compiler does not exist"
  57. }
  58. }
  59. #
  60. # gfortran_link_flags -- provide new version of gfortran_link_flags
  61. # (originally from libgloss.exp) which knows about the gcc tree structure
  62. #
  63. proc gfortran_link_flags { paths } {
  64. global srcdir
  65. global ld_library_path
  66. global GFORTRAN_UNDER_TEST
  67. global shlib_ext
  68. set gccpath ${paths}
  69. set libio_dir ""
  70. set flags ""
  71. set ld_library_path "."
  72. set shlib_ext [get_shlib_extension]
  73. verbose "shared lib extension: $shlib_ext"
  74. if { $gccpath != "" } {
  75. if [file exists "${gccpath}/libgfortran/.libs/libgfortran.a"] {
  76. # Some targets use libgfortran.a%s in their specs, so they need a -B option
  77. # for uninstalled testing.
  78. append flags "-B${gccpath}/libgfortran/.libs "
  79. append flags "-L${gccpath}/libgfortran/.libs "
  80. append ld_library_path ":${gccpath}/libgfortran/.libs"
  81. }
  82. if [file exists "${gccpath}/libgfortran/.libs/libgfortran.${shlib_ext}"] {
  83. append flags "-L${gccpath}/libgfortran/.libs "
  84. append ld_library_path ":${gccpath}/libgfortran/.libs"
  85. }
  86. if [file exists "${gccpath}/libgfortran/libgforbegin.a"] {
  87. append flags "-L${gccpath}/libgfortran "
  88. }
  89. if [file exists "${gccpath}/libatomic/.libs/libatomic.${shlib_ext}"] {
  90. append flags "-L${gccpath}/libatomic/.libs "
  91. append ld_library_path ":${gccpath}/libatomic/.libs"
  92. }
  93. if [file exists "${gccpath}/libatomic/libatomic.a"] {
  94. append flags "-L${gccpath}/libatomic "
  95. }
  96. if [file exists "${gccpath}/libquadmath/.libs/libquadmath.a"] {
  97. # Some targets use libquadmath.a%s in their specs, so they need a -B option
  98. # for uninstalled testing.
  99. append flags "-B${gccpath}/libquadmath/.libs "
  100. append flags "-L${gccpath}/libquadmath/.libs "
  101. append ld_library_path ":${gccpath}/libquadmath/.libs"
  102. }
  103. if [file exists "${gccpath}/libquadmath/.libs/libquadmath.${shlib_ext}"] {
  104. append flags "-L${gccpath}/libquadmath/.libs "
  105. append ld_library_path ":${gccpath}/libquadmath/.libs"
  106. }
  107. if [file exists "${gccpath}/libiberty/libiberty.a"] {
  108. append flags "-L${gccpath}/libiberty "
  109. }
  110. append ld_library_path \
  111. [gcc-set-multilib-library-path $GFORTRAN_UNDER_TEST ]
  112. }
  113. set_ld_library_path_env_vars
  114. return "$flags"
  115. }
  116. #
  117. # gfortran_init -- called at the start of each subdir of tests
  118. #
  119. proc gfortran_init { args } {
  120. global subdir
  121. global gpp_initialized
  122. global base_dir
  123. global tmpdir
  124. global libdir
  125. global gluefile wrap_flags
  126. global objdir srcdir
  127. global ALWAYS_GFORTRANFLAGS
  128. global TOOL_EXECUTABLE TOOL_OPTIONS
  129. global GFORTRAN_UNDER_TEST
  130. global TESTING_IN_BUILD_TREE
  131. global gcc_warning_prefix
  132. global gcc_error_prefix
  133. global TEST_ALWAYS_FLAGS
  134. # We set LC_ALL and LANG to C so that we get the same error messages as expected.
  135. setenv LC_ALL C
  136. setenv LANG C
  137. set gcc_warning_prefix "\[Ww\]arning:"
  138. set gcc_error_prefix "(Fatal )?\[Ee\]rror:"
  139. # Many hosts now default to a non-ASCII C locale, however, so
  140. # they can set a charset encoding here if they need.
  141. if { [ishost "*-*-cygwin*"] } {
  142. setenv LC_ALL C.ASCII
  143. setenv LANG C.ASCII
  144. }
  145. if ![info exists GFORTRAN_UNDER_TEST] then {
  146. if [info exists TOOL_EXECUTABLE] {
  147. set GFORTRAN_UNDER_TEST $TOOL_EXECUTABLE
  148. } else {
  149. if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
  150. set GFORTRAN_UNDER_TEST [transform gfortran]
  151. } else {
  152. if [info exists TOOL_OPTIONS] {
  153. set specpath [get_multilibs ${TOOL_OPTIONS}]
  154. } else {
  155. set specpath [get_multilibs]
  156. }
  157. set GFORTRAN_UNDER_TEST [findfile $base_dir/../../gfortran "$base_dir/../../gfortran -B$base_dir/../../ -B$specpath/libgfortran/" [findfile $base_dir/gfortran "$base_dir/gfortran -B$base_dir/" [transform gfortran]]]
  158. }
  159. }
  160. }
  161. if ![is_remote host] {
  162. if { [which $GFORTRAN_UNDER_TEST] == 0 } then {
  163. perror "GFORTRAN_UNDER_TEST ($GFORTRAN_UNDER_TEST) does not exist"
  164. exit 1
  165. }
  166. }
  167. if ![info exists tmpdir] {
  168. set tmpdir "/tmp"
  169. }
  170. if [info exists gluefile] {
  171. unset gluefile
  172. }
  173. gfortran_maybe_build_wrapper "${tmpdir}/gfortran-testglue.o"
  174. set ALWAYS_GFORTRANFLAGS ""
  175. # TEST_ALWAYS_FLAGS are flags that should be passed to every
  176. # compilation. They are passed first to allow individual
  177. # tests to override them.
  178. if [info exists TEST_ALWAYS_FLAGS] {
  179. lappend ALWAYS_GFORTRANFLAGS "additional_flags=$TEST_ALWAYS_FLAGS"
  180. }
  181. if ![is_remote host] {
  182. if [info exists TOOL_OPTIONS] {
  183. lappend ALWAYS_GFORTRANFLAGS "ldflags=[gfortran_link_flags [get_multilibs ${TOOL_OPTIONS}] ]"
  184. } else {
  185. lappend ALWAYS_GFORTRANFLAGS "ldflags=[gfortran_link_flags [get_multilibs] ]"
  186. }
  187. }
  188. if [info exists TOOL_OPTIONS] {
  189. lappend ALWAYS_GFORTRANFLAGS "additional_flags=$TOOL_OPTIONS"
  190. }
  191. # On the SPU, most of the fortran test cases exceed local store size.
  192. # Use automatic overlay support to make them fit.
  193. if { [check_effective_target_spu_auto_overlay] } {
  194. lappend ALWAYS_GFORTRANFLAGS "ldflags=-Wl,--auto-overlay"
  195. lappend ALWAYS_GFORTRANFLAGS "ldflags=-Wl,--reserved-space=131072"
  196. }
  197. verbose -log "ALWAYS_GFORTRANFLAGS set to $ALWAYS_GFORTRANFLAGS"
  198. verbose "gfortran is initialized" 3
  199. }
  200. #
  201. # gfortran_target_compile -- compile a source file
  202. #
  203. proc gfortran_target_compile { source dest type options } {
  204. global tmpdir
  205. global gluefile wrap_flags
  206. global ALWAYS_GFORTRANFLAGS
  207. global GFORTRAN_UNDER_TEST
  208. global flags_to_postpone
  209. global board_info
  210. if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
  211. lappend options "libs=${gluefile}"
  212. lappend options "ldflags=${wrap_flags}"
  213. }
  214. # bind_pic_locally adds -fpie/-fPIE flags to flags_to_postpone and it is
  215. # appended here to multilib_flags as it can be overridden by the latter
  216. # if it was added earlier. After the target_compile, multilib_flags is
  217. # restored to its orignal content.
  218. set tboard [target_info name]
  219. if {[board_info $tboard exists multilib_flags]} {
  220. set orig_multilib_flags "[board_info [target_info name] multilib_flags]"
  221. append board_info($tboard,multilib_flags) " $flags_to_postpone"
  222. }
  223. lappend options "compiler=$GFORTRAN_UNDER_TEST"
  224. lappend options "timeout=[timeout_value]"
  225. set options [concat "$ALWAYS_GFORTRANFLAGS" $options]
  226. set options [dg-additional-files-options $options $source]
  227. set return_val [target_compile $source $dest $type $options]
  228. if {[board_info $tboard exists multilib_flags]} {
  229. set board_info($tboard,multilib_flags) $orig_multilib_flags
  230. set flags_to_postpone ""
  231. }
  232. return $return_val
  233. }