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:
build
|-- objects -> .o output files for constructing libmclib.a
|-- includes
| |-- foo.h
| `-- bar.h
`-- libmclib.a
My SConstruct:
#!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])
My SConscript:
#!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)
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:
env.Command("includes", mclib_target, [Mkdir('$TARGET')])
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.