link_cond.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #! /bin/sh
  2. # Copyright (C) 2012-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. # Test that automatic determination of the linker works well with
  17. # conditional use of languages in a single program.
  18. # This currently doesn't truly work, but we have an easy workaround
  19. # at least, that is tested here.
  20. # See automake bug#11089.
  21. required='cc c++'
  22. . test-init.sh
  23. cat >> configure.ac << 'END'
  24. AC_PROG_CC
  25. AC_PROG_CXX
  26. AM_CONDITIONAL([HAVE_CXX], [test $have_cxx = yes])
  27. AC_OUTPUT
  28. END
  29. cat > Makefile.am << 'END'
  30. bin_PROGRAMS = foo
  31. if HAVE_CXX
  32. foo_SOURCES = more.c++
  33. else
  34. foo_SOURCES = less.c
  35. endif
  36. ## FIXME: ideally, this workaround shouldn't be needed.
  37. if HAVE_CXX
  38. foo_LINK = $(CXXLINK)
  39. else
  40. foo_LINK = $(LINK)
  41. endif
  42. END
  43. $ACLOCAL
  44. $AUTOMAKE
  45. $AUTOCONF
  46. rm -f *.c++
  47. cat > less.c <<'END'
  48. /* Valid C but deliberately invalid C++ */
  49. main ()
  50. {
  51. int new = 0;
  52. return new;
  53. }
  54. END
  55. ./configure have_cxx=no
  56. run_make CXX=false
  57. # Sanity check.
  58. rm -f foo foo.exe
  59. run_make CC=false && fatal_ '"make CC=false" succeeded unexpectedly'
  60. $MAKE distclean
  61. rm -f *.c
  62. cat > more.c++ <<'END'
  63. /* Valid C++ but deliberately invalid C */
  64. using namespace std;
  65. int main (void)
  66. {
  67. return 0;
  68. }
  69. END
  70. ./configure have_cxx=yes
  71. run_make CC=false
  72. # Sanity check.
  73. rm -f foo foo.exe
  74. run_make CXX=false && fatal_ '"make CXX=false" succeeded unexpectedly'
  75. :