# Hand crafted tests for GNU Libtool. -*- Autotest -*- # Copyright 2005 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. # Test C++ and templates with libtool AT_BANNER([C++ template tests.]) AT_SETUP([simple template test]) LT_AT_TAG([CXX]) AT_DATA(aclib.h, [[int cf(int); ]]) AT_DATA(aclib.cc, [[#include "aclib.h" template T cq(T b) { return b * 3; } int cf(int i) { return cq(i); } ]]) AT_DATA(alib.h, [[int f(int); ]]) AT_DATA(alib.cc, [[#include "alib.h" template T q(T b) { return b * 2; } int f(int i) { return q(i); } ]]) AT_DATA(prog.cc, [[#include #include "alib.h" #include "aclib.h" using namespace std; int main() { cout << "a sample prog" << endl; cout << "f(3) = " << f(3) << endl; cout << "cf(3) = " << cf(3) << endl; return 0; } ]]) AT_CHECK($LIBTOOL --tag=CXX --mode=compile $CXX -I. $CPPFLAGS $CXXFLAGS -c -o alib.lo alib.cc, [0], [ignore], [ignore]) AT_CHECK($LIBTOOL --tag=CXX --mode=compile $CXX -I. $CPPFLAGS $CXXFLAGS -c -o aclib.lo aclib.cc, [0], [ignore], [ignore]) AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CPPFLAGS $CXXFLAGS -o libaclib.la aclib.lo, [0], [ignore], [ignore]) AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CPPFLAGS $CXXFLAGS -o libalib.la -rpath /usr/local/lib alib.lo libaclib.la, [0], [ignore], [ignore]) AT_CHECK($CXX -I. $CPPFLAGS $CXXFLAGS -c -o prog.o prog.cc, [0], [ignore], [ignore]) AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CPPFLAGS $CXXFLAGS -o prog prog.o libalib.la, [0], [ignore], [ignore]) LT_AT_EXEC_CHECK([./prog], [0], [a sample prog f(3) = 6 cf(3) = 9 ], [ignore]) dnl with autoreconf, use: dnl AT_DATA(configure.ac, dnl [[AC_INIT([template_1], ]]AT_PACKAGE_VERSION[[, ]]AT_PACKAGE_BUGREPORT[[) dnl AC_CONFIG_HEADERS([config.h:config-h.in]) dnl AC_CONFIG_MACRO_DIR([m4]) dnl AC_CONFIG_AUX_DIR([config]) dnl AM_INIT_AUTOMAKE([foreign]) dnl AC_LANG([C++]) dnl AC_PROG_CXX dnl AC_PROG_LIBTOOL dnl AC_CONFIG_FILES([Makefile]) dnl AC_OUTPUT dnl ]]) dnl AT_DATA(Makefile.am, dnl [[ACLOCAL_AMFLAGS = -I m4 dnl noinst_LTLIBRARIES = libaclib.la dnl libaclib_la_SOURCES = aclib.cc aclib.h dnl lib_LTLIBRARIES = libalib.la dnl include_HEADERS = alib.h dnl libalib_la_SOURCES = alib.cc dnl libalib_la_LIBADD = libaclib.la dnl bin_PROGRAMS = prog dnl prog_SOURCES = prog.cc dnl LDADD = libalib.la dnl ]]) AT_CLEANUP AT_SETUP([template test with subdirs]) LT_AT_TAG([CXX]) CPPFLAGS="$CPPFLAGS -I../src/lib -I../src/lib2" mkdir src obj ( cd src; mkdir lib lib2 sub ) ( cd obj; mkdir lib lib2 sub ) AT_DATA(src/lib/a.hh, [[template unsigned int a(const T&); template unsigned int a(const T& t) { return sizeof t; } extern int a2(char t); inline int a3(const double* t) { return a(t); } ]]) AT_DATA(src/lib/a.cc, [[#include "a.hh" int a2(char t) { return a(t); } ]]) AT_DATA(src/lib2/b.hh, [[#include "a.hh" template unsigned int b(T& t) { return a(t); } extern int b2(char* t); struct bs { int bi; }; extern int b3(bs t); ]]) AT_DATA(src/lib2/b.cc, [[#include "b.hh" int b2(char* t) { return a2(t[0]); } int b3(bs t) { return b(t); } ]]) AT_DATA(src/sub/main.cc, [[#include "b.hh" int main() { double foo; const char s = ' '; char d; char *t = &d; return b(foo) + a3(&foo) + b2(t) - a(s) - (sizeof(double) + sizeof(double*)); } ]]) cd obj AT_CHECK($LIBTOOL --tag=CXX --mode=compile $CXX $CPPFLAGS $CXXFLAGS -c -o lib/a.lo ../src/lib/a.cc, [0], [ignore], [ignore]) AT_CHECK($LIBTOOL --tag=CXX --mode=compile $CXX $CPPFLAGS $CXXFLAGS -c -o lib2/b.lo ../src/lib2/b.cc, [0], [ignore], [ignore]) AT_CHECK($CXX $CPPFLAGS $CXXFLAGS -c -o sub/main.o ../src/sub/main.cc, [0], [ignore], [ignore]) # both convenience AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o lib/liba.la lib/a.lo, [0], [ignore], [ignore]) AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o lib2/libb.la lib2/b.lo, [0], [ignore], [ignore]) AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o sub/main sub/main.o lib2/libb.la lib/liba.la, [0], [ignore], [ignore]) LT_AT_EXEC_CHECK([./sub/main], [ignore]) # lib convenience AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o lib2/libb.la lib2/b.lo -rpath /foo, [0], [ignore], [ignore]) AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o sub/main sub/main.o lib2/libb.la lib/liba.la, [0], [ignore], [ignore]) LT_AT_EXEC_CHECK([./sub/main]) # both installed AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o lib/liba.la lib/a.lo -rpath /foo, [0], [ignore], [ignore]) AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o lib2/libb.la lib2/b.lo -rpath /bar, [0], [ignore], [ignore]) AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o sub/main sub/main.o lib2/libb.la lib/liba.la, [0], [ignore], [ignore]) LT_AT_EXEC_CHECK([./sub/main]) # both convenience, libb depending on liba AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o lib/liba.la lib/a.lo, [0], [ignore], [ignore]) AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o lib2/libb.la lib2/b.lo lib/liba.la, [0], [ignore], [ignore]) AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o sub/main sub/main.o lib2/libb.la, [0], [ignore], [ignore]) LT_AT_EXEC_CHECK([./sub/main]) # lib convenience AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o lib2/libb.la lib2/b.lo lib/liba.la -rpath /foo, [0], [ignore], [ignore]) AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o sub/main sub/main.o lib2/libb.la, [0], [ignore], [ignore]) LT_AT_EXEC_CHECK([./sub/main]) # both installed AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o lib/liba.la lib/a.lo -rpath /foo, [0], [ignore], [ignore]) AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o lib2/libb.la lib2/b.lo lib/liba.la -rpath /bar, [0], [ignore], [ignore]) AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o sub/main sub/main.o lib2/libb.la, [0], [ignore], [ignore]) LT_AT_EXEC_CHECK([./sub/main]) cd .. dnl with autoreconf use: dnl dnl AT_DATA(src/configure.ac, dnl [[AC_INIT([template_2], ]]AT_PACKAGE_VERSION[[, ]]AT_PACKAGE_BUGREPORT[[) dnl AC_CONFIG_HEADERS([config.h:config-h.in]) dnl AC_CONFIG_MACRO_DIR([m4]) dnl AC_CONFIG_AUX_DIR([config]) dnl AM_INIT_AUTOMAKE([foreign subdir-objects]) dnl AC_LANG([C++]) dnl AC_PROG_CXX dnl AC_PROG_LIBTOOL dnl AC_CONFIG_FILES([Makefile]) dnl AC_OUTPUT dnl ]]) dnl dnl AT_DATA(src/Makefile.am, dnl [[ACLOCAL_AMFLAGS = -I m4 dnl INCLUDES = -I$(srcdir)/lib -I$(srcdir)/lib2 dnl bin_PROGRAMS = sub/main dnl noinst_LTLIBRARIES = lib/liba.la lib2/libb.la dnl lib_liba_la_SOURCES = lib/a.cc lib/a.hh dnl lib2_libb_la_SOURCES = lib2/b.cc lib2/b.hh dnl #lib2_libb_la_LIBADD = lib/liba.la dnl sub_main_SOURCES = sub/main.cc dnl sub_main_LDADD = lib2/libb.la lib/liba.la dnl ]]) AT_CLEANUP