views:

109

answers:

2

I am writing my first project that will use autoconf and teaching it to myself as I go. For the most part, things are going extremely well. I have one last significant hurdle. I am having trouble locating library and header files that may be named differently from one system to the next.

For example, I need to compile with Mozilla's SpiderMonkey. When compiled from source, SpiderMonkey becomes libjs.so. On my Linux variant, however, SpiderMonkey is installed as libmozjs.so. It's the same library, just a different name, thus a different linker flag.

Is there a proper way to go about detecting the name of the library? Do I just default it to 'js' and give a configure option to override it?

I have the same situation with header files. The header files for SpiderMonkey are installed at /usr/include/mozjs/ on my operating system. I am sure that on other systems, it will be /usr/include/js/ or maybe even simply /usr/include/. How do I find the proper header file location? I was hesitant to do a vanilla "find" since it would be slow and I might find the wrong copy of the file (finding the file in a user's home directory instead of /usr/include/ for instance.)

A: 

I'd go with an option: --with-spidermonkey-library= --with-spidermonkey-include=

And then put defaults/searchs if the options aren't specified. (Probably just defaults)

Douglas Leeder
+1  A: 

In addition to adding an option to specify the path/name explicitly, if there are a few well-known names or locations, you can just try them in order until one succeeds, using something like this:

 AC_TRY_LINK([#include "mpi.h"],[MPI_Init(0, 0);], [mpi_link="yes"], [mpi_link="no"]);

Or just use test. I used the following to pick up the boost libraries that were actually built, possible with slightly different names:

for lib in "date_time" "filesystem" "regex" "unit_test_framework" "signals"; do
    if test -f ${$1_libdir}/libboost_$lib-gcc$boost_thread_flag.a; then
      BOOST_LIBS="$BOOST_LIBS -lboost_$lib-gcc$boost_thread_flag"
    elif test -f ${$1_libdir}/libboost_$lib-gcc$boost_thread_flag-s.a; then
      BOOST_LIBS="$BOOST_LIBS -lboost_$lib-gcc$boost_thread_flag-s"
    elif test -f ${$1_libdir}/libboost_$lib$boost_thread_flag.a; then
      BOOST_LIBS="$BOOST_LIBS -lboost_$lib$boost_thread_flag"
    elif test -f ${$1_libdir}/libboost_$lib.a; then
      BOOST_LIBS="$BOOST_LIBS -lboost_$lib"
    fi
done
KeithB