I would like the option to redefine the set开发者_如何学运维 of includes used by automake either at configure time or at compile time. I know the following works:
make DEFAULT_INCLUDES= CPPFLAGS="-I. -I/home/development/trunk"
My question is whether there's a better way to override DEFAULT_INCLUDES?
The solution has to work for the entire project which is somewhat large. A solution using configure.ac would be acceptable, but it must be optional. In other words, I don't think using nostdinc with AM_INIT_AUTOMAKE will work because there doesn't seem to be a way to call the macro conditionally.
If configure.ac
contains
AC_CONFIG_HEADERS([foo/config.h])
Then the generated Makefile.in
will contain
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/foo
Using just AC_CONFIG_HEADERS([config.h])
therefore will always cause -I$(top_builddir)
to be appended as last include search path.
This is to the accommodate
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
in your source code.
I'd argue that the top_builddir should only contain that config.h
; and your application should only have a single configure.ac
and hence a single config.h
,
so if an application does #include "config.h"
it would either not compile or find the config.h
in the top_builddir.
Then there still is the leading -I.
however. I consider that one a bit dubious
myself because it seems to be needed to pick up generated header files from the object directory (the build directory), only -- after all, while else would there be anything in the build directory to include? But since an application must be able to be compiled also when it is compiled in the source tree itself, in which case the builddir == srcdir, it automatically includes the source directory. In order to make the two cases at least equivalent one MUST (then) also include the source directory when the build directory and the source directory are NOT the same.
This is taken care of with the @am__isrc@
that expands to -I$(srcdir)
if and only if the build directory and source directory are not the same (this is just to avoid having two -I. -I.
after another).
Assuming that you either do not have any generated header files in your source directory (you could put them somewhere else) then this include would only "get in the way" when you include headers that ARE in your source directory but you don't want to include them. That seems rather broken if you ask me... Namely, if you have
#include "foo.h"
in your source file, and surely that source file should be in the srcdir (this is why you should not use 'source files' in subdirectories - aka FOO_SOURCES = subdir/foo.c
but use SUBDIRS = subdir
instead and compile foo.c
in subdir
), that include will look in the srcdir anyway because of the double quotes (such includes are always first looked for in the path of the including file).
Nevertheless, you can just override this define by adding
DEFAULT_INCLUDES =
To your Makefile.am
. Even when you add that at the very top of a Makefile.am
it will still end up below the first define and override it.
Or, for that matter, you could do:
DEFAULT_INCLUDES = @my_default_includes@
and set it to whatever you want (using AC_SUBST(my_default_includes)
in your configure.ac).
Autoconf's manual suggests using a config.site
file.
精彩评论