subdir-ac-subst.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #! /bin/sh
  2. # Copyright (C) 2002-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. # The for conditional SUBDIRS.
  17. # SUBDIRS + AC_SUBST setup from the manual.
  18. # Lots of lines here are duplicated in 'subcond-am-cond.sh'.
  19. . test-init.sh
  20. cat >> configure.ac <<'END'
  21. if test "$want_opt" = yes; then
  22. MAYBE_OPT=opt
  23. else
  24. MAYBE_OPT=
  25. fi
  26. AC_SUBST([MAYBE_OPT])
  27. AC_CONFIG_FILES([src/Makefile opt/Makefile])
  28. AC_OUTPUT
  29. END
  30. cat > Makefile.am <<'END'
  31. SUBDIRS = src $(MAYBE_OPT)
  32. DIST_SUBDIRS = src opt
  33. # Testing targets.
  34. #
  35. # We want to ensure that
  36. # - src/source and opt/source are always distributed.
  37. # - src/result is always built
  38. # - opt/result is built conditionally
  39. #
  40. # We rely on 'distcheck' to run 'check-local' and use
  41. # 'sanity1' and 'sanity2' as evidences that test-build was run.
  42. test_rootdir = $(top_builddir)/../../..
  43. test-build: all
  44. test -f src/result
  45. if test -n "$(MAYBE_OPT)"; then \
  46. test -f opt/result || exit 1; \
  47. : > $(test_rootdir)/sanity2 || exit 1; \
  48. else \
  49. test ! -f opt/result || exit 1; \
  50. : > $(test_rootdir)/sanity1 || exit 1; \
  51. fi
  52. test-dist: distdir
  53. test -f $(distdir)/src/source
  54. test -f $(distdir)/opt/source
  55. check-local: test-build test-dist
  56. END
  57. mkdir src opt
  58. : > src/source
  59. : > opt/source
  60. cat > src/Makefile.am <<'END'
  61. EXTRA_DIST = source
  62. all-local: result
  63. CLEANFILES = result
  64. result: source
  65. cp $(srcdir)/source result
  66. END
  67. # We want in opt/ the same Makefile as in src/. Let's exercise 'include'.
  68. cat > opt/Makefile.am <<'END'
  69. include ../src/Makefile.am
  70. END
  71. $ACLOCAL
  72. $AUTOCONF
  73. $AUTOMAKE --add-missing
  74. ./configure
  75. $MAKE distcheck
  76. test -f sanity1
  77. DISTCHECK_CONFIGURE_FLAGS=want_opt=yes $MAKE distcheck
  78. test -f sanity2
  79. :