For those of you who are interested here is the solution I came up with to
me preloading problem.
The basic idea is NOT to use the preload feature of libtool but instead
build up the data structure myself. To do this I use the following:
<<<
#ifndef PRELOAD__H
#define PRELOAD__H
#include <ltdl.h>
#include "pspell.h"
struct PspellManagerImplBase;
#ifndef __cplusplus
typedef struct PspellManagerImplBase PspellManagerImplBase;
#endif
typedef PspellManagerImplBase * (* NewPspellManagerClass)(PspellConfig * config,
lt_dlhandle);
struct PspellManagerFun {
const char * name;
NewPspellManagerClass fun;
};
#ifndef __cplusplus
typedef struct PspellManagerFun PspellManagerFun;
#endif
extern const PspellManagerFun pspell_manager_funs[];
extern size_t pspell_manager_funs_size;
#endif
#include "preload.h"
#include "conf.h"
#ifdef have_aspell
PspellCanHaveError *
libpspell_aspell_LTX_new_pspell_manager_class(PspellConfig * config,
lt_dlhandle h);
#endif
const PspellManagerFun pspell_manager_funs[] = {
#ifdef have_aspell
{"aspell", libpspell_aspell_LTX_new_pspell_manager_class},
#endif
{0,0}
};
size_t pspell_manager_funs_size = sizeof(pspell_manager_funs)/sizeof(PspellManagerFun);
>>>
Naturally I will add more modules to the array once they are created.
Now the only problem is how detecting the installed modules. Using
autoconf AC_CHECK_LIB is not sufficient because the necessary libraries which
must be linked in along with the module library varies from system to
system so I have to use libtool for the test. This leads to the
following configure.in
<<<
dnl Process this file with autoconf to produce a configure script.
AC_INIT(preload.h)
AC_CONFIG_HEADERS(conf.h)
AM_INIT_AUTOMAKE(pspell-modules, .11)
nl Checks for programs.
AC_PROG_CXX
AC_LANG_CPLUSPLUS
dnl Configure libtool
AM_PROG_LIBTOOL
AC_LIBTOOL_CXX
if test "$DONT_FIND_MODULES" != "1"
then
echo "BEGIN FIND MODULES TEST" >> config.log
echo "int main() {}" > confmain.cc
sh ./libtool --mode=compile $CXX -c confmain.cc >> config.log 2>&1
define([TEST_MODULE],
[
AC_MSG_CHECKING(for $1 module)
ac_expanded=`(
test "x$prefix" = xNONE && prefix="$ac_default_prefix"
test "x$exec_prefix" = xNONE && exec_prefix="${prefix}"
eval echo \""[$]libdir"\"
)`
if (sh ./libtool --mode=link \
$CXX confmain.o -o confmain -L$ac_expanded -lpspell_$1 \
>> config.log 2>&1)
then
AC_MSG_RESULT(found)
LIBS="$LIBS -lpspell_$1"
AC_DEFINE(have_$1)
else
AC_MSG_RESULT(not found)
fi
])
TEST_MODULE(aspell)
rm confmain.cc confmain.o confmain 2>> config.log
fi
AC_OUTPUT(Makefile)
>>>
The only problem is that pspell modules naturally depend on pspell
them self. Thus during the initial build of pspell none of the modules will
be installed thus detecting them is a waste of time. So the main pspell
configure script in ../ will first define DONT_FIND_MODULES before calling
AC_CONFIG_SUBDIRS. After pspell and the modules are installed the user
can go back to this subdirectory and rerun configure without
DONT_FIND_MODULES defined to properly detect and link in all the necessary
modules. To aid in doing this I provide the following shell script
add-modules:
<<<
#! /bin/sh
make clean
./config.status --recheck
./config.status
make
>>>
After the new library is installed a program using pspell needs to only
link in -lpspell and -lpspell-modules using libtools.
Now the only thing missing is the ability to do this without using
libtool. I would like to provide a special shell script called
pspell-config which when called with --libs will list out all the
necessary library linking information much like gnome-config and
gtk-config so that the user can simply link pspell in using something
like:
cc main.o -o main `pspell-config --libs`.
*********************** FEATURE REQUEST ****************************
The only problem is how to get this necessary information. I guess I could
scan libpspell.la and libspell-modules.la for the information but it would
be really nice if libtool would be able to this for me. Something link
libtool --mode=link-flags -lpspell -lpspell-modules
would be really great.
So how about it? How difficult would it be to add that to libtool?
---
Kevin Atkinson
[EMAIL PROTECTED]
http://metalab.unc.edu/kevina/