Fixed package groups
[platform/upstream/libtool.git] / tests / darwin.at
1 # darwin.at - tests specific to Mac OS X
2 #
3 #   Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc.
4 #   Written by Peter O'Gorman, 2008
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([Mac OS X tests])
26 AT_SETUP([darwin fat compile])
27 noskip=:
28 case "$host_os" in
29 darwin*) ;;
30 *) noskip=false ;;
31 esac
32
33 AT_DATA([simple.c] ,[[
34 int main() { return 0;}
35 ]])
36
37 $noskip && {
38 $CC $CPPFLAGS $CFLAGS -arch ppc -arch i386 -o simple simple.c 2>&1 > /dev/null || noskip=false
39 rm -f simple 
40 }
41
42 AT_CHECK([$noskip || (exit 77)])
43
44 AT_DATA([foo.c],[[
45 int x=0;
46 ]])
47
48 AT_DATA([baz.c],[[
49 int y=0;
50 ]])
51
52 AT_DATA([bar.c],[[
53 extern int x;
54 int bar(void);
55 int bar() { return x;}
56 ]])
57
58 AT_DATA([main.c],[[
59 extern int x;
60 extern int y;
61
62 int main() {
63 return x+y;
64 }
65 ]])
66
67 mkdir bin
68 AT_DATA([bin/basename],[[
69 #! /bin/sh
70
71 usage="usage: $0 argument"
72 if test $# != 1; then
73                   echo $usage >&2
74                   exit 1
75 fi
76
77 echo $1 | sed "s,^.*/,,"
78 ]])
79
80 chmod +x bin/basename
81 save_PATH=$PATH
82 PATH=`pwd`/bin:$PATH
83 export PATH
84
85 AT_CHECK([$LIBTOOL --mode=compile --tag=CC $CC -c -o foo.lo $CPPFLAGS $CFLAGS -arch ppc -arch i386 foo.c],[0],[ignore],[ignore])
86
87 AT_CHECK([$LIBTOOL --mode=compile --tag=CC $CC -c -o baz.lo $CPPFLAGS $CFLAGS -arch ppc -arch i386 baz.c],[0],[ignore],[ignore])
88
89 AT_CHECK([$LIBTOOL --mode=link --tag=CC $CC -o libfoo.la $CPPFLAGS $CFLAGS $LDFLAGS -arch ppc -arch i386 foo.lo baz.lo],[0],[ignore],[ignore])
90
91 AT_CHECK([$LIBTOOL --mode=compile --tag=CC $CC -c -o bar.lo $CPPFLAGS $CFLAGS -arch ppc -arch i386 bar.c],[0],[ignore],[ignore])
92
93 AT_CHECK([$LIBTOOL --mode=link --tag=CC $CC  -o libbar.la $CPPFLAGS $CFLAGS $LDFLAGS -arch ppc -arch i386 bar.lo libfoo.la -rpath /nonexistent],[0],[ignore],[ignore])
94
95 AT_CHECK([$LIBTOOL --mode=compile --tag=CC $CC -c -o main.lo $CPPFLAGS $CFLAGS -arch ppc -arch i386 main.c],[0],[ignore],[ignore])
96
97 AT_CHECK([$LIBTOOL --mode=link --tag=CC $CC  -o main$EXEEXT $CPPFLAGS $CFLAGS $LDFLAGS -arch ppc -arch i386 main.lo libbar.la],[0],[ignore],[ignore])
98
99 PATH=$save_PATH
100 AT_CLEANUP
101
102
103 AT_SETUP([darwin concurrent library extraction])
104
105 AT_DATA([foo.c], [[
106 int foo (void) { return 0; }
107 ]])
108
109 AT_DATA([bar.c], [[
110 extern int foo1 (void);
111 int bar (void) { return foo1 (); }
112 ]])
113 cp bar.c baz.c
114
115 objects=
116 for obj in 1 2 3 4 5 6 7 8; do
117   sed "s/foo/foo$obj/" < foo.c > foo$obj.c
118   AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c foo$obj.c],
119            [], [ignore], [ignore])
120   objects="$objects foo$obj.lo"
121 done
122 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c bar.c],
123          [], [ignore], [ignore])
124 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c baz.c],
125          [], [ignore], [ignore])
126 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o libfoo.la $objects],
127          [], [ignore], [ignore])
128
129 # Hypothesis: concurrent convenience archive extraction works.
130 for i in 1 2 3 4 5; do
131   rm -f libbar.la libbaz.la
132   AT_CHECK([($LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS ]dnl
133            [  -o libbar.la bar.lo -rpath /foo libfoo.la) & ]dnl
134            [($LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS ]dnl
135            [  -o libbaz.la baz.lo -rpath /foo libfoo.la) & ]dnl
136            [wait; test -f libbar.la && test -f libbaz.la],
137            [], [ignore], [ignore])
138 done
139
140 # Hypothesis: the lock is not used in dry run mode.
141 eval "`$LIBTOOL --config | $EGREP '^(objdir)='`"
142 # Next line is internal detail.
143 lockfile=$objdir/libfoo.a.lock
144 echo stamp > $lockfile
145 AT_CHECK([$LIBTOOL --dry-run --mode=link $CC $CFLAGS $LDFLAGS ]dnl
146          [ -o libbar.la bar.lo -rpath /foo libfoo.la],
147          [], [ignore], [ignore])
148 AT_CHECK([grep stamp $lockfile], [], [ignore])
149
150 AT_CLEANUP
151
152 AT_SETUP([darwin gdb debug information])
153
154 AT_CHECK([gdb --version || (exit 77)],[ignore],[ignore],[ignore])
155
156 AT_DATA([foo.c], [[
157 int foo (void) { return 0; }
158 ]])
159
160 AT_DATA([bar.c], [[
161 extern int foo (void);
162 int bar (void) { return foo (); }
163 ]])
164
165 AT_DATA([main.c], [[
166 extern int bar(void);
167
168 int main() { return bar();}
169 ]])
170
171 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c bar.c],
172          [], [ignore], [ignore])
173 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c foo.c],
174          [], [ignore], [ignore])
175 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c main.c],
176          [], [ignore], [ignore])
177
178 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o libfoo.la foo.lo],
179          [], [ignore], [ignore])
180
181 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS ]dnl
182          [  -o libbar.la bar.lo -rpath /foo libfoo.la ],
183          [], [ignore], [ignore])
184
185 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS ]dnl
186          [  -o main main.lo libbar.la],[], [ignore], [ignore])
187 AT_CHECK([echo quit | $LIBTOOL --mode=execute gdb main],
188          [ignore], [ignore], [stderr])
189
190 AT_CHECK([grep 'Could not find object file' stderr],[1],[ignore],[ignore])
191
192 AT_XFAIL_IF([
193 eval "`$LIBTOOL --config | $EGREP '^(whole_archive_flag_spec)='`"
194 case $whole_archive_flag_spec:$host_os in
195 :darwin*) : ;;
196 *) false ;;
197 esac ])
198
199 # Remove any dSYM bundle
200 rm -rf .libs/*.dSYM
201
202 AT_CHECK([echo quit | $LIBTOOL --mode=execute gdb main],
203          [ignore], [ignore], [stderr])
204 AT_CHECK([grep 'Could not find object file' stderr],[1],[ignore],[ignore])
205
206 AT_CLEANUP
207
208 AT_SETUP([darwin ld warnings changing configure results])
209
210 AT_DATA([configure.ac],
211 [[AC_INIT([ld-stderr], ]AT_PACKAGE_VERSION[, ]AT_PACKAGE_BUGREPORT[)
212 AC_CONFIG_MACRO_DIR([m4])
213 AM_INIT_AUTOMAKE([foreign])
214 AC_PROG_CC
215 LT_INIT
216 AC_CONFIG_FILES([Makefile])
217 AC_OUTPUT
218 ]])
219
220 AT_DATA([Makefile.am],[
221 ACLOCAL_AMFLAGS = -I m4
222 ])
223 LT_AT_LIBTOOLIZE([--copy --force])
224 LT_AT_AUTORECONF([--force --install])
225 LT_AT_CONFIGURE
226 AT_CHECK([./libtool --config],[ignore],[stdout],[ignore])
227 mv stdout expout
228 LT_AT_CONFIGURE([LDFLAGS=-L/there/is/no/dir/here])
229 AT_CHECK([./libtool --config],[ignore],[expout],[ignore])
230 AT_CLEANUP
231
232 AT_SETUP([darwin can lt_dlopen .dylib and .so files])
233
234 AT_KEYWORDS([libltdl dylib])
235
236 # This test requires shared library support.
237 AT_CHECK([$LIBTOOL --features | grep 'enable shared libraries' || exit 77],
238          [], [ignore])
239
240 eval `$LIBTOOL --config | $EGREP '^shrext_cmds='`
241
242 module=no
243 eval shared_ext=\"$shrext_cmds\"
244 module=yes
245 eval module_ext=\"$shrext_cmds\"
246
247 # Only bother with this test if module extension is different from
248 # shared extension
249 AT_CHECK([test "$shared_ext" != "$module_ext" || exit 77])
250
251 # Skip this test when called from:
252 #    make distcheck DISTCHECK_CONFIGURE_FLAGS=--disable-ltdl-install
253 AT_CHECK([case $LIBLTDL in #(
254  */_inst/lib/*) test -f $LIBLTDL || (exit 77) ;;
255 esac], [], [ignore])
256
257 prefix=`pwd`/inst
258 libdir=$prefix/lib
259 bindir=$prefix/bin
260 mkdir $prefix $libdir $bindir
261
262 # This code is copied from the Autobook:
263 # <http://sources.redhat.com/autobook/autobook/autobook_169.html>
264 # so if it needs changes, be sure to notify the Autobook authors
265 # about them.
266
267 AT_DATA([simple-module.c],
268 [[
269 #include <stdio.h>
270
271 #ifdef __cplusplus
272 extern "C"
273 #endif
274 int
275 run (const char *argument)
276 {
277   printf ("Hello, %s!\n", argument);
278   return 0;
279 }
280 ]])
281
282 AT_DATA([ltdl-loader.c],
283 [[
284 #include <stdio.h>
285 #include <stdlib.h>
286 #ifndef EXIT_FAILURE
287 #  define EXIT_FAILURE        1
288 #  define EXIT_SUCCESS        0
289 #endif
290
291 #include <limits.h>
292 #ifndef PATH_MAX
293 #  define PATH_MAX 255
294 #endif
295
296 #include <string.h>
297 #include <ltdl.h>
298
299 #ifndef MODULE_PATH_ENV
300 #  define MODULE_PATH_ENV        "MODULE_PATH"
301 #endif
302
303 typedef int entrypoint (const char *argument);
304
305 /* Save and return a copy of the dlerror() error  message,
306    since the next API call may overwrite the original. */
307 static char *dlerrordup (char *errormsg);
308
309 int
310 main (int argc, const char *argv[])
311 {
312   char *errormsg = NULL;
313   lt_dlhandle module = NULL;
314   entrypoint *run = NULL;
315   int errors = 0;
316
317   if (argc != 3)
318     {
319       fprintf (stderr, "USAGE: main MODULENAME ARGUMENT\n");
320       exit (EXIT_FAILURE);
321     }
322
323   /* Initialise libltdl. */
324   errors = lt_dlinit ();
325
326   /* Set the module search path. */
327   if (!errors)
328     {
329       const char *path = getenv (MODULE_PATH_ENV);
330
331       if (path != NULL)
332         errors = lt_dlsetsearchpath (path);
333     }
334
335   /* Load the module. */
336   if (!errors)
337     module = lt_dlopenext (argv[1]);
338
339   /* Find the entry point. */
340   if (module)
341     {
342       run = (entrypoint *) lt_dlsym (module, "run");
343
344       /* In principle, run might legitimately be NULL, so
345          I don't use run == NULL as an error indicator
346          in general. */
347       errormsg = dlerrordup (errormsg);
348       if (errormsg != NULL)
349         {
350           errors = lt_dlclose (module);
351           module = NULL;
352         }
353     }
354   else
355     errors = 1;
356
357   /* Call the entry point function. */
358   if (!errors)
359     {
360       int result = (*run) (argv[2]);
361       if (result < 0)
362         errormsg = strdup ("module entry point execution failed");
363       else
364         printf ("\t=> %d\n", result);
365     }
366
367   /* Unload the module, now that we are done with it. */
368   if (!errors)
369     errors = lt_dlclose (module);
370
371   if (errors)
372     {
373       /* Diagnose the encountered error. */
374       errormsg = dlerrordup (errormsg);
375
376       if (!errormsg)
377         {
378           fprintf (stderr, "%s: dlerror() failed.\n", argv[0]);
379           return EXIT_FAILURE;
380         }
381     }
382
383   /* Finished with ltdl now. */
384   if (!errors)
385     if (lt_dlexit () != 0)
386       errormsg = dlerrordup (errormsg);
387
388   if (errormsg)
389     {
390       fprintf (stderr, "%s: %s.\n", argv[0], errormsg);
391       free (errormsg);
392       exit (EXIT_FAILURE);
393     }
394
395   return EXIT_SUCCESS;
396 }
397
398 /* Be careful to save a copy of the error message,
399    since the  next API call may overwrite the original. */
400 static char *
401 dlerrordup (char *errormsg)
402 {
403   char *error = (char *) lt_dlerror ();
404   if (error && !errormsg)
405     errormsg = strdup (error);
406   return errormsg;
407 }
408 ]])
409
410 : ${LTDLINCL="-I$abs_top_srcdir/libltdl"}
411 : ${LIBLTDL="$abs_builddir/../libltdl/libltdlc.la"}
412
413 CPPFLAGS="$LTDLINCL $CPPFLAGS"
414 LDFLAGS="$LDFLAGS -no-undefined"
415
416 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c simple-module.c],
417          [], [ignore], [ignore])
418 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o simple-module.la ]dnl
419          [simple-module.lo -rpath $libdir -module -avoid-version],
420          [], [ignore], [ignore])
421 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o libsimple-dylib.la ]dnl
422          [simple-module.lo -rpath $libdir -avoid-version],
423          [], [ignore], [ignore])
424 AT_CHECK([$CC $CPPFLAGS $CFLAGS -c ltdl-loader.c],
425          [], [ignore], [ignore])
426 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o ltdl-loader$EXEEXT ]dnl
427          [ltdl-loader.$OBJEXT -dlopen self $LIBLTDL],
428          [], [ignore], [ignore])
429 AT_CHECK([$LIBTOOL --mode=install cp simple-module.la $libdir/simple-module.la], [], [ignore], [ignore])
430 AT_CHECK([$LIBTOOL --mode=install cp libsimple-dylib.la $libdir/libsimple-dylib.la], [], [ignore], [ignore])
431 AT_CHECK([$LIBTOOL --mode=clean rm -f simple-module.la], [], [ignore], [ignore])
432 AT_CHECK([$LIBTOOL --mode=clean rm -f libsimple-dylib.la], [], [ignore], [ignore])
433
434 rm $libdir/simple-module.la
435 rm $libdir/libsimple-dylib.la
436
437 for dir in inst/lib "$libdir"; do
438   LT_AT_EXEC_CHECK([./ltdl-loader], [], [stdout], [ignore],
439             [$dir/simple-module World])
440   AT_CHECK([grep "Hello, World" stdout], [], [ignore])
441   LT_AT_EXEC_CHECK([./ltdl-loader], [], [stdout], [ignore],
442             [$dir/libsimple-dylib World])
443   AT_CHECK([grep "Hello, World" stdout], [], [ignore])
444 done
445
446 AT_CLEANUP