1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
# need-lib-prefix.at -- test libltdl functionality -*- Autotest -*-
#
# Copyright (C) 2007, 2008, 2010 Free Software Foundation, Inc.
# Written by Gary V. Vaughan, 2007
#
# This file is part of GNU Libtool.
#
# GNU Libtool is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# GNU Libtool is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Libtool; see the file COPYING. If not, a copy
# can be downloaded from http://www.gnu.org/licenses/gpl.html,
# or obtained by writing to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
####
AT_SETUP([enforced lib prefix])
AT_KEYWORDS([libltdl libtool])
# Originally written to simulate a failure visible on systems
# which need a library prefix like 'lib', such as BeOS. Currently
# the prefix is hardcoded as 'lib', so systems that require a
# different prefix skips the test.
AT_DATA([main.c],
[[#include <ltdl.h>
#include <stdio.h>
typedef int fun (int);
static int errors = 0;
static void
complain (const char *msg)
{
const char *errmsg = lt_dlerror ();
fprintf (stderr, "%s", msg);
if (errmsg)
fprintf (stderr, ": %s\n", errmsg);
else
fprintf (stderr, ".\n");
++errors;
}
static lt_dlhandle
moduleopen (const char *filename)
{
lt_dlhandle handle;
handle = lt_dlopen (filename);
if (!handle)
{
fprintf (stderr, "can't open the module %s!\n", filename);
complain ("error was");
}
return handle;
}
static int
moduletest (lt_dlhandle handle)
{
const lt_dlinfo *info = lt_dlgetinfo (handle);
fun *f = (fun *) lt_dlsym (handle, "f");
int *v = (int *) lt_dlsym (handle, "i");
if (!f)
{
complain ("function `f' not found");
return 1;
}
if (!v)
{
complain ("variable `i' not found");
return 1;
}
printf ("%s: %d\n", info->name, f (*v));
return 0;
}
int
main (int argc, char **argv)
{
lt_dlhandle handle;
LTDL_SET_PRELOADED_SYMBOLS();
if (lt_dlinit() != 0)
{
fprintf (stderr, "error during initialization: %s\n", lt_dlerror());
return 1;
}
if (lt_dlpreload_open (0, moduletest) != 0)
complain ("error during preloading");
if (lt_dlexit () != 0)
complain ("error during exit");
return (errors != 0);
}
]])
AT_DATA([foo1.c],
[[#define f foo1_LTX_f
#define i foo1_LTX_i
#ifdef __cplusplus
extern "C" {
#endif
int f (int x) { return x / 3; }
int i = 7;
#ifdef __cplusplus
}
#endif
]])
AT_DATA([foo2.c],
[[#define f libfoo2_LTX_f
#define i libfoo2_LTX_i
#ifdef __cplusplus
extern "C" {
#endif
int f (int x) { return (x * x) / 10; }
int i = 6;
#ifdef __cplusplus
}
#endif
]])
LT_AT_HOST_DATA([expout],
[[libfoo1: 2
libfoo2: 3
]])
: ${LTDLINCL="-I$abs_top_srcdir/libltdl"}
: ${LIBLTDL="$abs_builddir/../libltdl/libltdlc.la"}
# Skip this test when called from:
# make distcheck DISTCHECK_CONFIGURE_FLAGS=--disable-ltdl-install
AT_CHECK([case $LIBLTDL in #(
*/_inst/lib/*) test -f $LIBLTDL || (exit 77) ;;
esac], [], [ignore])
CPPFLAGS="$LTDLINCL $CPPFLAGS"
LDFLAGS="$LDFLAGS"
# Skip this test when libraries are not normally prefixed with lib.
# E.g., for MSVC and OS/2.
eval "`$LIBTOOL --config | $EGREP '^(libname_spec)='`"
name=
eval libname=\"$libname_spec\"
AT_CHECK([test "$libname" = lib || exit 77])
# Create our own libtool, forcing need_lib_prefix setting
sed 's,^\(need_lib_prefix\)=.*$,\1=unknown,' $LIBTOOL > ./libtool
LIBTOOL="$SHELL ./libtool"
# Installation directory:
instdir=`pwd`/_inst
$CC $CPPFLAGS $CFLAGS -c main.c
for file in foo1 foo2; do
$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c $file.c
done
AT_CHECK([$LIBTOOL --mode=link $CC -module -avoid-version $CFLAGS $LDFLAGS -o foo1.la foo1.lo -rpath $instdir/lib],
[], [ignore], [ignore])
AT_CHECK([$LIBTOOL --mode=link $CC -module -avoid-version $CFLAGS $LDFLAGS -o libfoo2.la foo2.lo -rpath $instdir/lib],
[], [ignore], [ignore])
AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o main$EXEEXT main.$OBJEXT -dlpreopen foo1.la -dlpreopen libfoo2.la $LIBLTDL],
[], [ignore], [ignore])
LT_AT_NOINST_EXEC_CHECK([./main], [-dlopen foo1.la -dlopen libfoo2.la],
[], [expout], [])
# Install the libraries.
mkdir $instdir
mkdir $instdir/lib
$LIBTOOL --mode=install cp foo1.la $instdir/lib/foo1.la
$LIBTOOL --mode=install cp libfoo2.la $instdir/lib/libfoo2.la
# Install the binary
mkdir $instdir/bin
$LIBTOOL --mode=install cp main$EXEEXT $instdir/bin/main$EXEEXT
LT_AT_EXEC_CHECK([$instdir/bin/main], [], [expout], [])
AT_CLEANUP
|