It's often useful to keep any built files completely separate from the source files. This is usually done by creating one or more separate build directories that are used to hold the built objects files, libraries, and executable programs, etc. for a specific flavor of build. &SCons; provides two ways of doing this, one with a little more flexibility.
The &BuildDir; Function Use the &BuildDir; function to establish that target files should be built in a separate directory from the source files: BuildDir('build', 'src') env = Environment() env.Program('build/hello.c') Note that XXX % ls src hello.c % scons cc -c build/hello.c -o build/hello.o cc -o build/hello build/hello.o % ls -1 build hello hello.c hello.o
Avoiding Duplicate Source Files in the Build Directory X BuildDir('build', 'src', duplicate=0) env = Environment() env.Program('build/hello.c') X % ls -1 src hello.c % scons cc -c src/hello.c -o build/hello.o cc -o build/hello build/hello.o % ls -1 build hello hello.o X
Why &SCons; Duplicates Source Files by Default X env = Environmnet() X % scons cc -c build/hello.c -o build/hello.o cc -o build/hello build/hello.o
Using &BuildDir; With an &SConscript; File X env = Environment() env.Program('hello.c') X BuildDir('build', 'src') SConscript('build/SConscript') X % ls -1 src SConscript hello.c % scons cc -c build/hello.c -o build/hello.o cc -o build/hello build/hello.o % ls -1 build hello hello.c hello.o
Specifying a Build Directory as Part of an &SConscript; Call X SConscript('src/SConscript', build_dir='build') X % ls -1 src SConscript hello.c % scons cc -c build/hello.c -o build/hello.o cc -o build/hello build/hello.o % ls -1 build hello hello.c hello.o X SConscript('src/SConscript', build_dir='build', duplicate=0) X % ls -1 src SConscript hello.c % scons cc -c src/hello.c -o build/hello.o cc -o build/hello build/hello.o % ls -1 build hello hello.o