1 # cwrapper.at -- test cwrapper compliance with standards -*- Autotest -*-
3 # Copyright (C) 2009-2019, 2021-2024 Free Software Foundation, Inc.
4 # Written by Charles Wilson, 2009
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_SETUP([cwrapper for uninstalled executables])
26 AT_KEYWORDS([libtool])
28 # make sure existing libtool is configured for shared libraries
29 AT_CHECK([$LIBTOOL --features | $GREP 'disable shared libraries' && exit 77],
40 [[int liba_func1 (int arg)
46 [[extern int liba_func1 (int arg);
50 int b = liba_func1 (a);
58 for restrictive_flags in '-Wall -Werror' '-std=c89 -Wall -Werror' '-std=c99 -Wall -Werror'; do
59 CFLAGS="$orig_CFLAGS $restrictive_flags"
60 $SED "s/LTCFLAGS=.*/&' $restrictive_flags'/" < "$orig_LIBTOOL" > ./libtool
64 # Make sure $restrictive_flags do not cause a failure
65 # themselves (e.g. because a non-gcc compiler doesn't
66 # understand them). Tru64 cc only fails when linking.
67 $LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS trivial.c || continue
69 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c liba.c],
70 [], [ignore], [ignore])
71 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -version-info=0.0.0 -no-undefined -o liba.la -rpath /foo liba.lo],
72 [], [ignore], [ignore])
73 AT_CHECK([test -f liba.la])
75 AT_CHECK([$CC $CPPFLAGS $CFLAGS -c usea.c],
76 [], [ignore], [ignore])
77 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o usea$EXEEXT usea.$OBJEXT liba.la],
78 [], [ignore], [ignore])
79 LT_AT_EXEC_CHECK([./usea], [0], [ignore], [ignore], [])
83 # Test run-time activation of wrapper debugging.
84 # This is not part of the loop above, because we
85 # need to check, not ignore, the output.
89 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c liba.c],
90 [], [ignore], [ignore])
91 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -no-undefined -o liba.la -rpath /foo liba.lo],
92 [], [ignore], [ignore])
93 AT_CHECK([test -f liba.la])
95 AT_CHECK([$CC $CPPFLAGS $CFLAGS -c usea.c],
96 [], [ignore], [ignore])
97 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o usea$EXEEXT usea.$OBJEXT liba.la],
98 [], [ignore], [ignore])
99 LT_AT_EXEC_CHECK([./usea], [0], [ignore], [stderr], [--lt-debug])
100 LT_AT_UNIFY_NL([stderr])
101 AT_CHECK([$GREP 'libtool wrapper' stderr], [0], [ignore], [ignore])
104 # Test compile-time activation of wrapper debugging.
105 # We structure this test as a loop, so that we can 'break' out of it
106 # if necessary -- even though the loop by design executes only once.
107 for debugwrapper_flags in '-DLT_DEBUGWRAPPER'; do
108 CFLAGS="$orig_CFLAGS $debugwrapper_flags"
109 $SED -e "s/LTCFLAGS=.*/&' $debugwrapper_flags'/" \
110 -e "s/^lt_option_debug=/lt_option_debug=1/" \
111 < "$orig_LIBTOOL" > ./libtool
114 # Make sure $debugwrapper_flags do not cause a failure
115 # themselves (e.g. because a non-gcc compiler doesn't
116 # understand them). Tru64 cc only fails when linking.
117 $LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS trivial.c || continue
119 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c liba.c],
120 [], [ignore], [ignore])
121 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -no-undefined -o liba.la -rpath /foo liba.lo],
122 [], [ignore], [ignore])
123 AT_CHECK([test -f liba.la])
125 AT_CHECK([$CC $CPPFLAGS $CFLAGS -c usea.c],
126 [], [ignore], [ignore])
127 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o usea$EXEEXT usea.$OBJEXT liba.la],
128 [], [ignore], [ignore])
129 LT_AT_EXEC_CHECK([./usea], [0], [ignore], [stderr], [])
130 LT_AT_UNIFY_NL([stderr])
131 AT_CHECK([$GREP 'libtool wrapper' stderr], [0], [ignore], [ignore])
138 AT_SETUP([cwrapper string length])
140 eval "`$LIBTOOL --config | $EGREP '^(objdir)='`"
143 [[int liba_func1 (int arg)
149 [[extern int liba_func1 (int arg);
153 int b = liba_func1 (a);
154 if (b == 3) return 0;
159 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c liba.c],
160 [], [ignore], [ignore])
161 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -no-undefined ]dnl
162 [-o liba.la -rpath /foo liba.lo],
163 [], [ignore], [ignore])
164 AT_CHECK([$CC $CPPFLAGS $CFLAGS -c usea.c],
165 [], [ignore], [ignore])
168 # Make sure PATH is at least 250 chars, which should force line breaks
174 for dirpath in $PATH; do
180 until $ECHO "PATH=$PATH" | $GREP 'PATH=.\{250\}'; do
181 PATH=$PATH$PATH_SEPARATOR$dirpath
185 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -no-fast-install ]dnl
186 [-o usea$EXEEXT usea.$OBJEXT liba.la],
187 [], [ignore], [ignore])
189 # Skip if no cwrapper is generated.
190 AT_CHECK([test -f "$objdir/lt-usea.c" || exit 77])
192 # Try to make sure the test is relevant.
193 AT_CHECK([$GREP ' *fputs' $objdir/lt-usea.c > /dev/null])
194 # Check for no overly long fputs.
195 AT_CHECK([$GREP ' *fputs.\{250\}' $objdir/lt-usea.c], [1])
201 AT_SETUP([cwrapper and installed shared libraries])
202 AT_KEYWORDS([libtool])
204 # make sure existing libtool is configured for shared libraries
205 AT_CHECK([$LIBTOOL --features | $GREP 'enable shared libraries' || exit 77],
208 LDFLAGS="$LDFLAGS -no-undefined"
213 mkdir $inst $libdir $bindir
215 # Build the library in a separate directory to avoid the special case
216 # of loading from the current directory.
220 # build and install "old" library version
222 int liba_ver (void) { return 1; }
224 AT_CHECK([$LIBTOOL --mode=compile --tag=CC $CC $CPPFLAGS $CFLAGS -c a.c],
225 [], [ignore], [ignore])
226 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -version-info=0.0.0 -o liba.la -rpath $libdir a.lo],
227 [], [ignore], [ignore])
228 AT_CHECK([$LIBTOOL --mode=install $lt_INSTALL liba.la $libdir],
229 [], [ignore], [ignore])
231 # build a new library version
233 int liba_ver (void) { return 2; }
235 AT_CHECK([$LIBTOOL --mode=compile --tag=CC $CC $CPPFLAGS $CFLAGS -c a.c],
236 [], [ignore], [ignore])
237 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -version-info=0.0.0 -o liba.la -rpath $libdir a.lo],
238 [], [ignore], [ignore])
242 # build and run test application
244 extern int liba_ver (void);
247 int r = (liba_ver () == 2) ? 0 : 1;
252 AT_CHECK([$CC $CPPFLAGS $CFLAGS -c m.c], [], [ignore], [ignore])
254 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o m1$EXEEXT m.$OBJEXT foo/liba.la],
255 [], [ignore], [ignore])
256 LT_AT_EXEC_CHECK([./m1], [0], [ignore], [ignore], [])
258 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o m2$EXEEXT m.$OBJEXT foo/liba.la -L$inst/lib],
259 [], [ignore], [ignore])
260 LT_AT_EXEC_CHECK([./m2], [0], [ignore], [ignore], [])