autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Best practice for user decided unusual library paths ?


From: Johan Persson
Subject: Best practice for user decided unusual library paths ?
Date: Mon, 10 Jan 2011 22:05:46 +0100
User-agent: RoundCube Webmail/0.2

I have a package which uses a specific library that most user have
installed in the "usual" places so this works fine. 

However after having reports that some user have the library in
not-so-common places (like /opt/local) i decided to add a "--with-package"
switch so the user can add the root-directory for this alternative place.
However, I believe that my solution (while it works) is very "ugly" and
there must be a "best practice" for how to do this in a "proper" way.

What I did was adding the extra flag and some variables for use with
automake in configure.ac (in this case the library was libpcre.so) as in
(ignore the non-formatted help text)

AC_ARG_WITH(libpcre,
    [--with-libpcre   Specify parent directory for the PCRE library and
headers],
    [with_libpcre=${withval}],
    [])

PCRELIB=
if test ! -z ${with_libpcre}; then
   
AC_DEFINE_UNQUOTED(WITH_PCRELIBHEADER,["${with_libpcre}/include/pcre.h"],[Specify
header file for PCRE library])
    AC_SUBST(PCRELIB,[${with_libpcre}/lib/libpcre.so])
    AM_CONDITIONAL(need_pcrelib_special, test 1 = 1 )
else
    AM_CONDITIONAL(need_pcrelib_special, test 1 = 0 )
fi

I added the defines above to be able to include the correct header in the
source files as in:

#ifdef WITH_PCRELIBHEADER
#include WITH_PCRELIBHEADER
#else
#include <pcre.h>
#endif

and then some automake conditionals to be able to add a test in my
Makefile.am template

if need_pcrelib_special
myprogram_LDADD += ${PCRELIB}
endif

This looks pretty ugly to me and I can't help thinking there must be a
cleaner way to do this? 
How do others solve this particular issue? (it must be a fairly common
thing to want to do, I guess)

(Two things I particularly don't like are the fact that the library is
hard coded to the *.so name and the #include handling.)

A point to notice here might be that I don't want to add a generic -I and
-L flags to the compiler options so it searches in the extra directory
since the user may have generic version of the library in the normal places
so those places should never be searched. 

/J



reply via email to

[Prev in Thread] Current Thread [Next in Thread]