> Currently, my configure.in has: > > AC_CHECK_FUNC(getopt_long,, > [LIBS="$LIBS -L./getopt" CFLAGS="$CFLAGS -I./getopt"])
Close, but no cigar. What is the library's name? libgetopt.{a,so}? Well, the linker will see something like this: link -options <objects> -lintl -L./getopt This obviously does not do what you want, as you don't specify it should link in libgetopt.a. Additionally, unless you sources are in '.', using './getopt' as library search path is a bit suspect. And I'm not sure you're supposed to put any linker flags (other than libraries) in $LIBS. The right way to do it would be to use AC_CHECK_FUNC(getopt_long,, [LIBS="$LIBS @builddir@/getopt/libgetopt.a" CFLAGS="$CFLAGS -I./getopt"]) I think (not sure if LIBS can have substitution variables; if not, you'd have to use $ac_top_builddir, but that's an internal variable). If specifying the full library name is not acceptable, you can add "-lgetopt" to LIBS, and add -L./getopt to LDFLAGS (pretty sure you can't use substitution variables in LDFLAGS). Yet another alternative would be to let automake handle it; putting something like if SYSTEM_GETOPT else GETOPT = -L$builddir/getopt -lgetopt endif ... LIBS = $(GETOPT) in Makefile.am, and calling AM_CONDITIONAL in configure.in should also do the trick. Yet another option would be to ditch the library idea, and have configure.in do this: AC_CHECK_FUNC(getopt_long,, [# This goes directly to the Makefile, so you need $(OBJEXT) AC_SUBST(GETOPT_OBJECTS, 'getopt.$(OBJEXT) getopt1.$(OBJEXT)') CFLAGS="$CFLAGS -I./getopt"]) In Makefile.am, you'd list the getopt sources in EXTRA_x_SOURCES, so automake will create rules for them. And you use @GETOPT_OBJECTS@ in x_LDADD (with x the name of your executable). This will cause the list of required objects to only contain the getopt ones if there is no system getopt. You may need to keep the header separate so that it's only used when the local sources are used. > Also, feel free to point me to any good examples. (I have looked at > several examples of checking for getopt.h, but they don't do > what I want.) Well, you could look at what libiberty does; it decides what sources to compile and add to the library based on run-time tests.