subst-no-trailing-empty-line.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #! /bin/sh
  2. # Copyright (C) 2003-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. # If the last line of a automake-rewritten definition is made only of
  17. # @substitutions@, automake should take care of appending an empty
  18. # variable to make sure that line cannot end up substituted as a blank
  19. # line (that would confuse HP-UX Make).
  20. # These checks have been introduced in commit 'Release-1-9-254-g9d0eaef'
  21. # into the former test 'subst2.test'.
  22. . test-init.sh
  23. # These are deliberately quite long, so that the xxx_PROGRAMS definition
  24. # in Makefile.am below will be split on multiple lines, with the last
  25. # line containing only @substituted@ stuff that expands to empty (this is
  26. # required to expose the bug we are testing).
  27. v1=ABCDEFGHIJKLMNOPQRSTUVWX
  28. v2=ABCDEFGHIJKLMNOPQRSTUVWXY
  29. v3=ABCDEFGHIJKLMNOPQRSTUVWXYZ
  30. # Literal backslash for use by grep.
  31. bs='\\'
  32. cat >> configure.ac <<END
  33. AC_SUBST([A], [''])
  34. AC_SUBST([$v1], [''])
  35. AC_SUBST([$v2], [''])
  36. AC_SUBST([$v3], [''])
  37. AC_OUTPUT
  38. END
  39. cat >Makefile.am <<END
  40. AUTOMAKE_OPTIONS = no-dependencies
  41. CC = false
  42. EXEEXT =
  43. ## The "x" and "zardoz" strings and the use of '+=' are there to ensure
  44. ## that these variables get rewritten by Automake.
  45. noinst_PROGRAMS = x @$v1@ @$v2@ @$v3@
  46. bin_PROGRAMS = @A@
  47. bin_PROGRAMS += @$v1@ @$v2@ @$v3@
  48. check_PROGRAMS = zardoz \$(noinst_PROGRAMS)
  49. ## Required whenever there are @substituted@ values in the
  50. ## PROGRAMS primary, otherwise automake will complain.
  51. EXTRA_PROGRAMS =
  52. test-real-empty:
  53. is \$(noinst_PROGRAMS) == x
  54. is \$(bin_PROGRAMS) ==
  55. is \$(check_PROGRAMS) == zardoz x
  56. test-fake-empty:
  57. is \$(noinst_PROGRAMS) == x X
  58. is \$(bin_PROGRAMS) == X
  59. is \$(check_PROGRAMS) == zardoz x X
  60. END
  61. $ACLOCAL
  62. $AUTOCONF
  63. $AUTOMAKE
  64. # For debugging.
  65. $EGREP -n 'ABCD|am__empty' Makefile.in
  66. # Sanity check.
  67. test $($EGREP -c "^[ $tab]*@$v2@ @$v3@[ $tab]*$bs?$" Makefile.in) -eq 3
  68. ./configure
  69. {
  70. sed -n '/^noinst_PROGRAMS *=/,/[^\\]$/p' Makefile
  71. sed -n '/^bin_PROGRAMS *=/,/[^\\]$/p' Makefile
  72. sed -n '/^check_PROGRAMS *=/,/[^\\]$/p' Makefile
  73. sed -n '/^am__EXEEXT.*=/,/[^\\]$/p' Makefile
  74. } >t-programs
  75. cat t-programs
  76. grep '^ *$' t-programs && exit 1
  77. run_make test-real-empty
  78. run_make test-fake-empty am__empty=X
  79. :