My project included getopt1.c, getopt.c and getopt.h in the main source directory. And the Makefile listed them and they were compiled and link everytime.
I want it use the system's getopt_long() if available. I do not want to compile and link in the local getopt.c if it is not needed. (In my tests, I see it makes the executable binary a few kilobytes smaller.) And I want to move the getopt* code to a getopt subdirectory. If the system doesn't provide a getopt_long, then I want to use the locally included code. Currently, my configure.in has: AC_CHECK_FUNC(getopt_long,, [LIBS="$LIBS -L./getopt" CFLAGS="$CFLAGS -I./getopt"]) And on my Debian Linux and NetBSD systems, it uses the system's getopt_long (and works). But on my FreeBSD system (without gnugetopt), it doesn't build. (I receive "undefined reference to `getopt_long'".) I want it to do the right thing for other systems too. I have read several postings to the automake and autoconf mailing lists in regards to this. But, I have only seen solutions that use the system header file with the local code linked in. And a solution that uses "AC_LIBOBJ(getopt1)". I don't see AC_LIBOBJ in the currently available GNU.org autoconf book. (And it is not part of my autoconf 2.13.) Can anyone share some advice on how to get my Makefile created so it will only compile the local getopt as needed? 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.) Thanks, Jeremy C. Reed http://www.reedmedia.net/