1 # template.at -- test C++ templates with libtool -*- Autotest -*-
3 # Copyright (C) 2005, 2007 Free Software Foundation, Inc.
4 # Written by Markus Christen, 2005
6 # This file is part of GNU Libtool.
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.
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.
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.
25 AT_BANNER([C++ template tests.])
27 AT_SETUP([simple template test])
29 AT_KEYWORDS([libtool])
75 return f(3) + 3 - cf(3) != 0;
79 AT_CHECK([$LIBTOOL --tag=CXX --mode=compile $CXX -I. $CPPFLAGS $CXXFLAGS -c -o alib.lo alib.cpp],
80 [0], [ignore], [ignore])
81 AT_CHECK([$LIBTOOL --tag=CXX --mode=compile $CXX -I. $CPPFLAGS $CXXFLAGS -c -o aclib.lo aclib.cpp],
82 [0], [ignore], [ignore])
83 AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CPPFLAGS $CXXFLAGS $LDFLAGS -o libaclib.la aclib.lo],
84 [0], [ignore], [ignore])
85 AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CPPFLAGS $CXXFLAGS $LDFLAGS -o libalib.la -rpath /usr/local/lib alib.lo libaclib.la],
86 [0], [ignore], [ignore])
87 AT_CHECK([$CXX -I. $CPPFLAGS $CXXFLAGS -c prog.cpp],
88 [0], [ignore], [ignore])
89 AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CPPFLAGS $CXXFLAGS $LDFLAGS -o prog prog.$OBJEXT libalib.la],
90 [0], [ignore], [ignore])
92 LT_AT_EXEC_CHECK([./prog], [0], [ignore], [ignore])
95 dnl with autoreconf, use:
97 dnl AT_DATA(configure.ac,
98 dnl [[AC_INIT([template_1], ]]AT_PACKAGE_VERSION[[, ]]AT_PACKAGE_BUGREPORT[[)
99 dnl AC_CONFIG_HEADERS([config.h:config-h.in])
100 dnl AC_CONFIG_MACRO_DIR([m4])
101 dnl AC_CONFIG_AUX_DIR([config])
102 dnl AM_INIT_AUTOMAKE([foreign])
106 dnl AC_CONFIG_FILES([Makefile])
110 dnl AT_DATA(Makefile.am,
111 dnl [[ACLOCAL_AMFLAGS = -I m4
112 dnl noinst_LTLIBRARIES = libaclib.la
113 dnl libaclib_la_SOURCES = aclib.cpp aclib.h
114 dnl lib_LTLIBRARIES = libalib.la
115 dnl include_HEADERS = alib.h
116 dnl libalib_la_SOURCES = alib.cpp
117 dnl libalib_la_LIBADD = libaclib.la
118 dnl bin_PROGRAMS = prog
119 dnl prog_SOURCES = prog.cpp
120 dnl LDADD = libalib.la
126 AT_SETUP([template test with subdirs])
128 AT_KEYWORDS([libtool])
132 # The linker has issues with this test.
134 *-darwin*) noskip=false ;;
138 CPPFLAGS="$CPPFLAGS -I../src/lib -I../src/lib2"
141 ( cd src; mkdir lib lib2 sub )
142 ( cd obj; mkdir lib lib2 sub )
144 AT_DATA(src/lib/a.hh,
146 unsigned int a(const T&);
149 unsigned int a(const T& t)
154 extern int a2(char t);
156 inline int a3(const double* t)
162 AT_DATA(src/lib/a.cpp,
171 AT_DATA(src/lib2/b.hh,
179 extern int b2(char* t);
180 struct bs { int bi; };
184 AT_DATA(src/lib2/b.cpp,
198 AT_DATA(src/sub/main.cpp,
207 return b(foo) + a3(&foo) + b2(t) - a(s)
208 - (sizeof(double) + sizeof(double*));
214 # If the compiler supports -c -o, we want to use it:
215 # it may make a difference for templates
216 eval `$LIBTOOL --tag=CXX --config | grep ^compiler_c_o=`
217 case $compiler_c_o in
219 main_o=sub/main.$OBJEXT
220 AT_CHECK([$CXX $CPPFLAGS $CXXFLAGS -c -o $main_o ../src/sub/main.cpp],
221 [0], [ignore], [ignore])
225 AT_CHECK([$CXX $CPPFLAGS $CXXFLAGS -c ../src/sub/main.cpp],
226 [0], [ignore], [ignore])
230 AT_CHECK([$LIBTOOL --tag=CXX --mode=compile $CXX $CPPFLAGS $CXXFLAGS -c -o lib/a.lo ../src/lib/a.cpp],
231 [0], [ignore], [ignore])
232 AT_CHECK([$LIBTOOL --tag=CXX --mode=compile $CXX $CPPFLAGS $CXXFLAGS -c -o lib2/b.lo ../src/lib2/b.cpp],
233 [0], [ignore], [ignore])
234 AT_CHECK([$CXX $CPPFLAGS $CXXFLAGS -c ../src/sub/main.cpp],
235 [0], [ignore], [ignore])
237 AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS $LDFLAGS -o lib/liba.la lib/a.lo],
238 [0], [ignore], [ignore])
239 AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS $LDFLAGS -o lib2/libb.la lib2/b.lo],
240 [0], [ignore], [ignore])
241 AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS $LDFLAGS -o sub/main $main_o lib2/libb.la lib/liba.la],
242 [0], [ignore], [ignore])
243 LT_AT_EXEC_CHECK([./sub/main], [ignore])
246 AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS $LDFLAGS -o lib2/libb.la lib2/b.lo -rpath /foo],
247 [0], [ignore], [ignore])
248 AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS $LDFLAGS -o sub/main $main_o lib2/libb.la lib/liba.la],
249 [0], [ignore], [ignore])
250 LT_AT_EXEC_CHECK([./sub/main])
254 AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS $LDFLAGS -o lib/liba.la lib/a.lo -rpath /foo],
255 [0], [ignore], [ignore])
256 AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS $LDFLAGS -o lib2/libb.la lib2/b.lo -rpath /bar],
257 [0], [ignore], [ignore])
258 AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS $LDFLAGS -o sub/main $main_o lib2/libb.la lib/liba.la],
259 [0], [ignore], [ignore])
260 LT_AT_EXEC_CHECK([./sub/main])
261 # both convenience, libb depending on liba
262 AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS $LDFLAGS -o lib/liba.la lib/a.lo],
263 [0], [ignore], [ignore])
264 AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS $LDFLAGS -o lib2/libb.la lib2/b.lo lib/liba.la],
265 [0], [ignore], [ignore])
266 AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS $LDFLAGS -o sub/main $main_o lib2/libb.la],
267 [0], [ignore], [ignore])
268 LT_AT_EXEC_CHECK([./sub/main])
272 AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS $LDFLAGS -o lib2/libb.la lib2/b.lo lib/liba.la -rpath /foo],
273 [0], [ignore], [ignore])
274 AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS $LDFLAGS -o sub/main $main_o lib2/libb.la],
275 [0], [ignore], [ignore])
276 LT_AT_EXEC_CHECK([./sub/main])
280 AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS $LDFLAGS -o lib2/libb.la lib2/b.lo lib/liba.la -rpath /bar],
281 [0], [ignore], [ignore])
282 AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS $LDFLAGS -o sub/main $main_o lib2/libb.la],
283 [0], [ignore], [ignore])
284 LT_AT_EXEC_CHECK([./sub/main])
289 AT_CHECK([$noskip || (exit 77)])
291 dnl with autoreconf use:
293 dnl AT_DATA(src/configure.ac,
294 dnl [[AC_INIT([template_2], ]]AT_PACKAGE_VERSION[[, ]]AT_PACKAGE_BUGREPORT[[)
295 dnl AC_CONFIG_HEADERS([config.h:config-h.in])
296 dnl AC_CONFIG_MACRO_DIR([m4])
297 dnl AC_CONFIG_AUX_DIR([config])
298 dnl AM_INIT_AUTOMAKE([foreign subdir-objects])
302 dnl AC_CONFIG_FILES([Makefile])
306 dnl AT_DATA(src/Makefile.am,
307 dnl [[ACLOCAL_AMFLAGS = -I m4
308 dnl INCLUDES = -I$(srcdir)/lib -I$(srcdir)/lib2
309 dnl bin_PROGRAMS = sub/main
310 dnl noinst_LTLIBRARIES = lib/liba.la lib2/libb.la
311 dnl lib_liba_la_SOURCES = lib/a.cpp lib/a.hh
312 dnl lib2_libb_la_SOURCES = lib2/b.cpp lib2/b.hh
313 dnl #lib2_libb_la_LIBADD = lib/liba.la
314 dnl sub_main_SOURCES = sub/main.cpp
315 dnl sub_main_LDADD = lib2/libb.la lib/liba.la