1# tagdemo.at -- C++ Language support.			 -*- Autotest -*-
2#
3#   Copyright (C) 2003-2005, 2011-2015 Free Software Foundation, Inc.
4#   Written by Gary V. Vaughan, 2003
5#
6#   This file is part of GNU Libtool.
7#
8# GNU Libtool is free software; you can redistribute it and/or
9# modify it under the terms of the GNU General Public License as
10# published by the Free Software Foundation; either version 2 of
11# the License, or (at your option) any later version.
12#
13# GNU Libtool is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with GNU Libtool; see the file COPYING.  If not, a copy
20# can be downloaded from  http://www.gnu.org/licenses/gpl.html,
21# or obtained by writing to the Free Software Foundation, Inc.,
22# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23####
24
25
26AT_BANNER([C++ language support.])
27
28
29# _LT_SETUP
30# ---------
31m4_define([_LT_SETUP],
32[LT_AT_TAG([CXX])
33AT_KEYWORDS([libtool])
34
35AT_DATA([configure.ac],
36[[AC_INIT([tagdemo], ]AT_PACKAGE_VERSION[, ]AT_PACKAGE_BUGREPORT[)
37AC_CONFIG_AUX_DIR([build-aux])
38AC_CONFIG_MACRO_DIRS([m4])
39AC_CANONICAL_TARGET
40AM_INIT_AUTOMAKE
41AC_PROG_CC
42AC_PROG_CPP
43AC_PROG_CC_C_O
44AC_PROG_CXX
45AC_PROG_CXXCPP
46
47# Check for namespace support and new-style headers
48AC_LANG_PUSH([C++])
49AC_MSG_CHECKING([whether the compiler implements namespaces])
50AC_COMPILE_IFELSE(
51    [AC_LANG_PROGRAM([[namespace A { namespace B { int i = 0; }}]],
52		     [[using namespace A::B; return i;]])],
53    [AC_MSG_RESULT([yes])
54     AC_DEFINE([HAVE_NAMESPACES],[1],
55	       [define if the compiler implements namespaces])],
56    [AC_MSG_RESULT([no])])
57
58AC_MSG_CHECKING([whether the compiler has ISO C++ iostream])
59AC_COMPILE_IFELSE(
60    [AC_LANG_PROGRAM([[#include <iostream>
61#ifdef HAVE_NAMESPACES
62using namespace std;
63#endif ]], [[cout << "bingo\n"; return 0;]])],
64    [AC_MSG_RESULT([yes])
65     AC_DEFINE([HAVE_IOSTREAM],[1],
66	       [define if the compiler has ISO C++ iostream])],
67    [AC_MSG_RESULT([no])])
68AC_LANG_POP([C++])
69
70AC_LANG([C++])
71LT_INIT
72
73LT_LIB_M
74AC_CONFIG_FILES([Makefile])
75AC_CONFIG_HEADERS([config.h:config.in.h])
76AC_OUTPUT
77]])
78
79AT_DATA([Makefile.am],
80[[AUTOMAKE_OPTIONS = no-dependencies foreign
81ACLOCAL_AMFLAGS = -I m4
82
83noinst_LTLIBRARIES = libconv.la
84lib_LTLIBRARIES = libfoo.la libbaz.la
85
86libfoo_la_SOURCES = foo.cpp
87libfoo_la_LDFLAGS = -no-undefined
88libfoo_la_LIBADD = libconv.la $(LIBM)
89
90# Test some of the ILD support when using tagged configurations.
91libbaz_la_SOURCES = baz.cpp
92libbaz_la_LDFLAGS = -no-undefined
93libbaz_la_LIBADD = libfoo.la
94
95# Test convenience libraries.
96libconv_la_SOURCES = conv.cpp
97libconv_la_LDFLAGS = -no-undefined
98
99noinst_HEADERS = foo.h baz.h conv.h
100
101bin_PROGRAMS = tagdemo
102
103tagdemo_SOURCES = main.cpp
104tagdemo_LDADD = libbaz.la libfoo.la
105
106libtool: $(LIBTOOL_DEPS)
107	$(SHELL) ./config.status --recheck
108]])
109
110AT_DATA([main.cpp],
111[[#include <config.h>
112#if HAVE_IOSTREAM
113# include <iostream>
114#else
115# include <iostream.h>
116#endif
117
118#include "foo.h"
119#include "baz.h"
120#include "conv.h"
121
122#if HAVE_NAMESPACES
123namespace std { }
124using namespace std;
125#endif
126
127int main (int, char *[])
128{
129  cout << "Welcome to GNU libtool tagdemo C++!" << endl;
130
131  foobar_derived FB;
132  // Instantiate the derived class.
133
134  foobar *fb = &FB;
135  // Have some fun with polymorphism.
136
137  int value = fb->hello();
138
139  cout << "foobar::hello returned: " << value << endl;
140  if (value = HELLO_RET)
141    cout << "foobar::hello is ok!" << endl;
142
143  if (fb->foo() == FOO_RET)
144    cout << "foobar::foo is ok!" << endl;
145
146  // --------------
147
148  barbaz_derived BB;
149  // Instantiate the derived class.
150
151  barbaz *bb = &BB;
152  // Have some fun with polymorphism.
153
154  // barbaz_derived::baz() should return FOO_RET since it calls
155  // foobar_derived::foo(), which in turn calls ::foo().
156  if (bb->baz() == FOO_RET)
157    cout << "barbaz::baz is ok!" << endl;
158
159  // --------------
160
161  if (convenience())
162    cout << "convenience is ok!" << endl;
163
164  return 0;
165}
166]])
167
168AT_DATA([foo.h],
169[[#ifndef FOO_H
170#define FOO_H
171// Silly constants that the functions return.
172#define HELLO_RET 0xe110
173#define FOO_RET 0xf00
174
175// Our C test functions.
176extern "C"
177{
178  int foo(void);
179  int hello(void);
180}
181
182// Our test C++ base class.
183class foobar
184{
185public:
186  virtual int foo(void) = 0;
187  virtual int hello(void) = 0;
188  // Some dummy pure virtual functions.
189};
190
191
192// Our test C++ derived class.
193class foobar_derived : public foobar
194{
195public:
196  virtual int foo(void);
197  virtual int hello(void);
198  // Override the base class' pure virtual functions.
199};
200
201#endif
202]])
203
204AT_DATA([foo.cpp],
205[[#include <config.h>
206#ifdef HAVE_IOSTREAM
207# include <iostream>
208#else
209# include <iostream.h>
210#endif
211
212#ifdef HAVE_NAMESPACES
213namespace std { }
214using namespace std;
215#endif
216
217#include <math.h>
218
219#include "foo.h"
220
221// Our C functions.
222int
223foo(void)
224{
225  cout << "cos (0.0) = " << (double) cos ((double) 0.0) << endl;
226  return FOO_RET;
227}
228
229int
230hello(void)
231{
232  cout << "** This is libfoo (tagdemo) **" << endl;
233  return HELLO_RET;
234}
235
236
237// --------------------------------------------------------------------
238// Our C++ derived class methods.
239
240
241int
242foobar_derived::foo(void)
243{
244  return ::foo();
245}
246
247int
248foobar_derived::hello(void)
249{
250  return ::hello();
251}
252]])
253
254AT_DATA([baz.h],
255[[#ifndef BAZ_H
256#define BAZ_H 1
257
258// Our test C++ base class.
259class barbaz
260{
261public:
262  virtual int baz(void) = 0;
263  // Some dummy pure virtual functions.
264};
265
266// Our test C++ derived class.
267class barbaz_derived : public barbaz
268{
269public:
270  virtual int baz(void);
271  // Override the base class' pure virtual functions.
272};
273
274#endif
275]])
276
277AT_DATA([baz.cpp],
278[[#include <config.h>
279
280#include "foo.h"
281#include "baz.h"
282
283// --------------------------------------------------------------------
284// Our C++ derived class methods.
285
286
287int
288barbaz_derived::baz(void)
289{
290  foobar_derived FB;
291
292  return FB.foo();
293}
294]])
295
296AT_DATA([conv.h],
297[[#ifndef CONV_H
298#define CONV_H
299
300// Our C test functions.
301extern "C"
302{
303  int convenience(void);
304}
305
306#endif
307]])
308
309AT_DATA([conv.cpp],
310[[#include <config.h>
311
312#include "conv.h"
313
314//Our C function.
315int convenience (void) { return 1; }
316]])
317
318LT_AT_HOST_DATA([expout],
319[[Welcome to GNU libtool tagdemo C++!
320** This is libfoo (tagdemo) **
321foobar::hello returned: 57616
322foobar::hello is ok!
323cos (0.0) = 1
324foobar::foo is ok!
325cos (0.0) = 1
326barbaz::baz is ok!
327convenience is ok!
328]])
329
330prefix=`pwd`/_inst
331]) # _LT_SETUP
332
333
334## --------------- ##
335## Tagdemo static. ##
336## --------------- ##
337
338AT_SETUP([static library])
339
340_LT_SETUP
341
342LT_AT_CHECK_CONFIG([--disable-shared],
343                   [^build_old_libs=yes], [^build_libtool_libs=no])
344LT_AT_CHECK_EXECUTE([], [./tagdemo])
345
346AT_CLEANUP
347
348
349## --------------- ##
350## Tagdemo shared. ##
351## --------------- ##
352
353AT_SETUP([shared library])
354
355_LT_SETUP
356
357LT_AT_CHECK_CONFIG([--disable-static],
358                   [^build_old_libs=no], [^build_libtool_libs=yes])
359LT_AT_CHECK_EXECUTE([], [./tagdemo])
360
361AT_CLEANUP
362
363
364## ------------- ##
365## Tagdemo conf. ##
366## ------------- ##
367
368AT_SETUP([shared and static together])
369
370_LT_SETUP
371
372LT_AT_CHECK_CONFIG([],
373                   [^build_old_libs=yes], [^build_libtool_libs=yes])
374LT_AT_CHECK_EXECUTE([], [./tagdemo])
375
376AT_CLEANUP
377
378
379## -------------- ##
380## Tagdemo undef. ##
381## -------------- ##
382
383AT_SETUP([allow_undefined_flag])
384
385_LT_SETUP
386
387LT_AT_BOOTSTRAP([], [-I m4], [], [--add-missing], [],
388                [--disable-static], [ignore])
389AT_CHECK([$GREP "^allow_undefined_flag=.\{0,1\}unsupported.\{0,1\}$" libtool && (exit 77)],
390          1, [ignore])
391$SED 's|allow_undefined=no|allow_undefined=yes|g' libtool > ltnew && mv -f ltnew libtool
392LT_AT_CHECK_EXECUTE([], [./tagdemo])
393
394
395AT_CLEANUP
396