1 # darwin.at - tests specific to Mac OS X
3 # Copyright (C) 2008-2009, 2011-2019, 2021-2024 Free Software
5 # Written by Peter O'Gorman, 2008
7 # This file is part of GNU Libtool.
9 # GNU Libtool is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation; either version 2 of
12 # the License, or (at your option) any later version.
14 # GNU Libtool is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with GNU Libtool; see the file COPYING. If not, a copy
21 # can be downloaded from http://www.gnu.org/licenses/gpl.html,
22 # or obtained by writing to the Free Software Foundation, Inc.,
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 AT_BANNER([Mac OS X tests])
27 AT_SETUP([darwin fat compile])
34 AT_DATA([simple.c] ,[[
35 int main() { return 0;}
39 $CC $CPPFLAGS $CFLAGS -arch x86_64 -arch i386 -o simple simple.c 2>&1 > /dev/null || noskip=false
43 AT_CHECK([$noskip || (exit 77)])
56 int bar() { return x;}
69 AT_DATA([bin/basename],[[
72 usage="usage: $0 argument"
78 echo $1 | $SED "s|^.*/||"
86 AT_CHECK([$LIBTOOL --mode=compile --tag=CC $CC -c -o foo.lo $CPPFLAGS $CFLAGS -arch x86_64 -arch i386 foo.c],[0],[ignore],[ignore])
88 AT_CHECK([$LIBTOOL --mode=compile --tag=CC $CC -c -o baz.lo $CPPFLAGS $CFLAGS -arch x86_64 -arch i386 baz.c],[0],[ignore],[ignore])
90 AT_CHECK([$LIBTOOL --mode=link --tag=CC $CC -o libfoo.la $CPPFLAGS $CFLAGS $LDFLAGS -arch x86_64 -arch i386 foo.lo baz.lo],[0],[ignore],[ignore])
92 AT_CHECK([$LIBTOOL --mode=compile --tag=CC $CC -c -o bar.lo $CPPFLAGS $CFLAGS -arch x86_64 -arch i386 bar.c],[0],[ignore],[ignore])
94 AT_CHECK([$LIBTOOL --mode=link --tag=CC $CC -o libbar.la $CPPFLAGS $CFLAGS $LDFLAGS -arch x86_64 -arch i386 bar.lo libfoo.la -rpath /nonexistent],[0],[ignore],[ignore])
96 AT_CHECK([$LIBTOOL --mode=compile --tag=CC $CC -c -o main.lo $CPPFLAGS $CFLAGS -arch x86_64 -arch i386 main.c],[0],[ignore],[ignore])
98 AT_CHECK([$LIBTOOL --mode=link --tag=CC $CC -o main$EXEEXT $CPPFLAGS $CFLAGS $LDFLAGS -arch x86_64 -arch i386 main.lo libbar.la],[0],[ignore],[ignore])
104 AT_SETUP([darwin concurrent library extraction])
107 int foo (void) { return 0; }
111 extern int foo1 (void);
112 int bar (void) { return foo1 (); }
117 for obj in 1 2 3 4 5 6 7 8; do
118 $SED "s/foo/foo$obj/" < foo.c > foo$obj.c
119 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c foo$obj.c],
120 [], [ignore], [ignore])
121 objects="$objects foo$obj.lo"
123 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c bar.c],
124 [], [ignore], [ignore])
125 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c baz.c],
126 [], [ignore], [ignore])
127 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o libfoo.la $objects],
128 [], [ignore], [ignore])
130 # Hypothesis: concurrent convenience archive extraction works.
131 for i in 1 2 3 4 5; do
132 rm -f libbar.la libbaz.la
133 AT_CHECK([($LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS ]dnl
134 [ -o libbar.la bar.lo -rpath /foo libfoo.la) & ]dnl
135 [($LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS ]dnl
136 [ -o libbaz.la baz.lo -rpath /foo libfoo.la) & ]dnl
137 [wait; test -f libbar.la && test -f libbaz.la],
138 [], [ignore], [ignore])
141 # Hypothesis: the lock is not used in dry run mode.
142 eval "`$LIBTOOL --config | $EGREP '^(objdir)='`"
143 # Next line is internal detail.
144 lockfile=$objdir/libfoo.a.lock
145 echo stamp > $lockfile
146 AT_CHECK([$LIBTOOL --dry-run --mode=link $CC $CFLAGS $LDFLAGS ]dnl
147 [ -o libbar.la bar.lo -rpath /foo libfoo.la],
148 [], [ignore], [ignore])
149 AT_CHECK([$GREP stamp $lockfile], [], [ignore])
153 AT_SETUP([darwin gdb debug information])
155 AT_CHECK([gdb --version || (exit 77)],[ignore],[ignore],[ignore])
158 int foo (void) { return 0; }
162 extern int foo (void);
163 int bar (void) { return foo (); }
167 extern int bar(void);
169 int main() { return bar();}
172 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c bar.c],
173 [], [ignore], [ignore])
174 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c foo.c],
175 [], [ignore], [ignore])
176 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c main.c],
177 [], [ignore], [ignore])
179 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o libfoo.la foo.lo],
180 [], [ignore], [ignore])
182 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS ]dnl
183 [ -o libbar.la bar.lo -rpath /foo libfoo.la ],
184 [], [ignore], [ignore])
186 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS ]dnl
187 [ -o main main.lo libbar.la],[], [ignore], [ignore])
188 AT_CHECK([echo quit | $LIBTOOL --mode=execute gdb main],
189 [ignore], [ignore], [stderr])
191 AT_CHECK([$GREP 'Could not find object file' stderr],[1],[ignore],[ignore])
194 eval "`$LIBTOOL --config | $EGREP '^(whole_archive_flag_spec)='`"
195 case $whole_archive_flag_spec:$host_os in
200 # Remove any dSYM bundle
203 AT_CHECK([echo quit | $LIBTOOL --mode=execute gdb main],
204 [ignore], [ignore], [stderr])
205 AT_CHECK([$GREP 'Could not find object file' stderr],[1],[ignore],[ignore])
209 AT_SETUP([darwin ld warnings changing configure results])
211 AT_DATA([configure.ac],
212 [[AC_INIT([ld-stderr], ]AT_PACKAGE_VERSION[, ]AT_PACKAGE_BUGREPORT[)
213 AC_CONFIG_MACRO_DIRS([m4])
214 AM_INIT_AUTOMAKE([foreign])
217 AC_CONFIG_FILES([Makefile])
221 AT_DATA([Makefile.am],[
222 ACLOCAL_AMFLAGS = -I m4
224 LT_AT_LIBTOOLIZE([--copy --force])
225 LT_AT_AUTORECONF([--force --install])
227 AT_CHECK([./libtool --config],[ignore],[stdout],[ignore])
229 LT_AT_CONFIGURE([LDFLAGS=-L/there/is/no/dir/here])
230 AT_CHECK([./libtool --config],[ignore],[expout],[ignore])
233 AT_SETUP([darwin can lt_dlopen .dylib and .so files])
235 AT_KEYWORDS([libltdl dylib])
237 # This test requires shared library support.
238 AT_CHECK([$LIBTOOL --features | $GREP 'enable shared libraries' || exit 77],
241 eval `$LIBTOOL --config | $EGREP '^shrext_cmds='`
244 eval shared_ext=\"$shrext_cmds\"
246 eval module_ext=\"$shrext_cmds\"
248 # Only bother with this test if module extension is different from
250 AT_CHECK([test "$shared_ext" != "$module_ext" || exit 77])
252 # Skip this test when called from:
253 # make distcheck DISTCHECK_CONFIGURE_FLAGS=--disable-ltdl-install
254 AT_CHECK([case $LIBLTDL in #(
255 */_inst/lib/*) test -f "$LIBLTDL" || (exit 77) ;;
261 mkdir $prefix $libdir $bindir
263 # This code is copied from the Autobook:
264 # <http://sources.redhat.com/autobook/autobook/autobook_169.html>
265 # so if it needs changes, be sure to notify the Autobook authors
268 AT_DATA([simple-module.c],
276 run (const char *argument)
278 printf ("Hello, %s!\n", argument);
283 AT_DATA([ltdl-loader.c],
288 # define EXIT_FAILURE 1
289 # define EXIT_SUCCESS 0
294 # define PATH_MAX 255
300 #ifndef MODULE_PATH_ENV
301 # define MODULE_PATH_ENV "MODULE_PATH"
304 typedef int entrypoint (const char *argument);
306 /* Save and return a copy of the dlerror() error message,
307 since the next API call may overwrite the original. */
308 static char *dlerrordup (char *errormsg);
311 main (int argc, const char *argv[])
313 char *errormsg = NULL;
314 lt_dlhandle module = NULL;
315 entrypoint *run = NULL;
320 fprintf (stderr, "USAGE: main MODULENAME ARGUMENT\n");
324 /* Initialise libltdl. */
325 errors = lt_dlinit ();
327 /* Set the module search path. */
330 const char *path = getenv (MODULE_PATH_ENV);
333 errors = lt_dlsetsearchpath (path);
336 /* Load the module. */
338 module = lt_dlopenext (argv[1]);
340 /* Find the entry point. */
343 run = (entrypoint *) lt_dlsym (module, "run");
345 /* In principle, run might legitimately be NULL, so
346 I don't use run == NULL as an error indicator
348 errormsg = dlerrordup (errormsg);
349 if (errormsg != NULL)
351 errors = lt_dlclose (module);
358 /* Call the entry point function. */
361 int result = (*run) (argv[2]);
363 errormsg = strdup ("module entry point execution failed");
365 printf ("\t=> %d\n", result);
368 /* Unload the module, now that we are done with it. */
370 errors = lt_dlclose (module);
374 /* Diagnose the encountered error. */
375 errormsg = dlerrordup (errormsg);
379 fprintf (stderr, "%s: dlerror() failed.\n", argv[0]);
384 /* Finished with ltdl now. */
386 if (lt_dlexit () != 0)
387 errormsg = dlerrordup (errormsg);
391 fprintf (stderr, "%s: %s.\n", argv[0], errormsg);
399 /* Be careful to save a copy of the error message,
400 since the next API call may overwrite the original. */
402 dlerrordup (char *errormsg)
404 char *error = (char *) lt_dlerror ();
405 if (error && !errormsg)
406 errormsg = strdup (error);
411 : ${LTDLINCL="-I$abs_top_srcdir/libltdl"}
412 : ${LIBLTDL="$abs_builddir/../libltdl/libltdlc.la"}
414 CPPFLAGS="$LTDLINCL $CPPFLAGS"
415 LDFLAGS="$LDFLAGS -no-undefined"
417 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c simple-module.c],
418 [], [ignore], [ignore])
419 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o simple-module.la ]dnl
420 [simple-module.lo -rpath $libdir -module -avoid-version],
421 [], [ignore], [ignore])
422 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o libsimple-dylib.la ]dnl
423 [simple-module.lo -rpath $libdir -avoid-version],
424 [], [ignore], [ignore])
425 AT_CHECK([$CC $CPPFLAGS $CFLAGS -c ltdl-loader.c],
426 [], [ignore], [ignore])
427 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o ltdl-loader$EXEEXT ]dnl
428 [ltdl-loader.$OBJEXT -dlopen self $LIBLTDL],
429 [], [ignore], [ignore])
430 AT_CHECK([$LIBTOOL --mode=install cp simple-module.la $libdir/simple-module.la], [], [ignore], [ignore])
431 AT_CHECK([$LIBTOOL --mode=install cp libsimple-dylib.la $libdir/libsimple-dylib.la], [], [ignore], [ignore])
432 AT_CHECK([$LIBTOOL --mode=clean rm -f simple-module.la], [], [ignore], [ignore])
433 AT_CHECK([$LIBTOOL --mode=clean rm -f libsimple-dylib.la], [], [ignore], [ignore])
435 rm $libdir/simple-module.la
436 rm $libdir/libsimple-dylib.la
438 for dir in inst/lib "$libdir"; do
439 LT_AT_EXEC_CHECK([./ltdl-loader], [], [stdout], [ignore],
440 [$dir/simple-module World])
441 AT_CHECK([$GREP "Hello, World" stdout], [], [ignore])
442 LT_AT_EXEC_CHECK([./ltdl-loader], [], [stdout], [ignore],
443 [$dir/libsimple-dylib World])
444 AT_CHECK([$GREP "Hello, World" stdout], [], [ignore])