silent-nested-vars.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 silent-rules mode, on 'make' implementations that do not
  17. # support nested variables (Bug#9928, Bug#10237).
  18. . test-init.sh
  19. cat >>configure.ac <<'EOF'
  20. AM_SILENT_RULES
  21. AC_PROG_CC
  22. AC_OUTPUT
  23. EOF
  24. cat > Makefile.am <<'EOF'
  25. # Need generic and non-generic rules.
  26. bin_PROGRAMS = foo bar
  27. bar_CFLAGS = $(AM_CFLAGS)
  28. # Check that AM_V and AM_DEFAULT_V work as advertised.
  29. pkg_verbose = $(pkg_verbose_@AM_V@)
  30. pkg_verbose_ = $(pkg_verbose_@AM_DEFAULT_V@)
  31. pkg_verbose_0 = @echo PKG-GEN $@;
  32. bin_SCRIPTS = oop
  33. oop:
  34. $(pkg_verbose)echo $@ >$@
  35. mostlyclean-local:
  36. rm -f oop
  37. EOF
  38. cat > foo.c <<'EOF'
  39. int main ()
  40. {
  41. return 0;
  42. }
  43. EOF
  44. cp foo.c bar.c
  45. cat >mymake <<'EOF'
  46. #! /bin/sh
  47. makerules=
  48. case $1 in
  49. -f)
  50. makefile=$2
  51. case $2 in
  52. -) makerules=`cat` || exit ;;
  53. esac ;;
  54. *)
  55. for makefile in makefile Makefile; do
  56. test -f $makefile && break
  57. done ;;
  58. esac
  59. nested_var_pat='^[^#].*\$([^)]*\$'
  60. if
  61. case $makefile in
  62. -) printf '%s\n' "$makerules" | grep "$nested_var_pat";;
  63. *) grep "$nested_var_pat" $makefile;;
  64. esac
  65. then
  66. echo >&2 "mymake: $makefile contains nested variables"
  67. exit 1
  68. fi
  69. case $makefile in
  70. -) printf '%s\n' "$makerules" | $mymake_MAKE "$@";;
  71. *) exec $mymake_MAKE "$@";;
  72. esac
  73. EOF
  74. chmod a+x mymake
  75. mymake_MAKE=${MAKE-make}
  76. MAKE=./mymake
  77. export MAKE mymake_MAKE
  78. # As a sanity check, verify that 'mymake' rejects Makefiles that
  79. # use nested variables.
  80. cat > Makefile <<'END'
  81. a = $(b$(c))
  82. all:
  83. touch bar
  84. END
  85. $MAKE && exit 99
  86. mv -f Makefile foo.mk
  87. $MAKE -f foo.mk && exit 99
  88. cat foo.mk | $MAKE -f - && exit 99
  89. test -f bar && exit 99
  90. sed '/a =/d' foo.mk > Makefile
  91. $MAKE && test -f bar || exit 99
  92. rm -f bar Makefile foo.mk
  93. $ACLOCAL
  94. $AUTOMAKE --add-missing
  95. $AUTOCONF
  96. ./configure --enable-silent-rules >stdout || { cat stdout; exit 1; }
  97. cat stdout
  98. grep '^checking whether \./mymake supports nested variables\.\.\. no *$' \
  99. stdout
  100. $EGREP 'CC|AM_V|GEN' Makefile # For debugging.
  101. grep '^AM_V_CC = *\$(am__v_CC_0) *$' Makefile
  102. grep '^AM_V_GEN = *\$(am__v_GEN_0) *$' Makefile
  103. run_make -O
  104. $EGREP ' (-c|-o)' stdout && exit 1
  105. grep 'mv ' stdout && exit 1
  106. grep 'echo .*oop' stdout && exit 1
  107. grep 'CC .*foo\.' stdout
  108. grep 'CC .*bar\.' stdout
  109. grep 'CCLD .*foo' stdout
  110. grep 'CCLD .*bar' stdout
  111. grep 'PKG-GEN .*oop' stdout
  112. $MAKE distclean
  113. ./configure --disable-silent-rules > stdout || { cat stdout; exit 1; }
  114. cat stdout
  115. grep '^checking whether \./mymake supports nested variables\.\.\. no *$' \
  116. stdout
  117. $EGREP 'CC|AM_V|GEN' Makefile # For debugging.
  118. grep '^AM_V_CC = *\$(am__v_CC_1) *$' Makefile
  119. grep '^AM_V_GEN = *\$(am__v_GEN_1) *$' Makefile
  120. run_make -O
  121. grep ' -c' stdout
  122. grep ' -o foo' stdout
  123. grep ' -o bar' stdout
  124. grep 'echo .*>oop' stdout
  125. $EGREP '(CC|LD) ' stdout && exit 1
  126. :