am-prog-cc-c-o.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. # Check that uses of the obsolescent AM_PROG_CC_C_O macro doesn't
  17. # cause spurious warnings or errors. Suggested by Eric Blake.
  18. # We need gcc for for two reasons:
  19. # 1. to ensure our C compiler grasps "-c -o" together.
  20. # 2. to be able to later fake a dumb compiler not grasping that
  21. # (done with 'cc-no-c-o' script below, which required gcc).
  22. required=gcc
  23. . test-init.sh
  24. echo bin_PROGRAMS = foo > Makefile.am
  25. echo 'int main (void) { return 0; }' > foo.c
  26. cp configure.ac configure.bak
  27. cat > acinclude.m4 <<'END'
  28. AC_DEFUN([AM_TWEAKED_OUTPUT], [
  29. # For debugging.
  30. printf "CC = '%s'\\n" "$CC"
  31. # Make sure that $CC can be used after AM_PROG_CC_C_O.
  32. $CC --version || exit 1
  33. $CC -v || exit 1
  34. # $CC rewrite should only take place on time.
  35. case " $CC " in
  36. *" compile"*" compile"*) AC_MSG_ERROR([CC rewritten twice]);;
  37. esac
  38. AC_OUTPUT
  39. ])
  40. END
  41. # ---
  42. cat configure.bak - > configure.ac << 'END'
  43. dnl It's OK to call AM_PROG_CC_C_O after AC_PROG_CC.
  44. AC_PROG_CC
  45. AM_PROG_CC_C_O
  46. AM_TWEAKED_OUTPUT
  47. END
  48. $ACLOCAL
  49. $AUTOCONF
  50. $AUTOMAKE --add-missing
  51. ./configure >stdout || { cat stdout; exit 1; }
  52. cat stdout
  53. if test "$AM_TESTSUITE_SIMULATING_NO_CC_C_O" != no; then
  54. $EGREP 'understands? -c and -o together.* no$' stdout
  55. else
  56. $EGREP 'understands? -c and -o together.* yes$' stdout
  57. fi
  58. # No repeated checks please.
  59. test $(grep -c ".*-c['\" ].*-o['\" ]" stdout) -eq 1
  60. $MAKE
  61. $MAKE maintainer-clean
  62. rm -rf autom4te*.cache
  63. # ---
  64. cat configure.bak - > configure.ac << 'END'
  65. dnl It's also OK to call AM_PROG_CC_C_O *before* AC_PROG_CC.
  66. AM_PROG_CC_C_O
  67. AC_PROG_CC
  68. AM_TWEAKED_OUTPUT
  69. END
  70. $ACLOCAL
  71. $AUTOCONF
  72. $AUTOMAKE --add-missing
  73. ./configure >stdout || { cat stdout; exit 1; }
  74. cat stdout
  75. if test "$AM_TESTSUITE_SIMULATING_NO_CC_C_O" != no; then
  76. $EGREP 'understands? -c and -o together.* no$' stdout
  77. else
  78. $EGREP 'understands? -c and -o together.* yes$' stdout
  79. fi
  80. # Repeated checks are OK in this case, but should be cached.
  81. test $(grep ".*-c['\" ].*-o['\" ]" stdout \
  82. | $FGREP -v ' (cached) ' | wc -l) -eq 1
  83. $MAKE
  84. $MAKE maintainer-clean
  85. rm -rf autom4te*.cache
  86. # ---
  87. cat configure.bak - > configure.ac << 'END'
  88. dnl It's also OK to call AM_PROG_CC_C_O *without* AC_PROG_CC.
  89. AM_PROG_CC_C_O
  90. AM_TWEAKED_OUTPUT
  91. END
  92. $ACLOCAL
  93. $AUTOCONF
  94. $AUTOMAKE --add-missing
  95. # Make sure the compiler doesn't understand '-c -o'
  96. CC=$am_testaux_builddir/cc-no-c-o; export CC
  97. ./configure >stdout || { cat stdout; exit 1; }
  98. cat stdout
  99. $EGREP 'understands? -c and -o together.* no$' stdout
  100. # No repeated checks please.
  101. test $(grep -c ".*-c['\" ].*-o['\" ]" stdout) -eq 1
  102. $MAKE
  103. :