yflags-conditional.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #! /bin/sh
  2. # Copyright (C) 2011-2017 Free Software Foundation, Inc.
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2, or (at your option)
  7. # any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. # Check that automake complains about *_YFLAGS variables which have
  17. # conditional content.
  18. . test-init.sh
  19. cat >> configure.ac <<'END'
  20. AC_PROG_CC
  21. # 'YFLAGS' is AC_SUBST'd by AC_PROG_YACC by default, but we
  22. # don't want this, since it might confuse our error messages.
  23. # Also, AM_SUBST_NOTMAKE seems not to help about this.
  24. # So we simply define $(YACC) by hand.
  25. AC_SUBST([YACC], [yacc])
  26. AM_CONDITIONAL([COND], [:])
  27. END
  28. $ACLOCAL
  29. cat > Makefile.am <<'END'
  30. bin_PROGRAMS = foo zardoz
  31. foo_SOURCES = foo.y
  32. zardoz_SOURCES = zardoz.y
  33. if COND
  34. AM_YFLAGS = -v
  35. zardoz_YFLAGS = -v
  36. endif COND
  37. END
  38. cat > Makefile1.am <<'END'
  39. bin_PROGRAMS = foo
  40. foo_SOURCES = foo.y
  41. ## This is a dummy comment to keep line count right.
  42. if COND
  43. YFLAGS = foo
  44. endif COND
  45. END
  46. cat > Makefile2.am <<'END'
  47. bin_PROGRAMS = foo
  48. foo_SOURCES = foo.y
  49. AM_YFLAGS = am_yflags
  50. if COND
  51. YFLAGS = yflags
  52. endif COND
  53. END
  54. cat > Makefile3.am <<'END'
  55. bin_PROGRAMS = foo
  56. foo_SOURCES = foo.y
  57. foo_YFLAGS = foo_yflags
  58. if COND
  59. YFLAGS = yflags
  60. endif COND
  61. END
  62. cat > Makefile4.am <<'END'
  63. bin_PROGRAMS = foo zardoz
  64. foo_SOURCES = foo.y
  65. zardoz_SOURCES = $(foo_SOURCES)
  66. YFLAGS =
  67. AM_YFLAGS = $(COND_VAR1)
  68. zardoz_YFLAGS = $(COND_VAR2:z=r)
  69. COND_VAR2 = foo
  70. if COND
  71. YFLAGS += -v
  72. COND_VAR2 += bar
  73. else !COND
  74. COND_VAR1 = -d
  75. endif !COND
  76. END
  77. cat > Makefile5.am <<'END'
  78. bin_PROGRAMS = foo zardoz
  79. foo_SOURCES = foo.y
  80. zardoz_SOURCES = zardoz.y
  81. YFLAGS = -v
  82. AM_YFLAGS = -v
  83. if COND
  84. zardoz_YFLAGS = -v
  85. endif
  86. END
  87. cat > Makefile6.am <<'END'
  88. bin_PROGRAMS = foo
  89. foo_SOURCES = foo.y
  90. foo_YFLAGS = -v
  91. if COND
  92. quux_YFLAGS = -v
  93. AM_YFLAGS = -v
  94. endif
  95. END
  96. : > ylwrap
  97. LC_ALL=C; export LC_ALL; # For grep regexes below.
  98. AUTOMAKE_fails -Wnone -Wunsupported Makefile
  99. grep '^Makefile\.am:5:.*AM_YFLAGS.* conditional contents' stderr
  100. grep '^Makefile\.am:6:.*zardoz_YFLAGS.* conditional contents' stderr
  101. for i in 1 2 3; do
  102. AUTOMAKE_fails -Wnone -Wunsupported Makefile$i
  103. grep "^Makefile$i\\.am:5:.*[^a-zA-Z0-9_]YFLAGS.* conditional contents" \
  104. stderr
  105. done
  106. AUTOMAKE_fails -Wnone -Wunsupported Makefile4
  107. grep '^Makefile4\.am:6:.*[^a-zA-Z0-9_]YFLAGS.* conditional contents' stderr
  108. grep '^Makefile4\.am:7:.*AM_YFLAGS.* conditional contents' stderr
  109. grep '^Makefile4\.am:8:.*zardoz_YFLAGS.* conditional contents' stderr
  110. # Now let's check we avoid false positives.
  111. # Disable 'gnu' warnings because we override the user variable 'YFLAGS'.
  112. AUTOMAKE_fails -Wno-gnu Makefile5
  113. grep -v '^Makefile5\.am:.*zardoz_YFLAGS' stderr \
  114. | grep -v ': warnings are treated as errors' \
  115. | grep . && exit 1
  116. # Disable 'gnu' warnings because we override the user variable 'YFLAGS'.
  117. $AUTOMAKE -Wno-gnu Makefile6
  118. :