ltmain.in: Use func_warning for all warnings
[libtool.git] / tests / demo.at
blobfeb71dcda1f8aab7d685d4a0df4870f699a0f7ab
1 # demo.at -- Linking and loading. -*- Autotest -*-
3 #   Copyright (C) 2003-2004, 2011-2019, 2021-2024 Free Software
4 #   Foundation, Inc.
5 #   Written by Gary V. Vaughan, 2003
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 ####
27 AT_BANNER([Linking and loading.])
29 ## ------------------------------------------- ##
30 ## Some functions shared by later tests cases. ##
31 ## ------------------------------------------- ##
33 # This function needs to be used, rather than 'exit', when a 'trap' handler is
34 # in effect that refers to $?.
35 func_exit ()
37   (exit $1); exit $1
40 func_restore_files ()
42     test -n "$objdir" || exit 1
43     mv -f "$objdir"/temp/libs/* "$objdir"
44     mv -f "$objdir/temp/libhello.la" .
45     rm -rf "$objdir/temp"
48 func_save_files ()
50     test -n "$objdir" || exit 1
51     $lt_INSTALL -d "$objdir/temp/libs"
52     cp -f libhello.la "$objdir/temp"
53     cp -f "$objdir"/libhello.* "$objdir/lt-hell$EXEEXT" "$objdir/temp/libs"
57 # _LT_DEMO_SETUP
58 # --------------
59 m4_define([_LT_DEMO_SETUP],
60 [AT_DATA([configure.ac],
61 [[AC_INIT([demo], ]AT_PACKAGE_VERSION[, ]AT_PACKAGE_BUGREPORT[)
62 AC_CONFIG_AUX_DIR([build-aux])
63 AC_CONFIG_MACRO_DIRS([m4])
64 AM_INIT_AUTOMAKE
65 AC_PROG_CC
67 LT_INIT([dlopen win32-dll])
68 AC_SUBST([LIBTOOL_DEPS])
69 STATIC=
70 test yes = "$enable_static" && STATIC=-static
71 AC_SUBST([STATIC])
73 case $lt_cv_sys_global_symbol_pipe in
74   ?*) binary_helldl=yes ;;
75 esac
76 AM_CONDITIONAL([BINARY_HELLDL], [test yes = "$binary_helldl"])
78 LT_LIB_M
79 AC_CONFIG_FILES([Makefile])
80 AC_CONFIG_HEADERS([config.h:config.in.h])
81 AC_OUTPUT
82 ]])
84 AT_DATA([Makefile.am],
85 [[AUTOMAKE_OPTIONS = no-dependencies foreign
86 ACLOCAL_AMFLAGS = -I m4
88 # Build a libtool library, libhello.la for installation in libdir.
89 lib_LTLIBRARIES = libhello.la
90 libhello_la_SOURCES = hello.c foo.c
91 libhello_la_LIBADD = $(LIBM)
92 libhello_la_LDFLAGS = -no-undefined -version-info 3:12:1
93 libhello_la_CPPFLAGS = $(AM_CPPFLAGS) -DBUILDING_LIBHELLO
95 include_HEADERS = foo.h
97 if BINARY_HELLDL
98 BUILD_helldl = helldl
99 else
100 BUILD_helldl =
101 endif
103 bin_PROGRAMS = hell hell_static $(BUILD_helldl)
105 # Build hell from main.c and libhello.la
106 hell_SOURCES = main.c
107 hell_LDADD = libhello.la
109 # Create a statically linked version of hell.
110 hell_static_SOURCES = main.c
111 hell_static_LDADD = libhello.la
112 hell_static_LDFLAGS = $(STATIC)
114 if BINARY_HELLDL
116 # Create a version of hell that does a preloaded dlopen.
117 helldl_SOURCES = dlmain.c
118 helldl_LDFLAGS = -export-dynamic -dlpreopen libhello.la
119 helldl_DEPENDENCIES = libhello.la
121 else
123 # Create a script that says that -dlopen is not supported.
124 bin_SCRIPTS = helldl
125 helldl helldl$(EXEEXT):
126         rm -rf $@
127         echo '#! /bin/sh' > $@
128         echo 'echo sorry, -dlopen is unsupported' >> $@
129         chmod +x $@
131 endif
133 libtool: $(LIBTOOL_DEPS)
134         $(SHELL) ./config.status --recheck
136 include $(srcdir)/demo.mk
139 AT_DATA([demo.mk],
140 [[## Don't abort for lack of demo.mk
143 AT_DATA([foo.h],
144 [[#ifndef FOO_H
145 #define FOO_H
147 /* At some point, cygwin will stop defining __CYGWIN32__, but b19 and
148  * earlier do not define __CYGWIN__.  This snippet allows us to check
149  * for __CYGWIN__ reliably for both current, old, and (probable) future
150  * releases.
151  */
152 #ifdef __CYGWIN32__
153 #  ifndef __CYGWIN__
154 #    define __CYGWIN__
155 #  endif
156 #endif
158 #if (defined _WIN32 || defined _WIN32_WCE) && !defined __GNUC__
159 # ifdef BUILDING_LIBHELLO
160 #  ifdef DLL_EXPORT
161 #   define LIBHELLO_SCOPE extern __declspec (dllexport)
162 #  endif
163 # else
164 #  define LIBHELLO_SCOPE extern __declspec (dllimport)
165 # endif
166 #endif
167 #ifndef LIBHELLO_SCOPE
168 # define LIBHELLO_SCOPE extern
169 #endif
171 /* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
172 #if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
173 /* DATA imports from DLLs on WIN32 can't be const, because runtime
174    relocations are performed -- see ld's documentation on pseudo-relocs.  */
175 # define LT_DLSYM_CONST
176 #elif defined __osf__
177 /* This system does not cope well with relocations in const data.  */
178 # define LT_DLSYM_CONST
179 #else
180 # define LT_DLSYM_CONST const
181 #endif
183 /* Silly constants that the functions return. */
184 #define HELLO_RET 0xe110
185 #define FOO_RET 0xf00
187 #ifdef __cplusplus
188 extern "C" {
189 #endif
191 int foo (void);
192 int hello (void);
193 LIBHELLO_SCOPE int nothing;
195 #ifdef __cplusplus
197 #endif
199 #endif
202 AT_DATA([foo.c],
203 [[#include <config.h>
204 #include <stdio.h>
205 #include <math.h>
207 #include "foo.h"
209 /* Give a global variable definition. */
210 int nothing = FOO_RET;
212 int foo (void) {
213   printf ("cos (0.0) = %g\n", (double) cos ((double) 0.0));
214   return FOO_RET;
218 AT_DATA([hell1.c],
219 [[#include <config.h>
220 int hell1 (void) { return 1; }
223 AT_DATA([hell2.c],
224 [[#include <config.h>
225 int hell2 (void) { return 2; }
228 AT_DATA([hello.c],
229 [[#include <config.h>
230 #include <stdio.h>
232 #include "foo.h"
234 int hello (void) {
235   printf ("** This is not GNU Hello. There is no built-in mail reader. **\n");
236   return HELLO_RET;
240 AT_DATA([main.c],
241 [[#include <config.h>
242 #include <stdio.h>
244 #include "foo.h"
246 int main ()
248   printf ("Welcome to GNU Hell!\n");
250   /* Try assigning to the nothing variable. */
251   nothing = 1;
253   /* Just call the functions and check return values. */
254   if (foo () != FOO_RET)
255     return 1;
257   if (hello () != HELLO_RET)
258     return 2;
260   return 0;
264 AT_DATA([dlmain.c],
265 [[#include <config.h>
266 #include <stdio.h>
267 #include <string.h>
269 #include "foo.h"
271 #define STREQ !strcmp
273 #define lt_preloaded_symbols lt__PROGRAM__LTX_preloaded_symbols
275 typedef struct
277   const char *name;
278   void *address;
279 } lt_dlsymlist;
281 extern LT_DLSYM_CONST lt_dlsymlist lt_preloaded_symbols[];
283 int main ()
285   const lt_dlsymlist *s;
286   int (*pfoo)() = 0;
287   int (*phello)() = 0;
288   int *pnothing = 0;
290   printf ("Welcome to *modular* GNU Hell!\n");
292   /* Look up the symbols we require for this demonstration. */
293   s = lt_preloaded_symbols;
294   while (s->name)
295     {
296       if (s->address) {
297         const char *name = s->name;
298         printf ("found symbol: %s\n", name);
299         if (STREQ ("@INIT@", name))
300           ((void(*)())s->address)();
301         if (STREQ ("hello", name))
302           phello = (int(*)())s->address;
303         else if (STREQ ("foo", name))
304           pfoo = (int(*)())s->address;
305         else if (STREQ ("nothing", name))
306 #ifndef _WIN32
307           /* In an ideal world we could do this... */
308           pnothing = (int*)s->address;
309 #else /* !_WIN32 */
310           /* In an ideal world a shared lib would be able to export data */
311           pnothing = (int*)&nothing;
312 #endif
313       } else
314         printf ("found file: %s\n", s->name);
315       s ++;
316     }
318   /* Try assigning to the nothing variable. */
319   if (pnothing)
320     *pnothing = 1;
321   else
322     fprintf (stderr, "did not find the 'nothing' variable\n");
324   /* Just call the functions and check return values. */
325   if (pfoo)
326     {
327       if ((*pfoo) () != FOO_RET)
328         return 1;
329     }
330   else
331     fprintf (stderr, "did not find the 'foo' function\n");
333   if (phello)
334     {
335       if ((*phello) () != HELLO_RET)
336         return 3;
337     }
338   else
339     fprintf (stderr, "did not find the 'hello' function\n");
341   return 0;
345 LT_AT_HOST_DATA([expout],
346 [[Welcome to GNU Hell!
347 cos (0.0) = 1
348 ** This is not GNU Hello. There is no built-in mail reader. **
351 prefix=`pwd`/_inst
352 ]) # _LT_DEMO_SETUP
355 # _LT_CHECK_EXECUTE([TARGETS])
356 # ----------------------------
357 # Run the listed make rules, and check that the built binaries work.
358 m4_define([_LT_CHECK_EXECUTE],
359 [LT_AT_CHECK_EXECUTE([$1],
360         [./hell_static], [./hell])
361 AT_CHECK([./helldl$EXEEXT |
362     $EGREP '(Welcome to .*GNU Hell|unsupported)'], 0, [ignore])
366 # _LT_CHECK_INSTALL
367 # -----------------
368 # Run the make install rule, and check that installed binaries work too.
369 m4_define([_LT_CHECK_INSTALL],
370 [# Windows hosts search for dlls in the command path.
371 PATH=$prefix/lib:$PATH
373 LT_AT_CHECK_EXECUTE([install],
374         [$prefix/bin/hell_static], [$prefix/bin/hell])
375 AT_CHECK([$prefix/bin/helldl$EXEEXT |
376     $EGREP '(Welcome to .*GNU Hell|unsupported)'], 0, [ignore])
380 ## ------------ ##
381 ## Demo static. ##
382 ## ------------ ##
384 AT_SETUP([link against a preloaded static library])
386 _LT_DEMO_SETUP
388 LT_AT_CHECK_CONFIG([--disable-shared],
389                    [^build_old_libs=yes], [^build_libtool_libs=no])
390 _LT_CHECK_EXECUTE
391 _LT_CHECK_INSTALL
392 LT_AT_CHECK_UNINSTALL
394 AT_CLEANUP
397 ## ------------ ##
398 ## Demo shared. ##
399 ## ------------ ##
401 AT_SETUP([build and dynamically load a module])
403 _LT_DEMO_SETUP
405 LT_AT_CHECK_CONFIG([--disable-static],
406                    [^build_old_libs=no], [^build_libtool_libs=yes])
407 _LT_CHECK_EXECUTE
408 _LT_CHECK_INSTALL
409 LT_AT_CHECK_UNINSTALL
411 AT_CLEANUP
414 ## ---------- ##
415 ## Demo conf. ##
416 ## ---------- ##
418 AT_SETUP([preload static and dynamic module])
420 _LT_DEMO_SETUP
422 LT_AT_CHECK_CONFIG([],
423                    [^build_old_libs=yes], [^build_libtool_libs=yes])
424 _LT_CHECK_EXECUTE
425 _LT_CHECK_INSTALL
426 LT_AT_CHECK_UNINSTALL
428 AT_CLEANUP
431 ## ------------ ##
432 ## Demo deplib. ##
433 ## ------------ ##
435 # This is one of the essential tests for deplibs_check_method=pass_all.
436 # If this one passes with pass_all, it is likely that pass_all works.
438 AT_SETUP([deplibs_check_method])
440 _LT_DEMO_SETUP
442 AT_DATA([demo.mk],
443 [[EXTRA_LIBRARIES = libhell0.a
444 libhell0_a_SOURCES =
445 libhell0_a_LIBADD = hello.$(OBJEXT) foo.$(OBJEXT)
446 EXTRA_LTLIBRARIES = libhell1.la libhell2.la
447 libhell1_la_SOURCES = hell1.c
448 libhell1_la_LIBADD = -L. -lhell0
449 libhell1_la_LDFLAGS = -no-undefined -rpath $(libdir)
450 libhell1_la_DEPENDENCIES = libhell0.a
451 libhell2_la_SOURCES = hell2.c
452 libhell2_la_LIBADD = -L. -lhell0
453 libhell2_la_LDFLAGS = -no-undefined -rpath $(libdir)
454 libhell2_la_DEPENDENCIES = libhell0.a
455 EXTRA_PROGRAMS = hell0
456 hell0_SOURCES = main.c
457 hell0_LDADD = libhell1.la libhell2.la $(LIBM)
459 # 'hell0' in EXTRA_PROGRAMS gets translated to 'hell0.exe'; but we
460 # must explicitly list the wrapper script 'hell0'.  (bin_PROGRAMS
461 # are handled seamlessly by automake rules; the extra step is only
462 # necessary for EXTRA_PROGRAMS)
463 CLEANFILES = $(EXTRA_LIBRARIES) $(EXTRA_LTLIBRARIES) $(EXTRA_PROGRAMS) hell0
465 deplibs-check: hell0$(EXEEXT)
468 LT_AT_CHECK_CONFIG([--disable-static])
469 LT_AT_MAKE([deplibs-check])
470 LT_AT_EXEC_CHECK([./hell0], 0, [expout])
472 AT_CLEANUP
475 ## ------------ ##
476 ## Demo nofast. ##
477 ## ------------ ##
479 AT_SETUP([disable fast install])
481 _LT_DEMO_SETUP
483 LT_AT_CHECK_CONFIG([--enable-fast-install=no])
484 AT_CHECK([$EGREP '^hardcode_action=relink' libtool && (exit 77)], 1)
486 _LT_CHECK_EXECUTE
487 _LT_CHECK_INSTALL
488 LT_AT_CHECK_UNINSTALL
490 AT_CLEANUP
493 ## --------- ##
494 ## Demo pic. ##
495 ## --------- ##
497 AT_SETUP([force PIC objects])
499 _LT_DEMO_SETUP
501 LT_AT_CHECK_CONFIG([--with-pic])
502 _LT_CHECK_EXECUTE
504 AT_CLEANUP
507 ## ----------- ##
508 ## Demo nopic. ##
509 ## ----------- ##
511 AT_SETUP([force non-PIC objects])
513 AT_CHECK([case $host in
514 hppa*|amd64*|x86_64*|s390*)
515   # These hosts cannot use non-PIC shared libs
516   exit 77 ;;
517 *-solaris*|*-sunos*)
518   # Libtool does not build non-PIC shared libs on these hosts
519   exit 77 ;;
520 esac
522 if test "X$build" = "X$host" && test -d "/etc/selinux"; then
523         _selinux=`getenforce 2>/dev/null || echo "Disabled"`
524         case $_selinux in
525         *Enforcing)
526                 _sebool_allow_execmod=`getsebool allow_execmod 2>/dev/null`
527                 case $_sebool_allow_execmod in
528                 *off)
529                         # SELinux policy disallows non-PIC
530                         exit 77
531                         ;;
532                 esac
533                 ;;
534         esac
538 _LT_DEMO_SETUP
539 LT_AT_CHECK_CONFIG([--with-pic=no])
540 _LT_CHECK_EXECUTE
542 AT_CLEANUP
545 ## -------------- ##
546 ## Demo hardcode. ##
547 ## -------------- ##
549 AT_SETUP([hardcoding library path])
551 _LT_DEMO_SETUP
553 AT_DATA([demo.mk],
554 [[hardcode_tests = hc-direct hc-libflag hc-libpath hc-minusL
555 CLEANFILES = $(hardcode_tests)
557 # Unfortunately, in order to test libtool thoroughly, we need access
558 # to its private directory.
559 objdir = `$(LIBTOOL) --config | $(SED) -n -e 's/^objdir=\(.*\)$$/\1/p'`
561 # Test programs to see what gets hardcoded.
562 .PHONY: hardcode
563 hardcode: $(hardcode_tests)
564 SET_HARDCODE_FLAGS = \
565   eval `$(LIBTOOL) --config | $(SED) -n -e '/^hardcode_.*=/p; /^wl=/p'`
566 hc-direct: $(hell_OBJECTS) $(hell_DEPENDENCIES) $(libdir)/libhello.la
567         @rm -f hc-direct
568         @echo "You may ignore any linking errors from the following command:"
569         @shlib=./$(objdir)/libhello.a; \
570           eval "`$(GREP) '^library_names' libhello.la`"; \
571           for lib in $$library_names; do \
572             shlib="./$(objdir)/$$lib"; \
573           done; \
574           $(SET_HARDCODE_FLAGS); \
575           libdir=$(libdir); \
576           flag=`eval echo \"$$hardcode_libdir_flag_spec\"`; \
577           echo "$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(hell_OBJECTS) $$shlib $(LIBS) $(LIBM) $$flag || echo unsupported > $@"; \
578           eval "$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(hell_OBJECTS) $$shlib $(LIBS) $(LIBM) $$flag || echo unsupported > $@"
580 hc-libflag: $(hell_OBJECTS) $(hell_DEPENDENCIES) $(libdir)/libhello.la
581         @$(SET_HARDCODE_FLAGS); \
582           libdir=`pwd`/$(objdir); \
583           flag=`eval echo \"$$hardcode_libdir_flag_spec\"`; \
584           if test -z "$$flag"; then \
585             echo "echo unsupported > $@"; \
586             echo unsupported > $@ || status="$$?"; \
587           else \
588             echo "$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(hell_OBJECTS) $$flag -L$(libdir) -lhello $(LIBS) $(LIBM)"; \
589             $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(hell_OBJECTS) $$flag -L$(libdir) -lhello $(LIBS) $(LIBM) || status="$$?"; \
590           fi; \
591           exit $$status
593 hc-libpath: $(hell_OBJECTS) $(hell_DEPENDENCIES) $(libdir)/libhello.la
594         @rm -f hc-libpath
595         @echo "You may ignore any linking errors from the following command:"
596         @$(SET_HARDCODE_FLAGS); \
597           eval `$(LIBTOOL) --config | $(GREP) '^shlibpath_var='`; \
598           libdir=$(libdir); \
599           flag=`eval echo \"$$hardcode_libdir_flag_spec\"`; \
600           echo "$$shlibpath_var=./$(objdir) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(hell_OBJECTS) -lhello $(LIBS) $(LIBM) $$flag || echo unsupported > $@"; \
601           eval "$$shlibpath_var=./$(objdir) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(hell_OBJECTS) -lhello $(LIBS) $(LIBM) $$flag || echo unsupported > $@"
603 hc-minusL: $(hell_OBJECTS) $(hell_DEPENDENCIES)
604         @rm -f hc-minusL
605         @$(SET_HARDCODE_FLAGS); \
606           libdir=$(libdir); \
607           flag=`eval echo \"$$hardcode_libdir_flag_spec\"`; \
608           echo "$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(hell_OBJECTS) -L./$(objdir) -lhello $(LIBS) $(LIBM) $$flag || echo unsupported > $@"; \
609           eval "$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(hell_OBJECTS) -L./$(objdir) -lhello $(LIBS) $(LIBM) $$flag || echo unsupported > $@"
612 LT_AT_CHECK_CONFIG([--disable-static])
613 _LT_CHECK_EXECUTE
614 _LT_CHECK_INSTALL
616 eval `$EGREP '^library_names=' libhello.la`
617 AT_CHECK([test -n "$library_names" || (exit 77)])
619 # Extra tools we may need
620 : ${DUMPSTABS="dumpstabs"}
622 LT_AT_MAKE([hardcode])
624 eval "`$LIBTOOL --config | $EGREP '^hardcode_(direct|minus_L|shlibpath_var|libdir_flag_spec)='`"
626 AT_CHECK([[exit_status=0
627 func_hardcode_filter_fp ()
629   $FGREP -v "LT_OBJDIR \"$objdir/\"" 2>/dev/null
631 for file in hc-*; do
632   case $file in
633   hc-direct)  expected="$hardcode_direct" ;;
634   hc-libpath) expected="$hardcode_shlibpath_var" ;;
635   hc-minusL)  expected="$hardcode_minus_L" ;;
637   hc-libflag)
638     if test -n "$hardcode_libdir_flag_spec"; then
639       expected=yes
640     else
641       expected=unsupported
642     fi
643     ;;
645   *)
646     continue
647     ;;
648   esac
650   # Discover whether the objdir really was hardcoded.
651   hardcoded=no
653   # Solaris cc may store the command line in a debugging section,
654   # which leads to false positives.  Unfortunately, Solaris strip
655   # is not capable to remove the section (unlike GNU binutils strip).
656   # So we use dumpstabs if it seems to work.
657   if { $DUMPSTABS -d $file; } >/dev/null 2>&1; then
658     if $DUMPSTABS -d $file 2>/dev/null | $FGREP "$objdir" >/dev/null 2>&1; then
659       hardcoded=yes
660     else
661       hardcoded=no
662     fi
664   # At least AIX fgrep doesn't work for binary files, and AIX also
665   # doesn't have strings(1), so we need this strange conversion
666   # (which only works on ASCII).
667   # AIX fgrep also has a limited line length, so we turn unprintable
668   # characters into newlines.
669   elif cat $file | (tr '\000-\037\200-\377' '\n' || cat) 2>/dev/null \
670                  | func_hardcode_filter_fp | $FGREP "$objdir" > /dev/null 2>&1; then
671     hardcoded=yes
673   elif cat $file | func_hardcode_filter_fp | $FGREP "$objdir" > /dev/null 2>&1; then
674     # We retry fgrep without tr, in case the above lead to a false negative.
675     hardcoded=yes
676   elif ($SED -e '1!d' $file | $GREP 'unsupported') >/dev/null 2>&1; then
677     hardcoded=unsupported
678   fi
680   # Check the result.
681   case $hardcoded in
682   yes)
683     if test yes = "$expected"; then
684       echo "$objdir was hardcoded in '$file', as libtool expected"
685     else
686       echo "$objdir was hardcoded in '$file', which fooled libtool" 1>&2
687       exit_status=1
688     fi
689     ;;
691   no)
692     if test no = "$expected"; then
693       echo "$objdir was not hardcoded in '$file', as libtool expected"
694     else
695       echo "$objdir was not hardcoded in '$file', which fooled libtool" 1>&2
696       exit_status=1
697     fi
698     ;;
700   unsupported)
701     if test unsupported = "$expected"; then
702       echo "'$file' was not linked properly, as libtool expected"
703     else
704       echo "'$file' was not linked properly, which fooled libtool" 1>&2
705       exit_status=1
706     fi
707     ;;
708   esac
709 done
710 ]], 0, [ignore])
712 AT_CLEANUP
715 ## ------------ ##
716 ## Demo relink. ##
717 ## ------------ ##
719 AT_SETUP([binary relinking at install time])
720 AT_KEYWORDS([interactive])dnl This test causes a popup on Windows
722 _LT_DEMO_SETUP
724 LT_AT_CHECK_CONFIG
725 _LT_CHECK_EXECUTE
726 _LT_CHECK_INSTALL
728 # Check to make sure we have a dynamic library.
729 eval `$EGREP '^library_names=' libhello.la`
730 AT_CHECK([test -n "$library_names" || (exit 77)])
732 func_save_files
733 # AIX 5.3 '/bin/sh' will invoke the trap for 0 at the end of a
734 # function, so we set the trap outside of a function to be portable.
735 trap func_restore_files 0 1 2 13 15
737 eval "`$LIBTOOL --config | $EGREP '^shlibpath_overrides_runpath='`"
738 eval "`$LIBTOOL --config | $EGREP '^hardcode_(action|direct|into_libs)='`"
740 # Allow the binary to link on-demand if need be.
741 ./hell$EXEEXT >/dev/null || :
743 # Remove libhello.la from build tree.
744 rm -f libhello.la "$objdir"/libhello.*
746 # Either uninstalled ./hell will run using the just installed libraries
747 # when the uninstalled libs are missing, or relinking at install time
748 # is necessary, and the uninstalled ./hell has only the uninstalled
749 # library paths hardcoded.
750 AT_CHECK([./hell$EXEEXT >/dev/null || test relink,yes = "$hardcode_action,$hardcode_direct"])
752 # Link an incomplete libhello.la.
753 LT_AT_MAKE([libhello.la], [libhello_la_OBJECTS=hello.lo])
754 AT_CHECK([test -f libhello.la])
756 # Try running uninstalled ./hell with only broken libhello.la in build tree.
757 # If the following has normal exit status, shlibpath_overrides_runpath is
758 # wrong, and should be set to 'no' on this host.
759 # The unusual '|| (exit 1)' is to normalize all non-zero exit statuses.
760 LT_AT_CHECK([./hell || (exit 1)], 1, [ignore], [ignore])
762 test relink = "$hardcode_action" ||
763 test yes = "$shlibpath_overrides_runpath" ||
765     AT_CHECK([rm -f $objdir/lt-hell$EXEEXT])
766     AT_CHECK([cp $objdir/hell$EXEEXT $objdir/lt-hell$EXEEXT])
768     # Running demo/hell with installed libhello.la.
769     # If the following check fails, then shlibpath_overrides_runpath is
770     # wrong, and should be set to 'yes' on this host.
771     LT_AT_CHECK([./hell], 0, [expout])
774 func_restore_files
776 # Undo the effect of the previous 'trap' command. Some shellology:
777 # We cannot use "trap - 0 1 2 3 13 15", because Solaris sh would attempt to
778 # execute the command "-". "trap '' ..." is fine only for signal 0 (= normal
779 # exit); for the others we need to call 'exit' explicitly. The value of $? is
780 # 128 + signal number and is set before the trap-registered command is run.
781 trap '' 0
782 trap 'func_exit $?' 1 2 3 13 15
784 AT_CLEANUP
787 ## ----------------- ##
788 ## Demo noinst link. ##
789 ## ----------------- ##
791 AT_SETUP([uninstalled libraries have priority])
793 _LT_DEMO_SETUP
795 LT_AT_CHECK_CONFIG
796 _LT_CHECK_EXECUTE
797 _LT_CHECK_INSTALL
799 # Remove libhello.la and hell from build tree.
800 rm -f libhello.la "hell$EXEEXT"
802 # If this check fails (i.e. the make succeeds), then the installed library
803 # was used, which is wrong.
804 AT_CHECK([$as_unset LIBTOOL; $as_unset LIBTOOLIZE; $MAKE hell$EXEEXT libhello_la_OBJECTS=hello.lo || (exit 1)],
805          [1], [ignore], [ignore])
807 AT_CLEANUP
810 ## ----------- ##
811 ## Pdemo conf. ##
812 ## ----------- ##
814 AT_SETUP([linking with long file names])
816 _LT_DEMO_SETUP
818 AT_DATA([Makefile.am],
819 [[AUTOMAKE_OPTIONS = no-dependencies foreign
820 ACLOCAL_AMFLAGS = -I m4
822 # Build a libtool library, libhello.la for installation in libdir.
823 lib_LTLIBRARIES = libhello.la
824 libhello_la_SOURCES = longer_file_name_hello.c longer_file_name_foo.c longer_file_name_foo2.c
825 libhello_la_LIBADD = $(LIBM)
826 libhello_la_LDFLAGS = -no-undefined -version-info 3:12:1
827 libhello_la_CPPFLAGS = $(AM_CPPFLAGS) -DBUILDING_LIBHELLO
829 include_HEADERS = foo.h
831 if BINARY_HELLDL
832 BUILD_helldl = helldl
833 else
834 BUILD_helldl =
835 endif
837 bin_PROGRAMS = hell hell_static $(BUILD_helldl)
839 # Build hell from longer_file_name_main.c and libhello.la
840 hell_SOURCES = longer_file_name_main.c
841 hell_LDADD = libhello.la
843 # Create a statically linked version of hell.
844 hell_static_SOURCES = longer_file_name_main.c
845 hell_static_LDADD = libhello.la
846 hell_static_LDFLAGS = $(STATIC)
848 if BINARY_HELLDL
850 # Create a version of hell that does a preloaded dlopen.
851 helldl_SOURCES = longer_file_name_dlmain.c
852 helldl_LDFLAGS = -export-dynamic -dlpreopen libhello.la
853 helldl_DEPENDENCIES = libhello.la
855 else
857 # Create a script that says that -dlopen is not supported.
858 bin_SCRIPTS = helldl
859 helldl helldl$(EXEEXT):
860         rm -rf $@
861         echo '#! /bin/sh' > $@
862         echo 'echo sorry, -dlopen is unsupported' >> $@
863         chmod +x $@
865 endif
867 libtool: $(LIBTOOL_DEPS)
868         $(SHELL) ./config.status --recheck
871 AT_DATA([main.c],
872 [[#include <config.h>
873 #include <stdio.h>
875 #include "foo.h"
877 int main ()
879   printf ("Welcome to GNU Hell!\n");
881   /* Try assigning to the nothing variable. */
882   nothing = 1;
884   /* Just call the functions and check return values. */
885   if (foo () != FOO_RET)
886     return 1;
888   if (foo2 () != FOO_RET)
889     return 1;
891   if (hello () != HELLO_RET)
892     return 2;
894   return 0;
898 AT_DATA([foo.h],
899 [[#ifndef FOO_H
900 #define FOO_H
902 /* At some point, cygwin will stop defining __CYGWIN32__, but b19 and
903  * earlier do not define __CYGWIN__.  This snippet allows us to check
904  * for __CYGWIN__ reliably for both current, old, and (probable) future
905  * releases.
906  */
907 #ifdef __CYGWIN32__
908 #  ifndef __CYGWIN__
909 #    define __CYGWIN__
910 #  endif
911 #endif
913 #if (defined _WIN32 || defined _WIN32_WCE) && !defined __GNUC__
914 # ifdef BUILDING_LIBHELLO
915 #  ifdef DLL_EXPORT
916 #   define LIBHELLO_SCOPE extern __declspec (dllexport)
917 #  endif
918 # else
919 #  define LIBHELLO_SCOPE extern __declspec (dllimport)
920 # endif
921 #endif
922 #ifndef LIBHELLO_SCOPE
923 # define LIBHELLO_SCOPE extern
924 #endif
926 /* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
927 #if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
928 /* DATA imports from DLLs on WIN32 can't be const, because runtime
929    relocations are performed -- see ld's documentation on pseudo-relocs.  */
930 # define LT_DLSYM_CONST
931 #elif defined __osf__
932 /* This system does not cope well with relocations in const data.  */
933 # define LT_DLSYM_CONST
934 #else
935 # define LT_DLSYM_CONST const
936 #endif
938 /* Silly constants that the functions return. */
939 #define HELLO_RET 0xe110
940 #define FOO_RET 0xf00
942 #ifdef __cplusplus
943 extern "C" {
944 #endif
946 int foo (void);
947 int foo2 (void);
948 int hello (void);
949 LIBHELLO_SCOPE int nothing;
951 #ifdef __cplusplus
953 #endif
955 #endif
958 AT_DATA([foo2.c],
959 [[#include <config.h>
960 #include <stdio.h>
961 #include <math.h>
963 #include "foo.h"
965 int foo2 (void) {
966   printf ("foo2 cos (0.0) = %g\n", (double) cos ((double) 0.0));
967   return FOO_RET;
971 LT_AT_HOST_DATA([expout],
972 [[Welcome to GNU Hell!
973 cos (0.0) = 1
974 foo2 cos (0.0) = 1
975 ** This is not GNU Hello. There is no built-in mail reader. **
978 for file in dlmain.c foo.c foo2.c hello.c main.c; do
979   mv $file longer_file_name_$file
980 done
982 LT_AT_CHECK_CONFIG
983 _LT_CHECK_EXECUTE
984 _LT_CHECK_INSTALL
986 AT_CLEANUP