cxx-lt-demo.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. # Demo on Libtool/C++ support.
  17. required='libtoolize c++'
  18. am_create_testdir=empty
  19. . test-init.sh
  20. cat > configure.ac << 'END'
  21. AC_INIT([GNU C++/Libtool Demo], [0.73], [bug-automake@gnu.org])
  22. AC_CONFIG_SRCDIR([lib/libfoo.c++])
  23. AC_CONFIG_AUX_DIR([ax])
  24. AM_INIT_AUTOMAKE
  25. AC_CANONICAL_HOST
  26. AC_CANONICAL_BUILD
  27. AC_PROG_CXX
  28. AM_PROG_AR
  29. LT_INIT
  30. AC_CONFIG_FILES([
  31. Makefile
  32. src/Makefile
  33. lib/Makefile
  34. try.sh:try.in
  35. ])
  36. AC_OUTPUT
  37. END
  38. mkdir ax lib src
  39. cat > Makefile.am <<'END'
  40. SUBDIRS = lib src
  41. AUTOMAKE_OPTIONS = parallel-tests
  42. TEST_EXTENSIONS = .sh
  43. SH_LOG_COMPILER = $(SHELL) -ex
  44. TESTS = try.sh
  45. .PHONY: test-objs
  46. check-local: test-objs
  47. test-objs:
  48. test -f src/main.$(OBJEXT)
  49. test -f lib/libfoo.lo
  50. END
  51. cat > src/Makefile.am << 'END'
  52. bin_PROGRAMS = zardoz
  53. zardoz_SOURCES = main.cc
  54. zardoz_LDADD = $(top_builddir)/lib/libfoo.la
  55. AM_CPPFLAGS = -I$(top_builddir)/lib
  56. END
  57. cat > lib/Makefile.am << 'END'
  58. lib_LTLIBRARIES = libfoo.la
  59. nodist_libfoo_la_SOURCES = libfoo.h++
  60. libfoo_la_SOURCES = libfoo.c++
  61. libfoo.h++: $(srcdir)/libfoo.c++
  62. echo '#include <string>' >$@-t
  63. grep "target *(" "$(srcdir)/libfoo.c++" >>$@-t
  64. echo ';' >>$@-t
  65. chmod a-w $@-t && mv -f $@-t $@
  66. BUILT_SOURCES = libfoo.h++
  67. DISTCLEANFILES = $(BUILT_SOURCES)
  68. END
  69. cat > try.in << 'END'
  70. #!/bin/sh
  71. set -e
  72. if test x"$host_alias" = x || test x"$build_alias" = x"$host_alias"; then
  73. ./src/zardoz
  74. test "`./src/zardoz`" = 'Howdy, Testsuite!'
  75. else
  76. echo "Skip: cannot run a cross-compiled program"
  77. exit 77
  78. fi
  79. END
  80. libtoolize --copy
  81. $ACLOCAL
  82. $AUTOCONF
  83. $AUTOMAKE --add-missing --copy
  84. ls -l . ax # For debugging.
  85. # Ideally, the 'compile' script should not be required by C++ compilers.
  86. # But alas, LT_INIT seems to invoke AC_PROG_CC anyway, and that brings in
  87. # that script.
  88. for f in ltmain.sh depcomp compile config.guess config.sub; do
  89. test -f ax/$f && test ! -h ax/$f || exit 1
  90. done
  91. cat > src/main.cc << 'END'
  92. #include "libfoo.h++"
  93. #include <iostream>
  94. using namespace std;
  95. int main (void)
  96. {
  97. cout << "Howdy, " << target () << "!" << endl;
  98. return 0;
  99. }
  100. END
  101. cat > lib/libfoo.c++ << 'END'
  102. #include "libfoo.h++"
  103. std::string target (void)
  104. {
  105. std::string s1 = "Test";
  106. std::string s2 = "suite";
  107. return (s1 + s2);
  108. }
  109. END
  110. ./configure
  111. run_make CC=false
  112. ls -l . src lib # For debugging.
  113. $MAKE test-objs
  114. VERBOSE=yes $MAKE check-TESTS
  115. grep 'Howdy.*Testsuite' try.log || grep 'Skip:.*cross-compiled' try.log
  116. $MAKE distcheck
  117. :