ltmain.in: Use func_warning for all warnings
[libtool.git] / tests / cwrapper.at
blobc1d9c18a1cb98d2727535499a03c6e1e2669df39
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.
23 ####
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],
30          [1], [ignore])
32 AT_DATA([trivial.c],
34 int main (void)
36   return 0;
38 ]])
39 AT_DATA([liba.c],
40 [[int liba_func1 (int arg)
42   return arg + 1;
44 ]])
45 AT_DATA([usea.c],
46 [[extern int liba_func1 (int arg);
47 int main (void)
49   int a = 2;
50   int b = liba_func1 (a);
51   if (b == 3) return 0;
52   return 1;
54 ]])
56 orig_CFLAGS=$CFLAGS
57 orig_LIBTOOL=$LIBTOOL
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
61   chmod +x libtool
62   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], [])
80 done
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.
86 CFLAGS=$orig_CFLAGS
87 LIBTOOL=$orig_LIBTOOL
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
112   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])
132 done
135 AT_CLEANUP
138 AT_SETUP([cwrapper string length])
140 eval "`$LIBTOOL --config | $EGREP '^(objdir)='`"
142 AT_DATA([liba.c],
143 [[int liba_func1 (int arg)
145   return arg + 1;
148 AT_DATA([usea.c],
149 [[extern int liba_func1 (int arg);
150 int main (void)
152   int a = 2;
153   int b = liba_func1 (a);
154   if (b == 3) return 0;
155   return 1;
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
169 # in lt-usea.c.
171 dirpath=
172 save_IFS=$IFS
173 IFS=$PATH_SEPARATOR
174 for dirpath in $PATH; do
175   IFS=$save_IFS
176   break
177 done
178 IFS=$save_IFS
180 until $ECHO "PATH=$PATH" | $GREP 'PATH=.\{250\}'; do
181   PATH=$PATH$PATH_SEPARATOR$dirpath
182 done
183 export PATH
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])
198 AT_CLEANUP
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],
206          [], [ignore])
208 LDFLAGS="$LDFLAGS -no-undefined"
210 inst=`pwd`/inst
211 libdir=$inst/lib
212 bindir=$inst/bin
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.
218 mkdir foo
219 cd foo
220 # build and install "old" library version
221 AT_DATA([a.c], [[
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
232 AT_DATA([a.c], [[
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])
240 cd ..
242 # build and run test application
243 AT_DATA([m.c], [[
244 extern int liba_ver (void);
245 int main (void)
247   int r = (liba_ver () == 2) ? 0 : 1;
248   return r;
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], [])
263 AT_CLEANUP