subdir-am-cond.sh 2.2 KB

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