cond39.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/bin/sh
  2. # Copyright (C) 2008-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. # Build either as CONFIG_FILE or as PROGRAM.
  17. required=cc
  18. . test-init.sh
  19. mkdir sub
  20. cat >>configure.ac <<'END'
  21. AC_PROG_CC
  22. AM_CONDITIONAL([COND], [test "$COND" = true])
  23. AM_COND_IF([COND], [],
  24. [AC_CONFIG_FILES([prog1], [chmod 755 prog1])
  25. AC_CONFIG_FILES([sub/prog2], [chmod 755 sub/prog2])])
  26. AC_CONFIG_FILES([sub/Makefile])
  27. AC_OUTPUT
  28. END
  29. cat >Makefile.am <<'END'
  30. SUBDIRS = sub
  31. if COND
  32. bin_PROGRAMS = prog1
  33. prog1_SOURCES = prog.c
  34. else
  35. bin_SCRIPTS = prog1
  36. CLEANFILES = prog1
  37. endif
  38. sure-exist:
  39. test -f prog1 || test -f prog1$(EXEEXT)
  40. test -f sub/prog2 || test -f sub/prog2$(EXEEXT)
  41. sure-not-exist:
  42. test ! -f prog1 && test ! -f prog1$(EXEEXT)
  43. test ! -f sub/prog2 && test ! -f sub/prog2$(EXEEXT)
  44. END
  45. cat >sub/Makefile.am <<'END'
  46. if COND
  47. bin_PROGRAMS = prog2
  48. prog2_SOURCES = prog.c
  49. else
  50. bin_SCRIPTS = prog2
  51. CLEANFILES = prog2
  52. endif
  53. END
  54. cat >prog.c <<'END'
  55. int main () { return 42; }
  56. END
  57. cat >prog1.in <<'END'
  58. #! /bin/sh
  59. bindir='@bindir@'
  60. echo "hi, this is $0, and bindir is $bindir"
  61. END
  62. cp prog.c sub
  63. cp prog1.in sub/prog2.in
  64. $ACLOCAL
  65. $AUTOCONF
  66. $AUTOMAKE --add-missing
  67. ./configure COND=true
  68. run_make -E
  69. grep 'overriding commands' stderr && exit 1
  70. $MAKE sure-exist
  71. ./prog1 && exit 1
  72. ./sub/prog2 && exit 1
  73. $MAKE clean
  74. $MAKE sure-not-exist
  75. $MAKE
  76. $MAKE sure-exist
  77. ./prog1 && exit 1
  78. ./sub/prog2 && exit 1
  79. $MAKE distclean
  80. ./configure COND=false
  81. run_make -E
  82. grep 'overriding commands' stderr && exit 1
  83. ./prog1
  84. ./sub/prog2
  85. $MAKE clean
  86. $MAKE sure-not-exist
  87. $MAKE
  88. ./prog1
  89. ./sub/prog2
  90. :