From 40462e712cc468c42cb036a3429d23c5961e98ee Mon Sep 17 00:00:00 2001 From: Greg Eisenhauer Date: Thu, 31 Jul 2003 20:44:29 +0000 Subject: [PATCH] 2003-07-31 Greg Eisenhauer * ltmain.in: Provide absolute paths for dlopen and dlpreopen files in generating uninstalled libtool libraries. * mdemo2/main.c, mdemo2/Makefile.am, mdemo2/README, mdemo2/configure.ac, mdemo2/.cvsignore, mdemo/mlib.c, tests/mdemo2-conf.test, tests/mdemo2-exec.test, tests/mdemo2-make.test: New files for testing above feature. * configure.ac, bootstrap, tests/Makefile.am: Accomodate new test directory. * mdemo/Makefile.am: Build libmlib.la for mdemo2 tests. --- mdemo/mlib.c | 134 +++++++++++++++++++++++++++++++++++++++++ mdemo2/.cvsignore | 14 +++++ mdemo2/Makefile.am | 24 ++++++++ mdemo2/README | 5 ++ mdemo2/configure.ac | 70 +++++++++++++++++++++ mdemo2/main.c | 39 ++++++++++++ tests/mdemo2-conf.test | 35 +++++++++++ tests/mdemo2-exec.test | 35 +++++++++++ tests/mdemo2-make.test | 31 ++++++++++ 9 files changed, 387 insertions(+) create mode 100644 mdemo/mlib.c create mode 100644 mdemo2/.cvsignore create mode 100644 mdemo2/Makefile.am create mode 100644 mdemo2/README create mode 100644 mdemo2/configure.ac create mode 100644 mdemo2/main.c create mode 100755 tests/mdemo2-conf.test create mode 100755 tests/mdemo2-exec.test create mode 100755 tests/mdemo2-make.test diff --git a/mdemo/mlib.c b/mdemo/mlib.c new file mode 100644 index 000000000..bb859d3e6 --- /dev/null +++ b/mdemo/mlib.c @@ -0,0 +1,134 @@ +/* main.c -- mlib library + Copyright (C) 2002 Free Software Foundation, Inc. + Originally by greg Eisenhauer + Extracted from mdemo.c + This file is part of GNU Libtool. + +This program 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. + +This program 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 this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA. */ + +#include "foo.h" +#include "ltdl.h" +#include + +int +test_dl (filename) + char *filename; +{ + lt_dlhandle handle; + const lt_dlinfo *info; + int (*pfoo1)() = 0; + int (*pfoo2)() = 0; + int (*phello)() = 0; + int *pnothing = 0; + int ret = 0; + + handle = lt_dlopen(filename); + if (!handle) { + fprintf (stderr, "can't open the module %s!\n", filename); + fprintf (stderr, "error was: %s\n", lt_dlerror()); + return 1; + } + + info = lt_dlgetinfo(handle); + if (!info) { + fprintf (stderr, "can't get module info: %s\n", lt_dlerror()); + return 1; + } + if (info->name) { + printf ("module name: %s\n", info->name); + } else { + printf ("module is not a libtool module\n"); + } + printf ("module filename: %s\n", info->filename); + printf ("module reference count: %i\n", info->ref_count); + + phello = (int(*)())lt_dlsym(handle, "hello"); + if (phello) + { + int value = (*phello) (); + + printf ("hello returned: %i\n", value); + if (value == HELLO_RET) + printf("hello is ok!\n"); + } + else + { + fprintf (stderr, "did not find the `hello' function\n"); + fprintf (stderr, "error was: %s\n", lt_dlerror()); + ret = 1; + } + + pnothing = (int*)lt_dlsym(handle, "nothing"); + /* Try assigning to the nothing variable. */ + if (pnothing) + *pnothing = 1; + else + { + fprintf (stderr, "did not find the `nothing' variable\n"); + fprintf (stderr, "error was: %s\n", lt_dlerror()); + ret = 1; + } + + pfoo1 = (int(*)())lt_dlsym(handle, "foo1"); + /* Just call the functions and check return values. */ + if (pfoo1) + { + if ((*pfoo1) () == FOO_RET) + printf("foo1 is ok!\n"); + else + ret = 1; + } + else { + pfoo2 = (int(*)())lt_dlsym(handle, "foo2"); + if (pfoo2) + { + if ((*pfoo2) () == FOO_RET) + printf("foo2 is ok!\n"); + else ret = 1; + } + else + { + fprintf (stderr, "did not find any of the `foo' functions\n"); + fprintf (stderr, "error was: %s\n", lt_dlerror()); + ret = 1; + } + } + lt_dlclose(handle); + return ret; +} +int +mlib_func(argc, argv) +int argc; +char **argv; +{ + int ret = 0; + int i; + /* + * Would be nice if this somehow worked for libraries, not just executables. + * LTDL_SET_PRELOADED_SYMBOLS(); + */ + if (lt_dlinit() != 0) { + fprintf (stderr, "error during initialization: %s\n", lt_dlerror()); + return 1; + } + + for (i = 1; i < argc; i++) + if (test_dl(argv[i])) + ret = 1; + + lt_dlexit(); + return ret; +} diff --git a/mdemo2/.cvsignore b/mdemo2/.cvsignore new file mode 100644 index 000000000..e80c5131a --- /dev/null +++ b/mdemo2/.cvsignore @@ -0,0 +1,14 @@ +.deps +.libs +Makefile +Makefile.in +acinclude.m4 +aclocal.m4 +configure +config.* +conftest* +libtool +*.lo +*.la +mdemo +mdemo.static diff --git a/mdemo2/Makefile.am b/mdemo2/Makefile.am new file mode 100644 index 000000000..332949535 --- /dev/null +++ b/mdemo2/Makefile.am @@ -0,0 +1,24 @@ +## Process this file with automake to produce Makefile.in + +AUTOMAKE_OPTIONS = no-dependencies foreign + +INCLUDES = $(INCLTDL) + +EXTRA_DIST = acinclude.m4 + +bin_PROGRAMS = mdemo2 mdemo2_static + +# Create a version of mdemo2 that links a library that does dlopen. +mdemo2_SOURCES = main.c +mdemo2_LDFLAGS = -export-dynamic +mdemo2_LDADD = ../mdemo/libmlib.la + +# Create a statically linked version of mdemo. +mdemo2_static_SOURCES = $(mdemo2_SOURCES) +mdemo2_static_LDFLAGS = $(STATIC) $(mdemo2_LDFLAGS) +mdemo2_static_LDADD = $(mdemo2_LDADD) +mdemo2_static_DEPENDENCIES = $(mdemo2_DEPENDENCIES) + +$(OBJECTS): libtool +libtool: $(LIBTOOL_DEPS) + $(SHELL) ./config.status --recheck diff --git a/mdemo2/README b/mdemo2/README new file mode 100644 index 000000000..8a1e18ba8 --- /dev/null +++ b/mdemo2/README @@ -0,0 +1,5 @@ +This is mdemo2, an example package that attempts to use GNU libtool to +link with a library that itself does dlopening of libtool modules. + +This demo depends upon the libraries generated in ../mdemo. + diff --git a/mdemo2/configure.ac b/mdemo2/configure.ac new file mode 100644 index 000000000..9f7b3fd26 --- /dev/null +++ b/mdemo2/configure.ac @@ -0,0 +1,70 @@ +## Process this file with autoconf to create configure. -*- autoconf -*- +# Copyright 2001 Free Software Foundation, Inc. +# +# This program 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. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +# 02111-1307 USA + +AC_PREREQ(2.50) + + +## ------------------------ ## +## Autoconf initialisation. ## +## ------------------------ ## +AC_INIT([mdemo2], [0.1], [bug-libtool@gnu.org]) +AC_CONFIG_SRCDIR([main.c]) + + +## ------------------------ ## +## Automake Initialisation. ## +## ------------------------ ## +AM_INIT_AUTOMAKE(AC_PACKAGE_TARNAME, AC_PACKAGE_VERSION) + + +## ------------------ ## +## C compiler checks. ## +## ------------------ ## +AC_PROG_CC +AC_C_CONST + + +## ----------------------- ## +## Libtool initialisation. ## +## ----------------------- ## +AM_PROG_LIBTOOL +AC_SUBST(LIBTOOL_DEPS) + +if ${CONFIG_SHELL} ./libtool --features | grep "enable static" >/dev/null; then + STATIC=-static +else + STATIC= +fi +AC_SUBST([STATIC]) + + +## ---------------------------- ## +## C headers required by mdemo2. ## +## ---------------------------- ## + + +## ---------------------------- ## +## Libraries required by cdemo. ## +## ---------------------------- ## + + +## -------- ## +## Outputs. ## +## -------- ## +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/mdemo2/main.c b/mdemo2/main.c new file mode 100644 index 000000000..b6bd75a0e --- /dev/null +++ b/mdemo2/main.c @@ -0,0 +1,39 @@ +/* main.c -- mdemo2 test program + Copyright (C) 2003 Free Software Foundation, Inc. + Originally by Greg Eisenhauer < eisen at cc.gatech.edu > + This file is part of GNU Libtool. + +This program 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. + +This program 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 this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA. */ + +#include + +int +main (argc, argv) + int argc; + char **argv; +{ + int ret = 0; + + printf ("Welcome to GNU libtool mdemo2!\n"); + + if (argc < 2) { + fprintf (stderr, "usage: %s module [module...]\n", argv[0]); + } + + ret = mlib_func(argc, argv); + + return ret; +} diff --git a/tests/mdemo2-conf.test b/tests/mdemo2-conf.test new file mode 100755 index 000000000..b92dd2247 --- /dev/null +++ b/tests/mdemo2-conf.test @@ -0,0 +1,35 @@ +#! /bin/sh +# mdemo2-conf.test - try configuring the ../mdemo2 subdirectory + +# Test script header. +need_prefix=yes +if test -z "$srcdir"; then + srcdir=`echo "$0" | sed 's%/[^/]*$%%'` + test "$srcdir" = "$0" && srcdir=. + test "${VERBOSE+set}" != "set" && VERBOSE=yes +fi +. $srcdir/defs || exit 1 + +# Maybe we have a VPATH build, in which case, create a new subdir. +test -d ../mdemo2 || mkdir ../mdemo2 + +# Change to our build directory. +cd ../mdemo2 || exit 1 + +# Possibly clean up the distribution. +if test -f Makefile; then + echo "= Running $make distclean in ../mdemo2" + $make distclean +fi +rm -f config.cache + +# Configure the demonstration. +echo "= Configuring in ../mdemo2 (prefix=$prefix)" +CONFIG_SITE=/nonexistent ${CONFIG_SHELL-/bin/sh} $srcdir/../mdemo2/configure --srcdir=$srcdir/../mdemo2 --prefix=$prefix || exit 1 + +if grep '^build_old_libs=yes' libtool > /dev/null && + grep '^build_libtool_libs=yes' libtool > /dev/null; then : +else rm -f Makefile && exit 77 +fi + +exit 0 diff --git a/tests/mdemo2-exec.test b/tests/mdemo2-exec.test new file mode 100755 index 000000000..74aaacf69 --- /dev/null +++ b/tests/mdemo2-exec.test @@ -0,0 +1,35 @@ +#! /bin/sh +# mdemo2-exec.test - check that programs in the ../mdemo2 subdirectory are viable + +# Test script header. +need_prefix=no +if test -z "$srcdir"; then + srcdir=`echo "$0" | sed 's%/[^/]*$%%'` + test "$srcdir" = "$0" && srcdir=. + test "${VERBOSE+set}" != "set" && VERBOSE=yes +fi +. $srcdir/defs || exit 1 + +if test -f ../mdemo2/mdemo2; then : +else + echo "You must run mdemo2-make.test before running $0" 1>&2 + exit 77 +fi + +# Check to see if the programs really run. +echo "Executing uninstalled programs in ../mdemo2" + +status=0 +if ../mdemo2/mdemo2_static ../mdemo/foo1.la ../mdemo/libfoo2.la; then : +else + echo "$0: execution of ../mdemo2/mdemo2_static failed" 1>&2 + status=1 +fi + +if ../mdemo2/mdemo2 ../mdemo/foo1.la ../mdemo/libfoo2.la; then : +else + echo "$0: execution of ../mdemo2/mdemo2 failed" 1>&2 + status=1 +fi + +exit $status diff --git a/tests/mdemo2-make.test b/tests/mdemo2-make.test new file mode 100755 index 000000000..ebaf8b37b --- /dev/null +++ b/tests/mdemo2-make.test @@ -0,0 +1,31 @@ +#! /bin/sh +# mdemo2-make.test - try building in the ../mdemo2 subdirectory + +# Test script header. +need_prefix=no +if test -z "$srcdir"; then + srcdir=`echo "$0" | sed 's%/[^/]*$%%'` + test "$srcdir" = "$0" && srcdir=. + test "${VERBOSE+set}" != "set" && VERBOSE=yes +fi +. $srcdir/defs || exit 1 + +if test -f ../mdemo2/Makefile; then : +else + echo "You must run mdemo2-conf.test before running $0" 1>&2 + exit 77 +fi + +if test -f ../mdemo/libmlib.la; then : +else + echo "You must run mdemo-make.test before running $0" 1>&2 + exit 77 +fi + +# Change to our build directory. +cd ../mdemo2 || exit 1 + +# Do the actual build. +echo "Making in ../mdemo2" +$make || exit 1 +exit 0 -- 2.47.2