1 # darwin.at - tests specific to Mac OS X
3 # Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc.
4 # Written by Peter O'Gorman, 2008
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([Mac OS X tests])
26 AT_SETUP([darwin fat compile])
33 AT_DATA([simple.c] ,[[
34 int main() { return 0;}
38 $CC $CPPFLAGS $CFLAGS -arch ppc -arch i386 -o simple simple.c 2>&1 > /dev/null || noskip=false
42 AT_CHECK([$noskip || (exit 77)])
55 int bar() { return x;}
68 AT_DATA([bin/basename],[[
71 usage="usage: $0 argument"
77 echo $1 | sed "s,^.*/,,"
85 AT_CHECK([$LIBTOOL --mode=compile --tag=CC $CC -c -o foo.lo $CPPFLAGS $CFLAGS -arch ppc -arch i386 foo.c],[0],[ignore],[ignore])
87 AT_CHECK([$LIBTOOL --mode=compile --tag=CC $CC -c -o baz.lo $CPPFLAGS $CFLAGS -arch ppc -arch i386 baz.c],[0],[ignore],[ignore])
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])
91 AT_CHECK([$LIBTOOL --mode=compile --tag=CC $CC -c -o bar.lo $CPPFLAGS $CFLAGS -arch ppc -arch i386 bar.c],[0],[ignore],[ignore])
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])
95 AT_CHECK([$LIBTOOL --mode=compile --tag=CC $CC -c -o main.lo $CPPFLAGS $CFLAGS -arch ppc -arch i386 main.c],[0],[ignore],[ignore])
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])
103 AT_SETUP([darwin concurrent library extraction])
106 int foo (void) { return 0; }
110 extern int foo1 (void);
111 int bar (void) { return foo1 (); }
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"
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])
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])
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])
152 AT_SETUP([darwin gdb debug information])
154 AT_CHECK([gdb --version || (exit 77)],[ignore],[ignore],[ignore])
157 int foo (void) { return 0; }
161 extern int foo (void);
162 int bar (void) { return foo (); }
166 extern int bar(void);
168 int main() { return bar();}
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])
178 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o libfoo.la foo.lo],
179 [], [ignore], [ignore])
181 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS ]dnl
182 [ -o libbar.la bar.lo -rpath /foo libfoo.la ],
183 [], [ignore], [ignore])
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])
190 AT_CHECK([grep 'Could not find object file' stderr],[1],[ignore],[ignore])
193 eval "`$LIBTOOL --config | $EGREP '^(whole_archive_flag_spec)='`"
194 case $whole_archive_flag_spec:$host_os in
199 # Remove any dSYM bundle
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])
208 AT_SETUP([darwin ld warnings changing configure results])
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])
216 AC_CONFIG_FILES([Makefile])
220 AT_DATA([Makefile.am],[
221 ACLOCAL_AMFLAGS = -I m4
223 LT_AT_LIBTOOLIZE([--copy --force])
224 LT_AT_AUTORECONF([--force --install])
226 AT_CHECK([./libtool --config],[ignore],[stdout],[ignore])
228 LT_AT_CONFIGURE([LDFLAGS=-L/there/is/no/dir/here])
229 AT_CHECK([./libtool --config],[ignore],[expout],[ignore])
232 AT_SETUP([darwin can lt_dlopen .dylib and .so files])
234 AT_KEYWORDS([libltdl dylib])
236 # This test requires shared library support.
237 AT_CHECK([$LIBTOOL --features | grep 'enable shared libraries' || exit 77],
240 eval `$LIBTOOL --config | $EGREP '^shrext_cmds='`
243 eval shared_ext=\"$shrext_cmds\"
245 eval module_ext=\"$shrext_cmds\"
247 # Only bother with this test if module extension is different from
249 AT_CHECK([test "$shared_ext" != "$module_ext" || exit 77])
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) ;;
260 mkdir $prefix $libdir $bindir
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
267 AT_DATA([simple-module.c],
275 run (const char *argument)
277 printf ("Hello, %s!\n", argument);
282 AT_DATA([ltdl-loader.c],
287 # define EXIT_FAILURE 1
288 # define EXIT_SUCCESS 0
293 # define PATH_MAX 255
299 #ifndef MODULE_PATH_ENV
300 # define MODULE_PATH_ENV "MODULE_PATH"
303 typedef int entrypoint (const char *argument);
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);
310 main (int argc, const char *argv[])
312 char *errormsg = NULL;
313 lt_dlhandle module = NULL;
314 entrypoint *run = NULL;
319 fprintf (stderr, "USAGE: main MODULENAME ARGUMENT\n");
323 /* Initialise libltdl. */
324 errors = lt_dlinit ();
326 /* Set the module search path. */
329 const char *path = getenv (MODULE_PATH_ENV);
332 errors = lt_dlsetsearchpath (path);
335 /* Load the module. */
337 module = lt_dlopenext (argv[1]);
339 /* Find the entry point. */
342 run = (entrypoint *) lt_dlsym (module, "run");
344 /* In principle, run might legitimately be NULL, so
345 I don't use run == NULL as an error indicator
347 errormsg = dlerrordup (errormsg);
348 if (errormsg != NULL)
350 errors = lt_dlclose (module);
357 /* Call the entry point function. */
360 int result = (*run) (argv[2]);
362 errormsg = strdup ("module entry point execution failed");
364 printf ("\t=> %d\n", result);
367 /* Unload the module, now that we are done with it. */
369 errors = lt_dlclose (module);
373 /* Diagnose the encountered error. */
374 errormsg = dlerrordup (errormsg);
378 fprintf (stderr, "%s: dlerror() failed.\n", argv[0]);
383 /* Finished with ltdl now. */
385 if (lt_dlexit () != 0)
386 errormsg = dlerrordup (errormsg);
390 fprintf (stderr, "%s: %s.\n", argv[0], errormsg);
398 /* Be careful to save a copy of the error message,
399 since the next API call may overwrite the original. */
401 dlerrordup (char *errormsg)
403 char *error = (char *) lt_dlerror ();
404 if (error && !errormsg)
405 errormsg = strdup (error);
410 : ${LTDLINCL="-I$abs_top_srcdir/libltdl"}
411 : ${LIBLTDL="$abs_builddir/../libltdl/libltdlc.la"}
413 CPPFLAGS="$LTDLINCL $CPPFLAGS"
414 LDFLAGS="$LDFLAGS -no-undefined"
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])
434 rm $libdir/simple-module.la
435 rm $libdir/libsimple-dylib.la
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])