[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Mixing BUILT_SOURCES, double quote include and separation of source
From: |
jfasch |
Subject: |
Re: Mixing BUILT_SOURCES, double quote include and separation of source and binary directory |
Date: |
Thu, 31 Mar 2005 14:56:23 +0200 (CEST) |
>>>>> "Simon" == Simon Perreault <address@hidden> writes:
Simon> Hi,
Simon> I have a problem which I figure must be fairly common, although I found
no
Simon> reference to it anywhere. I think it must be common because the SCons
manual
Simon> says they fixed it. [1] Anyway...
Simon> Let's say I have two directories, "src" and "include". I place main.c in
src
Simon> and inc.h in include. main.c includes inc.h this way:
Simon> #include "../include/inc.h"
Simon> and inc.h includes built.h this way:
Simon> #include "built.h"
Simon> Now, my src/Makefile.am contains something like this:
Simon> BUILT_SOURCES = ../include/built.h
Simon> ../include/built.h:
Simon> mkdir -p $(@D)
Simon> touch $@
Simon> Everything works fine as long as I am building in the source directory.
If I
Simon> make a build directory and invoke configure and make from that
directory,
Simon> inc.h can't find built.h. And that's normal, since built.h is in
Simon> build/include instead of include. Because it is not in the same
directory as
Simon> inc.h, including it using double quotes can't work.
Simon> The quick fix is to add the location of inc.h, prefixed with
$(top_builddir).
Simon> However, in my real project I have hundreds of such files with hundreds
of
Simon> such locations. I would quickly hit the limit on command-line arguments.
Simon> How should I fix this problem?
How about this: after the successful build in one directory, copy all
header files into an artificial $(top_builddir)/temp_include
directory. You'd use the all-local target for this, for example.
This can be done for handwritten files as well as for generated
files. What you win is that none of the directories in your package
needs to know about the particular location of the fellow directories
(*). They just include header files of fellow directories as if these
were already installed, simply because you have consistently set
AM_CPPFLAGS = -I$(top_builddir)/temp_include
You'd just have to make sure that the build order is topologically
correct. That is, header files are "locally installed" before they are
included.
Joerg
(*) Hence you don't have to write #include "../include/inc.h" in
main.c, but rather #include <inc.h>, and you can simply write
#include <built.h>, no matter if built.h is generated or not.