options.exp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # Copyright (C) 2009-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. # We set LC_ALL and LANG to C so that we get the same error messages as expected.
  16. setenv LC_ALL C
  17. setenv LANG C
  18. # Many hosts now default to a non-ASCII C locale, however, so
  19. # they can set a charset encoding here if they need.
  20. if { [ishost "*-*-cygwin*"] } {
  21. setenv LC_ALL C.ASCII
  22. setenv LANG C.ASCII
  23. }
  24. # Run the LANGUAGE compiler with GCC_OPTIONS and inspect the compiler
  25. # output to make sure that they match the newline-separated patterns
  26. # in COMPILER_PATTERNS but not the patterns in COMPILER_NON_PATTERNS.
  27. # In case of failure, xfail if XFAIL is nonempty.
  28. proc check_for_options {language gcc_options compiler_patterns compiler_non_patterns expected_failure} {
  29. set filename test-[pid]
  30. set fd [open $filename.c w]
  31. puts $fd "int main (void) { return 0; }"
  32. close $fd
  33. remote_download host $filename.c
  34. set test "compiler driver $gcc_options option(s):"
  35. set gcc_options "\{additional_flags=$gcc_options\}"
  36. switch "$language" {
  37. "c" { set compiler cc1 }
  38. default { error "unknown language" }
  39. }
  40. set gcc_output [gcc_target_compile $filename.c $filename.x executable $gcc_options]
  41. remote_file build delete $filename.c $filename.x $filename.gcno
  42. foreach pattern [split $compiler_patterns "\n"] {
  43. if {$pattern != ""} {
  44. if {[regexp -- "$pattern" $gcc_output]} {
  45. pass "$test $pattern"
  46. } else {
  47. if {$expected_failure != ""} {
  48. xfail "$test $pattern"
  49. } else {
  50. fail "$test $pattern"
  51. }
  52. }
  53. }
  54. }
  55. foreach pattern [split $compiler_non_patterns "\n"] {
  56. if {$pattern != ""} {
  57. if {![regexp -- "$pattern" $gcc_output]} {
  58. pass "$test $pattern"
  59. } else {
  60. if {$expected_failure != ""} {
  61. xfail "$test $pattern"
  62. } else {
  63. fail "$test $pattern"
  64. }
  65. }
  66. }
  67. }
  68. }