yflags-force-conditional.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 the user can force automake to use *_YFLAGS variables
  17. # which have conditional content.
  18. . test-init.sh
  19. cat >> configure.ac <<'END'
  20. AC_SUBST([CC], [false])
  21. AC_PROG_YACC
  22. AM_CONDITIONAL([COND], [test x"$cond" = x"yes"])
  23. AC_OUTPUT
  24. END
  25. mkdir bin
  26. cat > bin/fake-yacc <<'END'
  27. #!/bin/sh
  28. echo "/* $* */" > y.tab.c
  29. echo 'extern int dummy;' >> y.tab.c
  30. END
  31. chmod a+x bin/fake-yacc
  32. PATH=$(pwd)/bin$PATH_SEPARATOR$PATH; export PATH
  33. YACC=fake-yacc; export YACC
  34. cat > Makefile.am <<'END'
  35. AUTOMAKE_OPTIONS = no-dependencies
  36. bin_PROGRAMS = foo bar
  37. foo_SOURCES = foo.y main.c
  38. bar_SOURCES = $(foo_SOURCES)
  39. bar_YFLAGS = $(bar_yflags2)
  40. if COND
  41. AM_YFLAGS = __am_cond_yes__
  42. bar_YFLAGS += __bar_cond_yes__
  43. else !COND
  44. AM_YFLAGS = __am_cond_no__
  45. bar_yflags2 = __bar_cond_no__
  46. endif !COND
  47. END
  48. : > foo.y
  49. $ACLOCAL
  50. $AUTOCONF
  51. $AUTOMAKE -a -Wno-unsupported
  52. $EGREP '(YFLAGS|yflags|am__append)' Makefile.in # For debugging.
  53. ./configure cond=yes
  54. $MAKE foo.c bar-foo.c
  55. cat foo.c
  56. cat bar-foo.c
  57. $FGREP ' __am_cond_yes__ ' foo.c
  58. $FGREP ' __bar_cond_yes__ ' bar-foo.c
  59. $FGREP 'cond_no' foo.c bar-foo.c && exit 1
  60. $MAKE maintainer-clean
  61. ls -l
  62. ./configure cond=no
  63. $MAKE foo.c bar-foo.c
  64. cat foo.c
  65. cat bar-foo.c
  66. $FGREP ' __am_cond_no__ ' foo.c
  67. $FGREP ' __bar_cond_no__ ' bar-foo.c
  68. $FGREP 'cond_yes' foo.c bar-foo.c && exit 1
  69. :