Scons copy header files to build directory
<p>I'm trying to copy a number of headers files from my source directories to an 'includes' directory inside my build directory using scons. My target is a static library and I want to distribute it together with its relevant headers. The expected end result:</p>

<pre><code>build
|-- objects -&gt; .o output files for constructing libmclib.a
|-- includes
|   |-- foo.h
|   `-- bar.h
`-- libmclib.a
</code></pre>

<p>My SConstruct:</p>

<pre class="lang-py prettyprint-override"><code>#!python
target = 'mock'

env = Environment(LINKCOM = "$LINK -o $TARGET $SOURCES $LINKFLAGS $CCFLAGS")
Export('env', 'target')

build_base = 'build'
SConscript('SConscript', variant_dir=build_base, duplicate=0)

# remove build directory
if GetOption('clean'):
    import subprocess
    subprocess.call(['rm', '-rf', build_base])
</code></pre>

<p>My SConscript:</p>

<pre class="lang-py prettyprint-override"><code>#!python
Import('env')

# ...
# other stuff to build 'mclib_target'
# ...

def copy_header_files(target, source, env):
    Mkdir(target)
    header_files = []
    for d in env['CPPPATH']:
        header_files += Glob(d + "/*.h")
    for f in header_files:
        Copy(target, f)

# copy all relevant header files
env.Command("includes", mclib_target, copy_header_files)
</code></pre>

<p>Scons does call 'copy_header_files' with arguments '["build/includes"], ["build/libmclib.a"]', but for some reason 'Mkdir' doesn't create the includes directory. Also 'Copy' seems to do nothing. If I however call Mkdir like this:</p>

<pre class="lang-py prettyprint-override"><code>env.Command("includes", mclib_target, [Mkdir('$TARGET')])
</code></pre>

<p>it seems to work well. How to fix/work around this? I'm also quite new to Scons so any alternative for doing this task are welcome. I'm using scons 2.5.0.</p>

<p>You probably want to use "<code>Install()</code>" instead of "<code>Copy()</code>". Also the <code>Mkdir()</code> shouldn't be necessary, SCons creates all intermediate folders for its targets automatically.</p>

<p>Finally, allow me some comments about your general approach: I'd rather not mix "building" with "installing/preparing for packaging". The "<code>variant_dir</code>" option is there to help you with building several "variants" (release, optimized, debug, ARM-specific,...) from the same source files (let's say you have a folder named "src"). By passing the name of the current "build" directory into your "src" SConscript you're embedding variant-specific knowledge into your local build description, meaning that you'll have to touch it with every variant that you add.
Instead, you should move the "<code>Install/Package</code>" steps into the top-level SConstruct...where you have global knowledge about which variants get built. From there you can copy (= Install) the final files to a separate subfolder, e.g. <code>distribution</code>, and archive that one instead.</p>

<p>For a simple example of how to handle variants right in SCons, check out the repo <a href="https://bitbucket.org/dirkbaechle/scons_talks" rel="nofollow">https://bitbucket.org/dirkbaechle/scons_talks</a> and there the "<code>pyconde_2013/examples/exvar</code>" folder.</p>

python scons