From: Alexandre Oliva Date: Wed, 18 Nov 1998 07:29:36 +0000 (+0000) Subject: * NEWS: -module and libtldl X-Git-Tag: start~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e76ee47bceeeb68440f850085d016929ef84c0d2;p=thirdparty%2Flibtool.git * NEWS: -module and libtldl * mdemo/Makefile.am: ../libltdl is within $(srcdir) * libltdl, Makefile.am: added libltdl (a system independent dlopen wrapper library extracted from mdemo) * ltmain.in: added -module flag for compiling and linking of modules. If enabled it compiles always both .o (with -DLT_RENAME) and .lo files * mdemo: modified mdemo to work with libltdl * tests/ltdl*: added tests for libltdl --- diff --git a/ChangeLog b/ChangeLog index fc0367c13..76db554e8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +1998-11-18 Alexandre Oliva + + * NEWS: -module and libtldl + * mdemo/Makefile.am: ../libltdl is within $(srcdir) + +1998-11-18 Thomas Tanner + + * libltdl, Makefile.am: added libltdl (a system independent + dlopen wrapper library extracted from mdemo) + * ltmain.in: added -module flag for compiling and linking of + modules. If enabled it compiles always both .o (with -DLT_RENAME) + and .lo files + * mdemo: modified mdemo to work with libltdl + * tests/ltdl*: added tests for libltdl + 1998-11-16 Steve Price * ltconfig.in: when $host_os is freebsd[23]* determine whether diff --git a/Makefile.am b/Makefile.am index a500d71a5..91a03d061 100644 --- a/Makefile.am +++ b/Makefile.am @@ -28,6 +28,12 @@ mdemo_distfiles = mdemo/Makefile.in mdemo/Makefile.am mdemo/README \ mdemo/libfoo1.sym mdemo/libfoo2.sym \ mdemo/main.c mdemo/ltdl.h mdemo/ltdl.c mdemo/ltdls.c +# Files in the libltdl subdirectory that go in the distribution. +libltdl_distfiles = libltdl/Makefile.in libltdl/Makefile.am libltdl/README \ + libltdl/acinclude.m4 libltdl/aclocal.m4 \ + libltdl/configure libltdl/configure.in \ + libltdl/ltdl.h libltdl/ltdl.c + # These are required by libtoolize. pkgdata_SCRIPTS = config.guess config.sub ltconfig pkgdata_DATA = ltmain.sh @@ -67,8 +73,8 @@ $(srcdir)/ltmain.sh: ltmain.in $(top_srcdir)/configure.in sed -e 's/@''PACKAGE@/@PACKAGE@/' -e 's/@''VERSION@/@VERSION@/' $(srcdir)/ltmain.in > ltmain.shT mv -f ltmain.shT $@ -# Distribute the demo and mdemo subdirectory. -dist-hook: $(demo_distfiles) $(mdemo_distfiles) +# Distribute the demo, mdemo and libltdl subdirectory. +dist-hook: $(demo_distfiles) $(mdemo_distfiles) $(libltdl_distfiles) mkdir $(distdir)/demo -chmod 755 $(distdir)/demo here=`pwd`; distdir=`cd $(distdir) && pwd` \ @@ -91,9 +97,21 @@ dist-hook: $(demo_distfiles) $(mdemo_distfiles) || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ || cp -p $$d/$$file $(distdir)/$$file; \ done + mkdir $(distdir)/libltdl + -chmod 755 $(distdir)/libltdl + here=`pwd`; distdir=`cd $(distdir) && pwd` \ + && cd $(srcdir)/libltdl \ + && $(AUTOMAKE) --include-deps --build-dir=$$here/libltdl --srcdir-name=$(srcdir)/libltdl --output-dir=$$distdir/libltdl + @for file in $(libltdl_distfiles); do \ + d=$(srcdir); \ + test -f $(distdir)/$$file \ + || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ + || cp -p $$d/$$file $(distdir)/$$file; \ + done # All our rules should depend on these demo files. -all: demo/Makefile.in demo/configure mdemo/Makefile.in mdemo/configure +all: demo/Makefile.in demo/configure mdemo/Makefile.in mdemo/configure \ + libltdl/Makefile.in libltdl/configure # We use our own libtool.m4. $(srcdir)/acinclude.m4: libtool.m4 @@ -105,6 +123,9 @@ $(srcdir)/demo/acinclude.m4: libtool.m4 $(srcdir)/mdemo/acinclude.m4: libtool.m4 rm -f $(srcdir)/mdemo/acinclude.m4 cd $(srcdir)/mdemo && $(LN_S) ../libtool.m4 acinclude.m4 +$(srcdir)/libltdl/acinclude.m4: libtool.m4 + rm -f $(srcdir)/libltdl/acinclude.m4 + cd $(srcdir)/libltdl && $(LN_S) ../libtool.m4 acinclude.m4 # Rules for rebuilding some of the demo source files. $(srcdir)/demo/Makefile.in: demo/Makefile.am demo/configure.in demo/aclocal.m4 @@ -125,6 +146,15 @@ $(srcdir)/mdemo/configure: mdemo/configure.in mdemo/aclocal.m4 $(srcdir)/mdemo/aclocal.m4: mdemo/configure.in mdemo/acinclude.m4 cd $(srcdir)/mdemo && $(ACLOCAL) +$(srcdir)/libltdl/Makefile.in: libltdl/Makefile.am libltdl/configure.in libltdl/aclocal.m4 + cd $(srcdir)/libltdl && $(AUTOMAKE) + +$(srcdir)/libltdl/configure: libltdl/configure.in libltdl/aclocal.m4 + cd $(srcdir)/libltdl && $(AUTOCONF) + +$(srcdir)/libltdl/aclocal.m4: libltdl/configure.in libltdl/acinclude.m4 + cd $(srcdir)/libltdl && $(ACLOCAL) + ###################################################################### # These commands really help my life as a maintainer who uses PRCS. # Feel free to copy them to your own project. I just run a diff --git a/NEWS b/NEWS index e27f2ad09..49df135e1 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,8 @@ NEWS - list of user-visible changes between releases of GNU Libtool New in 1.2c - 1998-XX-XX: +* New -module flag, to create loadable modules. +# New libltdl, a small library for portable dynamic loading of modules. * Inter-library dependencies patch finally integrated, but there's still much porting to do. See PORTING for details (some plans for the future in mail/deplibs in the CVS tree). diff --git a/libltdl/.cvsignore b/libltdl/.cvsignore new file mode 100644 index 000000000..d8e5c8eb3 --- /dev/null +++ b/libltdl/.cvsignore @@ -0,0 +1,11 @@ +.deps +.libs +Makefile +Makefile.in +aclocal.m4 +configure +config.* +conftest* +libtool +*.lo +*.la diff --git a/libltdl/Makefile.am b/libltdl/Makefile.am new file mode 100644 index 000000000..ccbb2b4dd --- /dev/null +++ b/libltdl/Makefile.am @@ -0,0 +1,16 @@ +# A brief demonstration of using Automake with Libtool. -*-Makefile-*- +# +# NOTE: Don't forget that in the libtool distribution, files in this +# directory are distributed by the demo_distfiles variable in the top +# level Makefile. +AUTOMAKE_OPTIONS = foreign + +CFLAGS = -module + +EXTRA_DIST = acinclude.m4 + +lib_LTLIBRARIES = libltdl.la +libltdl_la_SOURCES = ltdl.c +libltdl_la_LDFLAGS = $(LIBADD_DL) + +include_HEADERS = ltdl.h diff --git a/libltdl/README b/libltdl/README new file mode 100644 index 000000000..0b08ae281 --- /dev/null +++ b/libltdl/README @@ -0,0 +1 @@ +This is GNU libltdl, a system independent dlopen wrapper for GNU libtool. diff --git a/libltdl/configure.in b/libltdl/configure.in new file mode 100644 index 000000000..4d160aa4d --- /dev/null +++ b/libltdl/configure.in @@ -0,0 +1,21 @@ +dnl Initialize the hell package. +AC_INIT(ltdl.c) +AM_INIT_AUTOMAKE(libltdl,1.0) + +AC_PROG_CC +AM_PROG_LIBTOOL + +AC_CHECK_HEADERS(string.h dlfcn.h dl.h) + +LIBADD_DL= +AC_CHECK_FUNCS(dlopen, AC_DEFINE(HAVE_LIBDL), +[AC_CHECK_LIB(dl, dlopen, [AC_DEFINE(HAVE_LIBDL) LIBADD_DL="-ldl"], + [AC_CHECK_LIB(dld, dld_link, [AC_DEFINE(HAVE_DLD) LIBADD_DL="-ldld"], + [AC_CHECK_FUNCS(shl_load, AC_DEFINE(HAVE_SHL_LOAD) )] + )] + )] +) +AC_SUBST(LIBADD_DL) + +dnl Output the makefile +AC_OUTPUT(Makefile) diff --git a/libltdl/ltdl.c b/libltdl/ltdl.c new file mode 100644 index 000000000..7afdf93aa --- /dev/null +++ b/libltdl/ltdl.c @@ -0,0 +1,289 @@ +/* ltdl.c -- system independent dlopen wrapper + Copyright (C) 1998 Thomas Tanner + 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 "ltdl.h" + +#ifdef HAVE_STRING_H +#include +#endif + +#ifdef LT_RENAME + +/* emulate dynamic linking using dld_preloaded_symbols */ + +struct dld_symlist +{ + char *name; + void *address; +}; + +extern struct dld_symlist dld_preloaded_symbols[]; + +static void +sys_dlinit (void) +{ +} + +static lt_dlhandle +sys_dlopen (char *filename) +{ + struct dld_symlist *s = dld_preloaded_symbols; + + while (s->name) { + if (!s->address && !strcmp(s->name, filename)) + break; + s++; + } + if (!s->name) + return NULL; + return (void*)s; +} + +static void +sys_dlclose (lt_dlhandle handle) +{ +} + +static void * +sys_dlsym (lt_dlhandle handle, char *symbol) +{ + struct dld_symlist *s = (struct dld_symlist*)handle; + + if (!s) + return NULL; + s++; + while (s->address) { + if (!strncmp(s->name, "ltexp_", 6)) { + char *p = strstr(s->name, "___"); + if (p && !strcmp(&p[3], symbol)) + return s->address; + } + s++; + } + return NULL; +} + +#else +#ifdef HAVE_LIBDL + +/* dynamic linking with dlopen/dlsym */ + +#ifdef HAVE_DLFCN_H +#include +#endif + +#ifdef RTLD_LAZY /* Solaris 2. */ +# define DLOPEN_MODE RTLD_LAZY +#else +#ifdef DL_LAZY +# define DLOPEN_MODE DL_LAZY +#else +# define DLOPEN_MODE 1 /* Thats what it says in the man page. */ +#endif +#endif + +static void +sys_dlinit (void) +{ +} + +static lt_dlhandle +sys_dlopen (char *filename) +{ + return dlopen(filename, DLOPEN_MODE); +} + +static void +sys_dlclose (lt_dlhandle handle) +{ + dlclose(handle); +} + +static void * +sys_dlsym (lt_dlhandle handle, char *symbol) +{ +#ifdef __OpenBSD__ + char sym[128]; + + strcpy(sym, "_"); + strcat(sym, symbol); /* prefix symbol with leading underscore */ + return dlsym(handle, sym); +#else + return dlsym(handle, symbol); +#endif +} + +#else +#ifdef HAVE_SHL_LOAD + +/* dynamic linking with shl_load (HP-UX) */ + +#ifdef HAVE_DL_H +#include +#endif + +static void +sys_dlinit (void) +{ +} + +static lt_dlhandle +sys_dlopen (char *filename) +{ + /* Probably too much BIND_* flags */ + return shl_load (filename, BIND_IMMEDIATE || BIND_FIRST || + BIND_TOGETHER || BIND_VERBOSE || DYNAMIC_PATH, 0L); +} + +static void +sys_dlclose (lt_dlhandle handle) +{ + shl_unload((shl_t) handle); +} + +static void * +sys_dlsym (lt_dlhandle handle, char *symbol) +{ + int status, i; + struct shl_symbol *sym; + + status = shl_getsymbols((shl_t) handle, TYPE_PROCEDURE, + EXPORT_SYMBOLS, malloc, &sym); + for (i = 0; i < status; i++) + if (strcmp(symbol, sym[i].name) == 0) + return sym[i].value; + return NULL; +} + +#else +#ifdef HAVE_DLD + +/* dynamic linking with dld */ + +static void +sys_dlinit (void) +{ +} + +static lt_dlhandle +sys_dlopen (char *filename) +{ + if (dld_link (filename)) + return NULL; + return filename; +} + +static void +sys_dlclose (lt_dlhandle handle) +{ + dld_unlink_by_file ((char*)handle, 1); +} + +static void * +sys_dlsym (lt_dlhandle handle, char *symbol) +{ + return dld_get_func (symbol); +} + +#else +#ifdef _WIN32 + +/* dynamic linking for Win32 */ + +#include + +static void +sys_dlinit (void) +{ +} + +static lt_dlhandle +sys_dlopen (char *filename) +{ + return LoadLibrary(filename); +} + +static void +sys_dlclose (lt_dlhandle handle) +{ + FreeLibrary(handle); +} + +static void * +sys_dlsym (lt_dlhandle handle, char *symbol) +{ + return GetProcAddress(handle, symbol); +} + +#else + +/* no dynamic linking available */ + +static void +sys_dlinit (void) +{ +} + +static lt_dlhandle +sys_dlopen (char *filename) +{ + return NULL; +} + +static void +sys_dlclose (lt_dlhandle handle) +{ +} + +static void * +sys_dlsym (lt_dlhandle handle, char *symbol) +{ + return NULL; +} + +#endif +#endif +#endif +#endif +#endif + +void +lt_dlinit (void) +{ + sys_dlinit(); +} + +lt_dlhandle +lt_dlopen (char *filename) +{ + return sys_dlopen(filename); +} + + +void +lt_dlclose (lt_dlhandle handle) +{ + sys_dlclose(handle); +} + +void * +lt_dlsym (lt_dlhandle handle, char *symbol) +{ + return sys_dlsym(handle, symbol); +} diff --git a/mdemo/ltdl.h b/libltdl/ltdl.h similarity index 95% rename from mdemo/ltdl.h rename to libltdl/ltdl.h index 508c2e867..b738f7d86 100644 --- a/mdemo/ltdl.h +++ b/libltdl/ltdl.h @@ -18,8 +18,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ /* Only include this header file once. */ -#ifndef _DL_H_ -#define _DL_H_ 1 +#ifndef _LTDL_H_ +#define _LTDL_H_ 1 /* __BEGIN_DECLS should be used at the beginning of your declarations, so that C++ compilers don't mangle their names. Use __END_DECLS at @@ -47,9 +47,10 @@ USA. */ typedef void *lt_dlhandle; __BEGIN_DECLS +void lt_dlinit __P((void)); lt_dlhandle lt_dlopen __P((char *name)); void lt_dlclose __P((lt_dlhandle handle)); void *lt_dlsym __P((lt_dlhandle handle, char *name)); __END_DECLS -#endif /* !_DLL_H_ */ +#endif /* !_LTDL_H_ */ diff --git a/ltmain.in b/ltmain.in index a032ca985..d716721df 100644 --- a/ltmain.in +++ b/ltmain.in @@ -262,6 +262,7 @@ if test -z "$show_help"; then lastarg= srcfile="$nonopt" suppress_output= + module=no user_target=no for arg @@ -276,10 +277,15 @@ if test -z "$show_help"; then user_target=next ;; + -module) + module=yes + continue + ;; + -static) - build_old_libs=yes - continue - ;; + build_old_libs=yes + continue + ;; esac case "$user_target" in @@ -474,8 +480,9 @@ compiler." fi fi - # If we have no pic_flag, then copy the object into place and finish. - if test -z "$pic_flag"; then + # If we have no pic_flag and do not compile a module, + # then copy the object into place and finish. + if test -z "$pic_flag" && "$module" = no; then $show "$LN_S $libobj $obj" if $run $LN_S $libobj $obj; then exit 0 @@ -493,6 +500,7 @@ compiler." # Only build a position-dependent object if we build old libraries. if test "$build_old_libs" = yes; then command="$base_compile $srcfile" + test "$module" = yes && command="$command -DLT_RENAME" if test "$compiler_c_o" = yes; then command="$command -o $obj" output_obj="$obj" @@ -580,6 +588,7 @@ compiler." libobjs= link_against_libtool_libs= ltlibs= + module=no objs= prev= prevarg= @@ -741,6 +750,11 @@ compiler." -l*) deplibs="$deplibs $arg" ;; -El*) extradeplibs="$extradeplibs -`expr $arg : '-E\(.*\)'`" ;; + -module) + module=yes + continue + ;; + -no-undefined) allow_undefined=no continue diff --git a/mdemo/Makefile.am b/mdemo/Makefile.am index 0272e5b58..4bd49b916 100644 --- a/mdemo/Makefile.am +++ b/mdemo/Makefile.am @@ -5,25 +5,28 @@ # level Makefile. AUTOMAKE_OPTIONS = foreign +INCLUDES = -I$(srcdir)/../libltdl + EXTRA_DIST = acinclude.m4 lib_LTLIBRARIES = libfoo1.la libfoo2.la -libfoo1_la_SOURCES = foo1.c foolib1.h -libfoo1_la_LDFLAGS = -export-symbols $(srcdir)/libfoo1.sym -lm +libfoo1_la_SOURCES = foo1.c +libfoo1_la_LDFLAGS = -export-symbols $(srcdir)/libfoo1.sym -lm -module -libfoo2_la_SOURCES = foo2.c foolib2.h -libfoo2_la_LDFLAGS = -export-symbols $(srcdir)/libfoo2.sym -lm +libfoo2_la_SOURCES = foo2.c +libfoo2_la_LDFLAGS = -export-symbols $(srcdir)/libfoo2.sym -lm -module include_HEADERS = foo.h bin_PROGRAMS = hell hell.debug # Create a version of hell that does dlopen. -hell_SOURCES = main.c ltdl.c -hell_LDFLAGS = $(LIBADD_DL) -lm +hell_SOURCES = main.c +hell_LDADD = ../libltdl/libltdl.la -lm hell_DEPENDENCIES = libfoo1.la libfoo2.la # Create an easier-to-debug version of hell. -hell_debug_SOURCES = main.c ltdls.c -hell_debug_LDADD = libfoo1.la libfoo2.la -hell_debug_LDFLAGS = -export-dynamic -dlpreopen libfoo1.la -dlpreopen libfoo2.la -static +hell_debug_SOURCES = main.c +hell_debug_LDADD = ../libltdl/libltdl.la libfoo1.la libfoo2.la +hell_debug_LDFLAGS = -static -export-dynamic \ + -dlpreopen libfoo1.la -dlpreopen libfoo2.la diff --git a/mdemo/README b/mdemo/README index 10cbf4ca2..cb313852a 100644 --- a/mdemo/README +++ b/mdemo/README @@ -2,7 +2,7 @@ This is GNU modular hell, an example package that uses GNU libtool with an Automake-generated environment to build two simple libraries and programs. It demonstrates how to build both dynamic and static libraries -that can be dlopened. You need a wrapper (ltdl.c and ltdls.c) +that can be dlopened. You'll need a wrapper (libltdl) for your dlopen functions. For static libraries we prefix all non-static symbols with libname___ using the LTEXP(symbol) macro. When dlopening these static libraries, we cut the prefix off to diff --git a/mdemo/configure.in b/mdemo/configure.in index f54bede38..eb8031958 100644 --- a/mdemo/configure.in +++ b/mdemo/configure.in @@ -6,18 +6,5 @@ AC_PROG_CC AC_EXEEXT AM_PROG_LIBTOOL -AC_CHECK_HEADERS(string.h dlfcn.h dl.h) -AC_CHECK_FUNCS(strdup) - -LIBADD_DL= -AC_CHECK_FUNCS(dlopen,, -[AC_CHECK_LIB(dl, dlopen, LIBADD_DL="-ldl", - [AC_CHECK_LIB(dld, shl_load, LIBADD_DL="-ldld", - [AC_CHECK_FUNCS(dlopen, LIBADD_DL="")] - )] - )] -) -AC_SUBST(LIBADD_DL) - dnl Output the makefile AC_OUTPUT(Makefile) diff --git a/mdemo/foo.h b/mdemo/foo.h index 541becabd..9dc106269 100644 --- a/mdemo/foo.h +++ b/mdemo/foo.h @@ -21,40 +21,8 @@ USA. */ #ifndef _FOO_H_ #define _FOO_H_ 1 -/* __BEGIN_DECLS should be used at the beginning of your declarations, - so that C++ compilers don't mangle their names. Use __END_DECLS at - the end of C declarations. */ -#undef __BEGIN_DECLS -#undef __END_DECLS -#ifdef __cplusplus -# define __BEGIN_DECLS extern "C" { -# define __END_DECLS } -#else -# define __BEGIN_DECLS /* empty */ -# define __END_DECLS /* empty */ -#endif - -/* __P is a macro used to wrap function prototypes, so that compilers - that don't understand ANSI C prototypes still work, and ANSI C - compilers can issue warnings about type mismatches. */ -#undef __P -#if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(WIN32) || defined(__cplusplus) -# define __P(protos) protos -#else -# define __P(protos) () -#endif - /* Silly constants that the functions return. */ #define HELLO_RET 0xe110 #define FOO_RET 0xf00 -#ifndef PIC -#define glue(a,b) a ## b -#define symglue(a,b) glue(a,b) -#define LTPREFIX(name) ___ ## name -#define LTEXP(name) symglue(DLNAME,LTPREFIX(name)) -#else -#define LTEXP(name) name -#endif - #endif /* !_FOO_H_ */ diff --git a/mdemo/foo1.c b/mdemo/foo1.c index 929eb5d11..c2d579c22 100644 --- a/mdemo/foo1.c +++ b/mdemo/foo1.c @@ -17,24 +17,38 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#define DLNAME foo1 - #include "foo.h" #include #include +#ifndef PIC /* fixme */ +/*#ifdef LT_RENAME */ +#define nothing ltexp_foo1___nothing +#define foo1 ltexp_foo1___foo1 +#define hello ltexp_foo1___hello +#endif + /* Give a global variable definition. */ -int LTEXP(nothing); +int nothing; +/* private function */ int -LTEXP(foo1)() +_foo1_helper() { - printf ("cos (0.0) = %g\n", (double) cos ((double) 0.0)); return FOO_RET; } +/* exported functions */ + +int +foo1() +{ + printf ("cos (0.0) = %g\n", (double) cos ((double) 0.0)); + return _foo1_helper(); +} + int -LTEXP(hello) () +hello() { printf ("** This is foolib 1 **\n"); return HELLO_RET; diff --git a/mdemo/foo2.c b/mdemo/foo2.c index 7af5c98a4..e701d22c7 100644 --- a/mdemo/foo2.c +++ b/mdemo/foo2.c @@ -17,24 +17,38 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#define DLNAME foo2 - #include "foo.h" #include #include +#ifndef PIC /* fixme */ +/*#ifdef LT_RENAME */ +#define nothing ltexp_foo2___nothing +#define foo2 ltexp_foo2___foo2 +#define hello ltexp_foo2___hello +#endif + /* Give a global variable definition. */ -int LTEXP(nothing); +int nothing; +/* private function */ int -LTEXP(foo2)() +_foo2_helper() { - printf ("sin (0.0) = %g\n", (double) sin ((double) 0.0)); return FOO_RET; } +/* exported functions */ + +int +foo2() +{ + printf ("sin (0.0) = %g\n", (double) sin ((double) 0.0)); + return _foo2_helper(); +} + int -LTEXP(hello) () +hello() { printf ("** This is foolib 2 **\n"); return HELLO_RET; diff --git a/mdemo/ltdl.c b/mdemo/ltdl.c deleted file mode 100644 index 05f1b5add..000000000 --- a/mdemo/ltdl.c +++ /dev/null @@ -1,43 +0,0 @@ -/* ltdl.c -- dlopen functions - Copyright (C) 1998 Thomas Tanner - 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 "ltdl.h" - -#ifdef HAVE_DLFCN_H -#include -#endif - -#ifdef HAVE_DL_H -#include -#endif - -lt_dlhandle lt_dlopen(char *name) -{ - return dlopen(name, RTLD_LAZY); -} - -void lt_dlclose(lt_dlhandle handle) -{ - dlclose(handle); -} - -void *lt_dlsym(lt_dlhandle handle, char *name) -{ - return dlsym(handle, name); -} diff --git a/mdemo/ltdls.c b/mdemo/ltdls.c deleted file mode 100644 index e799cfb56..000000000 --- a/mdemo/ltdls.c +++ /dev/null @@ -1,76 +0,0 @@ -/* ltdls.c -- static dlopen functions - Copyright (C) 1998 Thomas Tanner - 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 "ltdl.h" - -#ifdef HAVE_STRING_H -#include -#endif - -struct dld_symlist -{ - char *name; - void *address; -}; - -extern struct dld_symlist dld_preloaded_symbols[]; - -lt_dlhandle lt_dlopen(char *name) -{ - struct dld_symlist *s; - - s = dld_preloaded_symbols; - while (s->name) { - if (!s->address && !strcmp(s->name, name)) - break; - s++; - } - if (!s->name) - return NULL; - return strdup(name); -} - -void lt_dlclose(lt_dlhandle handle) -{ - free(handle); -} - -void *lt_dlsym(lt_dlhandle handle, char *name) -{ - struct dld_symlist *s; - char *p; - - s = dld_preloaded_symbols; - while (s->name) { - if (!s->address && !strcmp(s->name, handle)) - break; - s++; - } - if (!s->name) - return NULL; - s++; - while (s->address) { - p = strstr(s->name, "___"); - if (p && !strcmp(&p[3], name)) - return s->address; - s++; - } - return NULL; -} - diff --git a/mdemo/main.c b/mdemo/main.c index bf142f318..7157e51ac 100644 --- a/mdemo/main.c +++ b/mdemo/main.c @@ -22,7 +22,8 @@ USA. */ #include #include -int testlib(char *lib) +int +test_dl (char *filename) { lt_dlhandle handle; int (*pfoo1)() = 0; @@ -30,9 +31,9 @@ int testlib(char *lib) int (*phello)() = 0; int *pnothing = 0; - handle = lt_dlopen(lib); + handle = lt_dlopen(filename); if (!handle) { - fprintf (stderr, "can't open library %s!\n", lib); + fprintf (stderr, "can't open the module %s!\n", filename); return 1; } phello = lt_dlsym(handle, "hello"); @@ -83,11 +84,12 @@ main (int argc, char **argv) printf ("Welcome to *modular* GNU Hell!\n"); if (argc < 2) { - fprintf (stderr, "usage: %s libname [libname...]\n", argv[0]); + fprintf (stderr, "usage: %s module [module...]\n", argv[0]); } - + + lt_dlinit(); for (i = 1; i < argc; i++) - if (testlib(argv[i])) + if (test_dl(argv[i])) return 1; return 0; } diff --git a/tests/Makefile.am b/tests/Makefile.am index d1688a092..ab009453b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,11 +2,11 @@ AUTOMAKE_OPTIONS = gnits -makesequence = demo-make.test demo-exec.test \ +TESTS = demo-conf.test demo-make.test demo-exec.test \ demo-inst.test demo-unst.test hardcode.test \ - mdemo-make.test mdemo-exec.test \ - mdemo-inst.test mdemo-unst.test -TESTS = demo-conf.test mdemo-conf.test $(makesequence) \ + ltdl-conf.test ltdl-make.test ltdl-inst.test \ + mdemo-conf.test mdemo-make.test mdemo-exec.test \ + mdemo-inst.test mdemo-unst.test ltdl-unst.test \ link.test link-2.test nomode.test \ quote.test sh.test suffix.test @@ -20,4 +20,5 @@ EXTRA_DIST = defs $(TESTS) clean-local: -test -f ../demo/Makefile && cd ../demo && $(MAKE) distclean -test -f ../mdemo/Makefile && cd ../mdemo && $(MAKE) distclean + -test -f ../libltdl/Makefile && cd ../libltdl && $(MAKE) distclean rm -rf _inst diff --git a/tests/ltdl-conf.test b/tests/ltdl-conf.test new file mode 100644 index 000000000..c2a672742 --- /dev/null +++ b/tests/ltdl-conf.test @@ -0,0 +1,30 @@ +#! /bin/sh +# ltdl-conf.test - try configuring the ../libltdl 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 ../libltdl || mkdir ../libltdl + +# Change to our build directory. +cd ../libltdl || exit 1 + +# Possibly clean up the distribution. +if test -f Makefile; then + echo "= Running $make distclean in ../libltdl" + $make distclean +fi +rm -f config.cache + +# Configure the demonstration. +echo "= Configuring in ../libltdl (prefix=$prefix)" +CONFIG_SITE=/dev/null ${CONFIG_SHELL-/bin/sh} $srcdir/../libltdl/configure --srcdir=$srcdir/../libltdl --prefix=$prefix || exit 1 + +exit 0 diff --git a/tests/ltdl-inst.test b/tests/ltdl-inst.test new file mode 100644 index 000000000..9661837e1 --- /dev/null +++ b/tests/ltdl-inst.test @@ -0,0 +1,26 @@ +#! /bin/sh +# ltdl-inst.test - try installing from the ../libltdl 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 + +# Check that things are built. +if test -f ../libltdl/libltdl.la; then : +else + echo "You must run ltdl-make.test before $0" 1>&2 + exit 1 +fi + +# Change to our build directory. +cd ../libltdl || exit 1 + +echo "= Running $make install in ../libltdl" +$make install || exit 1 + +exit 0 diff --git a/tests/ltdl-make.test b/tests/ltdl-make.test new file mode 100644 index 000000000..bfb26e02a --- /dev/null +++ b/tests/ltdl-make.test @@ -0,0 +1,25 @@ +#! /bin/sh +# ltdl-make.test - try building in the ../libltdl 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 ../libltdl/Makefile; then : +else + echo "You must run ltdl-conf.test before running $0" 1>&2 + exit 1 +fi + +# Change to our build directory. +cd ../libltdl || exit 1 + +# Do the actual build. +echo "Making in ../libltdl" +$make || exit 1 +exit 0 diff --git a/tests/ltdl-unst.test b/tests/ltdl-unst.test new file mode 100644 index 000000000..4d2c0d1a0 --- /dev/null +++ b/tests/ltdl-unst.test @@ -0,0 +1,35 @@ +#! /bin/sh +# ltdl.test - try uninstalling in the ../libltdl 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. +if test "$prefix/bin/hell"; then : +else + echo "You must run ltdl-inst.test before $0." 1>&2 + exit 1 +fi + +# Change to our build directory. +cd ../libltdl || exit 1 + +echo "= Running $make uninstall in ../libltdl" +$make uninstall || exit 1 + +# See that there were no files leftover in $prefix. +# Ignore dotfiles, so that .nfsXXX files don't screw up the test. +leftovers=`find $prefix ! -type d ! -name '.*' -print` +if test -n "$leftovers"; then + echo "= Leftover after make uninstall:" + ls -l $leftovers + exit 1 +fi + +exit 0 diff --git a/tests/mdemo-make.test b/tests/mdemo-make.test index d530d0af2..f3ed64eb2 100755 --- a/tests/mdemo-make.test +++ b/tests/mdemo-make.test @@ -10,6 +10,13 @@ if test -z "$srcdir"; then fi . $srcdir/defs || exit 1 +# Check that things are built. +if test -f ../libltdl/libltdl.la; then : +else + echo "You must run ltdl-make.test before $0" 1>&2 + exit 1 +fi + if test -f ../mdemo/Makefile; then : else echo "You must run mdemo-conf.test before running $0" 1>&2