1# cdemo.at -- Using Automake to build a program and library -*- Autotest -*-
2#
3#   Copyright (C) 2003-2004, 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([Convenience libraries.])
27
28
29# _LT_SETUP
30# ---------
31m4_define([_LT_SETUP],
32[AT_DATA([configure.ac],
33[[AC_INIT([cdemo], ]AT_PACKAGE_VERSION[, ]AT_PACKAGE_BUGREPORT[)
34AC_CONFIG_AUX_DIR([build-aux])
35AC_CONFIG_MACRO_DIRS([m4])
36AM_INIT_AUTOMAKE
37AC_PROG_CC
38LT_INIT
39AC_SUBST([LIBTOOL_DEPS])
40LT_LIB_M
41AC_CONFIG_FILES([Makefile])
42AC_CONFIG_HEADERS([config.h:config.in.h])
43AC_OUTPUT
44]])
45
46AT_DATA([Makefile.am],
47[[AUTOMAKE_OPTIONS = no-dependencies foreign
48ACLOCAL_AMFLAGS = -I m4
49
50noinst_LTLIBRARIES = libfoo.la
51libfoo_la_SOURCES = foo.c
52libfoo_la_LIBADD = $(LIBM)
53libfoo_la_LDFLAGS = -no-undefined
54noinst_HEADERS = foo.h
55
56bin_PROGRAMS = cdemo
57cdemo_SOURCES = main.c
58cdemo_LDADD = libfoo.la
59
60libtool: $(LIBTOOL_DEPS)
61	 $(SHELL) ./config.status --recheck
62]])
63
64AT_DATA([foo.h],
65[[#ifndef FOO_H
66#define FOO_H 1
67
68/* Silly constants that the functions return. */
69#define HELLO_RET 0xe110
70#define FOO_RET 0xf00
71
72extern int foo();
73
74extern int hello();
75
76#endif
77]])
78
79AT_DATA([foo.c],
80[[#include <config.h>
81#include <stdio.h>
82#include <math.h>
83
84#include "foo.h"
85
86int foo() {
87  printf ("cos (0.0) = %g\n", (double) cos ((double) 0.0));
88  return FOO_RET;
89}
90
91int hello() {
92  printf ("** This is libfoo **\n");
93  return HELLO_RET;
94}
95]])
96
97AT_DATA([main.c],
98[[#include <config.h>
99#include <stdio.h>
100#include "foo.h"
101
102int main ()
103{
104  int value;
105
106  printf ("Welcome to GNU libtool cdemo!\n");
107
108  value = hello();
109  printf ("hello returned: %i\n", value);
110  if (value == HELLO_RET)
111    printf("hello is ok!\n");
112
113  if (foo () == FOO_RET)
114    printf("foo is ok!\n");
115
116  return 0;
117}
118]])
119
120LT_AT_HOST_DATA([expout],
121[[Welcome to GNU libtool cdemo!
122** This is libfoo **
123hello returned: 57616
124hello is ok!
125cos (0.0) = 1
126foo is ok!
127]])
128]) # _LT_SETUP
129
130
131## ------------- ##
132## Cdemo static. ##
133## ------------- ##
134
135AT_SETUP([build and link against a static library])
136
137_LT_SETUP
138
139LT_AT_CHECK_CONFIG([--disable-shared],
140                   [^build_old_libs=yes], [^build_libtool_libs=no])
141LT_AT_CHECK_EXECUTE([], [./cdemo])
142
143AT_CLEANUP
144
145
146## ------------- ##
147## Cdemo shared. ##
148## ------------- ##
149
150AT_SETUP([build and link against a dynamic library])
151
152_LT_SETUP
153
154LT_AT_CHECK_CONFIG([--disable-static],
155                   [^build_old_libs=no], [^build_libtool_libs=yes])
156LT_AT_CHECK_EXECUTE([], [./cdemo])
157
158AT_CLEANUP
159
160
161## ----------- ##
162## Cdemo conf. ##
163## ----------- ##
164
165AT_SETUP([build both static and dynamic])
166
167_LT_SETUP
168
169LT_AT_CHECK_CONFIG([],
170                   [^build_old_libs=yes], [^build_libtool_libs=yes])
171LT_AT_CHECK_EXECUTE([], [./cdemo])
172
173AT_CLEANUP
174
175
176## ------------ ##
177## Cdemo undef. ##
178## ------------ ##
179
180AT_SETUP([allow_undefined_flag])
181
182_LT_SETUP
183
184LT_AT_CHECK_CONFIG([--disable-static])
185
186AT_CHECK([$EGREP "^allow_undefined_flag=.\{0,1\}unsupported.\{0,1\}$" libtool && (exit 77)],
187          1, [ignore])
188
189$SED 's|allow_undefined=no|allow_undefined=yes|g' libtool > ltnew && mv -f ltnew libtool
190
191LT_AT_CHECK_EXECUTE([], [./cdemo])
192
193AT_CLEANUP
194