2 # Copyright (C) 2012 Free Software Foundation, Inc.
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)
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.
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/>.
17 # Stress test on Objective C/C++.
20 am_create_testdir=empty
23 ## Autotools Input Files.
25 cat > configure.ac << 'END'
26 AC_INIT([play], [1.3], [bug-automake@gnu.org])
28 dnl Support for Object C++ was introduced only in Autoconf 2.65.
30 AC_CONFIG_SRCDIR([play.c])
31 AC_CONFIG_AUX_DIR([build-aux])
32 AC_CONFIG_MACRO_DIR([m4])
44 AC_LANG_PUSH([Objective C])
46 [whether the Objective C compiler really works],
48 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#import <stdio.h>]],
49 [[printf ("foo\n");]])],
50 [my_cv_objc_works=yes],
51 [my_cv_objc_works=no])])
52 AC_LANG_POP([Objective C])
54 AC_LANG_PUSH([Objective C++])
56 [whether the Objective C++ compiler really works],
58 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#import <iostream>]],
59 [[std::cout << "foo" << "\n";]])],
60 [my_cv_objcxx_works=yes],
61 [my_cv_objcxx_works=no])])
62 AC_LANG_POP([Objective C++])
64 if test $my_cv_objc_works != yes; then
65 AC_MSG_ERROR([couldn't find a working Objective C compiler], [77])
68 if test $my_cv_objcxx_works != yes; then
69 AC_MSG_ERROR([couldn't find a working Objective C++ compiler], [77])
72 AC_CONFIG_HEADERS([config.h])
73 AC_CONFIG_FILES([Makefile])
78 cat > Makefile.am << 'END'
80 play_SOURCES = play.h play.c playxx.cxx playo.m playoxx.mm
81 play_LDADD = libfoo.la
83 lib_LTLIBRARIES = libfoo.la
84 libfoo_la_SOURCES = foo.h foo.c fooxx.cxx fooo.m foooxx.mm
91 : We have a modern enough autoconf, go ahead.
92 elif test $? -eq 63; then
93 skip_ "Object C++ support requires Autoconf 2.65 or later"
95 exit 1 # Some other aclocal failure.
99 $AUTOMAKE --add-missing
103 cat > play.h << 'END'
113 void hello_cxx (void);
114 void hello_objc (void);
115 void hello_objcxx (void);
118 @interface Hello_ObjC
122 #endif /* __OBJC__ */
131 virtual ~Hello_CXX () { }
136 @interface Hello_ObjCXX
145 virtual ~Hello_OBJCXX () { }
148 #endif /* __OBJC__ */
150 #endif /* __cplusplus */
155 cat > play.c << 'END'
159 printf ("[Hello C,");
168 cat > playxx.cxx << 'END'
173 Hello_CXX *hello = new Hello_CXX;
177 void Hello_CXX::hello_cxx()
179 std::cout << "[Hello C++,";
180 World_CXX *world = new World_CXX;
185 cat > playo.m << 'END'
188 void hello_objc (void)
190 [Hello_ObjC display];
193 @implementation Hello_ObjC
196 printf ("[Hello ObjC,");
197 [World_ObjC display];
202 cat > playoxx.mm << 'END'
205 // Calling: C -> C++ -> ObjC
207 void hello_objcxx (void)
209 Hello_OBJCXX *hello = new Hello_OBJCXX;
210 hello->hello_objcxx ();
213 void Hello_OBJCXX::hello_objcxx ()
215 [Hello_ObjCXX display];
218 @implementation Hello_ObjCXX
221 std::cout << "[Hello ObjC++,";
222 [World_ObjCXX display];
243 @interface World_ObjC
247 #endif /* __OBJC__ */
256 virtual ~World_CXX () { }
265 virtual ~World_OBJCXX () { }
266 void world_objcxx ();
269 @interface World_ObjCXX
273 #endif /* __OBJC__ */
275 #endif /* __cplusplus */
285 printf (" world C]\n");
289 cat > fooxx.cxx << 'END'
292 void World_CXX::world_cxx ()
294 std::cout << " world C++]" << "\n";
298 cat > fooo.m << 'END'
301 @implementation World_ObjC
304 printf (" world ObjC]\n");
309 cat > foooxx.mm << 'END'
312 // Calling: ObjC -> C++
314 @implementation World_ObjCXX
317 World_OBJCXX *world = new World_OBJCXX;
318 world->world_objcxx ();
322 void World_OBJCXX::world_objcxx ()
324 std::cout << " world ObjC++]" << "\n";
328 ## Configure and build.
333 if ! cross_compiling; then
334 unindent > exp << 'END'
336 [Hello C++, world C++]
337 [Hello ObjC, world ObjC]
338 [Hello ObjC++, world ObjC++]
340 ./play > got || { cat got; exit 1; }