Imported Upstream version 2.4.2
[platform/upstream/libtool.git] / tests / configure-iface.at
1 # configure-iface.at -- test ltdl configure interface         -*- Autotest -*-
2 #
3 #   Copyright (C) 2007, 2008 Free Software Foundation, Inc.
4 #   Written by Gary V. Vaughan, 2007
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 AT_BANNER([configure interface to libltdl.])
26
27 # _LT_AT_LTDL_SETUP
28 # -----------------
29 m4_pushdef([_LT_AT_LTDL_SETUP],
30 [AT_DATA([main.c],
31 [[#include <ltdl.h>
32 #include <stdio.h>
33
34 typedef int funcp (void);
35
36 static int errors = 0;
37
38 int
39 main (void)
40 {
41   lt_dlhandle handle;
42
43   LTDL_SET_PRELOADED_SYMBOLS();
44
45   if (lt_dlinit () != 0)
46     {
47       fprintf (stderr, "error during initialization: %s\n", lt_dlerror ());
48       return 1;
49     }
50
51   handle = lt_dlopenext ("libmodule");
52   if (!handle)
53     {
54       fprintf (stderr, "can't open libmodule: %s\n", lt_dlerror ());
55       ++errors;
56     }
57
58   {
59     funcp *f = (funcp *) lt_dlsym (handle, "f");
60
61     if (f)
62       {
63         printf ("%d\n", f ());
64       }
65     else
66       {
67         fprintf (stderr, "function `f' not found: %s\n", lt_dlerror ());
68         ++errors;
69       }
70   }
71
72   if (lt_dlexit () != 0)
73     {
74       fprintf (stderr, "error during exit: %s\n", lt_dlerror ());
75       ++errors;
76     }
77
78   return (errors != 0);
79 }
80 ]])
81
82 AT_DATA([libmodule.c],
83 [[#ifdef __cplusplus
84 extern "C" {
85 #endif
86 int f (void) { return 5150; }
87 #ifdef __cplusplus
88 }
89 #endif
90 ]])
91
92 LT_AT_HOST_DATA([expout],
93 [[5150
94 ]])
95 ])# _LT_AT_LTDL_SETUP
96
97
98 ## -------------------- ##
99 ## Installable libltdl. ##
100 ## -------------------- ##
101
102 AT_SETUP([installable libltdl])
103 AT_KEYWORDS([libltdl])
104
105 _LT_AT_LTDL_SETUP
106
107 AT_DATA([configure.ac],
108 [[AC_INIT([installable-ltdl-demo], ]AT_PACKAGE_VERSION[, ]AT_PACKAGE_BUGREPORT[)
109 AC_CONFIG_AUX_DIR([libltdl/config])
110 AC_CONFIG_MACRO_DIR([libltdl/m4])
111 AC_CONFIG_HEADERS([config.h:config.hin])
112 LT_CONFIG_LTDL_DIR([libltdl])
113 AM_INIT_AUTOMAKE([foreign])
114 AC_PROG_CC
115 AM_PROG_CC_C_O
116 LT_INIT([dlopen])
117 LTDL_INIT([installable])
118 AC_CONFIG_FILES([Makefile])
119 AC_OUTPUT
120 ]])
121
122 AT_DATA([Makefile.am],
123 [[AUTOMAKE_OPTIONS      = 1.7
124
125 SUBDIRS                 = libltdl
126
127 AM_CPPFLAGS             = $(LTDLINCL)
128
129 lib_LTLIBRARIES         = libmodule.la
130 # Automake < 1.8 will use libmodule.la.c as default source,
131 # while newer will choose libmodule.c; so specify it here.
132 libmodule_la_SOURCES    = libmodule.c
133 libmodule_la_LDFLAGS    = -module
134
135 bin_PROGRAMS            = main
136 main_LDFLAGS            = -dlopen libmodule.la
137 main_LDADD              = $(LIBLTDL)
138 main_DEPENDENCIES       = $(LTDLDEPS) libmodule.la
139 ]])
140
141 # Install everything!
142 prefix=`pwd`/_inst
143
144 LT_AT_BOOTSTRAP([--ltdl], [-I libltdl/m4], [], [--add-missing], [],
145         [--with-included-ltdl --prefix=$prefix], [all install])
146
147 # TODO: Check that the installed program `main' is linked against our libltdl
148 AT_CHECK([test -f $prefix/lib/libltdl.la])
149 AT_CHECK([test -f $prefix/include/ltdl.h])
150
151 # Check that main is rebuilt if libltdl.la is newer
152 rm -f libltdl/libltdl.la
153 AT_CHECK([$MAKE -q main$EXEEXT || exit 1], [1], [ignore], [ignore])
154
155 AT_CLEANUP
156
157
158 ## ------------------------------- ##
159 ## Link against installed libltdl. ##
160 ## ------------------------------- ##
161
162 AT_SETUP([--with-ltdl-include/lib])
163 AT_KEYWORDS([libltdl])
164
165 # Install libltdl
166 prefix=`pwd`/_inst
167
168 LT_AT_LIBTOOLIZE([--copy --ltdl=ltdl])
169
170 (cd ltdl
171 LT_AT_CONFIGURE([--enable-ltdl-install --prefix=$prefix])
172 LT_AT_MAKE([all install])
173 )
174
175 # Remove build files
176 rm -rf ltdl/
177
178 AT_CHECK([test -f $prefix/lib/libltdl.la])
179 AT_CHECK([test -f $prefix/include/ltdl.h])
180
181 _LT_AT_LTDL_SETUP
182
183 AT_DATA([configure.ac],
184 [[AC_INIT([configure-iface-demo], ]AT_PACKAGE_VERSION[, ]AT_PACKAGE_BUGREPORT[)
185 AC_CONFIG_MACRO_DIR([_inst/aclocal])
186 AC_CONFIG_HEADERS([config.h:config.hin])
187 AM_INIT_AUTOMAKE([foreign])
188 AC_PROG_CC
189 AM_PROG_CC_C_O
190 LT_INIT([dlopen])
191 LTDL_INIT
192 AC_CONFIG_FILES([Makefile])
193 AC_OUTPUT
194 ]])
195
196 AT_DATA([Makefile.am],
197 [[AUTOMAKE_OPTIONS      = 1.7
198
199 AM_CPPFLAGS             = $(LTDLINCL)
200
201 lib_LTLIBRARIES         = libmodule.la
202 # Automake < 1.8 will use libmodule.la.c as default source,
203 # while newer will choose libmodule.c; so specify it here.
204 libmodule_la_SOURCES    = libmodule.c
205 libmodule_la_LDFLAGS    = -module
206
207 bin_PROGRAMS            = main
208 main_LDFLAGS            = -dlopen libmodule.la
209 main_LDADD              = $(LIBLTDL)
210 main_DEPENDENCIES       = $(LTDLDEPS) libmodule.la
211 ]])
212
213 ## Try to avoid linking against a previously installed libltdl found
214 ## with an explicit -L/path.
215 save_LDFLAGS=$LDFLAGS
216 LDFLAGS=
217 for l in $save_LDFLAGS
218 do
219   case $l in
220   -L*) ;;
221   *) LDFLAGS="$LDFLAGS $l" ;;
222   esac
223 done
224
225 # We don't use 'libtoolize --ltdl', so that we get an error if the test
226 # tries to build and link against its own ltdl sources:
227 LT_AT_BOOTSTRAP([], [-I _inst/aclocal], [], [--add-missing], [],
228         [--with-ltdl-lib=$prefix/lib --with-ltdl-include=$prefix/include],
229         [all])
230
231 ## TODO: portable ldd check for correct libltdl
232 ## Currently, this test doesn't fail if `main' ends up linking against a
233 ## previously installed system libltdl.
234 LT_AT_NOINST_EXEC_CHECK([./main], [-dlopen libmodule.la], [], [expout], [])
235
236 AT_CLEANUP
237
238
239 ## ------------------------------------- ##
240 ## Link against shipped libltdl sources. ##
241 ## ------------------------------------- ##
242
243 AT_SETUP([--with-included-ltdl])
244 AT_KEYWORDS([libltdl])
245
246 _LT_AT_LTDL_SETUP
247
248 AT_DATA([configure.ac],
249 [[AC_INIT([configure-iface-demo], ]AT_PACKAGE_VERSION[, ]AT_PACKAGE_BUGREPORT[)
250 AC_CONFIG_AUX_DIR([libltdl/config])
251 AC_CONFIG_MACRO_DIR([libltdl/m4])
252 AC_CONFIG_HEADERS([config.h:config.hin])
253 LT_CONFIG_LTDL_DIR([libltdl])
254 AM_INIT_AUTOMAKE([foreign])
255 AC_PROG_CC
256 AM_PROG_CC_C_O
257 LT_INIT([dlopen])
258 LTDL_INIT
259 AC_CONFIG_FILES([Makefile])
260 AC_OUTPUT
261 ]])
262
263 AT_DATA([Makefile.am],
264 [[AUTOMAKE_OPTIONS      = 1.7
265
266 SUBDIRS                 = libltdl
267
268 AM_CPPFLAGS             = $(LTDLINCL)
269
270 lib_LTLIBRARIES         = libmodule.la
271 # Automake < 1.8 will use libmodule.la.c as default source,
272 # while newer will choose libmodule.c; so specify it here.
273 libmodule_la_SOURCES    = libmodule.c
274 libmodule_la_LDFLAGS    = -module
275
276 bin_PROGRAMS            = main
277 main_LDFLAGS            = -dlopen libmodule.la
278 main_LDADD              = $(LIBLTDL)
279 main_DEPENDENCIES       = $(LTDLDEPS) libmodule.la
280 ]])
281
282 LT_AT_BOOTSTRAP([--ltdl], [-I libltdl/m4], [], [--add-missing], [],
283         [--with-included-ltdl], [all])
284
285 # --with-included-ltdl should build a convenience lib by default
286 AT_CHECK([test -f libltdl/libltdlc.la])
287
288 ## TODO: portable ldd check for correct libltdl
289 ## Currently, this test doesn't fail if `main' ends up linking against a
290 ## previously installed system libltdl.
291 LT_AT_NOINST_EXEC_CHECK([./main], [-dlopen libmodule.la], [], [expout], [])
292
293 # Check that main is rebuilt if libltdlc.la is newer
294 rm -f libltdl/libltdlc.la
295 AT_CHECK([$MAKE -q main$EXEEXT || exit 1], [1], [ignore], [ignore])
296
297 AT_CLEANUP
298
299
300 ## -------------------- ##
301 ## Convenience libltdl. ##
302 ## -------------------- ##
303
304 AT_SETUP([convenience libltdl])
305
306 AT_DATA([configure.ac],
307 [[AC_INIT
308 AC_CONFIG_AUX_DIR([libltdl/config])
309 AC_LIBLTDL_CONVENIENCE
310 AC_LIBTOOL_DLOPEN
311 AC_PROG_LIBTOOL
312 AC_CONFIG_FILES(Makefile)
313 AC_OUTPUT
314 ]])
315 AT_DATA([Makefile.in],
316 [[LIBLTDL = @LIBLTDL@
317 print-ltdl:
318         echo $(LIBLTDL)
319 ]])
320
321 LT_AT_BOOTSTRAP([--ltdl], [-I libltdl/m4], [ignore], [ignore], [], [], [ignore])
322 AT_CHECK([$MAKE print-ltdl], [], [stdout], [ignore])
323 AT_CHECK([grep libltdl/libltdlc.la stdout], [], [ignore])
324
325 AT_CLEANUP
326
327 dnl Be careful not to let the definition leak into other tests
328 m4_popdef([_LT_AT_LTDL_SETUP])