cond5.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #! /bin/sh
  2. # Copyright (C) 1998-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. # Yet another sources-in-conditional test. Report from Tim Goodwin.
  17. . test-init.sh
  18. cat >> configure.ac << 'END'
  19. AC_PROG_CC
  20. AM_CONDITIONAL([ONE], [true])
  21. AM_CONDITIONAL([TWO], [false])
  22. AC_OUTPUT
  23. END
  24. cat > Makefile.am << 'END'
  25. bin_PROGRAMS = targ
  26. if ONE
  27. OPT_SRC = one.c
  28. endif
  29. if TWO
  30. OPT_SRC = $(OPT_SRC) two.c
  31. endif
  32. targ_SOURCES = main.c $(OPT_SRC)
  33. END
  34. # The bug is that automake hangs. So we give it an appropriate grace
  35. # time, then kill it if necessary.
  36. $ACLOCAL
  37. $AUTOMAKE 2>stderr &
  38. pid=$!
  39. # MSYS bash seems to have a bug in kill, so don't try to kill too soon.
  40. # The extra quoting avoids a maintainer-check failure.
  41. sleep '2'
  42. # Make at most 30 tries, one every 10 seconds (= 300 seconds = 5 min).
  43. try=1
  44. while test $try -le 30; do
  45. if kill -0 $pid; then
  46. : process $pid is still alive, wait and retry
  47. sleep '10'
  48. try=$(($try + 1))
  49. else
  50. cat stderr >&2
  51. # Automake must fail with a proper error message.
  52. grep 'variable.*OPT_SRC.*recursively defined' stderr
  53. exit 0
  54. fi
  55. done
  56. # The automake process probably hung. Kill it, and exit with failure.
  57. echo "$me: Automake process $pid hung"
  58. kill $pid
  59. exit 1