preproc-basics.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #! /bin/sh
  2. # Copyright (C) 2013-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. # Basic tests for '%...%' preprocessing in included Makefile fragments:
  17. # %reldir% a.k.a. %D%
  18. # %canon_reldir% a.k.a. %C%
  19. . test-init.sh
  20. cat >> configure.ac << 'END'
  21. AC_CONFIG_FILES([zot/Makefile])
  22. AC_OUTPUT
  23. END
  24. mkdir foo foo/bar foo/foobar zot
  25. cat > Makefile.am << 'END'
  26. include $(top_srcdir)/foo/local.mk
  27. include $(srcdir)/foo/foobar/local.mk
  28. include local.mk
  29. END
  30. cat > zot/Makefile.am << 'END'
  31. include $(top_srcdir)/zot/local.mk
  32. ## Check that '%canon_reldir%' doesn't remain overridden
  33. ## by the previous include.
  34. %canon_reldir%_zot_whoami:
  35. echo "I am %reldir%/Makefile.am" >$@
  36. include $(top_srcdir)/top.mk
  37. include ../reltop.mk
  38. END
  39. cat > local.mk << 'END'
  40. %canon_reldir%_whoami:
  41. echo "I am %reldir%/local.mk" >$@
  42. END
  43. cat > top.mk << 'END'
  44. %canon_reldir%_top_whoami:
  45. echo "I am %reldir%/top.mk" >$@
  46. END
  47. cat > reltop.mk << 'END'
  48. %C%_reltop_whoami:
  49. echo "I am %D%/reltop.mk" >$@
  50. END
  51. cp local.mk foo
  52. cp local.mk foo/bar
  53. cp local.mk foo/foobar
  54. cp local.mk zot
  55. cat >> foo/local.mk << 'END'
  56. include %reldir%/bar/local.mk
  57. ## Check that '%canon_reldir%' doesn't remain overridden by the
  58. ## previous include. The duplicated checks are done to ensure that
  59. ## Automake substitutes all pre-processing occurrences on a line,
  60. ## not just the first one.
  61. test-%reldir%:
  62. test '%reldir%' = foo && test '%reldir%' = foo
  63. test '%D%' = foo && test '%D%' = foo
  64. test '%canon_reldir%' = foo && test '%C%' = foo
  65. END
  66. $ACLOCAL
  67. $AUTOCONF
  68. $AUTOMAKE
  69. ./configure
  70. check ()
  71. {
  72. test $# -eq 2 || fatal_ "made_into(): bad usage"
  73. target=$1 contents=$2
  74. rm -f "$target" \
  75. && $MAKE "$target" \
  76. && test x"$(cat "$target")" = x"$contents"
  77. }
  78. check whoami "I am local.mk"
  79. check foo_whoami "I am foo/local.mk"
  80. check foo_bar_whoami "I am foo/bar/local.mk"
  81. check foo_foobar_whoami "I am foo/foobar/local.mk"
  82. $MAKE test-foo
  83. cd zot
  84. check whoami "I am local.mk"
  85. check ___top_whoami "I am ../top.mk"
  86. check ___reltop_whoami "I am ../reltop.mk"
  87. check zot_whoami "I am Makefile.am"
  88. :