ltmain.in: Use func_warning for all warnings
[libtool.git] / tests / darwin.at
blob5e6e22d69ba5773c12ba4329dce5f6ab802283bf
1 # darwin.at - tests specific to Mac OS X
3 #   Copyright (C) 2008-2009, 2011-2019, 2021-2024 Free Software
4 #   Foundation, Inc.
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.
24 ####
26 AT_BANNER([Mac OS X tests])
27 AT_SETUP([darwin fat compile])
28 noskip=:
29 case $host_os in
30 darwin*) ;;
31 *) noskip=false ;;
32 esac
34 AT_DATA([simple.c] ,[[
35 int main() { return 0;}
36 ]])
38 $noskip && {
39 $CC $CPPFLAGS $CFLAGS -arch x86_64 -arch i386 -o simple simple.c 2>&1 > /dev/null || noskip=false
40 rm -f simple
43 AT_CHECK([$noskip || (exit 77)])
45 AT_DATA([foo.c],[[
46 int x=0;
47 ]])
49 AT_DATA([baz.c],[[
50 int y=0;
51 ]])
53 AT_DATA([bar.c],[[
54 extern int x;
55 int bar(void);
56 int bar() { return x;}
57 ]])
59 AT_DATA([main.c],[[
60 extern int x;
61 extern int y;
63 int main() {
64 return x+y;
66 ]])
68 mkdir bin
69 AT_DATA([bin/basename],[[
70 #! /bin/sh
72 usage="usage: $0 argument"
73 if test $# != 1; then
74                   echo $usage >&2
75                   exit 1
78 echo $1 | $SED "s|^.*/||"
79 ]])
81 chmod +x bin/basename
82 save_PATH=$PATH
83 PATH=`pwd`/bin:$PATH
84 export PATH
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])
100 PATH=$save_PATH
101 AT_CLEANUP
104 AT_SETUP([darwin concurrent library extraction])
106 AT_DATA([foo.c], [[
107 int foo (void) { return 0; }
110 AT_DATA([bar.c], [[
111 extern int foo1 (void);
112 int bar (void) { return foo1 (); }
114 cp bar.c baz.c
116 objects=
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"
122 done
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])
139 done
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])
151 AT_CLEANUP
153 AT_SETUP([darwin gdb debug information])
155 AT_CHECK([gdb --version || (exit 77)],[ignore],[ignore],[ignore])
157 AT_DATA([foo.c], [[
158 int foo (void) { return 0; }
161 AT_DATA([bar.c], [[
162 extern int foo (void);
163 int bar (void) { return foo (); }
166 AT_DATA([main.c], [[
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])
193 AT_XFAIL_IF([
194 eval "`$LIBTOOL --config | $EGREP '^(whole_archive_flag_spec)='`"
195 case $whole_archive_flag_spec:$host_os in
196 :darwin*) : ;;
197 *) false ;;
198 esac ])
200 # Remove any dSYM bundle
201 rm -rf .libs/*.dSYM
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])
207 AT_CLEANUP
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])
215 AC_PROG_CC
216 LT_INIT
217 AC_CONFIG_FILES([Makefile])
218 AC_OUTPUT
221 AT_DATA([Makefile.am],[
222 ACLOCAL_AMFLAGS = -I m4
224 LT_AT_LIBTOOLIZE([--copy --force])
225 LT_AT_AUTORECONF([--force --install])
226 LT_AT_CONFIGURE
227 AT_CHECK([./libtool --config],[ignore],[stdout],[ignore])
228 mv stdout expout
229 LT_AT_CONFIGURE([LDFLAGS=-L/there/is/no/dir/here])
230 AT_CHECK([./libtool --config],[ignore],[expout],[ignore])
231 AT_CLEANUP
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],
239          [], [ignore])
241 eval `$LIBTOOL --config | $EGREP '^shrext_cmds='`
243 module=no
244 eval shared_ext=\"$shrext_cmds\"
245 module=yes
246 eval module_ext=\"$shrext_cmds\"
248 # Only bother with this test if module extension is different from
249 # shared extension
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) ;;
256 esac], [], [ignore])
258 prefix=`pwd`/inst
259 libdir=$prefix/lib
260 bindir=$prefix/bin
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
266 # about them.
268 AT_DATA([simple-module.c],
270 #include <stdio.h>
272 #ifdef __cplusplus
273 extern "C"
274 #endif
276 run (const char *argument)
278   printf ("Hello, %s!\n", argument);
279   return 0;
283 AT_DATA([ltdl-loader.c],
285 #include <stdio.h>
286 #include <stdlib.h>
287 #ifndef EXIT_FAILURE
288 #  define EXIT_FAILURE        1
289 #  define EXIT_SUCCESS        0
290 #endif
292 #include <limits.h>
293 #ifndef PATH_MAX
294 #  define PATH_MAX 255
295 #endif
297 #include <string.h>
298 #include <ltdl.h>
300 #ifndef MODULE_PATH_ENV
301 #  define MODULE_PATH_ENV        "MODULE_PATH"
302 #endif
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;
316   int errors = 0;
318   if (argc != 3)
319     {
320       fprintf (stderr, "USAGE: main MODULENAME ARGUMENT\n");
321       exit (EXIT_FAILURE);
322     }
324   /* Initialise libltdl. */
325   errors = lt_dlinit ();
327   /* Set the module search path. */
328   if (!errors)
329     {
330       const char *path = getenv (MODULE_PATH_ENV);
332       if (path != NULL)
333         errors = lt_dlsetsearchpath (path);
334     }
336   /* Load the module. */
337   if (!errors)
338     module = lt_dlopenext (argv[1]);
340   /* Find the entry point. */
341   if (module)
342     {
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
347          in general. */
348       errormsg = dlerrordup (errormsg);
349       if (errormsg != NULL)
350         {
351           errors = lt_dlclose (module);
352           module = NULL;
353         }
354     }
355   else
356     errors = 1;
358   /* Call the entry point function. */
359   if (!errors)
360     {
361       int result = (*run) (argv[2]);
362       if (result < 0)
363         errormsg = strdup ("module entry point execution failed");
364       else
365         printf ("\t=> %d\n", result);
366     }
368   /* Unload the module, now that we are done with it. */
369   if (!errors)
370     errors = lt_dlclose (module);
372   if (errors)
373     {
374       /* Diagnose the encountered error. */
375       errormsg = dlerrordup (errormsg);
377       if (!errormsg)
378         {
379           fprintf (stderr, "%s: dlerror() failed.\n", argv[0]);
380           return EXIT_FAILURE;
381         }
382     }
384   /* Finished with ltdl now. */
385   if (!errors)
386     if (lt_dlexit () != 0)
387       errormsg = dlerrordup (errormsg);
389   if (errormsg)
390     {
391       fprintf (stderr, "%s: %s.\n", argv[0], errormsg);
392       free (errormsg);
393       exit (EXIT_FAILURE);
394     }
396   return EXIT_SUCCESS;
399 /* Be careful to save a copy of the error message,
400    since the  next API call may overwrite the original. */
401 static char *
402 dlerrordup (char *errormsg)
404   char *error = (char *) lt_dlerror ();
405   if (error && !errormsg)
406     errormsg = strdup (error);
407   return errormsg;
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])
445 done
447 AT_CLEANUP