[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: help setting LDFLAGS and CFLAGS within AC_ARG_ENABLE
From: |
Ralf Wildenhues |
Subject: |
Re: help setting LDFLAGS and CFLAGS within AC_ARG_ENABLE |
Date: |
Fri, 19 Aug 2005 10:02:37 +0200 |
User-agent: |
Mutt/1.4.1i |
Hi Patrick,
* J. Patrick Bedell wrote on Fri, Aug 19, 2005 at 03:52:17AM CEST:
> I am trying to modify the configure.in file of a pre-existing
> project (CVS) to include a CFLAGS and LDFLAGS addition when I find the
> libraries I'm looking for. The content of the addition that I am making
> is derived from a shell command, namely 'xmlsec1-config --cflags' and
> 'xmlsec1-config --libs'. I'm trying to use the following in configure.in
> to make the modification to CFLAGS and LDFLAGS in the compilation process,
> but it's not working at all. :( How would I include in the AC_ARG_ENABLE
> macro a modification to the global CFLAGS and LDFLAGS variables?
A few comments to your code: (I have not looked thoroughly, it might not
solve all issues with it)
> AC_ARG_ENABLE(
> [certification],
> AC_HELP_STRING(
> [--enable-certification],
> [Include code for interfacing to an information currency server.
> (default)]), ,
> [enable_certification=yes])
>
> if test no != "$enable_certification"; then
I'd write
test Xno != X"$enable_certification"
but I think Autoconf sanitizes the $enable_* variables so that it is not
necessary to do so (`-' is changed to `_').
> AC_CHECK_HEADERS(openssl/evp.h libxml/tree.h libcsoap/soap-client.h
> xmlsec/xmlsec.h,
> AC_DEFINE(
> [CERTIFICATION_SUPPORT], [1],
> [Define if you want CVS to be able to create information currency from
> submitted code.])
> AC_CHECK_LIB(ssl,printf,[LIBS="${LIBS} -lssl"])
You should _not_ check for printf in the ssl library.
Use a function that is defined in libssl. Preferably one that you use.
Also, in general, you should prepend to LIBS, not append. Rationale:
the library you check for might depend on other libraries already in
$LIBS. The order of libraries in $LIBS might be important on other
systems! (For specific libraries, there might be reasons for the other
way round.)
I see that several examples in the Autoconf manual do this differently.
Below is a proposed patch to fix this.
> AC_CHECK_LIB(xml2,printf,[LIBS="${LIBS} -lxml2"])
> AC_CHECK_LIB(xmlsec1,xmlSecCryptoInit,[LIBS="${LIBS} -lxmlsec1"])
> AC_CHECK_LIB(csoap,printf,[LIBS="${LIBS} -lcsoap"])
Same with these three lines above.
> CFLAGS=$CFLAGS -g `xmlsec1-config --cflags`;
> LDFLAGS="$LDFLAGS -g `xmlsec1-config --libs`;
You need more quoting in these two lines. Also, I would _not_ add "-g".
This is not portable, because some compilers do not allow -g in
combination with optimization. The AC_PROG_CC macro causes configure to
add "-g -O2" by default for gcc, and either -g or -O2 otherwise, when
they work; in any case, that choice can be overridden by the user
through $CFLAGS.
Then again, I think you should use LIBS, not LDFLAGS.
So, good would be like this:
CFLAGS="$CFLAGS `xmlsec1-config --cflags`"
LIBS="`xmlsec1-config --libs` $LIBS"
But now you start to use xmlsec1-config. I don't know the package, but
I believe this would make some of the other tests you did above
obsolete, at least the check for xmlsec1:
xmlsec1-config --libs
should give you what you want (unless there exist xmlsec1 libs without
xmlsec1-config). I'd replace the "AC_CHECK_LIB(xmlsec1,...)" check
with a check for the tool xmlsec1-config.
> )
> fi
> dnl
> dnl end --enable-certification
> dnl
Cheers,
Ralf
* doc/autoconf.texi (Defining Symbols, Changed Results):
Prepend to LIBS, not append, in examples.
Index: doc/autoconf.texi
===================================================================
RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v
retrieving revision 1.925
diff -u -r1.925 autoconf.texi
--- doc/autoconf.texi 6 Jul 2005 21:39:31 -0000 1.925
+++ doc/autoconf.texi 19 Aug 2005 07:39:05 -0000
@@ -7330,7 +7342,7 @@
@example
AC_CHECK_HEADER([elf.h],
- [AC_DEFINE([SVR4], [1], [System V Release 4]) LIBS="$LIBS -lelf"])
+ [AC_DEFINE([SVR4], [1], [System V Release 4]) LIBS="-lelf $LIBS"])
@end example
@noindent
@@ -7339,7 +7351,7 @@
@example
AC_CHECK_HEADER([elf.h],
[AC_DEFINE([SVR4], [1], [System V Release 4])
- LIBS="$LIBS -lelf"])
+ LIBS="-lelf $LIBS"])
@end example
@noindent
@@ -7347,7 +7359,7 @@
@example
AC_CHECK_HEADER([elf.h],
- [AC_DEFINE([SVR4], [1], [System V Release 4]); LIBS="$LIBS -lelf"])
+ [AC_DEFINE([SVR4], [1], [System V Release 4]); LIBS="-lelf $LIBS"])
@end example
@node Setting Output Variables
@@ -15340,7 +15352,7 @@
saved_LIBS="$LIBS"
for lib in bsd socket inet; do
AC_CHECKING(for syslog in -l$lib)
- LIBS="$saved_LIBS -l$lib"
+ LIBS="-l$lib $saved_LIBS"
AC_HAVE_FUNCS(syslog)
case "$DEFS" in
*-DHAVE_SYSLOG*) break ;;
@@ -15359,7 +15371,7 @@
# syslog is not in the default libraries. See if it's in some other.
for lib in bsd socket inet; do
AC_CHECK_LIB([$lib], [syslog], [AC_DEFINE([HAVE_SYSLOG])
- LIBS="$LIBS -l$lib"; break])
+ LIBS="-l$lib $LIBS"; break])
done
fi
@end example