1# lalib-syntax.at -- parsing .la files robustly  -*- Autotest -*-
2#
3#   Copyright (C) 2009-2015 Free Software Foundation, Inc.
4#
5#   This file is part of GNU Libtool.
6#
7# GNU Libtool is free software; you can redistribute it and/or
8# modify it under the terms of the GNU General Public License as
9# published by the Free Software Foundation; either version 2 of
10# the License, or (at your option) any later version.
11#
12# GNU Libtool is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with GNU Libtool; see the file COPYING.  If not, a copy
19# can be downloaded from  http://www.gnu.org/licenses/gpl.html,
20# or obtained by writing to the Free Software Foundation, Inc.,
21# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22####
23
24AT_SETUP([syntax of .la files])
25AT_KEYWORDS([libtool])
26AT_KEYWORDS([libltdl])
27
28AT_XFAIL_IF([:]) dnl libltdl does not consistently return non-NULL lt_dlerror
29
30AT_DATA([main.c],
31[[#include <ltdl.h>
32#include <stdio.h>
33#include <assert.h>
34
35int
36main (int argc, char* argv[])
37{
38  int err = 0;
39  lt_dlhandle plugin_handle;
40
41  if (argc < 2)
42    {
43      fprintf (stderr, "usage: %s plugin\n", argv[0]);
44      return 1;
45    }
46
47  lt_dlinit ();
48  plugin_handle = lt_dlopenext (argv[1]);
49  if (NULL != plugin_handle)
50    {
51      printf ("plugin opened successfully!\n");
52      lt_dlclose (plugin_handle);
53    }
54  else
55    {
56      const char *error = lt_dlerror ();
57      assert (error != NULL);
58      printf ("plugin failed to open: %s\n", error);
59      err = 1;
60    }
61  lt_dlexit ();
62  return err;
63}
64]])
65
66AT_DATA([module.c],
67[[int foo (void) { return 0; }
68]])
69
70: ${LTDLINCL="-I$abs_top_srcdir/libltdl"}
71: ${LIBLTDL="$abs_builddir/../libltdl/libltdlc.la"}
72
73# Skip this test when called from:
74#    make distcheck DISTCHECK_CONFIGURE_FLAGS=--disable-ltdl-install
75AT_CHECK([case $LIBLTDL in #(
76 */_inst/lib/*) test -f "$LIBLTDL" || (exit 77) ;;
77esac], [], [ignore])
78
79CPPFLAGS="$CPPFLAGS $LTDLINCL"
80
81AT_CHECK([$CC $CPPFLAGS $CFLAGS -c main.c], [], [ignore], [ignore])
82AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c module.c],
83	 [], [ignore], [ignore])
84AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o module.la module.lo ]dnl
85	 [-module -avoid-version -rpath /somewhere], [], [ignore], [ignore])
86AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o main main.$OBJEXT $LIBLTDL],
87	 [], [ignore], [ignore])
88
89
90# Several bogus test cases.
91
92AT_DATA([missing-closing-quote.la],
93[[# missing-closing-quote.la - a libtool library file
94# Generated by libtool
95dlname='module.so
96library_names='module.so module.so module.so'
97old_library='module.a'
98installed=no
99shouldnotlink=yes
100libdir='/somewhere'
101]])
102
103AT_DATA([wrong-quotes.la],
104[[# wrong-quotes.la - a libtool library file
105# Generated by libtool
106dlname=module.so
107library_names='module.so module.so module.so'
108old_library='module.a'
109installed=no
110shouldnotlink=yes
111libdir='/somewhere'
112]])
113
114AT_DATA([no-dlname.la],
115[[# no-dlname.la - a libtool library file
116# Generated by libtool
117installed=no
118shouldnotlink=yes
119libdir='/somewhere'
120]])
121
122AT_DATA([nonexistent-dlname.la],
123[[# nonexistent-dlname.la - a libtool library file
124# Generated by libtool
125dlname='does-not-exist.so'
126installed=no
127shouldnotlink=yes
128libdir='/somewhere'
129]])
130
131for file in ./missing-closing-quote.la ./wrong-quotes.la \
132	    ./no-dlname.la ./nonexistent-dlname.la; do
133  LT_AT_EXEC_CHECK([./main], [1], [stdout], [ignore], [$file])
134  AT_CHECK([$GREP 'plugin failed to open' stdout], [], [ignore])
135done
136
137AT_CLEANUP
138