Imported Upstream version 2.4.2
[platform/upstream/libtool.git] / tests / ltdl-libdir.at
1 # ltdl-libdir.at -- test libltdl functionality             -*- Autotest -*-
2 #
3 #   Copyright (C) 2010 Free Software Foundation, Inc.
4 #   This file is part of GNU Libtool.
5 #
6 # GNU Libtool is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; either version 2 of
9 # the License, or (at your option) any later version.
10 #
11 # GNU Libtool is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Libtool; see the file COPYING.  If not, a copy
18 # can be downloaded from  http://www.gnu.org/licenses/gpl.html,
19 # or obtained by writing to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 ####
22
23 AT_SETUP([libdir of installed modules])
24 AT_KEYWORDS([libltdl])
25
26 # This test requires shared library support.
27 AT_CHECK([$LIBTOOL --features | grep 'enable shared libraries' || exit 77],
28          [], [ignore])
29
30 # With MinGW, try Windows-style paths only.
31 if pwd -W >/dev/null 2>&1; then
32   prefix=`pwd -W`/inst
33 else
34   prefix=`pwd`/inst
35 fi
36 libdir=$prefix/lib
37 bindir=$prefix/bin
38 mkdir $prefix $libdir $bindir
39
40 AT_DATA([a.c],
41 [[#ifdef __cplusplus
42 extern "C"
43 #endif
44 int f (void)
45 {
46   return 42;
47 }
48 ]])
49
50 AT_DATA([m.c],
51 [[
52 #include <stdio.h>
53 #include <ltdl.h>
54
55 typedef int func_f(void);
56
57 int
58 main (int argc, const char *argv[])
59 {
60   lt_dlhandle module = NULL;
61   func_f *f = NULL;
62
63   if (lt_dlinit()) {
64     fprintf(stderr, "lt_dlinit failed '%s'\n", lt_dlerror());
65     return 1;
66   }
67
68   module = lt_dlopen("./a.la");
69
70   if (!module) {
71     fprintf(stderr, "lt_dlopen failed '%s'\n", lt_dlerror());
72     return 1;
73   }
74
75   f = (func_f *)lt_dlsym(module, "f");
76
77   if (!f) {
78     fprintf(stderr, "lt_dlsym failed '%s'\n", lt_dlerror());
79     return 1;
80   }
81
82   if (f() != 42) {
83     fprintf(stderr, "f did not return 42\n");
84     return 1;
85   }
86
87   lt_dlclose(module);
88   lt_dlexit();
89   return 0;
90 }
91 ]])
92
93 : ${LTDLINCL="-I$abs_top_srcdir/libltdl"}
94 : ${LIBLTDL="$abs_builddir/../libltdl/libltdlc.la"}
95
96 # Skip installcheck if --disable-ltdl-install was used.
97 AT_CHECK([test -f "$LIBLTDL" || exit 77])
98
99 CPPFLAGS="$LTDLINCL $CPPFLAGS"
100 LDFLAGS="$LDFLAGS -no-undefined"
101
102 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c a.c],
103          [], [ignore], [ignore])
104 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o a.la ]dnl
105          [a.lo -rpath $libdir -module -shared -avoid-version],
106          [], [ignore], [ignore])
107 AT_CHECK([$CC $CPPFLAGS $CFLAGS -c m.c],
108          [], [ignore], [ignore])
109 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o m$EXEEXT ]dnl
110          [m.$OBJEXT $LIBLTDL],
111          [], [ignore], [ignore])
112 AT_CHECK([$LIBTOOL --mode=install cp a.la $libdir/a.la],
113          [], [ignore], [ignore])
114 AT_CHECK([$LIBTOOL --mode=install cp m$EXEEXT $bindir/m$EXEEXT],
115          [], [ignore], [ignore])
116
117 # Try finding the module via the libdir entry in a misplaced .la file.
118
119 mv $libdir/a.la $bindir/a.la
120 cd $bindir
121 LT_AT_EXEC_CHECK([./m],
122                  [], [ignore], [ignore])
123
124 AT_CLEANUP