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>The <em>Mkdir</em> and <em>Copy</em> operations that you are using are Action factories for use in Command definitions, described in <a href="http://scons.org/doc/production/HTML/scons-user.html#chap-factories" rel="nofollow">Platform-Independent File System Manipulation</a>:</p>

<blockquote>
  <p>SCons provides a number of platform-independent functions, called
  factories, that perform common file system manipulations like copying,
  moving or deleting files and directories, or making directories. <strong>These
  functions are factories because they don't perform the action at the
  time they're called, they each return an Action object that can be
  executed at the appropriate time.</strong></p>
</blockquote>

<p>I have always had problems trying to use these functions within my own action functions. Perhaps I am missing something, but I don't think these functions can be used outside of the immediate list of operations in the Command builder.</p>

<p>Instead I use the platform-independent functions in python for creating directories and copying files, such as <a href="https://docs.python.org/2/library/os.html#os.makedirs" rel="nofollow"><code>os.makedirs</code></a> and <a href="https://docs.python.org/2/library/shutil.html#shutil.copy" rel="nofollow"><code>shutil.copy</code></a>.</p>

python scons